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

Open in your IDE?
  1. <?php
  2. namespace App\MDS\AvexpressBundle\Controller;
  3. use App\Constants\BusinessTypeSettingsCompanyConstants;
  4. use App\Constants\InvoiceProformaExtraFieldConstants;
  5. use App\Entity\Cities;
  6. use App\Entity\InvoiceProformaExtraField;
  7. use App\Entity\Space;
  8. use App\Entity\Supplier;
  9. use App\Form\InvoiceProformaExtraFieldType;
  10. use App\MDS\AvexpressBundle\Entity\AveBenefitsPermissions;
  11. use App\MDS\AvexpressBundle\Entity\AveBenefitsInvoiceInvoiceRec;
  12. use App\MDS\VenuesBundle\Entity\Reservation;
  13. use App\MDS\VenuesBundle\Entity\ReservationInvoice;
  14. use App\MDS\VenuesBundle\Entity\ReservationInvoiceItems;
  15. use App\MDS\VenuesBundle\Entity\ReservationInvoiceRec;
  16. use App\Service\CommissionEnterprisesService;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use DateTime;
  21. use App\MDS\AvexpressBundle\Entity\AveFiles;
  22. use App\MDS\AvexpressBundle\Entity\AveProductFile;
  23. use App\MDS\AvexpressBundle\Entity\AvePaymentsClient;
  24. use App\MDS\AvexpressBundle\Entity\AveDocProformaDeposit;
  25. use App\MDS\AvexpressBundle\Entity\AveDocInvoice;
  26. use App\MDS\AvexpressBundle\Entity\AveDocInvoiceRec;
  27. use App\MDS\AvexpressBundle\Entity\AveDocProformaItems;
  28. use App\MDS\AvexpressBundle\Entity\AveDocProforma;
  29. use App\MDS\AvexpressBundle\Entity\AveDocInvoiceItems;
  30. use App\MDS\AvexpressBundle\Entity\AveDocInvoiceRecItems;
  31. use App\MDS\AvexpressBundle\Entity\AveBudgetToProforma;
  32. use App\Entity\Client;
  33. use App\Entity\Configuration;
  34. use App\Entity\Country;
  35. use App\Entity\Regions;
  36. use App\Entity\SettingsCompany;
  37. use App\Entity\User;
  38. use App\MDS\AvexpressBundle\Entity\AveBenefitsSupplier;
  39. use App\MDS\AvexpressBundle\Entity\AveBriefings;
  40. use App\MDS\AvexpressBundle\Entity\AveBudgetPending;
  41. use App\MDS\AvexpressBundle\Entity\AveProduct;
  42. use App\MDS\AvexpressBundle\Entity\AveServices;
  43. use App\MDS\AvexpressBundle\Entity\AveTemplateItems;
  44. use App\MDS\DevelupBundle\Entity\MdvDocProformaItems;
  45. use App\MDS\DevelupBundle\Entity\MdvTelegramUser;
  46. use App\MDS\EventsBundle\Entity\ProposalAgents;
  47. use App\MDS\EventsBundle\Entity\ProposalSupplierServices;
  48. use App\MDS\VenuesBundle\Entity\ReservationInvoiceRecItems;
  49. use App\Service\InvoiceProformaExtraFieldService;
  50. use Swift_Mailer;
  51. use Swift_Message;
  52. use Swift_SmtpTransport;
  53. class InvoiceController extends AbstractController
  54. {
  55.     private $commisionEnterpriseService;
  56.     private InvoiceProformaExtraFieldService $extraFieldService;
  57.     public function __construct(CommissionEnterprisesService $commisionEnterpriseServiceInvoiceProformaExtraFieldService $extraFieldService)
  58.     {
  59.         $this->commisionEnterpriseService $commisionEnterpriseService;
  60.         $this->extraFieldService $extraFieldService;
  61.     }
  62.     /**
  63.      * @Route("/listpaydep/{id}",  name="ave_list_payments_deposits")
  64.      * Listar pagos y depositos de un expediente
  65.      */
  66.     public function listPaymentsDespositsAction($idRequest $request)
  67.     {
  68.         $em $this->getDoctrine()->getManager();
  69.         $paymentsInFile $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  70.         $proformaDepositsInFile $em->getRepository(AveDocProformaDeposit::class)->findByFileId($id);
  71.         $proformas = array();
  72.         $allProformas $em->getRepository(AveDocProforma::class)->findByFileId($id);
  73.         foreach ($allProformas as $item) {
  74.             $data $this->baseInvoiceDoneFileTwo($id$item->getId(), 'P');
  75.             $bases 0;
  76.             if (is_numeric($data['totales']) and is_numeric($data['totales_neto'])) {
  77.                 $bases $data['totales'] - $data['totales_neto'];
  78.             }
  79.             $proformas[] = array(
  80.                 'id' => $data['number'],
  81.                 'date' => $data['date'],
  82.                 'neto' => $data['totales_neto'],
  83.                 'bases_imponibles' => $bases,
  84.                 'total' => $data['totales'],
  85.             );
  86.         }
  87.         return $this->render(
  88.             'MDS/AvexpressBundle/Avexpress/list-payments-deposits.html.twig',
  89.             array(
  90.                 'id' => $id,
  91.                 'proformas' => $proformas,
  92.                 'payments' => $paymentsInFile,
  93.                 'allInvoiceDeposit' => null,
  94.                 'proformaDepositsInFile' => $proformaDepositsInFile,
  95.             )
  96.         );
  97.     }
  98.     /**
  99.      * @Route("/paymentadd/{id}",  name="ave_add_payment")
  100.      * Agregar pago a un expediente
  101.      */
  102.     public function addPaymentsAction($idRequest $request)
  103.     {
  104.         $em $this->getDoctrine()->getManager();
  105.         $newRequest $request->request->get('invoicepay');
  106.         /* Obtengo usuario logueado */
  107.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  108.         $user_id $user_logueado->getId();
  109.         if (!empty($newRequest['amount']) and !empty($newRequest['datePayAt']) and !empty($newRequest['wayToPay'])) {
  110.             if (is_numeric($newRequest['amount'])) {
  111.                 $pay = new AvePaymentsClient();
  112.                 $pay->setAmount($newRequest['amount']);
  113.                 $pay->setConcept($newRequest['concept']);
  114.                 $pay->setDatePayAt(new \DateTime($newRequest['datePayAt']));
  115.                 $pay->setWayToPay($newRequest['wayToPay']);
  116.                 $pay->setFileId($id);
  117.                 $pay->setUpdatedId($user_id);
  118.                 $pay->setUpdatedAt(new \DateTime("now"));
  119.                 $pay->setCreatedId($user_id);
  120.                 $pay->setCreatedAt(new \DateTime("now"));
  121.                 $em->persist($pay);
  122.                 $em->flush();
  123.             }
  124.         }
  125.         return $this->redirectToRoute(
  126.             'ave_list_payments_deposits',
  127.             array(
  128.                 'id' => $id
  129.             )
  130.         );
  131.     }
  132.     /**
  133.      * @Route("/paymentdelete/{id}",  name="ave_delete_payment")
  134.      * Eliminar pago de un expediente
  135.      */
  136.     public function deletePaymentsAction($idRequest $request)
  137.     {
  138.         $em $this->getDoctrine()->getManager();
  139.         $payment $em->getRepository(AvePaymentsClient::class)->findOneById($id);
  140.         $fileId $payment->getFileId();
  141.         $em->remove($payment);
  142.         $em->flush();
  143.         return $this->redirectToRoute(
  144.             'ave_list_payments_deposits',
  145.             array(
  146.                 'id' => $fileId
  147.             )
  148.         );
  149.     }
  150.     /**
  151.      * @Route("/newproformadeposit/{id}",  name="ave_new_proforma_deposit")
  152.      * Crear nueva proforma de deposito en un expediente
  153.      */
  154.     public function newProformaDepositAction($idRequest $request)
  155.     {
  156.         $em $this->getDoctrine()->getManager();
  157.         $newRequest $request->request->get('invoicedep');
  158.         /* Obtengo usuario logueado */
  159.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  160.         $user_id $user_logueado->getId();
  161.         $proforma = new AveDocProformaDeposit();
  162.         if (!empty($newRequest['amount']) and !empty($newRequest['name']) and !empty($newRequest['iva'])) {
  163.             if (is_numeric($newRequest['amount']) and is_numeric($newRequest['iva'])) {
  164.                 $proforma->setAmount($newRequest['amount']);
  165.                 $proforma->setName($newRequest['name']);
  166.                 $proforma->setFileId($id);
  167.                 $proforma->setIva($newRequest['iva']);
  168.                 $proforma->setTotal($newRequest['amount'] + ($newRequest['amount'] * ($newRequest['iva'] / 100)));
  169.                 $proforma->setUpdatedId($user_id);
  170.                 $proforma->setUpdatedAt(new \DateTime("now"));
  171.                 $proforma->setCreatedId($user_id);
  172.                 $proforma->setCreatedAt(new \DateTime("now"));
  173.                 $em->persist($proforma);
  174.                 $em->flush();
  175.             }
  176.         } else {
  177.             // Falta algun dato
  178.             return $this->redirectToRoute('ave_list_payments_deposits', array('id' => $id));
  179.         }
  180.         return $this->redirectToRoute(
  181.             'ave_view_proforma_deposit',
  182.             array(
  183.                 'id' => $proforma->getId()
  184.             )
  185.         );
  186.     }
  187.     /**
  188.      * @Route("/viewproformadeposit/{id}",  name="ave_view_proforma_deposit")
  189.      * Ver una proforma de deposito
  190.      */
  191.     public function viewProformaDepositAction($idRequest $request)
  192.     {
  193.         $docType 'Proforma de Deposito';
  194.         $em $this->getDoctrine()->getManager();
  195.         $proforma =  $em->getRepository(AveDocProformaDeposit::class)->findOneById($id);
  196.         $id $proforma->getFileId();
  197.         /* Obtengo usuario logueado */
  198.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  199.         $user_id $user_logueado->getId();
  200.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  201.         // Buscamos el cliente
  202.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  203.         $client $em->getRepository(Client::class)->findById($file->getClient());
  204.         if (empty($client)) {
  205.             $client[0] = new Client();
  206.             $client[0]->setName('');
  207.             $client[0]->setTitle('');
  208.             $client[0]->setIdDocument('');
  209.             $client[0]->setPopulation('');
  210.             $client[0]->setRegion('');
  211.             $client[0]->setCountry('');
  212.         } else {
  213.             if (is_numeric($client[0]->getPopulation())) {
  214.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  215. //                $client[0]->setPopulation($city->getCity());
  216.             }
  217.             if (is_numeric($client[0]->getRegion())) {
  218.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  219. //                $client[0]->setRegion($region->getRegion());
  220.             }
  221.             if (is_numeric($client[0]->getCountry())) {
  222.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  223. //                $client[0]->setCountry($country->getCountry());
  224.             }
  225.         }
  226.         if (empty($client)) {
  227.             $client[0] = new Client();
  228.             $client[0]->setName('');
  229.             $client[0]->setTitle('');
  230.             $client[0]->setIdDocument('');
  231.             $client[0]->setPopulation('');
  232.             $client[0]->setRegion('');
  233.             $client[0]->setCountry('');
  234.             $clientNew = array(
  235.                 'name' => '',
  236.                 'title' => '',
  237.                 'idDocument' => '',
  238.                 'population' => '',
  239.                 'region' => '',
  240.                 'country' => '',
  241.                 'address' => '',
  242.                 'addressNumber' => '',
  243.                 'zipCode' => '',
  244.                 'typeDocument' => '',
  245.             );
  246.         } else {
  247.             $clientNew = array(
  248.                 'name' => $client[0]->getName(),
  249.                 'title' => $client[0]->getTitle(),
  250.                 'idDocument' => $client[0]->getIdDocument(),
  251.                 'population' => '',
  252.                 'region' => '',
  253.                 'country' => '',
  254.                 'address' => $client[0]->getAddress(),
  255.                 'addressNumber' => $client[0]->getAddressNumber(),
  256.                 'zipCode' => $client[0]->getZipCode(),
  257.                 'typeDocument' => $client[0]->getTypeDocument(),
  258.             );
  259.             if (is_numeric($client[0]->getPopulation())) {
  260.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  261.                 $clientNew['population'] = $city->getCity();
  262.             }
  263.             if (is_numeric($client[0]->getRegion())) {
  264.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  265.                 $clientNew['region'] = $region->getRegion();
  266.             }
  267.             if (is_numeric($client[0]->getCountry())) {
  268.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  269.                 $clientNew['country'] = $country->getCountry();
  270.             }
  271.         }
  272.         // Buscamos el cliente
  273.         $bases_imponibles['ivaMontoVeintiUno'] = $proforma->getAmount() * 0.21;
  274.         $allProformas =  $em->getRepository(AveDocProformaDeposit::class)->findByFileId($id);
  275.         // Falta agregar en $allProformas las proformas de facturas, hasta ahora solo estan las proformas de deposito  //6*6*6
  276.         $commentsBool false;
  277.         $comments null;
  278.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  279.         if ($fileAv->getCommentsInPro()) {
  280.             $commentsBool true;
  281.         }
  282.         if ($commentsBool) {
  283.             $comments $fileAv->getComments();
  284.         }
  285.         // Obtengo usuario logueado
  286.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  287.         $user_id $user_logueado->getId();
  288.         return $this->render(
  289.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
  290.             array(
  291.                 'id' => $id,
  292.                 'docType' => $docType,
  293.                 'proforma' => $proforma,
  294.                 'company' => $company,
  295.                 'clients' => $clientNew,
  296.                 'date' => $proforma->getCreatedAt(),
  297.                 'number' => $proforma->getId(),
  298.                 'invoice' => null,
  299.                 'fid' => $proforma->getId(),
  300.                 'boolToRec' => false,
  301.                 'proformas' => $allProformas,
  302.                 'currency' => '€',
  303.                 'totales_neto' => $proforma->getAmount(),
  304.                 'totales' => $proforma->getTotal(),
  305.                 'balance' => $proforma->getTotal(),
  306.                 'bases_imponibles' => $bases_imponibles,
  307.                 'file' => $fileAv,
  308.                 'user' => $user_logueado,
  309.                 'services' => null,
  310.                 'facturas' => null,
  311.                 'paymentNotIvoiced' => null,
  312.                 'paymentsAll' => null,
  313.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  314.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  315.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  316.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  317.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  318.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  319.                 'comments' => $comments,
  320.             )
  321.         );
  322.     }
  323.     /**
  324.      * @Route("/avexternal/printproformadeposit/{id}",  name="ave_print_proforma_deposit")
  325.      * Imprimir una proforma de deposito
  326.      */
  327.     public function printProformaDepositAction($idRequest $request)
  328.     {
  329.         $docType 'Proforma de Deposito';
  330.         $em $this->getDoctrine()->getManager();
  331.         $proforma =  $em->getRepository(AveDocProformaDeposit::class)->findOneById($id);
  332.         $id $proforma->getFileId();
  333.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  334.         // Buscamos el cliente
  335.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  336.         $client $em->getRepository(Client::class)->findById($file->getClient());
  337.         if (empty($client)) {
  338.             $client[0] = new Client();
  339.             $client[0]->setName('');
  340.             $client[0]->setTitle('');
  341.             $client[0]->setIdDocument('');
  342.             $client[0]->setPopulation('');
  343.             $client[0]->setRegion('');
  344.             $client[0]->setCountry('');
  345.         } else {
  346.             if (is_numeric($client[0]->getPopulation())) {
  347.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  348. //                $client[0]->setPopulation($city->getCity());
  349.             }
  350.             if (is_numeric($client[0]->getRegion())) {
  351.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  352. //                $client[0]->setRegion($region->getRegion());
  353.             }
  354.             if (is_numeric($client[0]->getCountry())) {
  355.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  356. //                $client[0]->setCountry($country->getCountry());
  357.             }
  358.         }
  359.         if (empty($client)) {
  360.             $client[0] = new Client();
  361.             $client[0]->setName('');
  362.             $client[0]->setTitle('');
  363.             $client[0]->setIdDocument('');
  364.             $client[0]->setPopulation('');
  365.             $client[0]->setRegion('');
  366.             $client[0]->setCountry('');
  367.             $clientNew = array(
  368.                 'name' => '',
  369.                 'title' => '',
  370.                 'idDocument' => '',
  371.                 'population' => '',
  372.                 'region' => '',
  373.                 'country' => '',
  374.                 'address' => '',
  375.                 'addressNumber' => '',
  376.                 'zipCode' => '',
  377.                 'typeDocument' => '',
  378.             );
  379.         } else {
  380.             $clientNew = array(
  381.                 'name' => $client[0]->getName(),
  382.                 'title' => $client[0]->getTitle(),
  383.                 'idDocument' => $client[0]->getIdDocument(),
  384.                 'population' => '',
  385.                 'region' => '',
  386.                 'country' => '',
  387.                 'address' => $client[0]->getAddress(),
  388.                 'addressNumber' => $client[0]->getAddressNumber(),
  389.                 'zipCode' => $client[0]->getZipCode(),
  390.                 'typeDocument' => $client[0]->getTypeDocument(),
  391.             );
  392.             if (is_numeric($client[0]->getPopulation())) {
  393.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  394.                 $clientNew['population'] = $city->getCity();
  395.             }
  396.             if (is_numeric($client[0]->getRegion())) {
  397.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  398.                 $clientNew['region'] = $region->getRegion();
  399.             }
  400.             if (is_numeric($client[0]->getCountry())) {
  401.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  402.                 $clientNew['country'] = $country->getCountry();
  403.             }
  404.         }
  405.         // Buscamos el cliente
  406.         $bases_imponibles['ivaMontoVeintiUno'] = $proforma->getAmount() * 0.21;
  407.         $allProformas =  $em->getRepository(AveDocProformaDeposit::class)->findByFileId($id);
  408.         // Falta agregar en $allProformas las proformas de facturas, hasta ahora solo estan las proformas de deposito  //6*6*6
  409.         $commentsBool false;
  410.         $comments null;
  411.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  412.         if ($fileAv->getCommentsInPro()) {
  413.             $commentsBool true;
  414.         }
  415.         if ($commentsBool) {
  416.             $comments $fileAv->getComments();
  417.         }
  418.         return $this->render(
  419.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
  420.             array(
  421.                 'id' => $id,
  422.                 'docType' => $docType,
  423.                 'proforma' => $proforma,
  424.                 'company' => $company,
  425.                 'clients' => $clientNew,
  426.                 'date' => $proforma->getCreatedAt(),
  427.                 'number' => $proforma->getId(),
  428.                 'invoice' => null,
  429.                 'fid' => $proforma->getId(),
  430.                 'boolToRec' => false,
  431.                 'proformas' => $allProformas,
  432.                 'currency' => '€',
  433.                 'totales_neto' => $proforma->getAmount(),
  434.                 'totales' => $proforma->getTotal(),
  435.                 'balance' => $proforma->getTotal(),
  436.                 'bases_imponibles' => $bases_imponibles,
  437.                 'comments' => $comments,
  438.                 'file' => $fileAv,
  439.                 'services' => null,
  440.                 'facturas' => null,
  441.                 'paymentNotIvoiced' => null,
  442.                 'paymentsAll' => null,
  443.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  444.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  445.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  446.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  447.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  448.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  449.             )
  450.         );
  451.     }
  452.     /**
  453.      * @Route("/newinvoicedeposit/{id}",  name="ave_new_invoice_deposit")
  454.      * Crear nueva factura de deposito en un expediente
  455.      */
  456.     public function newInvoiceDepositAction($idRequest $request)
  457.     {
  458.         $docType 'Factura de Deposito';
  459.         $em $this->getDoctrine()->getManager();
  460.         $proforma =  $em->getRepository(AveDocProformaDeposit::class)->findOneById($id);
  461.         $id $proforma->getFileId();
  462.         /* Obtengo usuario logueado */
  463.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  464.         $user_id $user_logueado->getId();
  465.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  466.         // Buscamos el cliente
  467.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  468.         $client $em->getRepository(Client::class)->findById($file->getClient());
  469.         if (empty($client)) {
  470.             $client[0] = new Client();
  471.             $client[0]->setName('');
  472.             $client[0]->setTitle('');
  473.             $client[0]->setIdDocument('');
  474.             $client[0]->setPopulation('');
  475.             $client[0]->setRegion('');
  476.             $client[0]->setCountry('');
  477.         }
  478.         // Buscamos el cliente
  479.         // Generamos la factura con la proforma especificada
  480.         $invoice = new AveDocInvoice();
  481.         $invoice->setAccessKey(md5(rand() * time()));
  482.         $invoice->setFileId($proforma->getFileId());
  483.         $invoice->setDateAt(new \DateTime("now"));
  484.         $invoice->setName($proforma->getName());
  485.         $invoice->setTotalNet($proforma->getAmount());
  486.         $invoice->setIva($proforma->getIva());
  487.         $invoice->setVat(($proforma->getAmount() * $proforma->getIva()) / 100);
  488.         $totalInv $invoice->getTotalNet() + $invoice->getVat();
  489.         $invoice->setTotal($totalInv);
  490.         $invoice->setMaster(null);
  491.         $invoice->setNumber(null);
  492.         $invoice->setPrefix(null);
  493.         $invoice->setBalance($totalInv * (-1));
  494.         $invoice->setType('Factura de Deposito');
  495.         $invoice->setUpdatedId($user_id);
  496.         $invoice->setUpdatedAt(new \DateTime("now"));
  497.         $invoice->setCreatedId($user_id);
  498.         $invoice->setCreatedAt(new \DateTime("now"));
  499.         $em->persist($invoice);
  500.         $em->flush();
  501.         $bases_imponibles['ivaMontoVeintiUno'] = $proforma->getAmount() * 0.21;
  502.         $allInvoices =  $em->getRepository(AveDocInvoice::class)->findByFileId($id);
  503.         $allProformas null;
  504.         // Una factura solo se puede rectificar una vez
  505.         $rectf $em->getRepository(AveDocInvoiceRec::class)->findBy(array('invoiceToRec' => $invoice->getId()));
  506.         $boolToRec = empty($rectf);
  507.         return $this->redirectToRoute(
  508.             'ave_view_invoice_deposit',
  509.             array(
  510.                 'id' => $invoice->getId()
  511.             )
  512.         );
  513.     }
  514.     /**
  515.      * @Route("/viewinvoicedeposit/{id}",  name="ave_view_invoice_deposit")
  516.      * Ver una factura de deposito en un expediente
  517.      */
  518.     public function viewInvoiceDepositAction($idRequest $request)
  519.     {
  520.         $docType 'Factura de Deposito';
  521.         $em $this->getDoctrine()->getManager();
  522.         $invoice =  $em->getRepository(AveDocInvoice::class)->findOneById($id);
  523.         $id $invoice->getFileId();
  524.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  525.         // Buscamos el cliente
  526.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  527.         $client $em->getRepository(Client::class)->findById($file->getClient());
  528.         if (empty($client)) {
  529.             $client[0] = new Client();
  530.             $client[0]->setName('');
  531.             $client[0]->setTitle('');
  532.             $client[0]->setIdDocument('');
  533.             $client[0]->setPopulation('');
  534.             $client[0]->setRegion('');
  535.             $client[0]->setCountry('');
  536.         } else {
  537.             if (is_numeric($client[0]->getPopulation())) {
  538.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  539. //                $client[0]->setPopulation($city->getCity());
  540.             }
  541.             if (is_numeric($client[0]->getRegion())) {
  542.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  543. //                $client[0]->setRegion($region->getRegion());
  544.             }
  545.             if (is_numeric($client[0]->getCountry())) {
  546.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  547. //                $client[0]->setCountry($country->getCountry());
  548.             }
  549.         }
  550.         if (empty($client)) {
  551.             $client[0] = new Client();
  552.             $client[0]->setName('');
  553.             $client[0]->setTitle('');
  554.             $client[0]->setIdDocument('');
  555.             $client[0]->setPopulation('');
  556.             $client[0]->setRegion('');
  557.             $client[0]->setCountry('');
  558.             $clientNew = array(
  559.                 'name' => '',
  560.                 'title' => '',
  561.                 'idDocument' => '',
  562.                 'population' => '',
  563.                 'region' => '',
  564.                 'country' => '',
  565.                 'address' => '',
  566.                 'addressNumber' => '',
  567.                 'zipCode' => '',
  568.                 'typeDocument' => '',
  569.             );
  570.         } else {
  571.             $clientNew = array(
  572.                 'name' => $client[0]->getName(),
  573.                 'title' => $client[0]->getTitle(),
  574.                 'idDocument' => $client[0]->getIdDocument(),
  575.                 'population' => '',
  576.                 'region' => '',
  577.                 'country' => '',
  578.                 'address' => $client[0]->getAddress(),
  579.                 'addressNumber' => $client[0]->getAddressNumber(),
  580.                 'zipCode' => $client[0]->getZipCode(),
  581.                 'typeDocument' => $client[0]->getTypeDocument(),
  582.             );
  583.             if (is_numeric($client[0]->getPopulation())) {
  584.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  585.                 $clientNew['population'] = $city->getCity();
  586.             }
  587.             if (is_numeric($client[0]->getRegion())) {
  588.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  589.                 $clientNew['region'] = $region->getRegion();
  590.             }
  591.             if (is_numeric($client[0]->getCountry())) {
  592.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  593.                 $clientNew['country'] = $country->getCountry();
  594.             }
  595.         }
  596.         // Buscamos el cliente
  597.         // Obtengo usuario logueado
  598.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  599.         $user_id $user_logueado->getId();
  600.         $bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet() * 0.21;
  601.         $allInvoices =  $em->getRepository(AveDocInvoice::class)->findByFileId($id);
  602.         $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($id);
  603.         foreach ($allInvoicesRec as $item) {
  604.             array_push($allInvoices$item);
  605.         }
  606.         $allProformas null;
  607.         // Una factura solo se puede rectificar una vez
  608.         $rectf $em->getRepository(AveDocInvoiceRec::class)->findBy(array('invoiceToRec' => $invoice->getId()));
  609.         $boolToRec = empty($rectf);
  610.         $commentsBool false;
  611.         $comments null;
  612.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  613.         if ($fileAv->getCommentsInInv()) {
  614.             $commentsBool true;
  615.         }
  616.         if ($commentsBool) {
  617.             $comments $fileAv->getComments();
  618.         }
  619.         return $this->render(
  620.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
  621.             array(
  622.                 'id' => $id,
  623.                 'docType' => $docType,
  624.                 'proforma' => null,
  625.                 'company' => $company,
  626.                 'clients' => $clientNew,
  627.                 'file' => $file,
  628.                 'date' => $invoice->getDateAt(),
  629.                 'number' => $invoice->getId(),
  630.                 'invoice' => $invoice,
  631.                 'fid' => $invoice->getId(),
  632.                 'boolToRec' => $boolToRec,
  633.                 'proformas' => $allProformas,
  634.                 'facturas' => $allInvoices,
  635.                 'currency' => '€',
  636.                 'user' => $user_logueado,
  637.                 'totales_neto' => $invoice->getTotalNet(),
  638.                 'totales' => $invoice->getTotal(),
  639.                 'balance' => $invoice->getTotal(),
  640.                 'bases_imponibles' => $bases_imponibles,
  641.                 'services' => null,
  642.                 //                'facturas' => null,
  643.                 'paymentNotIvoiced' => null,
  644.                 'paymentsAll' => null,
  645.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  646.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  647.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  648.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  649.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  650.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  651.                 'comments' => $comments,
  652.             )
  653.         );
  654.     }
  655.     /**
  656.      * @Route("/avexternal/printinvoicedeposit/{id}",  name="ave_print_invoice_deposit")
  657.      * Imprimir una factura de deposito
  658.      */
  659.     public function printInvoiceDepositAction($idRequest $request)
  660.     {
  661.         $docType 'Factura de Deposito';
  662.         $em $this->getDoctrine()->getManager();
  663.         $invoice =  $em->getRepository(AveDocInvoice::class)->findOneById($id);
  664.         $id $invoice->getFileId();
  665.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  666.         // Buscamos el cliente
  667.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  668.         $client $em->getRepository(Client::class)->findById($file->getClient());
  669.         if (empty($client)) {
  670.             $client[0] = new Client();
  671.             $client[0]->setName('');
  672.             $client[0]->setTitle('');
  673.             $client[0]->setIdDocument('');
  674.             $client[0]->setPopulation('');
  675.             $client[0]->setRegion('');
  676.             $client[0]->setCountry('');
  677.         } else {
  678.             if (is_numeric($client[0]->getPopulation())) {
  679.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  680. //                $client[0]->setPopulation($city->getCity());
  681.             }
  682.             if (is_numeric($client[0]->getRegion())) {
  683.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  684. //                $client[0]->setRegion($region->getRegion());
  685.             }
  686.             if (is_numeric($client[0]->getCountry())) {
  687.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  688. //                $client[0]->setCountry($country->getCountry());
  689.             }
  690.         }
  691.         if (empty($client)) {
  692.             $client[0] = new Client();
  693.             $client[0]->setName('');
  694.             $client[0]->setTitle('');
  695.             $client[0]->setIdDocument('');
  696.             $client[0]->setPopulation('');
  697.             $client[0]->setRegion('');
  698.             $client[0]->setCountry('');
  699.             $clientNew = array(
  700.                 'name' => '',
  701.                 'title' => '',
  702.                 'idDocument' => '',
  703.                 'population' => '',
  704.                 'region' => '',
  705.                 'country' => '',
  706.                 'address' => '',
  707.                 'addressNumber' => '',
  708.                 'zipCode' => '',
  709.                 'typeDocument' => '',
  710.             );
  711.         } else {
  712.             $clientNew = array(
  713.                 'name' => $client[0]->getName(),
  714.                 'title' => $client[0]->getTitle(),
  715.                 'idDocument' => $client[0]->getIdDocument(),
  716.                 'population' => '',
  717.                 'region' => '',
  718.                 'country' => '',
  719.                 'address' => $client[0]->getAddress(),
  720.                 'addressNumber' => $client[0]->getAddressNumber(),
  721.                 'zipCode' => $client[0]->getZipCode(),
  722.                 'typeDocument' => $client[0]->getTypeDocument(),
  723.             );
  724.             if (is_numeric($client[0]->getPopulation())) {
  725.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  726.                 $clientNew['population'] = $city->getCity();
  727.             }
  728.             if (is_numeric($client[0]->getRegion())) {
  729.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  730.                 $clientNew['region'] = $region->getRegion();
  731.             }
  732.             if (is_numeric($client[0]->getCountry())) {
  733.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  734.                 $clientNew['country'] = $country->getCountry();
  735.             }
  736.         }
  737.         // Buscamos el cliente
  738.         $bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet() * 0.21;
  739.         $allInvoices =  $em->getRepository(AveDocInvoice::class)->findByFileId($id);
  740.         $allProformas null;
  741.         // Una factura solo se puede rectificar una vez
  742.         $rectf $em->getRepository(AveDocInvoiceRec::class)->findBy(array('invoiceToRec' => $invoice->getId()));
  743.         $boolToRec = empty($rectf);
  744.         $commentsBool false;
  745.         $comments null;
  746.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  747.         if ($fileAv->getCommentsInPro()) {
  748.             $commentsBool true;
  749.         }
  750.         if ($commentsBool) {
  751.             $comments $fileAv->getComments();
  752.         }
  753.         return $this->render(
  754.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
  755.             array(
  756.                 'id' => $id,
  757.                 'docType' => $docType,
  758.                 'proforma' => null,
  759.                 'company' => $company,
  760.                 'clients' => $clientNew,
  761.                 'file' => $file,
  762.                 'date' => $invoice->getDateAt(),
  763.                 'number' => $invoice->getId(),
  764.                 'invoice' => $invoice,
  765.                 'fid' => $invoice->getId(),
  766.                 'boolToRec' => $boolToRec,
  767.                 'proformas' => $allProformas,
  768.                 'facturas' => $allInvoices,
  769.                 'currency' => '€',
  770.                 'totales_neto' => $invoice->getTotalNet(),
  771.                 'totales' => $invoice->getTotal(),
  772.                 'balance' => $invoice->getTotal(),
  773.                 'bases_imponibles' => $bases_imponibles,
  774.                 'services' => null,
  775.                 'paymentNotIvoiced' => null,
  776.                 'paymentsAll' => null,
  777.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  778.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  779.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  780.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  781.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  782.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  783.                 'comments' => $comments,
  784.             )
  785.         );
  786.     }
  787.     /**
  788.      * @Route("/newinvoicedepositrec/{id}",  name="ave_invoice_deposit_rec")
  789.      * Crear nueva factura rectificativa de deposito
  790.      */
  791.     public function newInvoiceDepositRecAction($idRequest $request)
  792.     {
  793.         $docType 'Factura Rectificativa de Deposito';
  794.         $em $this->getDoctrine()->getManager();
  795.          // Verificamos que no exista una factura rectificativa previa sobre la misma factura
  796.         $previusInvoiceRec $em->getRepository(AveDocInvoiceRec::class)->findOneByInvoiceToRec($id);
  797.         if (!empty($previusInvoiceRec)) {
  798.             return $this->redirectToRoute('ave_view_invoice_deposit_rec', array('id' => $previusInvoiceRec->getId()));
  799.         }
  800.         $invoice =  $em->getRepository(AveDocInvoice::class)->findOneById($id);
  801.         $id $invoice->getFileId();
  802.         /* Obtengo usuario logueado */
  803.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  804.         $user_id $user_logueado->getId();
  805.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  806.         // Buscamos el cliente
  807.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  808.         $client $em->getRepository(Client::class)->findById($file->getClient());
  809.         if (empty($client)) {
  810.             $client[0] = new Client();
  811.             $client[0]->setName('');
  812.             $client[0]->setTitle('');
  813.             $client[0]->setIdDocument('');
  814.             $client[0]->setPopulation('');
  815.             $client[0]->setRegion('');
  816.             $client[0]->setCountry('');
  817.         } else {
  818.             if (is_numeric($client[0]->getPopulation())) {
  819.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  820. //                $client[0]->setPopulation($city->getCity());
  821.             }
  822.             if (is_numeric($client[0]->getRegion())) {
  823.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  824. //                $client[0]->setRegion($region->getRegion());
  825.             }
  826.             if (is_numeric($client[0]->getCountry())) {
  827.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  828. //                $client[0]->setCountry($country->getCountry());
  829.             }
  830.         }
  831.         if (empty($client)) {
  832.             $client[0] = new Client();
  833.             $client[0]->setName('');
  834.             $client[0]->setTitle('');
  835.             $client[0]->setIdDocument('');
  836.             $client[0]->setPopulation('');
  837.             $client[0]->setRegion('');
  838.             $client[0]->setCountry('');
  839.             $clientNew = array(
  840.                 'name' => '',
  841.                 'title' => '',
  842.                 'idDocument' => '',
  843.                 'population' => '',
  844.                 'region' => '',
  845.                 'country' => '',
  846.                 'address' => '',
  847.                 'addressNumber' => '',
  848.                 'zipCode' => '',
  849.                 'typeDocument' => '',
  850.             );
  851.         } else {
  852.             $clientNew = array(
  853.                 'name' => $client[0]->getName(),
  854.                 'title' => $client[0]->getTitle(),
  855.                 'idDocument' => $client[0]->getIdDocument(),
  856.                 'population' => '',
  857.                 'region' => '',
  858.                 'country' => '',
  859.                 'address' => $client[0]->getAddress(),
  860.                 'addressNumber' => $client[0]->getAddressNumber(),
  861.                 'zipCode' => $client[0]->getZipCode(),
  862.                 'typeDocument' => $client[0]->getTypeDocument(),
  863.             );
  864.             if (is_numeric($client[0]->getPopulation())) {
  865.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  866.                 $clientNew['population'] = $city->getCity();
  867.             }
  868.             if (is_numeric($client[0]->getRegion())) {
  869.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  870.                 $clientNew['region'] = $region->getRegion();
  871.             }
  872.             if (is_numeric($client[0]->getCountry())) {
  873.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  874.                 $clientNew['country'] = $country->getCountry();
  875.             }
  876.         }
  877.         // Buscamos el cliente
  878.         // Generamos la factura con la proforma especificada
  879.         $invoiceRec = new AveDocInvoiceRec();
  880.         $invoiceRec->setFileId($invoice->getFileId());
  881.         $invoiceRec->setInvoiceToRec($invoice->getId());
  882.         $invoiceRec->setDateAt(new \DateTime("now"));
  883.         $invoiceRec->setName($invoice->getName());
  884.         $invoiceRec->setTotalNet($invoice->getTotalNet() * (-1));
  885.         $invoiceRec->setIva($invoice->getIva());
  886.         $invoiceRec->setVat((($invoice->getTotalNet() * $invoice->getIva()) / 100) * (-1));
  887.         $totalInv $invoice->getTotalNet() + $invoice->getVat();
  888.         $invoiceRec->setTotal($totalInv * (-1));
  889.         $invoiceRec->setMaster(null);
  890.         $invoiceRec->setNumber(null);
  891.         //        $invoiceRec->setPrefix(null);
  892.         $invoiceRec->setPrefix('R');
  893.         $invoiceRec->setBalance($totalInv);
  894.         $invoiceRec->setType('Factura Rectificativa de Deposito');
  895.         $invoiceRec->setUpdatedId($user_id);
  896.         $invoiceRec->setUpdatedAt(new \DateTime("now"));
  897.         $invoiceRec->setCreatedId($user_id);
  898.         $invoiceRec->setCreatedAt(new \DateTime("now"));
  899.         $em->persist($invoiceRec);
  900.         $em->flush();
  901.         return $this->redirectToRoute('ave_view_invoice_deposit_rec', array('id' => $invoiceRec->getId()));
  902.     }
  903.     /**
  904.      * @Route("/viewinvoicedepositrec/{id}",  name="ave_view_invoice_deposit_rec")
  905.      * Ver una factura rectificativa de deposito
  906.      */
  907.     public function viewInvoiceDepositRecAction($idRequest $request)
  908.     {
  909.         $docType 'Factura Rectificativa de Deposito';
  910.         $em $this->getDoctrine()->getManager();
  911.         $invoice =  $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
  912.         $id $invoice->getFileId();
  913.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  914.         // Buscamos el cliente
  915.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  916.         $client $em->getRepository(Client::class)->findById($file->getClient());
  917.         if (empty($client)) {
  918.             $client[0] = new Client();
  919.             $client[0]->setName('');
  920.             $client[0]->setTitle('');
  921.             $client[0]->setIdDocument('');
  922.             $client[0]->setPopulation('');
  923.             $client[0]->setRegion('');
  924.             $client[0]->setCountry('');
  925.         } else {
  926.             if (is_numeric($client[0]->getPopulation())) {
  927.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  928. //                $client[0]->setPopulation($city->getCity());
  929.             }
  930.             if (is_numeric($client[0]->getRegion())) {
  931.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  932. //                $client[0]->setRegion($region->getRegion());
  933.             }
  934.             if (is_numeric($client[0]->getCountry())) {
  935.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  936. //                $client[0]->setCountry($country->getCountry());
  937.             }
  938.         }
  939.         if (empty($client)) {
  940.             $client[0] = new Client();
  941.             $client[0]->setName('');
  942.             $client[0]->setTitle('');
  943.             $client[0]->setIdDocument('');
  944.             $client[0]->setPopulation('');
  945.             $client[0]->setRegion('');
  946.             $client[0]->setCountry('');
  947.             $clientNew = array(
  948.                 'name' => '',
  949.                 'title' => '',
  950.                 'idDocument' => '',
  951.                 'population' => '',
  952.                 'region' => '',
  953.                 'country' => '',
  954.                 'address' => '',
  955.                 'addressNumber' => '',
  956.                 'zipCode' => '',
  957.                 'typeDocument' => '',
  958.             );
  959.         } else {
  960.             $clientNew = array(
  961.                 'name' => $client[0]->getName(),
  962.                 'title' => $client[0]->getTitle(),
  963.                 'idDocument' => $client[0]->getIdDocument(),
  964.                 'population' => '',
  965.                 'region' => '',
  966.                 'country' => '',
  967.                 'address' => $client[0]->getAddress(),
  968.                 'addressNumber' => $client[0]->getAddressNumber(),
  969.                 'zipCode' => $client[0]->getZipCode(),
  970.                 'typeDocument' => $client[0]->getTypeDocument(),
  971.             );
  972.             if (is_numeric($client[0]->getPopulation())) {
  973.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  974.                 $clientNew['population'] = $city->getCity();
  975.             }
  976.             if (is_numeric($client[0]->getRegion())) {
  977.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  978.                 $clientNew['region'] = $region->getRegion();
  979.             }
  980.             if (is_numeric($client[0]->getCountry())) {
  981.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  982.                 $clientNew['country'] = $country->getCountry();
  983.             }
  984.         }
  985.         // Buscamos el cliente
  986.         $bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet() * 0.21;
  987.         $allInvoices =  $em->getRepository(AveDocInvoice::class)->findByFileId($id);
  988.         $allProformas null;
  989.         // Una factura solo se puede rectificar una vez
  990.         //        $rectf = $em->getRepository(AveDocInvoiceRec::class)->findBy( array('invoiceToRec' => $invoice->getId()));
  991.         $boolToRec false;
  992.         $commentsBool false;
  993.         $comments null;
  994.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  995.         if ($fileAv->getCommentsInInv()) {
  996.             $commentsBool true;
  997.         }
  998.         if ($commentsBool) {
  999.             $comments $fileAv->getComments();
  1000.         }
  1001.         // Obtengo usuario logueado
  1002.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1003.         $user_id $user_logueado->getId();
  1004.         return $this->render(
  1005.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
  1006.             array(
  1007.                 'id' => $id,
  1008.                 'docType' => $docType,
  1009.                 'proforma' => null,
  1010.                 'company' => $company,
  1011.                 'clients' => $clientNew,
  1012.                 'file' => $file,
  1013.                 'date' => $invoice->getDateAt(),
  1014.                 'number' => $invoice->getId(),
  1015.                 'invoice' => $invoice,
  1016.                 'fid' => $invoice->getId(),
  1017.                 'boolToRec' => $boolToRec,
  1018.                 'proformas' => $allProformas,
  1019.                 'facturas' => $allInvoices,
  1020.                 'currency' => '€',
  1021.                 'totales_neto' => $invoice->getTotalNet(),
  1022.                 'totales' => $invoice->getTotal(),
  1023.                 'balance' => $invoice->getTotal(),
  1024.                 'bases_imponibles' => $bases_imponibles,
  1025.                 'user' => $user_logueado,
  1026.                 'services' => null,
  1027.                 //                'facturas' => null,
  1028.                 'paymentNotIvoiced' => null,
  1029.                 'paymentsAll' => null,
  1030.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  1031.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  1032.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  1033.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  1034.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  1035.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  1036.                 'comments' => $comments,
  1037.             )
  1038.         );
  1039.     }
  1040.     /**
  1041.      * @Route("/avexternal/printinvoicedepositrec/{id}",  name="ave_print_invoice_deposit_rec")
  1042.      * Imprimir una factura rectificativa de deposito
  1043.      */
  1044.     public function printInvoiceDepositRecAction($idRequest $request)
  1045.     {
  1046.         $docType 'Factura Rectificativa de Deposito';
  1047.         $em $this->getDoctrine()->getManager();
  1048.         $invoice =  $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
  1049.         $id $invoice->getFileId();
  1050.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  1051.         // Buscamos el cliente
  1052.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  1053.         $client $em->getRepository(Client::class)->findById($file->getClient());
  1054.         if (empty($client)) {
  1055.             $client[0] = new Client();
  1056.             $client[0]->setName('');
  1057.             $client[0]->setTitle('');
  1058.             $client[0]->setIdDocument('');
  1059.             $client[0]->setPopulation('');
  1060.             $client[0]->setRegion('');
  1061.             $client[0]->setCountry('');
  1062.         } else {
  1063.             if (is_numeric($client[0]->getPopulation())) {
  1064.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  1065. //                $client[0]->setPopulation($city->getCity());
  1066.             }
  1067.             if (is_numeric($client[0]->getRegion())) {
  1068.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  1069. //                $client[0]->setRegion($region->getRegion());
  1070.             }
  1071.             if (is_numeric($client[0]->getCountry())) {
  1072.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  1073. //                $client[0]->setCountry($country->getCountry());
  1074.             }
  1075.         }
  1076.         if (empty($client)) {
  1077.             $client[0] = new Client();
  1078.             $client[0]->setName('');
  1079.             $client[0]->setTitle('');
  1080.             $client[0]->setIdDocument('');
  1081.             $client[0]->setPopulation('');
  1082.             $client[0]->setRegion('');
  1083.             $client[0]->setCountry('');
  1084.             $clientNew = array(
  1085.                 'name' => '',
  1086.                 'title' => '',
  1087.                 'idDocument' => '',
  1088.                 'population' => '',
  1089.                 'region' => '',
  1090.                 'country' => '',
  1091.                 'address' => '',
  1092.                 'addressNumber' => '',
  1093.                 'zipCode' => '',
  1094.                 'typeDocument' => '',
  1095.             );
  1096.         } else {
  1097.             $clientNew = array(
  1098.                 'name' => $client[0]->getName(),
  1099.                 'title' => $client[0]->getTitle(),
  1100.                 'idDocument' => $client[0]->getIdDocument(),
  1101.                 'population' => '',
  1102.                 'region' => '',
  1103.                 'country' => '',
  1104.                 'address' => $client[0]->getAddress(),
  1105.                 'addressNumber' => $client[0]->getAddressNumber(),
  1106.                 'zipCode' => $client[0]->getZipCode(),
  1107.                 'typeDocument' => $client[0]->getTypeDocument(),
  1108.             );
  1109.             if (is_numeric($client[0]->getPopulation())) {
  1110.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  1111.                 $clientNew['population'] = $city->getCity();
  1112.             }
  1113.             if (is_numeric($client[0]->getRegion())) {
  1114.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  1115.                 $clientNew['region'] = $region->getRegion();
  1116.             }
  1117.             if (is_numeric($client[0]->getCountry())) {
  1118.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  1119.                 $clientNew['country'] = $country->getCountry();
  1120.             }
  1121.         }
  1122.         // Buscamos el cliente
  1123.         $bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet() * 0.21;
  1124.         $allInvoices =  $em->getRepository(AveDocInvoice::class)->findByFileId($id);
  1125.         $allProformas null;
  1126.         // Una factura solo se puede rectificar una vez
  1127.         //        $rectf = $em->getRepository(AveDocInvoiceRec::class)->findBy( array('invoiceToRec' => $invoice->getId()));
  1128.         $boolToRec false;
  1129.         $commentsBool false;
  1130.         $comments null;
  1131.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  1132.         if ($fileAv->getCommentsInPro()) {
  1133.             $commentsBool true;
  1134.         }
  1135.         if ($commentsBool) {
  1136.             $comments $fileAv->getComments();
  1137.         }
  1138.         return $this->render(
  1139.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
  1140.             array(
  1141.                 'id' => $id,
  1142.                 'docType' => $docType,
  1143.                 'proforma' => null,
  1144.                 'company' => $company,
  1145.                 'clients' => $clientNew,
  1146.                 'file' => $file,
  1147.                 'date' => $invoice->getDateAt(),
  1148.                 'number' => $invoice->getId(),
  1149.                 'invoice' => $invoice,
  1150.                 'fid' => $invoice->getId(),
  1151.                 'boolToRec' => $boolToRec,
  1152.                 'proformas' => $allProformas,
  1153.                 'facturas' => $allInvoices,
  1154.                 'currency' => '€',
  1155.                 'totales_neto' => $invoice->getTotalNet(),
  1156.                 'totales' => $invoice->getTotal(),
  1157.                 'balance' => $invoice->getTotal(),
  1158.                 'bases_imponibles' => $bases_imponibles,
  1159.                 'services' => null,
  1160.                 'paymentNotIvoiced' => null,
  1161.                 'paymentsAll' => null,
  1162.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  1163.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  1164.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  1165.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  1166.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  1167.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  1168.                 'comments' => $comments,
  1169.             )
  1170.         );
  1171.     }
  1172.     /**
  1173.      * @Route("/selinvoice/{id}",  name="ave_select_invoice")
  1174.      * Seleccionar los items que pasaran a la proforma o factura
  1175.      */
  1176.     public function selectItemsInvoiceAction($idRequest $request)
  1177.     {
  1178.         $em $this->getDoctrine()->getManager();
  1179.         $paymentsClient = new AvePaymentsClient();
  1180.         $paymentsClient->setFileId($id);
  1181.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  1182.         $payments $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  1183.         $allProformas $em->getRepository(AveDocProforma::class)->findAll();
  1184.         if (!empty($allProformas)) {
  1185.             $number end($allProformas)->getId() + 1;
  1186.         } else {
  1187.             // Primer registro de proformas
  1188.             $number 1;
  1189.         }
  1190.         $type 'Proforma';
  1191.         $docType 'Proforma';
  1192.         $date = new DateTime('now');
  1193.         $prefix "AVE-" $date->format('dmy') . "-";
  1194.         $fileInv = new AveDocInvoice();
  1195.         $fileInv->setAccessKey(md5(rand() * time()));
  1196.         $fileInv->setFileId($id);
  1197.         $data $this->baseInvoiceFile($id$type$number$prefix$date);
  1198.         $token $data['token'];
  1199.         $idProducts = [];
  1200.         if (array_key_exists('product'$data['datasupplier'])) {
  1201.             foreach ($data['datasupplier']['product'] as $key => $item) {
  1202.                 $existe $em->getRepository(AveDocInvoiceItems::class)->findOneByPrdControlId($item['id']);
  1203.                 if (empty($existe)) {
  1204.                     $data['datasupplier']['product'][$key]['enabledToInvoice'] = true;
  1205.                 } else {
  1206.                     $data['datasupplier']['product'][$key]['enabledToInvoice'] = false;
  1207.                 }
  1208.             }
  1209.         }
  1210.         if (array_key_exists('service'$data['datasupplier'])) {
  1211.             foreach ($data['datasupplier']['service'] as $key => $item) {
  1212.                 $existe $em->getRepository(AveDocInvoiceItems::class)->findOneBySrvControlId($item['id']);
  1213.                 if (empty($existe)) {
  1214.                     $data['datasupplier']['service'][$key]['enabledToInvoice'] = true;
  1215.                 } else {
  1216.                     $data['datasupplier']['service'][$key]['enabledToInvoice'] = false;
  1217.                 }
  1218.             }
  1219.         }
  1220.         $idPayments = [];
  1221.         if (array_key_exists('payment'$data['datasupplier'])) {
  1222.             foreach ($data['datasupplier']['payment'] as $key => $item) {
  1223.                 $existe $em->getRepository(AveDocInvoiceItems::class)->findOneByPayControlId($item['id']);
  1224.                 if (empty($existe)) {
  1225.                     $data['datasupplier']['payment'][$key]['enabledToInvoice'] = true;
  1226.                 } else {
  1227.                     $data['datasupplier']['payment'][$key]['enabledToInvoice'] = false;
  1228.                 }
  1229.             }
  1230.         }
  1231.         /* Obtengo usuario logueado */
  1232.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1233.         $user_id $user_logueado->getId();
  1234.         $company $data['company'] ?? null;
  1235.         if (!$company) {
  1236.             $company $em->getRepository(SettingsCompany::class)->findOneBy(['businessType' => BusinessTypeSettingsCompanyConstants::AUDIOVISUAL]);
  1237.         }
  1238.         // Formulario de campos extras
  1239.         $extraField = new InvoiceProformaExtraField();
  1240.         $formExtraField $this->createForm(InvoiceProformaExtraFieldType::class, $extraField);
  1241.         $companyId $company->getId();
  1242.         $extraFields $this->extraFieldService->findValidUndefinedByCompany($companyId);
  1243.         return $this->render(
  1244.             'MDS/AvexpressBundle/Avexpress/invoice-select-items.html.twig',
  1245.             array(
  1246.                 'id' => $id,
  1247.                 'idLounges' => $idProducts,
  1248.                 'file' => $file,
  1249.                 'idPayments' => $idPayments,
  1250.                 'type' => $data['type'],
  1251.                 'docType' => $docType,
  1252.                 'number' => $data['number'],
  1253.                 'prefix' => $data['prefix'],
  1254.                 'date' => $data['date'],
  1255.                 'token' => $token,
  1256.                 'company' => $data['company'],
  1257.                 'clients' => $data['clients'],
  1258.                 'datasupplier' => $data['datasupplier'],
  1259.                 'currency' => $data['currency'],
  1260.                 'totales_neto' => $data['totales_neto'],
  1261.                 'bases_imponibles' => $data['bases_imponibles'],
  1262.                 'totales' => $data['totales'],
  1263.                 'balance' => $data['balance'],
  1264.                 'paymentInvoice' => $data['paymentInvoice'],
  1265.                 'payments' => $payments,
  1266.                 'user_id' => $user_id,
  1267.                 'extraFields' => $extraFields,
  1268.                 'formExtra' => $formExtraField->createView(),
  1269.             )
  1270.         );
  1271.     }
  1272.     /**
  1273.      * @Route("/selproforma/{id}",  name="ave_select_proforma")
  1274.      * Seleccionar los items que pasaran a la proforma o factura a partir de los datos de una proforma
  1275.      */
  1276.     public function selectItemsProformaAction($idRequest $request)
  1277.     {
  1278.         $em $this->getDoctrine()->getManager();
  1279.         //Se cambia el ID de proforma a ID file
  1280.         $proforma $em->getRepository(AveDocProforma::class)->findOneById($id);
  1281.         $id $proforma->getFileId();
  1282.         $proformaId $proforma->getId();
  1283.         $paymentsClient = new AvePaymentsClient();
  1284.         $paymentsClient->setFileId($id);
  1285.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  1286.         $payments $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  1287.         $allProformas $em->getRepository(AveDocProforma::class)->findAll();
  1288.         if (!empty($allProformas)) {
  1289.             $number end($allProformas)->getId() + 1;
  1290.         } else {
  1291.             // Primer registro de proformas
  1292.             $number 1;
  1293.         }
  1294.         $type 'Proforma';
  1295.         $docType 'Proforma';
  1296.         $date = new DateTime('now');
  1297.         $prefix "AVE-" $date->format('dmy') . "-";
  1298.         $fileInv = new AveDocInvoice();
  1299.         $fileInv->setAccessKey(md5(rand() * time()));
  1300.         $fileInv->setFileId($id);
  1301.         $data $this->baseProformaSelect($id$type$number$prefix$date$proformaId);
  1302.         $token $data['token'];
  1303.         $idProducts = array();
  1304.         if (array_key_exists('product'$data['datasupplier'])) {
  1305.             foreach ($data['datasupplier']['product'] as $key => $item) {
  1306.                 $existe $em->getRepository(AveDocInvoiceItems::class)->findOneByPrdControlId($item['id']);
  1307.                 if (empty($existe)) {
  1308.                     $data['datasupplier']['product'][$key]['enabledToInvoice'] = true;
  1309.                 } else {
  1310.                     $data['datasupplier']['product'][$key]['enabledToInvoice'] = false;
  1311.                 }
  1312.             }
  1313.         }
  1314.         if (array_key_exists('service'$data['datasupplier'])) {
  1315.             foreach ($data['datasupplier']['service'] as $key => $item) {
  1316.                 $existe $em->getRepository(AveDocInvoiceItems::class)->findOneBySrvControlId($item['id']);
  1317.                 if (empty($existe)) {
  1318.                     $data['datasupplier']['service'][$key]['enabledToInvoice'] = true;
  1319.                 } else {
  1320.                     $data['datasupplier']['service'][$key]['enabledToInvoice'] = false;
  1321.                 }
  1322.             }
  1323.         }
  1324.         $idPayments = array();
  1325.         if (array_key_exists('payment'$data['datasupplier'])) {
  1326.             foreach ($data['datasupplier']['payment'] as $key => $item) {
  1327.                 $existe $em->getRepository(AveDocInvoiceItems::class)->findOneByPayControlId($item['id']);
  1328.                 if (empty($existe)) {
  1329.                     $data['datasupplier']['payment'][$key]['enabledToInvoice'] = true;
  1330.                 } else {
  1331.                     $data['datasupplier']['payment'][$key]['enabledToInvoice'] = false;
  1332.                 }
  1333.             }
  1334.         }
  1335.         /* Obtengo usuario logueado */
  1336.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1337.         $user_id $user_logueado->getId();
  1338.         return $this->render(
  1339.             'MDS/AvexpressBundle/Avexpress/invoice-select-items.html.twig',
  1340.             array(
  1341.                 'id' => $id,
  1342.                 'idLounges' => $idProducts,
  1343.                 'file' => $file,
  1344.                 'idPayments' => $idPayments,
  1345.                 'type' => $data['type'],
  1346.                 'docType' => $docType,
  1347.                 'number' => $data['number'],
  1348.                 'prefix' => $data['prefix'],
  1349.                 'date' => $data['date'],
  1350.                 'token' => $token,
  1351.                 'company' => $data['company'],
  1352.                 'clients' => $data['clients'],
  1353.                 'datasupplier' => $data['datasupplier'],
  1354.                 'currency' => $data['currency'],
  1355.                 'totales_neto' => $data['totales_neto'],
  1356.                 'bases_imponibles' => $data['bases_imponibles'],
  1357.                 'totales' => $data['totales'],
  1358.                 'balance' => $data['balance'],
  1359.                 'paymentInvoice' => $data['paymentInvoice'],
  1360.                 'payments' => $payments,
  1361.                 'user_id' => $user_id,
  1362.             )
  1363.         );
  1364.     }
  1365.     /**
  1366.      * @Route("/newmultiproforma/", name="ave_new_multi_proforma")
  1367.      * Crear nueva proforma con los elementos seleccionados y retornar al selector
  1368.      */
  1369.     public function generateNewMultiProformaAction(Request $request)
  1370.     {
  1371.         $em $this->getDoctrine()->getManager();
  1372.         // Se genera y muestra en nueva pantalla la nueva proforma
  1373.         $arrayBools = array(
  1374.             'product' => null,
  1375.             'service' => null,
  1376.             'payment' => null,
  1377.         );
  1378.         $arrayBools['product'] = $request->request->get('multi_lounge_hidden_bool');
  1379.         $arrayBools['service'] = $request->request->get('multi_service_hidden_bool');
  1380.         $arrayBools['payment'] = $request->request->get('multi_payment_hidden_bool');
  1381.         $id $request->request->get('multi_file_id');
  1382.         $proforma_number $request->request->get('multi_proforma_number');
  1383.         $proforma_prefix $request->request->get('multi_proforma_prefix') . $proforma_number '-' $id;
  1384.         //INICIO: buscamos el ID de la factura
  1385.         $boolMakeInvoice false;  // Control para verificar si se debe hacer (PROFORMA) o todos los indicadores (sala, servicios y pagos) estaban en falso
  1386.         //FIN: buscamos el ID de la factura
  1387.         /* Obtengo usuario logueado */
  1388.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1389.         $user_id $user_logueado->getId();
  1390.         //Acumuladores de datos globales de la factura
  1391.         $valorTotalNet 0;
  1392.         $valorVat 0;
  1393.         //INICIO: Creamos los items de la proforma
  1394.         if (!empty($arrayBools['product'])) {
  1395.             foreach ($arrayBools['product'] as $key => $item) {
  1396.                 if ($item == 'true') {
  1397.                     $boolMakeInvoice true;
  1398.                     $product $em->getRepository(AveProductFile::class)->findOneById($key);
  1399.                     $boolKeyChange false;
  1400.                     //INICIO: Creamos el nuevo ProductFile para evitar cruce de datos entre proformas
  1401.                     // Si el producto esta contenido en una proforma debemos crear un nuevo porducto
  1402.                     $productInProforma $em->getRepository(AveDocProformaItems::class)->findOneByControlId($key);
  1403.                     if (!empty($productInProforma)) {
  1404.                         //INICIO: Si el producto esta sincronizado con un proposal debemos crear un servicio nuevo en el proposal
  1405.                         $boolKeyChange true;
  1406.                         $newProductFile = new AveProductFile();
  1407.                         //INICIO: Duplicamos en Eventos
  1408.                         if (!empty($product->getOriginId())) {
  1409.                             $serviceEvent $em->getRepository(ProposalSupplierServices::class)->findOneById($product->getOriginId());
  1410.                             if (!empty($serviceEvent)) {
  1411.                                 $newServiceEvent = new ProposalSupplierServices();
  1412.                                 $newServiceEvent->setServiceIdFather($serviceEvent->getServiceIdFather());
  1413.                                 $newServiceEvent->setControlId($serviceEvent->getControlId());
  1414.                                 $newServiceEvent->setProposalId($serviceEvent->getProposalId());
  1415.                                 $newServiceEvent->setDestinationId($serviceEvent->getDestinationId());
  1416.                                 $newServiceEvent->setSupplierId($serviceEvent->getSupplierId());
  1417.                                 $newServiceEvent->setIdeaId($serviceEvent->getIdeaId());
  1418.                                 $newServiceEvent->setActivityId($serviceEvent->getActivityId());
  1419.                                 $newServiceEvent->setServiceId($serviceEvent->getServiceId());
  1420.                                 $newServiceEvent->setServiceCatId($serviceEvent->getServiceCatId());
  1421.                                 $newServiceEvent->setServiceCatName($serviceEvent->getServiceCatName());
  1422.                                 $newServiceEvent->setName($serviceEvent->getName());
  1423.                                 $newServiceEvent->setPrice($serviceEvent->getPrice());
  1424.                                 $newServiceEvent->setCurrency($serviceEvent->getCurrency());
  1425.                                 $newServiceEvent->setUnits($serviceEvent->getUnits());
  1426.                                 $newServiceEvent->setCommission($serviceEvent->getCommission());
  1427.                                 $newServiceEvent->setOver($serviceEvent->getOver());
  1428.                                 $newServiceEvent->setIva($serviceEvent->getIva());
  1429.                                 $newServiceEvent->setPax($serviceEvent->getPax());
  1430.                                 $newServiceEvent->setHour($serviceEvent->getHour());
  1431.                                 $newServiceEvent->setDateInAt($serviceEvent->getDateInAt());
  1432.                                 $newServiceEvent->setDateOutAt($serviceEvent->getDateOutAt());
  1433.                                 $newServiceEvent->setDirectPayment($serviceEvent->getDirectPayment());
  1434.                                 $newServiceEvent->setStatus($serviceEvent->getStatus());
  1435.                                 $newServiceEvent->setCreatedAt(new DateTime('now'));
  1436.                                 $newServiceEvent->setCreatedId($user_id);
  1437.                                 $newServiceEvent->setUpdatedAt(new DateTime('now'));
  1438.                                 $newServiceEvent->setUpdatedId($user_id);
  1439.                                 $newServiceEvent->setStatusinternal($serviceEvent->getStatusinternal());
  1440.                                 $newServiceEvent->setPreCommission($serviceEvent->getPreCommission());
  1441.                                 $newServiceEvent->setPreIva($serviceEvent->getPreIva());
  1442.                                 $newServiceEvent->setDateBlockLimit($serviceEvent->getDateBlockLimit());
  1443.                                 $newServiceEvent->setOpCommission($serviceEvent->getOpCommission());
  1444.                                 $newServiceEvent->setOpOver($serviceEvent->getOpOver());
  1445.                                 $newServiceEvent->setOpIva($serviceEvent->getOpIva());
  1446.                                 $newServiceEvent->setBreakdown($serviceEvent->getBreakdown());
  1447.                                 $newServiceEvent->setIsFather($serviceEvent->getIsFather());
  1448.                                 $newServiceEvent->setRankQuote($serviceEvent->getRankQuote());
  1449.                                 $newServiceEvent->setOriginalopIva($serviceEvent->getOriginalopIva());
  1450.                                 $newServiceEvent->setOriginalIva($serviceEvent->getOriginalIva());
  1451.                                 $newServiceEvent->setOriginalPrice($serviceEvent->getOriginalPrice());
  1452.                                 $newServiceEvent->setStatusRec($serviceEvent->getStatusRec());   //setStatusRecommended
  1453.                                 $newServiceEvent->setAssistantId($serviceEvent->getAssistantId());
  1454.                                 $em->persist($newServiceEvent);
  1455.                                 $em->flush();
  1456.                             }
  1457.                             if (!empty($serviceEvent)) {
  1458.                                 $newProductFile->setOriginId($newServiceEvent->getId());
  1459.                             } else {
  1460.                                 $newProductFile->setOriginId(null);
  1461.                             }
  1462.                         }
  1463.                         //FIN: Duplicamos en Eventos
  1464.                         //FIN: Si el producto esta sincronizado con un proposal debemos crear un servicio nuevo en el proposal
  1465.                         $newProductFile->setProductName($product->getProductName());
  1466.                         $newProductFile->setProductId($product->getProductId());
  1467.                         $newProductFile->setDateStart($product->getDateStart());
  1468.                         $newProductFile->setDateEnd($product->getDateEnd());
  1469.                         $newProductFile->setServicePrice($product->getServicePrice());
  1470.                         $newProductFile->setFileId($product->getFileId());
  1471.                         $newProductFile->setPax($product->getPax());
  1472.                         $newProductFile->setType($product->getType());
  1473.                         $newProductFile->setHourStart($product->getHourStart());
  1474.                         $newProductFile->setMinStart($product->getMinStart());
  1475.                         $newProductFile->setHourEnd($product->getHourEnd());
  1476.                         $newProductFile->setMinEnd($product->getMinEnd());
  1477.                         $newProductFile->setDescription($product->getDescription());
  1478.                         $newProductFile->setServiceIdProposal($product->getServiceIdProposal());
  1479.                         $newProductFile->setServiceIdFather($product->getServiceIdFather());
  1480.                         $newProductFile->setControlId($product->getControlId());
  1481.                         $newProductFile->setProposalId($product->getProposalId());
  1482.                         $newProductFile->setDestinationId($product->getDestinationId());
  1483.                         $newProductFile->setIdeaId($product->getIdeaId());
  1484.                         $newProductFile->setActivityId($product->getActivityId());
  1485.                         $newProductFile->setSupplierId($product->getSupplierId());
  1486.                         $newProductFile->setAssistantId($product->getAssistantId());
  1487.                         $newProductFile->setServiceId($product->getServiceId());
  1488.                         $newProductFile->setServiceCatId($product->getServiceCatId());
  1489.                         $newProductFile->setServiceCatName($product->getServiceCatName());
  1490.                         $newProductFile->setName($product->getName());
  1491.                         $newProductFile->setPrice($product->getPrice());
  1492.                         $newProductFile->setCurrency($product->getCurrency());
  1493.                         $newProductFile->setUnits($product->getUnits());
  1494.                         $newProductFile->setOpCommission($product->getOpCommission());
  1495.                         $newProductFile->setCommission($product->getCommission());
  1496.                         $newProductFile->setOpOver($product->getOpOver());
  1497.                         $newProductFile->setOver($product->getOver());
  1498.                         $newProductFile->setOpIva($product->getOpIva());
  1499.                         $newProductFile->setIva($product->getIva());
  1500.                         $newProductFile->setHour($product->getHour());
  1501.                         $newProductFile->setDateInAt($product->getDateInAt());
  1502.                         $newProductFile->setDateOutAt($product->getDateOutAt());
  1503.                         $newProductFile->setContcolor($product->getContcolor());
  1504.                         $newProductFile->setRankQuote($product->getRankQuote());
  1505.                         $newProductFile->setRenovate($product->getRenovate());
  1506.                         $newProductFile->setPay($product->getPay());
  1507.                         $newProductFile->setSubTotalPrice($product->getSubTotalPrice());
  1508.                         $newProductFile->setDays($product->getDays());
  1509.                         $newProductFile->setCreatedAt(new DateTime('now'));
  1510.                         $newProductFile->setCreatedId($user_id);
  1511.                         $newProductFile->setUpdatedAt(new DateTime('now'));
  1512.                         $newProductFile->setUpdatedId($user_id);
  1513.                         $em->persist($newProductFile);
  1514.                         $em->flush();
  1515.                     }
  1516.                     //FIN: Creamos el nuevo ProductFile para evitar cruce de datos entre proformas
  1517.                     $itemProforma = new AveDocProformaItems();
  1518.                     $itemProforma->setType('PRODUCT');
  1519.                     $itemProforma->setFileId($id);
  1520.                     $itemProforma->setProformaId($proforma_number);
  1521.                     if ($boolKeyChange) {
  1522.                         $itemProforma->setControlId($newProductFile->getId());
  1523.                     } else {
  1524.                         $itemProforma->setControlId($key);
  1525.                     }
  1526.                     $em->persist($itemProforma);
  1527.                     $em->flush();
  1528.                     //Acumulamos neto e iva para la factura (PROFORMA)
  1529.                     //                    $valorTotalNet = $valorTotalNet + $product->getServicePrice();
  1530.                     $valorTotalNet $valorTotalNet $product->getSubTotalPrice();
  1531.                     //                    $valorVat = $valorVat + round(($product->getServicePrice() * 0.21), 2, PHP_ROUND_HALF_UP);
  1532.                     $valorVat $valorVat round(($product->getSubTotalPrice() * 0.21), 2PHP_ROUND_HALF_UP);
  1533.                 }
  1534.             }
  1535.         }
  1536.         if (!empty($arrayBools['service'])) {
  1537.             foreach ($arrayBools['service'] as $key => $item) {
  1538.                 if ($item == 'true') {
  1539.                     $boolMakeInvoice true;
  1540.                     $servicio $em->getRepository(AveServices::class)->findOneById($key);
  1541.                     $itemProforma = new AveDocProformaItems();
  1542.                     $itemProforma->setType('SERVICE');
  1543.                     $itemProforma->setFileId($id);
  1544.                     $itemProforma->setProformaId($proforma_number);
  1545.                     $itemProforma->setControlId($key);
  1546.                     $em->persist($itemProforma);
  1547.                     $em->flush();
  1548.                     //Acumulamos neto e iva para la factura
  1549.                     if (is_null($servicio->getPrice()) or empty($servicio->getPrice())) {
  1550.                         $subtotal 0;
  1551.                         $neto 0;
  1552.                         $subtotalService 0;
  1553.                     } else {
  1554.                         $subtotalService $servicio->getPrice();
  1555.                         $subneto $servicio->getPrice();
  1556.                         // Commission
  1557.                         if ($servicio->getOpCommission() == '1') {
  1558.                             $subtotalService $subtotalService * (+ ($servicio->getCommission() / 100));
  1559.                             $subneto $subneto * (+ ($servicio->getCommission() / 100));
  1560.                         } else {
  1561.                             $subtotalService $subtotalService * (- ($servicio->getCommission() / 100));
  1562.                             $subneto $subneto * (- ($servicio->getCommission() / 100));
  1563.                         }
  1564.                         // Over
  1565.                         if ($servicio->getOpOver() == '1') {
  1566.                             $subtotalService $subtotalService $servicio->getOver();
  1567.                             $subneto $subneto $servicio->getOver();
  1568.                         } else {
  1569.                             $subtotalService $subtotalService $servicio->getOver();
  1570.                             $subneto $subneto $servicio->getOver();
  1571.                         }
  1572.                         // IVA
  1573.                         if ($servicio->getOpIva() == '1') {
  1574.                             $subtotalService $subtotalService * (+ ($servicio->getIva() / 100));
  1575.                         } else {
  1576.                             $subtotalService $servicio->getPrice();
  1577.                             $subneto = ($subneto 100) / (100 $servicio->getIva());
  1578.                         }
  1579.                         switch ($servicio->getServiceCatId()) {
  1580.                             case 1// Alojamiento
  1581.                                 // el numero de noches $numNoches; precio unitario $subneto
  1582.                                 $numNoches = (($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days;
  1583.                                 // La personas no afectan este calculo
  1584.                                 $subtotal $subtotalService $numNoches $servicio->getUnits();
  1585.                                 $subnetoUnit $subneto;
  1586.                                 $subneto $subneto $numNoches $servicio->getUnits();
  1587.                                 break;
  1588.                             case 2//Actividades
  1589.                                 // El nĂºmero de personas es considerado en el calculo
  1590.                                 $pax $servicio->getPax();
  1591.                                 if (empty($pax) or $pax == "0") {
  1592.                                     $pax 1;
  1593.                                 }
  1594.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1595.                                 if ($days 1) {
  1596.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1597.                                 } else {
  1598.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1599.                                 }
  1600.                                 $subtotal $subtotalService $days $servicio->getUnits();
  1601.                                 $subnetoUnit $subneto;
  1602.                                 $subneto $subneto $days $servicio->getUnits();
  1603.                                 break;
  1604.                             case 3// AV
  1605.                                 $pax $servicio->getPax();
  1606.                                 if (empty($pax) or $pax == "0") {
  1607.                                     $pax 1;
  1608.                                 }
  1609.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1610.                                 if ($days 1) {
  1611.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1612.                                 } else {
  1613.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1614.                                 }
  1615.                                 $unitsServ $servicio->getUnits();
  1616.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1617.                                     $unitsServ 1;
  1618.                                 }
  1619.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1620.                                 $subnetoUnit $subneto;
  1621.                                 $subneto $subneto $days $unitsServ $pax;
  1622.                                 break;
  1623.                             case 4//Creative
  1624.                                 $pax $servicio->getPax();
  1625.                                 if (empty($pax) or $pax == "0") {
  1626.                                     $pax 1;
  1627.                                 }
  1628.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1629.                                 if ($days 1) {
  1630.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1631.                                 } else {
  1632.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1633.                                 }
  1634.                                 $unitsServ $servicio->getUnits();
  1635.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1636.                                     $unitsServ 1;
  1637.                                 }
  1638.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1639.                                 $subnetoUnit $subneto;
  1640.                                 $subneto $subneto $days $unitsServ $pax;
  1641.                                 break;
  1642.                             case 5//Cruise
  1643.                                 $pax $servicio->getPax();
  1644.                                 if (empty($pax) or $pax == "0") {
  1645.                                     $pax 1;
  1646.                                 }
  1647.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days);
  1648.                                 if ($days 1) {
  1649.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1650.                                 } else {
  1651.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1652.                                 }
  1653.                                 $unitsServ $servicio->getUnits();
  1654.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1655.                                     $unitsServ 1;
  1656.                                 }
  1657.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1658.                                 $subnetoUnit $subneto;
  1659.                                 $subneto $subneto $days $unitsServ $pax;
  1660.                                 break;
  1661.                             case 6//Entertaiment
  1662.                                 $pax $servicio->getPax();
  1663.                                 if (empty($pax) or $pax == "0") {
  1664.                                     $pax 1;
  1665.                                 }
  1666.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1667.                                 if ($days 1) {
  1668.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1669.                                 } else {
  1670.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1671.                                 }
  1672.                                 $unitsServ $servicio->getUnits();
  1673.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1674.                                     $unitsServ 1;
  1675.                                 }
  1676.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1677.                                 $subnetoUnit $subneto;
  1678.                                 $subneto $subneto $days $unitsServ $pax;
  1679.                                 break;
  1680.                             case 7// Gifts
  1681.                                 $pax $servicio->getPax();
  1682.                                 if (empty($pax) or $pax == "0") {
  1683.                                     $pax 1;
  1684.                                 }
  1685.                                 $days 1;
  1686.                                 if ($days 1) {
  1687.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1688.                                 } else {
  1689.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1690.                                 }
  1691.                                 $unitsServ $servicio->getUnits();
  1692.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1693.                                     $unitsServ 1;
  1694.                                 }
  1695.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1696.                                 $subnetoUnit $subneto;
  1697.                                 $subneto $subneto $days $unitsServ $pax;
  1698.                                 break;
  1699.                             case 8//Guide
  1700.                                 $pax $servicio->getPax();
  1701.                                 if (empty($pax) or $pax == "0") {
  1702.                                     $pax 1;
  1703.                                 }
  1704.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1705.                                 if ($days 1) {
  1706.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1707.                                 } else {
  1708.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1709.                                 }
  1710.                                 $unitsServ $servicio->getUnits();
  1711.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1712.                                     $unitsServ 1;
  1713.                                 }
  1714.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1715.                                 $subnetoUnit $subneto;
  1716.                                 $subneto $subneto $days $unitsServ $pax;
  1717.                                 break;
  1718.                             case 9//Itineraries
  1719.                                 $pax $servicio->getPax();
  1720.                                 if (empty($pax) or $pax == "0") {
  1721.                                     $pax 1;
  1722.                                 }
  1723.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1724.                                 if ($days 1) {
  1725.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1726.                                 } else {
  1727.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1728.                                 }
  1729.                                 $unitsServ $servicio->getUnits();
  1730.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1731.                                     $unitsServ 1;
  1732.                                 }
  1733.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1734.                                 $subnetoUnit $subneto;
  1735.                                 $subneto $subneto $days $unitsServ $pax;
  1736.                                 break;
  1737.                             case 10//Lounge  -- No Aplica  6*6*6 en GreenPatio no, pero en Develup ???
  1738.                                 break;
  1739.                             case 11//Menu
  1740.                                 $pax $servicio->getPax();
  1741.                                 if (empty($pax) or $pax == "0") {
  1742.                                     $pax 1;
  1743.                                 }
  1744.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1745.                                 if ($days 1) {
  1746.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1747.                                 } else {
  1748.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1749.                                 }
  1750.                                 $unitsServ $servicio->getUnits();
  1751.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1752.                                     $unitsServ 1;
  1753.                                 }
  1754.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1755.                                 $subnetoUnit $subneto;
  1756.                                 $subneto $subneto $days $unitsServ $pax;
  1757.                                 break;
  1758.                             case 12//Others
  1759.                                 $pax $servicio->getPax();
  1760.                                 if (empty($pax) or $pax == "0") {
  1761.                                     $pax 1;
  1762.                                 }
  1763.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1764.                                 if ($days 1) {
  1765.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1766.                                 } else {
  1767.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1768.                                 }
  1769.                                 $unitsServ $servicio->getUnits();
  1770.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1771.                                     $unitsServ 1;
  1772.                                 }
  1773.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1774.                                 $subnetoUnit $subneto;
  1775.                                 $subneto $subneto $days $unitsServ $pax;
  1776.                                 break;
  1777.                             case 13//Transport
  1778.                                 $pax $servicio->getPax();
  1779.                                 if (empty($pax) or $pax == "0") {
  1780.                                     $pax 1;
  1781.                                 }
  1782.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1783.                                 if ($days 1) {
  1784.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1785.                                 } else {
  1786.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1787.                                 }
  1788.                                 $unitsServ $servicio->getUnits();
  1789.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1790.                                     $unitsServ 1;
  1791.                                 }
  1792.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1793.                                 $subnetoUnit $subneto;
  1794.                                 $subneto $subneto $days $unitsServ $pax;
  1795.                                 break;
  1796.                             case 14//Technology
  1797.                                 $pax $servicio->getPax();
  1798.                                 if (empty($pax) or $pax == "0") {
  1799.                                     $pax 1;
  1800.                                 }
  1801.                                 $days 1;
  1802.                                 $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1803.                                 $unitsServ $servicio->getUnits();
  1804.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1805.                                     $unitsServ 1;
  1806.                                 }
  1807.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1808.                                 $subnetoUnit $subneto;
  1809.                                 $subneto $subneto $days $unitsServ $pax;
  1810.                                 break;
  1811.                             case 15//Assisstant
  1812.                                 $pax $servicio->getPax();
  1813.                                 if (empty($pax) or $pax == "0") {
  1814.                                     $pax 1;
  1815.                                 }
  1816.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1817.                                 if ($days 1) {
  1818.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1819.                                 } else {
  1820.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1821.                                 }
  1822.                                 $unitsServ $servicio->getUnits();
  1823.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1824.                                     $unitsServ 1;
  1825.                                 }
  1826.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1827.                                 $subnetoUnit $subneto;
  1828.                                 $subneto $subneto $days $unitsServ $pax;
  1829.                                 break;
  1830.                             case 16//DDR
  1831.                                 $pax $servicio->getPax();
  1832.                                 if (empty($pax) or $pax == "0") {
  1833.                                     $pax 1;
  1834.                                 }
  1835.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1836.                                 if ($days 1) {
  1837.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1838.                                 } else {
  1839.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1840.                                 }
  1841.                                 $unitsServ $servicio->getUnits();
  1842.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1843.                                     $unitsServ 1;
  1844.                                 }
  1845.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1846.                                 $subnetoUnit $subneto;
  1847.                                 $subneto $subneto $days $unitsServ $pax;
  1848.                                 break;
  1849.                             default:
  1850.                                 break;
  1851.                         }
  1852.                         // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  1853.                         $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  1854.                         $neto round($subneto2PHP_ROUND_HALF_UP);
  1855.                         $valorTotalNet $valorTotalNet $neto;
  1856.                         $valorVat $valorVat + ($subtotal $neto);
  1857.                     }
  1858.                 }
  1859.             }
  1860.         }
  1861.         if (!empty($arrayBools['payment'])) {
  1862.             foreach ($arrayBools['payment'] as $key => $item) {
  1863.                 if ($item == 'true') {
  1864.                     $boolMakeInvoice true;
  1865.                     $pago $em->getRepository(AvePaymentsClient::class)->findOneById($key);
  1866.                     $itemProforma = new AveDocProformaItems();
  1867.                     $itemProforma->setType('PAYMENT');
  1868.                     $itemProforma->setFileId($id);
  1869.                     $itemProforma->setProformaId($proforma_number);
  1870.                     $itemProforma->setControlId($key);
  1871.                     $em->persist($itemProforma);
  1872.                     $em->flush();
  1873.                 }
  1874.             }
  1875.         }
  1876.         //FIN: Creamos los items de la proforma
  1877.         $valorTotal $valorTotalNet $valorVat;
  1878.         //INICIO: Creamos la proforma
  1879.         $newProforma = new AveDocProforma();
  1880.         $newProforma->setPrefix($proforma_prefix);
  1881.         $newProforma->setDateAt(new DateTime('now'));
  1882.         $newProforma->setFileId($id);
  1883.         $newProforma->setCreatedAt(new DateTime('now'));
  1884.         $newProforma->setCreatedId($user_id);
  1885.         $newProforma->setUpdatedAt(new DateTime('now'));
  1886.         $newProforma->setUpdatedId($user_id);
  1887.         $newProforma->setItems(null);
  1888.         $newProforma->setAccessKey(null);
  1889.         if ($boolMakeInvoice) {
  1890.             // Solo se debe crear proforma si hay un elemento
  1891.             $em->persist($newProforma);
  1892.             $em->flush();
  1893.         } else {
  1894.             // Se llama a la vista de editar el expediente
  1895.             return $this->redirectToRoute('ave_edit_file', array('id' => $id));
  1896.         }
  1897.         //FIN: Creamos la proforma
  1898.         return $this->redirectToRoute('ave_select_invoice', array('id' => $id));
  1899.     }
  1900.     /**
  1901.      * @Route("/newproforma/", name="ave_new_proforma")
  1902.      * Crear nueva proforma con los elementos seleccionados
  1903.      */
  1904.     public function generateNewProformaAction(Request $request)
  1905.     {
  1906.         $em $this->getDoctrine()->getManager();
  1907.         // Se genera y muestra en nueva pantalla la nueva proforma
  1908.         $arrayBools = array(
  1909.             'product' => null,
  1910.             'service' => null,
  1911.             'payment' => null,
  1912.         );
  1913.         $arrayBools['product'] = $request->request->get('lounge_hidden_bool');
  1914.         $arrayBools['service'] = $request->request->get('service_hidden_bool');
  1915.         $arrayBools['payment'] = $request->request->get('payment_hidden_bool');
  1916.         $id $request->request->get('file_id');
  1917.         $proforma_number $request->request->get('proforma_number');
  1918.         $proforma_prefix $request->request->get('proforma_prefix') . $proforma_number '-' $id;
  1919.         //INICIO: buscamos el ID de la factura
  1920.         $boolMakeInvoice false;  // Control para verificar si se debe hacer (PROFORMA) o todos los indicadores (sala, servicios y pagos) estaban en falso
  1921.         //FIN: buscamos el ID de la factura
  1922.         /* Obtengo usuario logueado */
  1923.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1924.         $user_id $user_logueado->getId();
  1925.         //Acumuladores de datos globales de la factura
  1926.         $valorTotalNet $valorVat 0;
  1927.         //INICIO: Creamos los items de la proforma
  1928.         if (!empty($arrayBools['product'])) {
  1929.             foreach ($arrayBools['product'] as $key => $item) {
  1930.                 if ($item == 'true') {
  1931.                     $boolMakeInvoice true;
  1932.                     $product $em->getRepository(AveProductFile::class)->findOneById($key);
  1933.                     $boolKeyChange false;
  1934.                     //INICIO: Creamos el nuevo ProductFile para evitar cruce de datos entre proformas
  1935.                     // Si el producto esta contenido en una proforma debemos crear un nuevo porducto
  1936.                     $productInProforma $em->getRepository(AveDocProformaItems::class)->findOneByControlId($key);
  1937.                     $productInProforma null;                  // Duplicacion innecesaria
  1938.                     if (!empty($productInProforma)) {
  1939.                         //INICIO: Si el producto esta sincronizado con un proposal debemos crear un servicio nuevo en el proposal
  1940.                         $boolKeyChange true;
  1941.                         $newProductFile = new AveProductFile();
  1942.                         //INICIO: Duplicamos en Eventos
  1943.                         if (!empty($product->getOriginId())) {
  1944.                             $serviceEvent $em->getRepository(ProposalSupplierServices::class)->findOneById($product->getOriginId());
  1945.                             if (!empty($serviceEvent)) {
  1946.                                 $newServiceEvent = new ProposalSupplierServices();
  1947.                                 $newServiceEvent->setServiceIdFather($serviceEvent->getServiceIdFather());
  1948.                                 $newServiceEvent->setControlId($serviceEvent->getControlId());
  1949.                                 $newServiceEvent->setProposalId($serviceEvent->getProposalId());
  1950.                                 $newServiceEvent->setDestinationId($serviceEvent->getDestinationId());
  1951.                                 $newServiceEvent->setSupplierId($serviceEvent->getSupplierId());
  1952.                                 $newServiceEvent->setIdeaId($serviceEvent->getIdeaId());
  1953.                                 $newServiceEvent->setActivityId($serviceEvent->getActivityId());
  1954.                                 $newServiceEvent->setServiceId($serviceEvent->getServiceId());
  1955.                                 $newServiceEvent->setServiceCatId($serviceEvent->getServiceCatId());
  1956.                                 $newServiceEvent->setServiceCatName($serviceEvent->getServiceCatName());
  1957.                                 $newServiceEvent->setName($serviceEvent->getName());
  1958.                                 $newServiceEvent->setPrice($serviceEvent->getPrice());
  1959.                                 $newServiceEvent->setCurrency($serviceEvent->getCurrency());
  1960.                                 $newServiceEvent->setUnits($serviceEvent->getUnits());
  1961.                                 $newServiceEvent->setCommission($serviceEvent->getCommission());
  1962.                                 $newServiceEvent->setOver($serviceEvent->getOver());
  1963.                                 $newServiceEvent->setIva($serviceEvent->getIva());
  1964.                                 $newServiceEvent->setPax($serviceEvent->getPax());
  1965.                                 $newServiceEvent->setHour($serviceEvent->getHour());
  1966.                                 $newServiceEvent->setDateInAt($serviceEvent->getDateInAt());
  1967.                                 $newServiceEvent->setDateOutAt($serviceEvent->getDateOutAt());
  1968.                                 $newServiceEvent->setDirectPayment($serviceEvent->getDirectPayment());
  1969.                                 $newServiceEvent->setStatus($serviceEvent->getStatus());
  1970.                                 $newServiceEvent->setCreatedAt(new DateTime('now'));
  1971.                                 $newServiceEvent->setCreatedId($user_id);
  1972.                                 $newServiceEvent->setUpdatedAt(new DateTime('now'));
  1973.                                 $newServiceEvent->setUpdatedId($user_id);
  1974.                                 $newServiceEvent->setStatusinternal($serviceEvent->getStatusinternal());
  1975.                                 $newServiceEvent->setPreCommission($serviceEvent->getPreCommission());
  1976.                                 $newServiceEvent->setPreIva($serviceEvent->getPreIva());
  1977.                                 $newServiceEvent->setDateBlockLimit($serviceEvent->getDateBlockLimit());
  1978.                                 $newServiceEvent->setOpCommission($serviceEvent->getOpCommission());
  1979.                                 $newServiceEvent->setOpOver($serviceEvent->getOpOver());
  1980.                                 $newServiceEvent->setOpIva($serviceEvent->getOpIva());
  1981.                                 $newServiceEvent->setBreakdown($serviceEvent->getBreakdown());
  1982.                                 $newServiceEvent->setIsFather($serviceEvent->getIsFather());
  1983.                                 $newServiceEvent->setRankQuote($serviceEvent->getRankQuote());
  1984.                                 $newServiceEvent->setOriginalopIva($serviceEvent->getOriginalopIva());
  1985.                                 $newServiceEvent->setOriginalIva($serviceEvent->getOriginalIva());
  1986.                                 $newServiceEvent->setOriginalPrice($serviceEvent->getOriginalPrice());
  1987.                                 $newServiceEvent->setStatusRec($serviceEvent->getStatusRec());   //setStatusRecommended
  1988.                                 $newServiceEvent->setAssistantId($serviceEvent->getAssistantId());
  1989.                                 $em->persist($newServiceEvent);
  1990.                                 $em->flush();
  1991.                             }
  1992.                             if (!empty($serviceEvent)) {
  1993.                                 $newProductFile->setOriginId($newServiceEvent->getId());
  1994.                             } else {
  1995.                                 $newProductFile->setOriginId(null);
  1996.                             }
  1997.                         }
  1998.                         //FIN: Duplicamos en Eventos
  1999.                         //FIN: Si el producto esta sincronizado con un proposal debemos crear un servicio nuevo en el proposal
  2000.                         $newProductFile->setProductName($product->getProductName());
  2001.                         $newProductFile->setProductId($product->getProductId());
  2002.                         $newProductFile->setDateStart($product->getDateStart());
  2003.                         $newProductFile->setDateEnd($product->getDateEnd());
  2004.                         $newProductFile->setServicePrice($product->getServicePrice());
  2005.                         $newProductFile->setFileId($product->getFileId());
  2006.                         $newProductFile->setPax($product->getPax());
  2007.                         $newProductFile->setType($product->getType());
  2008.                         $newProductFile->setHourStart($product->getHourStart());
  2009.                         $newProductFile->setMinStart($product->getMinStart());
  2010.                         $newProductFile->setHourEnd($product->getHourEnd());
  2011.                         $newProductFile->setMinEnd($product->getMinEnd());
  2012.                         $newProductFile->setDescription($product->getDescription());
  2013.                         $newProductFile->setServiceIdProposal($product->getServiceIdProposal());
  2014.                         $newProductFile->setServiceIdFather($product->getServiceIdFather());
  2015.                         $newProductFile->setControlId($product->getControlId());
  2016.                         $newProductFile->setProposalId($product->getProposalId());
  2017.                         $newProductFile->setDestinationId($product->getDestinationId());
  2018.                         $newProductFile->setIdeaId($product->getIdeaId());
  2019.                         $newProductFile->setActivityId($product->getActivityId());
  2020.                         $newProductFile->setSupplierId($product->getSupplierId());
  2021.                         $newProductFile->setAssistantId($product->getAssistantId());
  2022.                         $newProductFile->setServiceId($product->getServiceId());
  2023.                         $newProductFile->setServiceCatId($product->getServiceCatId());
  2024.                         $newProductFile->setServiceCatName($product->getServiceCatName());
  2025.                         $newProductFile->setName($product->getName());
  2026.                         $newProductFile->setPrice($product->getPrice());
  2027.                         $newProductFile->setCurrency($product->getCurrency());
  2028.                         $newProductFile->setUnits($product->getUnits());
  2029.                         $newProductFile->setOpCommission($product->getOpCommission());
  2030.                         $newProductFile->setCommission($product->getCommission());
  2031.                         $newProductFile->setOpOver($product->getOpOver());
  2032.                         $newProductFile->setOver($product->getOver());
  2033.                         $newProductFile->setOpIva($product->getOpIva());
  2034.                         $newProductFile->setIva($product->getIva());
  2035.                         $newProductFile->setHour($product->getHour());
  2036.                         $newProductFile->setDateInAt($product->getDateInAt());
  2037.                         $newProductFile->setDateOutAt($product->getDateOutAt());
  2038.                         $newProductFile->setContcolor($product->getContcolor());
  2039.                         $newProductFile->setRankQuote($product->getRankQuote());
  2040.                         $newProductFile->setRenovate($product->getRenovate());
  2041.                         $newProductFile->setPay($product->getPay());
  2042.                         $newProductFile->setSubTotalPrice($product->getSubTotalPrice());
  2043.                         $newProductFile->setDays($product->getDays());
  2044.                         $newProductFile->setCreatedAt(new DateTime('now'));
  2045.                         $newProductFile->setCreatedId($user_id);
  2046.                         $newProductFile->setUpdatedAt(new DateTime('now'));
  2047.                         $newProductFile->setUpdatedId($user_id);
  2048.                         $em->persist($newProductFile);
  2049.                         $em->flush();
  2050.                     }
  2051.                     //FIN: Creamos el nuevo ProductFile para evitar cruce de datos entre proformas
  2052.                     $itemProforma = new AveDocProformaItems();
  2053.                     $itemProforma->setType('PRODUCT');
  2054.                     $itemProforma->setFileId($id);
  2055.                     $itemProforma->setProformaId($proforma_number);
  2056.                     if ($boolKeyChange) {
  2057.                         $itemProforma->setControlId($newProductFile->getId());
  2058.                     } else {
  2059.                         $itemProforma->setControlId($key);
  2060.                     }
  2061.                     $em->persist($itemProforma);
  2062.                     $em->flush();
  2063.                     //Acumulamos neto e iva para la factura (PROFORMA)
  2064.                     //                    $valorTotalNet = $valorTotalNet + $product->getServicePrice();
  2065.                     $valorTotalNet $valorTotalNet $product->getSubTotalPrice();
  2066.                     if ($product->getIva() == '21') {
  2067.                         $valorVat $valorVat round(($product->getSubTotalPrice() * 0.21), 2PHP_ROUND_HALF_UP);
  2068.                     }
  2069.                     if ($product->getIva() == '10') {
  2070.                         $valorVat $valorVat round(($product->getSubTotalPrice() * 0.1), 2PHP_ROUND_HALF_UP);
  2071.                     }
  2072.                     if ($product->getIva() == '0') {
  2073.                         $valorVat $valorVat round(($product->getSubTotalPrice() * 0), 2PHP_ROUND_HALF_UP);
  2074.                     }
  2075.                 }
  2076.             }
  2077.         }
  2078.         if (!empty($arrayBools['service'])) {
  2079.             foreach ($arrayBools['service'] as $key => $item) {
  2080.                 if ($item == 'true') {
  2081.                     $boolMakeInvoice true;
  2082.                     $servicio $em->getRepository(AveServices::class)->findOneById($key);
  2083.                     $itemProforma = new AveDocProformaItems();
  2084.                     $itemProforma->setType('SERVICE');
  2085.                     $itemProforma->setFileId($id);
  2086.                     $itemProforma->setProformaId($proforma_number);
  2087.                     $itemProforma->setControlId($key);
  2088.                     $em->persist($itemProforma);
  2089.                     $em->flush();
  2090.                     //Acumulamos neto e iva para la factura
  2091.                     if (is_null($servicio->getPrice()) or empty($servicio->getPrice())) {
  2092.                         $subtotal 0;
  2093.                         $neto 0;
  2094.                         $subtotalService 0;
  2095.                     } else {
  2096.                         $subtotalService $servicio->getPrice();
  2097.                         $subneto $servicio->getPrice();
  2098.                         // Commission
  2099.                         if ($servicio->getOpCommission() == '1') {
  2100.                             $subtotalService $subtotalService * (+ ($servicio->getCommission() / 100));
  2101.                             $subneto $subneto * (+ ($servicio->getCommission() / 100));
  2102.                         } else {
  2103.                             $subtotalService $subtotalService * (- ($servicio->getCommission() / 100));
  2104.                             $subneto $subneto * (- ($servicio->getCommission() / 100));
  2105.                         }
  2106.                         // Over
  2107.                         if ($servicio->getOpOver() == '1') {
  2108.                             $subtotalService $subtotalService $servicio->getOver();
  2109.                             $subneto $subneto $servicio->getOver();
  2110.                         } else {
  2111.                             $subtotalService $subtotalService $servicio->getOver();
  2112.                             $subneto $subneto $servicio->getOver();
  2113.                         }
  2114.                         // IVA
  2115.                         if ($servicio->getOpIva() == '1') {
  2116.                             $subtotalService $subtotalService * (+ ($servicio->getIva() / 100));
  2117.                         } else {
  2118.                             $subtotalService $servicio->getPrice();
  2119.                             $subneto = ($subneto 100) / (100 $servicio->getIva());
  2120.                         }
  2121.                         switch ($servicio->getServiceCatId()) {
  2122.                             case 1// Alojamiento
  2123.                                 // el numero de noches $numNoches; precio unitario $subneto
  2124.                                 $numNoches = (($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days;
  2125.                                 // La personas no afectan este calculo
  2126.                                 $subtotal $subtotalService $numNoches $servicio->getUnits();
  2127.                                 $subnetoUnit $subneto;
  2128.                                 $subneto $subneto $numNoches $servicio->getUnits();
  2129.                                 break;
  2130.                             case 2//Actividades
  2131.                                 // El nĂºmero de personas es considerado en el calculo
  2132.                                 $pax $servicio->getPax();
  2133.                                 if (empty($pax) or $pax == "0") {
  2134.                                     $pax 1;
  2135.                                 }
  2136.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2137.                                 if ($days 1) {
  2138.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2139.                                 } else {
  2140.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2141.                                 }
  2142.                                 $subtotal $subtotalService $days $servicio->getUnits();
  2143.                                 $subnetoUnit $subneto;
  2144.                                 $subneto $subneto $days $servicio->getUnits();
  2145.                                 break;
  2146.                             case 3// AV
  2147.                                 $pax $servicio->getPax();
  2148.                                 if (empty($pax) or $pax == "0") {
  2149.                                     $pax 1;
  2150.                                 }
  2151.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2152.                                 if ($days 1) {
  2153.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2154.                                 } else {
  2155.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2156.                                 }
  2157.                                 $unitsServ $servicio->getUnits();
  2158.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2159.                                     $unitsServ 1;
  2160.                                 }
  2161.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2162.                                 $subnetoUnit $subneto;
  2163.                                 $subneto $subneto $days $unitsServ $pax;
  2164.                                 break;
  2165.                             case 4//Creative
  2166.                                 $pax $servicio->getPax();
  2167.                                 if (empty($pax) or $pax == "0") {
  2168.                                     $pax 1;
  2169.                                 }
  2170.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2171.                                 if ($days 1) {
  2172.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2173.                                 } else {
  2174.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2175.                                 }
  2176.                                 $unitsServ $servicio->getUnits();
  2177.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2178.                                     $unitsServ 1;
  2179.                                 }
  2180.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2181.                                 $subnetoUnit $subneto;
  2182.                                 $subneto $subneto $days $unitsServ $pax;
  2183.                                 break;
  2184.                             case 5//Cruise
  2185.                                 $pax $servicio->getPax();
  2186.                                 if (empty($pax) or $pax == "0") {
  2187.                                     $pax 1;
  2188.                                 }
  2189.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days);
  2190.                                 if ($days 1) {
  2191.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2192.                                 } else {
  2193.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2194.                                 }
  2195.                                 $unitsServ $servicio->getUnits();
  2196.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2197.                                     $unitsServ 1;
  2198.                                 }
  2199.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2200.                                 $subnetoUnit $subneto;
  2201.                                 $subneto $subneto $days $unitsServ $pax;
  2202.                                 break;
  2203.                             case 6//Entertaiment
  2204.                                 $pax $servicio->getPax();
  2205.                                 if (empty($pax) or $pax == "0") {
  2206.                                     $pax 1;
  2207.                                 }
  2208.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2209.                                 if ($days 1) {
  2210.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2211.                                 } else {
  2212.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2213.                                 }
  2214.                                 $unitsServ $servicio->getUnits();
  2215.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2216.                                     $unitsServ 1;
  2217.                                 }
  2218.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2219.                                 $subnetoUnit $subneto;
  2220.                                 $subneto $subneto $days $unitsServ $pax;
  2221.                                 break;
  2222.                             case 7// Gifts
  2223.                                 $pax $servicio->getPax();
  2224.                                 if (empty($pax) or $pax == "0") {
  2225.                                     $pax 1;
  2226.                                 }
  2227.                                 $days 1;
  2228.                                 if ($days 1) {
  2229.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2230.                                 } else {
  2231.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2232.                                 }
  2233.                                 $unitsServ $servicio->getUnits();
  2234.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2235.                                     $unitsServ 1;
  2236.                                 }
  2237.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2238.                                 $subnetoUnit $subneto;
  2239.                                 $subneto $subneto $days $unitsServ $pax;
  2240.                                 break;
  2241.                             case 8//Guide
  2242.                                 $pax $servicio->getPax();
  2243.                                 if (empty($pax) or $pax == "0") {
  2244.                                     $pax 1;
  2245.                                 }
  2246.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2247.                                 if ($days 1) {
  2248.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2249.                                 } else {
  2250.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2251.                                 }
  2252.                                 $unitsServ $servicio->getUnits();
  2253.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2254.                                     $unitsServ 1;
  2255.                                 }
  2256.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2257.                                 $subnetoUnit $subneto;
  2258.                                 $subneto $subneto $days $unitsServ $pax;
  2259.                                 break;
  2260.                             case 9//Itineraries
  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 10//Lounge  -- No Aplica  6*6*6 en GreenPatio no, pero en Develup ???
  2280.                                 break;
  2281.                             case 11//Menu
  2282.                                 $pax $servicio->getPax();
  2283.                                 if (empty($pax) or $pax == "0") {
  2284.                                     $pax 1;
  2285.                                 }
  2286.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2287.                                 if ($days 1) {
  2288.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2289.                                 } else {
  2290.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2291.                                 }
  2292.                                 $unitsServ $servicio->getUnits();
  2293.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2294.                                     $unitsServ 1;
  2295.                                 }
  2296.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2297.                                 $subnetoUnit $subneto;
  2298.                                 $subneto $subneto $days $unitsServ $pax;
  2299.                                 break;
  2300.                             case 12//Others
  2301.                                 $pax $servicio->getPax();
  2302.                                 if (empty($pax) or $pax == "0") {
  2303.                                     $pax 1;
  2304.                                 }
  2305.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2306.                                 if ($days 1) {
  2307.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2308.                                 } else {
  2309.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2310.                                 }
  2311.                                 $unitsServ $servicio->getUnits();
  2312.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2313.                                     $unitsServ 1;
  2314.                                 }
  2315.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2316.                                 $subnetoUnit $subneto;
  2317.                                 $subneto $subneto $days $unitsServ $pax;
  2318.                                 break;
  2319.                             case 13//Transport
  2320.                                 $pax $servicio->getPax();
  2321.                                 if (empty($pax) or $pax == "0") {
  2322.                                     $pax 1;
  2323.                                 }
  2324.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2325.                                 if ($days 1) {
  2326.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2327.                                 } else {
  2328.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2329.                                 }
  2330.                                 $unitsServ $servicio->getUnits();
  2331.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2332.                                     $unitsServ 1;
  2333.                                 }
  2334.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2335.                                 $subnetoUnit $subneto;
  2336.                                 $subneto $subneto $days $unitsServ $pax;
  2337.                                 break;
  2338.                             case 14//Technology
  2339.                                 $pax $servicio->getPax();
  2340.                                 if (empty($pax) or $pax == "0") {
  2341.                                     $pax 1;
  2342.                                 }
  2343.                                 $days 1;
  2344.                                 $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2345.                                 $unitsServ $servicio->getUnits();
  2346.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2347.                                     $unitsServ 1;
  2348.                                 }
  2349.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2350.                                 $subnetoUnit $subneto;
  2351.                                 $subneto $subneto $days $unitsServ $pax;
  2352.                                 break;
  2353.                             case 15//Assisstant
  2354.                                 $pax $servicio->getPax();
  2355.                                 if (empty($pax) or $pax == "0") {
  2356.                                     $pax 1;
  2357.                                 }
  2358.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2359.                                 if ($days 1) {
  2360.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2361.                                 } else {
  2362.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2363.                                 }
  2364.                                 $unitsServ $servicio->getUnits();
  2365.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2366.                                     $unitsServ 1;
  2367.                                 }
  2368.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2369.                                 $subnetoUnit $subneto;
  2370.                                 $subneto $subneto $days $unitsServ $pax;
  2371.                                 break;
  2372.                             case 16//DDR
  2373.                                 $pax $servicio->getPax();
  2374.                                 if (empty($pax) or $pax == "0") {
  2375.                                     $pax 1;
  2376.                                 }
  2377.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2378.                                 if ($days 1) {
  2379.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2380.                                 } else {
  2381.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2382.                                 }
  2383.                                 $unitsServ $servicio->getUnits();
  2384.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2385.                                     $unitsServ 1;
  2386.                                 }
  2387.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2388.                                 $subnetoUnit $subneto;
  2389.                                 $subneto $subneto $days $unitsServ $pax;
  2390.                                 break;
  2391.                             default:
  2392.                                 break;
  2393.                         }
  2394.                         // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  2395.                         $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  2396.                         $neto round($subneto2PHP_ROUND_HALF_UP);
  2397.                         $valorTotalNet $valorTotalNet $neto;
  2398.                         $valorVat $valorVat + ($subtotal $neto);
  2399.                     }
  2400.                 }
  2401.             }
  2402.         }
  2403.         if (!empty($arrayBools['payment'])) {
  2404.             foreach ($arrayBools['payment'] as $key => $item) {
  2405.                 if ($item == 'true') {
  2406.                     $boolMakeInvoice true;
  2407.                     $pago $em->getRepository(AvePaymentsClient::class)->findOneById($key);
  2408.                     $itemProforma = new AveDocProformaItems();
  2409.                     $itemProforma->setType('PAYMENT');
  2410.                     $itemProforma->setFileId($id);
  2411.                     $itemProforma->setProformaId($proforma_number);
  2412.                     $itemProforma->setControlId($key);
  2413.                     $em->persist($itemProforma);
  2414.                     $em->flush();
  2415.                 }
  2416.             }
  2417.         }
  2418.         //FIN: Creamos los items de la proforma
  2419.         $valorTotal $valorTotalNet $valorVat;
  2420.         //INICIO: Creamos la proforma
  2421.         $newProforma = new AveDocProforma();
  2422.         //        $newProforma->setPrefix("GPP-".date('dmy')."-".$id);
  2423.         $newProforma->setPrefix($proforma_prefix);
  2424.         $newProforma->setDateAt(new DateTime('now'));
  2425.         $newProforma->setFileId($id);
  2426.         $newProforma->setCreatedAt(new DateTime('now'));
  2427.         $newProforma->setCreatedId($user_id);
  2428.         $newProforma->setUpdatedAt(new DateTime('now'));
  2429.         $newProforma->setUpdatedId($user_id);
  2430.         $newProforma->setItems(null);
  2431.         $newProforma->setAccessKey(null);
  2432.         if ($boolMakeInvoice) {
  2433.             // Solo se debe crear proforma si hay un elemento
  2434.             $em->persist($newProforma);
  2435.             $em->flush();
  2436.         } else {
  2437.             // Se llama a la vista de editar el expediente
  2438.             return $this->redirectToRoute('ave_edit_file', array('id' => $id));
  2439.         }
  2440.         //FIN: Creamos la proforma
  2441.         // Actualizamos las entidades InvoiceProformaExtraField y las asociamos con la proforma
  2442.         $company $em->getRepository(SettingsCompany::class)->findOneByBusinessType(['businessType' => BusinessTypeSettingsCompanyConstants::AUDIOVISUAL]);
  2443.         $companyId $company->getId();
  2444.         $this->extraFieldService->attachUndefinedExtraFieldsToDocument($companyIdInvoiceProformaExtraFieldConstants::TYPE_PROFORMA$newProforma->getId(), null);
  2445.         return $this->redirectToRoute('ave_view_proforma', array('id' => $newProforma->getId()));
  2446.     }
  2447.     /**
  2448.      * @Route("/discardproforma/{id}",  name="ave_discard_proforma")
  2449.      * Descartar la proforma especificada en el ID
  2450.      */
  2451.     public function discardProformaAction($idRequest $request)
  2452.     {
  2453.         $em $this->getDoctrine()->getManager();
  2454.         $proforma =  $em->getRepository(AveDocProforma::class)->findOneById($id);
  2455.         $fileId $proforma->getFileId();
  2456.         //Buscamos en la tabla de proformas a enviar
  2457.         $budToPro =  $em->getRepository(AveBudgetToProforma::class)->findOneByProformaId($id);
  2458.         if (!empty($budToPro)) {
  2459.             $em->remove($budToPro);
  2460.             $em->flush();
  2461.         }
  2462.         //Eliminamos los productos dentro de la proforma
  2463.         $proformaItems =  $em->getRepository(AveDocProformaItems::class)->findByProformaId($id);
  2464.         foreach ($proformaItems as $item) {
  2465.             $em->remove($item);
  2466.             $em->flush();
  2467.         }
  2468.         //No se puede eliminar el registro porque es necesario mantener la numeraciĂ³n de las proformas si se desean generar correctamente
  2469.         $proforma->setFileId(0);
  2470.         $em->persist($proforma);
  2471.         $em->flush();
  2472.         return $this->redirectToRoute('ave_edit_file', array('id' => $fileId));
  2473.     }
  2474.     /**
  2475.      * @Route("/viewproforma/{id}",  name="ave_view_proforma")
  2476.      * Ver una proforma
  2477.      */
  2478.     public function viewProformaAction($idRequest $request)
  2479.     {
  2480.         $docType 'Proforma';
  2481.         $em $this->getDoctrine()->getManager();
  2482.         $proforma =  $em->getRepository(AveDocProforma::class)->findOneById($id);
  2483.         $id $proforma->getFileId();
  2484.         /* Obtengo usuario logueado */
  2485.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2486.         $user_id $user_logueado->getId();
  2487.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  2488.         // Buscamos el cliente
  2489.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  2490.         $client $em->getRepository(Client::class)->findById($file->getClient());
  2491.         if (empty($client)) {
  2492.             $client[0] = new Client();
  2493.             $client[0]->setName('');
  2494.             $client[0]->setTitle('');
  2495.             $client[0]->setIdDocument('');
  2496.             $client[0]->setPopulation('');
  2497.             $client[0]->setRegion('');
  2498.             $client[0]->setCountry('');
  2499.         } else {
  2500.             if (is_numeric($client[0]->getPopulation())) {
  2501.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  2502. //                $client[0]->setPopulation($city->getCity());
  2503.             }
  2504.             if (is_numeric($client[0]->getRegion())) {
  2505.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  2506. //                $client[0]->setRegion($region->getRegion());
  2507.             }
  2508.             if (is_numeric($client[0]->getCountry())) {
  2509.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  2510. //                $client[0]->setCountry($country->getCountry());
  2511.             }
  2512.         }
  2513.         if (empty($client)) {
  2514.             $client[0] = new Client();
  2515.             $client[0]->setName('');
  2516.             $client[0]->setTitle('');
  2517.             $client[0]->setIdDocument('');
  2518.             $client[0]->setPopulation('');
  2519.             $client[0]->setRegion('');
  2520.             $client[0]->setCountry('');
  2521.             $clientNew = array(
  2522.                 'name' => '',
  2523.                 'title' => '',
  2524.                 'idDocument' => '',
  2525.                 'population' => '',
  2526.                 'region' => '',
  2527.                 'country' => '',
  2528.                 'address' => '',
  2529.                 'addressNumber' => '',
  2530.                 'zipCode' => '',
  2531.                 'typeDocument' => '',
  2532.             );
  2533.         } else {
  2534.             $clientNew = array(
  2535.                 'name' => $client[0]->getName(),
  2536.                 'title' => $client[0]->getTitle(),
  2537.                 'idDocument' => $client[0]->getIdDocument(),
  2538.                 'population' => '',
  2539.                 'region' => '',
  2540.                 'country' => '',
  2541.                 'address' => $client[0]->getAddress(),
  2542.                 'addressNumber' => $client[0]->getAddressNumber(),
  2543.                 'zipCode' => $client[0]->getZipCode(),
  2544.                 'typeDocument' => $client[0]->getTypeDocument(),
  2545.             );
  2546.             if (is_numeric($client[0]->getPopulation())) {
  2547.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  2548.                 $clientNew['population'] = $city->getCity();
  2549.             }
  2550.             if (is_numeric($client[0]->getRegion())) {
  2551.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  2552.                 $clientNew['region'] = $region->getRegion();
  2553.             }
  2554.             if (is_numeric($client[0]->getCountry())) {
  2555.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  2556.                 $clientNew['country'] = $country->getCountry();
  2557.             }
  2558.         }
  2559.         // Buscamos el cliente
  2560.         $data $this->baseInvoiceDoneDocument($file->getId(), $proforma->getId(), 'P');
  2561.         $allProformas =  $em->getRepository(AveDocProforma::class)->findByFileId($id);
  2562.         // Falta agregar en $allProformas las proformas de facturas, hasta ahora solo estan las proformas de deposito  //6*6*6
  2563.         $commentsBool false;
  2564.         $comments null;
  2565.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  2566.         if ($fileAv->getCommentsInPro()) {
  2567.             $commentsBool true;
  2568.         }
  2569.         if ($commentsBool) {
  2570.             $comments $fileAv->getComments();
  2571.         }
  2572.         // Obtengo usuario logueado
  2573.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2574.         $user_id $user_logueado->getId();
  2575.         // Buscamos los extrafields
  2576.         $extraFields $this->extraFieldService->getExtraFieldsIndexedByPosition($data['company']->getId(), InvoiceProformaExtraFieldConstants::TYPE_PROFORMA$proforma->getId(), null);
  2577.         return $this->render(
  2578.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
  2579.             array(
  2580.                 'id' => $id,
  2581.                 'docType' => $docType,
  2582.                 'proforma' => $proforma,
  2583.                 'company' => $company,
  2584.                 'clients' => $clientNew,
  2585.                 'file' => $file,
  2586.                 'date' => $proforma->getDateAt(),
  2587.                 'number' => $proforma->getId(),
  2588.                 'invoice' => null,
  2589.                 'fid' => $proforma->getId(),
  2590.                 'boolToRec' => false,
  2591.                 'proformas' => $allProformas,
  2592.                 'currency' => '€',
  2593.                 'user' => $user_logueado,
  2594.                 'totales_neto' => $data['totales_neto'],
  2595.                 'totales' => $data['totales'],
  2596.                 'balance' => $data['balance'],
  2597.                 'bases_imponibles' => $data['bases_imponibles'],
  2598.                 'datasupplier' => $data['datasupplier'],
  2599.                 'services' => null,
  2600.                 'facturas' => null,
  2601.                 'paymentNotIvoiced' => null,
  2602.                 'paymentsAll' => null,
  2603.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  2604.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  2605.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  2606.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  2607.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  2608.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  2609.                 'comments' => $comments,
  2610.                 'extraFields' => $extraFields,
  2611.             )
  2612.         );
  2613.     }
  2614.     /**
  2615.      * @Route("/avexternal/printproforma/{id}",  name="ave_print_proforma")
  2616.      * Imprimir una proforma
  2617.      */
  2618.     public function printProformaAction($idRequest $request)
  2619.     {
  2620.         $docType 'Proforma';
  2621.         $em $this->getDoctrine()->getManager();
  2622.         $proforma =  $em->getRepository(AveDocProforma::class)->findOneById($id);
  2623.         $id $proforma->getFileId();
  2624.         $company $em->getRepository(SettingsCompany::class)->findOneByBusinessType(['businessType' => BusinessTypeSettingsCompanyConstants::AUDIOVISUAL]);
  2625.         if ($id == 0) {
  2626.             // La proforma ha sido descartada o eliminada desde AV
  2627.             d('La proforma ha sido descartada o eliminada desde AV');
  2628.             exit();
  2629.         }
  2630.         // Buscamos el cliente
  2631.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  2632.         $client $em->getRepository(Client::class)->findById($file->getClient());
  2633.         if (empty($client)) {
  2634.             $client[0] = new Client();
  2635.             $client[0]->setName('');
  2636.             $client[0]->setTitle('');
  2637.             $client[0]->setIdDocument('');
  2638.             $client[0]->setPopulation('');
  2639.             $client[0]->setRegion('');
  2640.             $client[0]->setCountry('');
  2641.         } else {
  2642.             if (is_numeric($client[0]->getPopulation())) {
  2643.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  2644. //                $client[0]->setPopulation($city->getCity());
  2645.             }
  2646.             if (is_numeric($client[0]->getRegion())) {
  2647.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  2648. //                $client[0]->setRegion($region->getRegion());
  2649.             }
  2650.             if (is_numeric($client[0]->getCountry())) {
  2651.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  2652. //                $client[0]->setCountry($country->getCountry());
  2653.             }
  2654.         }
  2655.         if (empty($client)) {
  2656.             $client[0] = new Client();
  2657.             $client[0]->setName('');
  2658.             $client[0]->setTitle('');
  2659.             $client[0]->setIdDocument('');
  2660.             $client[0]->setPopulation('');
  2661.             $client[0]->setRegion('');
  2662.             $client[0]->setCountry('');
  2663.             $clientNew = array(
  2664.                 'name' => '',
  2665.                 'title' => '',
  2666.                 'idDocument' => '',
  2667.                 'population' => '',
  2668.                 'region' => '',
  2669.                 'country' => '',
  2670.                 'address' => '',
  2671.                 'addressNumber' => '',
  2672.                 'zipCode' => '',
  2673.                 'typeDocument' => '',
  2674.             );
  2675.         } else {
  2676.             $clientNew = array(
  2677.                 'name' => $client[0]->getName(),
  2678.                 'title' => $client[0]->getTitle(),
  2679.                 'idDocument' => $client[0]->getIdDocument(),
  2680.                 'population' => '',
  2681.                 'region' => '',
  2682.                 'country' => '',
  2683.                 'address' => $client[0]->getAddress(),
  2684.                 'addressNumber' => $client[0]->getAddressNumber(),
  2685.                 'zipCode' => $client[0]->getZipCode(),
  2686.                 'typeDocument' => $client[0]->getTypeDocument(),
  2687.             );
  2688.             if (is_numeric($client[0]->getPopulation())) {
  2689.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  2690.                 $clientNew['population'] = $city->getCity();
  2691.             }
  2692.             if (is_numeric($client[0]->getRegion())) {
  2693.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  2694.                 $clientNew['region'] = $region->getRegion();
  2695.             }
  2696.             if (is_numeric($client[0]->getCountry())) {
  2697.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  2698.                 $clientNew['country'] = $country->getCountry();
  2699.             }
  2700.         }
  2701.         // Buscamos el cliente
  2702.         $data $this->baseInvoiceDoneDocument($file->getId(), $proforma->getId(), 'P');
  2703.         $allProformas =  $em->getRepository(AveDocProformaDeposit::class)->findByFileId($id);
  2704.         $commentsBool false;
  2705.         $comments null;
  2706.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  2707.         if ($fileAv->getCommentsInPro()) {
  2708.             $commentsBool true;
  2709.         }
  2710.         if ($commentsBool) {
  2711.             $comments $fileAv->getComments();
  2712.         }
  2713.         // Buscamos los extrafields
  2714.         $extraFields $this->extraFieldService->getExtraFieldsIndexedByPosition($company->getId(), InvoiceProformaExtraFieldConstants::TYPE_PROFORMA$proforma->getId(), null);
  2715.         return $this->render(
  2716.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
  2717.             array(
  2718.                 'id' => $id,
  2719.                 'docType' => $docType,
  2720.                 'proforma' => $proforma,
  2721.                 'company' => $company,
  2722.                 'clients' => $clientNew,
  2723.                 'file' => $file,
  2724.                 'date' => $proforma->getDateAt(),
  2725.                 'number' => $proforma->getId(),
  2726.                 'invoice' => null,
  2727.                 'fid' => $proforma->getId(),
  2728.                 'boolToRec' => false,
  2729.                 'proformas' => $allProformas,
  2730.                 'currency' => '€',
  2731.                 'totales_neto' => $data['totales_neto'],
  2732.                 'totales' => $data['totales'],
  2733.                 'balance' => $data['balance'],
  2734.                 'bases_imponibles' => $data['bases_imponibles'],
  2735.                 'datasupplier' => $data['datasupplier'],
  2736.                 'services' => null,
  2737.                 'facturas' => null,
  2738.                 'paymentNotIvoiced' => null,
  2739.                 'paymentsAll' => null,
  2740.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  2741.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  2742.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  2743.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  2744.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  2745.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  2746.                 'comments' => $comments,
  2747.                 'extraFields' => $extraFields,
  2748.             )
  2749.         );
  2750.     }
  2751.     /**
  2752.      * @Route("/newinvoice/", name="ave_new_invoice")
  2753.      * Crear nueva factura con los elementos seleccionados
  2754.      */
  2755.     public function generateNewInvoiceAction(Request $request)
  2756.     {
  2757.         $em $this->getDoctrine()->getManager();
  2758.         // Se genera y muestra en nueva pantalla la nueva proforma
  2759.         $arrayBools = array(
  2760.             'product' => null,
  2761.             'service' => null,
  2762.             'payment' => null,
  2763.         );
  2764.         $arrayBools['product'] = $request->request->get('inv_lounge_hidden_bool');
  2765.         $arrayBools['service'] = $request->request->get('inv_service_hidden_bool');
  2766.         $arrayBools['payment'] = $request->request->get('inv_payment_hidden_bool');
  2767.         $id $request->request->get('inv_file_id');
  2768.         //INICIO: buscamos el ID de la factura
  2769.         $allFacturas $em->getRepository(AveDocInvoice::class)->findAll();
  2770.         if (!empty($allFacturas)) {
  2771.             $invoiceId end($allFacturas)->getId() + 1;
  2772.         } else {
  2773.             $invoiceId 1;
  2774.             //            $invoiceId = 10;    //La primera factura de AV en el sistema serĂ¡ la 10, se cambia el numero de serie a A1, A2,...
  2775.         }
  2776.         $boolMakeInvoice false;  // Control para verificar si se debe hacer factura o todos los indicadores (sala, servicios y pagos) estaban en falso
  2777.         //FIN: buscamos el ID de la factura
  2778.         /* Obtengo usuario logueado */
  2779.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2780.         $user_id $user_logueado->getId();
  2781.         //Acumuladores de datos globales de la factura
  2782.         $valorTotalNet 0;
  2783.         $valorVat 0;
  2784.         //INICIO: Creamos los items de la factura
  2785.         if (!empty($arrayBools['product'])) {
  2786.             foreach ($arrayBools['product'] as $key => $item) {
  2787.                 if ($item == 'true') {
  2788.                     $boolMakeInvoice true;
  2789.                     $sala $em->getRepository(AveProductFile::class)->findOneById($key);
  2790.                     $itemInvoice = new AveDocInvoiceItems();
  2791.                     $itemInvoice->setFileId($id);
  2792.                     $itemInvoice->setInvoiceId($invoiceId);
  2793.                     $itemInvoice->setItemType('PRODUCT');
  2794.                     $itemInvoice->setPrdControlId($key);
  2795.                     $itemInvoice->setPrdName($sala->getProductName());
  2796.                     $itemInvoice->setPrdProductId($sala->getProductId());
  2797.                     $itemInvoice->setPrdType($sala->getType());
  2798.                     $itemInvoice->setPrdDateStart($sala->getDateStart());
  2799.                     $itemInvoice->setPrdDateEnd($sala->getDateEnd());
  2800.                     $itemInvoice->setPrdServicePrice($sala->getServicePrice());
  2801.                     $itemInvoice->setPrdSubTotalPrice($sala->getSubTotalPrice());
  2802.                     $itemInvoice->setPrdQty($sala->getUnits());
  2803.                     $itemInvoice->setPrdDays($sala->getDays());
  2804.                     $itemInvoice->setPrdPax($sala->getPax());
  2805.                     $itemInvoice->setCreatedId($user_id);
  2806.                     $itemInvoice->setCreatedAt(new DateTime('now'));
  2807.                     $itemInvoice->setUpdatedId($user_id);
  2808.                     $itemInvoice->setUpdatedAt(new DateTime('now'));
  2809.                     $itemInvoice->setPrdHourStart($sala->getHourStart());
  2810.                     $itemInvoice->setPrdMinStart($sala->getMinStart());
  2811.                     $itemInvoice->setPrdHourEnd($sala->getHourEnd());
  2812.                     $itemInvoice->setPrdMinEnd($sala->getMinEnd());
  2813.                     if (empty($sala->getLocation())) {
  2814.                         $itemInvoice->setLocation(null);
  2815.                     } else {
  2816.                         $itemInvoice->setLocation($sala->getLocation());
  2817.                     }
  2818.                     $itemInvoice->setRankQuoteAv($sala->getRankQuoteAv());
  2819.                     $itemInvoice->setPrdIva($sala->getIva());
  2820.                     $itemInvoice->setPrdOpIva($sala->getOpIva());
  2821.                     $em->persist($itemInvoice);
  2822.                     $em->flush();
  2823.                     //Acumulamos neto e iva para la factura
  2824.                     //                    $valorTotalNet = $valorTotalNet + $itemInvoice->getPrdServicePrice();
  2825.                     $valorTotalNet $valorTotalNet $itemInvoice->getPrdSubTotalPrice();
  2826.                     //                    $valorVat = $valorVat + round(($itemInvoice->getPrdServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
  2827.                     $valorVat $valorVat round(($itemInvoice->getPrdSubTotalPrice() * ($sala->getIva() / 100)), 2PHP_ROUND_HALF_UP);
  2828.                 }
  2829.             }
  2830.         }
  2831.         if (!empty($arrayBools['service'])) {
  2832.             foreach ($arrayBools['service'] as $key => $item) {
  2833.                 if ($item == 'true') {
  2834.                     $boolMakeInvoice true;
  2835.                     $servicio $em->getRepository(AveServices::class)->findOneById($key);
  2836.                     $itemInvoice = new AveDocInvoiceItems();
  2837.                     $itemInvoice->setFileId($id);
  2838.                     $itemInvoice->setInvoiceId($invoiceId);
  2839.                     $itemInvoice->setItemType('SERVICE');
  2840.                     $itemInvoice->setSrvControlId($key);
  2841.                     $itemInvoice->setSrvSupplierId($servicio->getSupplierId());
  2842.                     $itemInvoice->setSrvServiceId($servicio->getServiceId());
  2843.                     $itemInvoice->setSrvServiceCatId($servicio->getServiceCatId());
  2844.                     $itemInvoice->setSrvServiceCatName($servicio->getServiceCatName());
  2845.                     $itemInvoice->setSrvPrice($servicio->getPrice());
  2846.                     $itemInvoice->setSrvCurrency($servicio->getCurrency());
  2847.                     $itemInvoice->setSrvUnits($servicio->getUnits());
  2848.                     $itemInvoice->setSrvOpCommission($servicio->getOpCommission());
  2849.                     $itemInvoice->setSrvCommission($servicio->getCommission());
  2850.                     $itemInvoice->setSrvOpOver($servicio->getOpOver());
  2851.                     $itemInvoice->setSrvOver($servicio->getOver());
  2852.                     $itemInvoice->setSrvOpIva($servicio->getOpIva());
  2853.                     $itemInvoice->setSrvIva($servicio->getIva());
  2854.                     $itemInvoice->setSrvPax($servicio->getPax());
  2855.                     $itemInvoice->setSrvHour($servicio->getHour());
  2856.                     $itemInvoice->setSrvDateInAt($servicio->getDateInAt());
  2857.                     $itemInvoice->setSrvDateOutAt($servicio->getDateOutAt());
  2858.                     $itemInvoice->setSrvContcolor($servicio->getContcolor());
  2859.                     $itemInvoice->setSrvRankQuote($servicio->getRankQuote());
  2860.                     $itemInvoice->setSrvAssistantId($servicio->getAssistantId());
  2861.                     $itemInvoice->setSrvActivityId($servicio->getActivityId());
  2862.                     $itemInvoice->setSrvPay($servicio->getPay());
  2863.                     $itemInvoice->setCreatedAt(new DateTime('now'));
  2864.                     $itemInvoice->setUpdatedAt(new DateTime('now'));
  2865.                     $itemInvoice->setCreatedId($user_id);
  2866.                     $itemInvoice->setUpdatedId($user_id);
  2867.                     $em->persist($itemInvoice);
  2868.                     $em->flush();
  2869.                     //Acumulamos neto e iva para la factura
  2870.                     if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())) {
  2871.                         $subtotal 0;
  2872.                         $neto 0;
  2873.                         $subtotalService 0;
  2874.                     } else {
  2875.                         $subtotalService $itemInvoice->getSrvPrice();
  2876.                         $subneto $itemInvoice->getSrvPrice();
  2877.                         // Commission
  2878.                         if ($itemInvoice->getSrvOpCommission() == '1') {
  2879.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvCommission() / 100));
  2880.                             $subneto $subneto  * (+ ($itemInvoice->getSrvCommission() / 100));
  2881.                         } else {
  2882.                             $subtotalService $subtotalService * (- ($itemInvoice->getSrvCommission() / 100));
  2883.                             $subneto $subneto * (- ($itemInvoice->getSrvCommission() / 100));
  2884.                         }
  2885.                         // Over
  2886.                         if ($itemInvoice->getSrvOpOver() == '1') {
  2887.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  2888.                             $subneto $subneto $itemInvoice->getSrvOver();
  2889.                         } else {
  2890.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  2891.                             $subneto $subneto $itemInvoice->getSrvOver();
  2892.                         }
  2893.                         // IVA
  2894.                         if ($itemInvoice->getSrvOpIva() == '1') {
  2895.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvIva() / 100));
  2896.                         } else {
  2897.                             $subtotalService $itemInvoice->getSrvPrice();
  2898.                             $subneto = ($subneto 100) / (100 $itemInvoice->getSrvIva());
  2899.                         }
  2900.                         switch ($itemInvoice->getSrvServiceCatId()) {
  2901.                             case 1// Alojamiento
  2902.                                 // el numero de noches $numNoches; precio unitario $subneto
  2903.                                 $numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
  2904.                                 // La personas no afectan este calculo
  2905.                                 $subtotal $subtotalService $numNoches $itemInvoice->getSrvUnits();
  2906.                                 $subnetoUnit $subneto;
  2907.                                 $subneto $subneto $numNoches $itemInvoice->getSrvUnits();
  2908.                                 break;
  2909.                             case 2//Actividades
  2910.                                 // El nĂºmero de personas es considerado en el calculo
  2911.                                 $pax $itemInvoice->getSrvPax();
  2912.                                 if (empty($pax) or $pax == "0") {
  2913.                                     $pax 1;
  2914.                                 }
  2915.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2916.                                 if ($days 1) {
  2917.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  2918.                                 } else {
  2919.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2920.                                 }
  2921.                                 $subtotal $subtotalService $days $itemInvoice->getSrvUnits();
  2922.                                 $subnetoUnit $subneto;
  2923.                                 $subneto $subneto $days $itemInvoice->getSrvUnits();
  2924.                                 break;
  2925.                             case 3// AV
  2926.                                 $pax $itemInvoice->getSrvPax();
  2927.                                 if (empty($pax) or $pax == "0") {
  2928.                                     $pax 1;
  2929.                                 }
  2930.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2931.                                 if ($days 1) {
  2932.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  2933.                                 } else {
  2934.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2935.                                 }
  2936.                                 $unitsServ $itemInvoice->getSrvUnits();
  2937.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2938.                                     $unitsServ 1;
  2939.                                 }
  2940.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2941.                                 $subnetoUnit $subneto;
  2942.                                 $subneto $subneto $days $unitsServ $pax;
  2943.                                 break;
  2944.                             case 4//Creative
  2945.                                 $pax $itemInvoice->getSrvPax();
  2946.                                 if (empty($pax) or $pax == "0") {
  2947.                                     $pax 1;
  2948.                                 }
  2949.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2950.                                 if ($days 1) {
  2951.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  2952.                                 } else {
  2953.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2954.                                 }
  2955.                                 $unitsServ $itemInvoice->getSrvUnits();
  2956.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2957.                                     $unitsServ 1;
  2958.                                 }
  2959.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2960.                                 $subnetoUnit $subneto;
  2961.                                 $subneto $subneto $days $unitsServ $pax;
  2962.                                 break;
  2963.                             case 5//Cruise
  2964.                                 $pax $itemInvoice->getSrvPax();
  2965.                                 if (empty($pax) or $pax == "0") {
  2966.                                     $pax 1;
  2967.                                 }
  2968.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
  2969.                                 if ($days 1) {
  2970.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  2971.                                 } else {
  2972.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2973.                                 }
  2974.                                 $unitsServ $itemInvoice->getSrvUnits();
  2975.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2976.                                     $unitsServ 1;
  2977.                                 }
  2978.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2979.                                 $subnetoUnit $subneto;
  2980.                                 $subneto $subneto $days $unitsServ $pax;
  2981.                                 break;
  2982.                             case 6//Entertaiment
  2983.                                 $pax $itemInvoice->getSrvPax();
  2984.                                 if (empty($pax) or $pax == "0") {
  2985.                                     $pax 1;
  2986.                                 }
  2987.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2988.                                 if ($days 1) {
  2989.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  2990.                                 } else {
  2991.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2992.                                 }
  2993.                                 $unitsServ $itemInvoice->getSrvUnits();
  2994.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2995.                                     $unitsServ 1;
  2996.                                 }
  2997.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2998.                                 $subnetoUnit $subneto;
  2999.                                 $subneto $subneto $days $unitsServ $pax;
  3000.                                 break;
  3001.                             case 7// Gifts
  3002.                                 $pax $itemInvoice->getSrvPax();
  3003.                                 if (empty($pax) or $pax == "0") {
  3004.                                     $pax 1;
  3005.                                 }
  3006.                                 $days 1;
  3007.                                 if ($days 1) {
  3008.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3009.                                 } else {
  3010.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3011.                                 }
  3012.                                 $unitsServ $itemInvoice->getSrvUnits();
  3013.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3014.                                     $unitsServ 1;
  3015.                                 }
  3016.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3017.                                 $subnetoUnit $subneto;
  3018.                                 $subneto $subneto $days $unitsServ $pax;
  3019.                                 break;
  3020.                             case 8//Guide
  3021.                                 $pax $itemInvoice->getSrvPax();
  3022.                                 if (empty($pax) or $pax == "0") {
  3023.                                     $pax 1;
  3024.                                 }
  3025.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3026.                                 if ($days 1) {
  3027.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3028.                                 } else {
  3029.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3030.                                 }
  3031.                                 $unitsServ $itemInvoice->getSrvUnits();
  3032.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3033.                                     $unitsServ 1;
  3034.                                 }
  3035.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3036.                                 $subnetoUnit $subneto;
  3037.                                 $subneto $subneto $days $unitsServ $pax;
  3038.                                 break;
  3039.                             case 9//Itineraries
  3040.                                 $pax $itemInvoice->getSrvPax();
  3041.                                 if (empty($pax) or $pax == "0") {
  3042.                                     $pax 1;
  3043.                                 }
  3044.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3045.                                 if ($days 1) {
  3046.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3047.                                 } else {
  3048.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3049.                                 }
  3050.                                 $unitsServ $itemInvoice->getSrvUnits();
  3051.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3052.                                     $unitsServ 1;
  3053.                                 }
  3054.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3055.                                 $subnetoUnit $subneto;
  3056.                                 $subneto $subneto $days $unitsServ $pax;
  3057.                                 break;
  3058.                             case 10//Lounge  -- No Aplica
  3059.                                 break;
  3060.                             case 11//Menu
  3061.                                 $pax $itemInvoice->getSrvPax();
  3062.                                 if (empty($pax) or $pax == "0") {
  3063.                                     $pax 1;
  3064.                                 }
  3065.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3066.                                 if ($days 1) {
  3067.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3068.                                 } else {
  3069.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3070.                                 }
  3071.                                 $unitsServ $itemInvoice->getSrvUnits();
  3072.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3073.                                     $unitsServ 1;
  3074.                                 }
  3075.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3076.                                 $subnetoUnit $subneto;
  3077.                                 $subneto $subneto $days $unitsServ $pax;
  3078.                                 break;
  3079.                             case 12//Others
  3080.                                 $pax $itemInvoice->getSrvPax();
  3081.                                 if (empty($pax) or $pax == "0") {
  3082.                                     $pax 1;
  3083.                                 }
  3084.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3085.                                 if ($days 1) {
  3086.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3087.                                 } else {
  3088.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3089.                                 }
  3090.                                 $unitsServ $itemInvoice->getSrvUnits();
  3091.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3092.                                     $unitsServ 1;
  3093.                                 }
  3094.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3095.                                 $subnetoUnit $subneto;
  3096.                                 $subneto $subneto $days $unitsServ $pax;
  3097.                                 break;
  3098.                             case 13//Transport
  3099.                                 $pax $itemInvoice->getSrvPax();
  3100.                                 if (empty($pax) or $pax == "0") {
  3101.                                     $pax 1;
  3102.                                 }
  3103.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3104.                                 if ($days 1) {
  3105.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3106.                                 } else {
  3107.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3108.                                 }
  3109.                                 $unitsServ $itemInvoice->getSrvUnits();
  3110.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3111.                                     $unitsServ 1;
  3112.                                 }
  3113.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3114.                                 $subnetoUnit $subneto;
  3115.                                 $subneto $subneto $days $unitsServ $pax;
  3116.                                 break;
  3117.                             case 14//Technology
  3118.                                 $pax $itemInvoice->getSrvPax();
  3119.                                 if (empty($pax) or $pax == "0") {
  3120.                                     $pax 1;
  3121.                                 }
  3122.                                 $days 1;
  3123.                                 $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3124.                                 $unitsServ $itemInvoice->getSrvUnits();
  3125.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3126.                                     $unitsServ 1;
  3127.                                 }
  3128.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3129.                                 $subnetoUnit $subneto;
  3130.                                 $subneto $subneto $days $unitsServ $pax;
  3131.                                 break;
  3132.                             case 15//Assisstant
  3133.                                 $pax $itemInvoice->getSrvPax();
  3134.                                 if (empty($pax) or $pax == "0") {
  3135.                                     $pax 1;
  3136.                                 }
  3137.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3138.                                 if ($days 1) {
  3139.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3140.                                 } else {
  3141.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3142.                                 }
  3143.                                 $unitsServ $itemInvoice->getSrvUnits();
  3144.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3145.                                     $unitsServ 1;
  3146.                                 }
  3147.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3148.                                 $subnetoUnit $subneto;
  3149.                                 $subneto $subneto $days $unitsServ $pax;
  3150.                                 break;
  3151.                             case 16//DDR
  3152.                                 $pax $itemInvoice->getSrvPax();
  3153.                                 if (empty($pax) or $pax == "0") {
  3154.                                     $pax 1;
  3155.                                 }
  3156.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3157.                                 if ($days 1) {
  3158.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3159.                                 } else {
  3160.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3161.                                 }
  3162.                                 $unitsServ $itemInvoice->getSrvUnits();
  3163.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3164.                                     $unitsServ 1;
  3165.                                 }
  3166.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3167.                                 $subnetoUnit $subneto;
  3168.                                 $subneto $subneto $days $unitsServ $pax;
  3169.                                 break;
  3170.                             default:
  3171.                                 break;
  3172.                         }
  3173.                         // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  3174.                         $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  3175.                         $neto round($subneto2PHP_ROUND_HALF_UP);
  3176.                         $valorTotalNet $valorTotalNet $neto;
  3177.                         $valorVat $valorVat + ($subtotal $neto);
  3178.                     }
  3179.                 }
  3180.             }
  3181.         }
  3182.         if (!empty($arrayBools['payment'])) {
  3183.             foreach ($arrayBools['payment'] as $key => $item) {
  3184.                 if ($item == 'true') {
  3185.                     $boolMakeInvoice true;
  3186.                     $pago $em->getRepository(AvePaymentsClient::class)->findOneById($key);
  3187.                     $itemInvoice = new AveDocInvoiceItems();
  3188.                     $itemInvoice->setFileId($id);
  3189.                     $itemInvoice->setInvoiceId($invoiceId);
  3190.                     $itemInvoice->setItemType('PAYMENT');
  3191.                     $itemInvoice->setPayControlId($key);
  3192.                     $itemInvoice->setPayAmount($pago->getAmount());
  3193.                     $itemInvoice->setPayVat($pago->getVat());
  3194.                     $itemInvoice->setPayAmountTotal($pago->getAmountTotal());
  3195.                     $itemInvoice->setPayDatePayAt($pago->getDatePayAt());
  3196.                     $itemInvoice->setPayWayToPay($pago->getWayToPay());
  3197.                     $itemInvoice->setCreatedAt(new DateTime('now'));
  3198.                     $itemInvoice->setUpdatedAt(new DateTime('now'));
  3199.                     $itemInvoice->setCreatedId($user_id);
  3200.                     $itemInvoice->setUpdatedId($user_id);
  3201.                     $em->persist($itemInvoice);
  3202.                     $em->flush();
  3203.                     //Acumulamos neto e iva para la factura
  3204.                     //$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();    // El pago no puede afectar el neto de la factura
  3205.                 }
  3206.             }
  3207.         }
  3208.         //FIN: Creamos los items de la factura
  3209.         $valorTotal $valorTotalNet $valorVat;
  3210.         //INICIO: Creamos la factura
  3211.         $newInvoice = new AveDocInvoice();
  3212.         $newInvoice->setAccessKey(md5(rand() * time()));
  3213.         $newInvoice->setNumber('AVE-' date('dmy') . "-" $id);
  3214.         $newInvoice->setDateAt(new DateTime('now'));
  3215.         $newInvoice->setType('Invoice');
  3216.         $newInvoice->setFileId($id);
  3217.         $newInvoice->setTotalNet($valorTotalNet);
  3218.         $newInvoice->setVat($valorVat);
  3219.         $newInvoice->setTotal($valorTotal);
  3220.         $newInvoice->setCreatedAt(new DateTime('now'));
  3221.         $newInvoice->setCreatedId($user_id);
  3222.         $newInvoice->setUpdatedAt(new DateTime('now'));
  3223.         $newInvoice->setUpdatedId($user_id);
  3224.         $newInvoice->setMaster('master');
  3225.         if ($boolMakeInvoice) {
  3226.             // Solo se debe crear factura si hay un elemento
  3227.             $em->persist($newInvoice);
  3228.             $em->flush();
  3229.             $newInvoice->setNumber($newInvoice->getNumber() . '-' $newInvoice->getId());
  3230.             $em->persist($newInvoice);
  3231.             $em->flush();
  3232.         } else {
  3233.             // Se llama a la vista de facturas del expediente
  3234.             return $this->redirectToRoute('ave_view_invoice', array('id' => $id));
  3235.         }
  3236.         //FIN: Creamos la factura
  3237.         $data = array();
  3238.         $data $this->baseInvoiceSelectedFile($id$arrayBools'I' $newInvoice->getId());
  3239.         $paymentsClient = new AvePaymentsClient();
  3240.         $paymentsClient->setFileId($id);
  3241.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  3242.         $payments $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  3243.         $services $em->getRepository(AveServices::class)->findByFileId($id);
  3244.         $proforma $em->getRepository(AveDocProforma::class)->findOneByFileId($id);
  3245.         $reservaInv = new AveDocInvoice();
  3246.         $reservaInv->setAccessKey(md5(rand() * time()));
  3247.         $reservaInv->setFileId($id);
  3248.         $idProducts = array();
  3249.         $productsBoolToInvoice = array();
  3250.         if (array_key_exists('lounge'$data['datasupplier'])) {
  3251.             foreach ($data['datasupplier']['lounge'] as $item) {
  3252.                 $idProducts[] = $item['id'];
  3253.                 $productsBoolToInvoice[] = 1;
  3254.             }
  3255.             $idProducts implode(','$idProducts);
  3256.             $productsBoolToInvoice implode(','$productsBoolToInvoice);
  3257.         } else {
  3258.             $idProducts '0';
  3259.             $productsBoolToInvoice '0';
  3260.         }
  3261.         $idPayments = array();
  3262.         $paymentsBoolToInvoice = array();
  3263.         if (array_key_exists('payment'$data['datasupplier'])) {
  3264.             foreach ($data['datasupplier']['payment'] as $item) {
  3265.                 $idPayments[] = $item['id'];
  3266.                 $paymentsBoolToInvoice[] = 1;
  3267.             }
  3268.             $idPayments implode(','$idPayments);
  3269.             $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  3270.             // Se han generado dos arreglos, cada uno dividido en 2 strings
  3271.             // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  3272.             // Para manipularlos entre la vista y el JS
  3273.         } else {
  3274.             $idPayments '0';
  3275.             $paymentsBoolToInvoice '0';
  3276.         }
  3277.         // Una factura solo se puede rectificar una vez
  3278.         $rectf $em->getRepository(AveDocInvoiceRec::class)->findBy(array('number' => 'REC-' $newInvoice->getNumber()));
  3279.         $boolToRec = empty($rectf);
  3280.         $allInvoices $em->getRepository(AveDocInvoice::class)->findByFileId($id);
  3281.         $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($id);
  3282.         foreach ($allInvoicesRec as $item) {
  3283.             array_push($allInvoices$item);
  3284.         }
  3285.         $allProformas $em->getRepository(AveDocProforma::class)->findByFileId($id);
  3286.         if (empty($data['type'])) {
  3287.             $data['type'] = 'Invoice';
  3288.         }
  3289.         if (array_key_exists('paymentSubTotal'$data['datasupplier'])) {
  3290.             $paymentInvoice $data['datasupplier']['paymentSubTotal']['sumSubT'];
  3291.         } else {
  3292.             $paymentInvoice 0;
  3293.         }
  3294.         $this->calculoBeneficiosDocumento($newInvoice->getId(), 'Invoice');
  3295.         // Actualizamos las entidades InvoiceProformaExtraField y las asociamos con la factura
  3296.         $company $em->getRepository(SettingsCompany::class)->findOneByBusinessType('audiovisual');
  3297.         $companyId = empty($company) ? null $company->getId();
  3298.         $this->extraFieldService->attachUndefinedExtraFieldsToDocument($companyIdInvoiceProformaExtraFieldConstants::TYPE_INVOICE$newInvoice->getId(), null);
  3299.         return $this->redirectToRoute(
  3300.             'ave_view_invoice',
  3301.             array(
  3302.                 'id' => $newInvoice->getId()
  3303.             )
  3304.         );
  3305.     }
  3306.     /**
  3307.      * @Route("/newinvoicefromproforma/{id}", name="ave_new_invoice_from_proforma")
  3308.      * Crear nueva factura con los elementos seleccionados en una proforma
  3309.      */
  3310.     public function generateNewInvoiceFromProformaAction($idRequest $request)
  3311.     {
  3312.         $em $this->getDoctrine()->getManager();
  3313.         $proformaOrigen $em->getRepository(AveDocProforma::class)->findOneById($id);
  3314.         //INICIO: Buscamos los elementos de la proforma y verificamos disponibilidad
  3315.         $proformaOrigenItems $em->getRepository(AveDocProformaItems::class)->findByProformaId($id);
  3316.         $algunItemEstaFacturado false;
  3317.         foreach ($proformaOrigenItems as $item) {
  3318.             if ($item->getType() == 'PRODUCT') {
  3319.                 $estaFacturado $em->getRepository(AveDocInvoiceItems::class)->findByPrdControlId($item->getControlId());
  3320.                 if (!empty($estaFacturado)) {
  3321.                     $algunItemEstaFacturado true;
  3322.                 }
  3323.             }
  3324.             if ($item->getType() == 'PAYMENT') {
  3325.                 $estaFacturado $em->getRepository(AveDocInvoiceItems::class)->findByPayControlId($item->getControlId());
  3326.                 if (!empty($estaFacturado)) {
  3327.                     $algunItemEstaFacturado true;
  3328.                 }
  3329.             }
  3330.             if ($item->getType() == 'SERVICE') {
  3331.                 $estaFacturado $em->getRepository(AveDocInvoiceItems::class)->findByPayControlId($item->getControlId());
  3332.                 if (!empty($estaFacturado)) {
  3333.                     $algunItemEstaFacturado true;
  3334.                 }
  3335.             }
  3336.         }
  3337.         //FIN: Buscamos los elementos de la proforma y verificamos disponibilidad
  3338.         // Obtengo usuario logueado
  3339.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  3340.         $user_id $user_logueado->getId();
  3341.         if ($algunItemEstaFacturado) {
  3342.             $id $proformaOrigen->getFileId();
  3343.             return $this->render(
  3344.                 'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
  3345.                 array(
  3346.                     'id' => $id,
  3347.                     'docType' => 'Error Elementos ya Facturados',
  3348.                     'proforma' => '',
  3349.                     'company' => '',
  3350.                     'clients' => '',
  3351.                     'date' => '',
  3352.                     'number' => '',
  3353.                     'invoice' => null,
  3354.                     'fid' => '',
  3355.                     'boolToRec' => false,
  3356.                     'proformas' => '',
  3357.                     'currency' => '',
  3358.                     'totales_neto' => '',
  3359.                     'totales' => '',
  3360.                     'balance' => '',
  3361.                     'bases_imponibles' => '',
  3362.                     'user' => $user_logueado,
  3363.                     'comments' => null,
  3364.                     'services' => null,
  3365.                     'facturas' => null,
  3366.                     'paymentNotIvoiced' => null,
  3367.                     'paymentsAll' => null,
  3368.                     'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  3369.                     'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  3370.                     'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  3371.                     'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  3372.                     'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  3373.                     'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  3374.                 )
  3375.             );
  3376.         } else {
  3377.             // Se genera y muestra en nueva pantalla la nueva proforma
  3378.             $arrayBools = array(
  3379.                 'product' => null,
  3380.                 'service' => null,
  3381.                 'payment' => null,
  3382.             );
  3383.             foreach ($proformaOrigenItems as $item) {
  3384.                 if ($item->getType() == 'PRODUCT') {
  3385.                     $arrayBools['product'][$item->getControlId()] = 'true';
  3386.                 }
  3387.                 if ($item->getType() == 'SERVICE') {
  3388.                     $arrayBools['service'][$item->getControlId()] = 'true';
  3389.                 }
  3390.                 if ($item->getType() == 'PAYMENT') {
  3391.                     $arrayBools['payment'][$item->getControlId()] = 'true';
  3392.                 }
  3393.             }
  3394.             //            $arrayBools['product'] = $request->request->get('inv_lounge_hidden_bool');
  3395.             //            $arrayBools['service'] = $request->request->get('inv_service_hidden_bool');
  3396.             //            $arrayBools['payment'] = $request->request->get('inv_payment_hidden_bool');
  3397.             $id $proformaOrigen->getFileId();
  3398.             //INICIO: buscamos el ID de la factura
  3399.             $allFacturas $em->getRepository(AveDocInvoice::class)->findAll();
  3400.             if (!empty($allFacturas)) {
  3401.                 $invoiceId end($allFacturas)->getId() + 1;
  3402.             } else {
  3403.                 $invoiceId 1;
  3404.                 //                $invoiceId = 10;    //La primera factura de AV en el sistema serĂ¡ la 10, se cambia el numero de serie a A1, A2,...
  3405.             }
  3406.             $boolMakeInvoice false;  // Control para verificar si se debe hacer factura o todos los indicadores (sala, servicios y pagos) estaban en falso
  3407.             //FIN: buscamos el ID de la factura
  3408.             /* Obtengo usuario logueado */
  3409.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  3410.             $user_id $user_logueado->getId();
  3411.             //Acumuladores de datos globales de la factura
  3412.             $valorTotalNet 0;
  3413.             $valorVat 0;
  3414.             //INICIO: Creamos los items de la factura
  3415.             if (!empty($arrayBools['product'])) {
  3416.                 foreach ($arrayBools['product'] as $key => $item) {
  3417.                     if ($item == 'true') {
  3418.                         $boolMakeInvoice true;
  3419.                         $sala $em->getRepository(AveProductFile::class)->findOneById($key);
  3420.                         $itemInvoice = new AveDocInvoiceItems();
  3421.                         $itemInvoice->setFileId($id);
  3422.                         $itemInvoice->setInvoiceId($invoiceId);
  3423.                         $itemInvoice->setItemType('PRODUCT');
  3424.                         $itemInvoice->setPrdControlId($key);
  3425.                         $itemInvoice->setPrdName($sala->getProductName());
  3426.                         $itemInvoice->setPrdProductId($sala->getProductId());
  3427.                         $itemInvoice->setPrdProductId($sala->getProductId());
  3428.                         $itemInvoice->setPrdDateStart($sala->getDateStart());
  3429.                         $itemInvoice->setPrdType($sala->getType());
  3430.                         if (empty($sala->getLocation())) {
  3431.                             $itemInvoice->setLocation(null);
  3432.                         } else {
  3433.                             $itemInvoice->setLocation($sala->getLocation());
  3434.                         }
  3435.                         $itemInvoice->setRankQuoteAv($sala->getRankQuoteAv());
  3436.                         $itemInvoice->setPrdDateEnd($sala->getDateEnd());
  3437.                         $itemInvoice->setPrdServicePrice($sala->getServicePrice());
  3438.                         $itemInvoice->setPrdSubTotalPrice($sala->getSubTotalPrice());
  3439.                         $itemInvoice->setPrdQty($sala->getUnits());
  3440.                         $itemInvoice->setPrdPax($sala->getPax());
  3441.                         $itemInvoice->setPrdDays($sala->getDays());
  3442.                         $itemInvoice->setCreatedId($user_id);
  3443.                         $itemInvoice->setCreatedAt(new DateTime('now'));
  3444.                         $itemInvoice->setUpdatedId($user_id);
  3445.                         $itemInvoice->setUpdatedAt(new DateTime('now'));
  3446.                         $itemInvoice->setPrdHourStart($sala->getHourStart());
  3447.                         $itemInvoice->setPrdMinStart($sala->getMinStart());
  3448.                         $itemInvoice->setPrdHourEnd($sala->getHourEnd());
  3449.                         $itemInvoice->setPrdMinEnd($sala->getMinEnd());
  3450.                         $itemInvoice->setPrdIva($sala->getIva());
  3451.                         $itemInvoice->setPrdOpIva($sala->getOpIva());
  3452.                         $em->persist($itemInvoice);
  3453.                         $em->flush();
  3454.                         //Acumulamos neto e iva para la factura
  3455.                         //                        $valorTotalNet = $valorTotalNet + $itemInvoice->getPrdServicePrice();
  3456.                         $valorTotalNet $valorTotalNet $itemInvoice->getPrdSubTotalPrice();
  3457.                         //                        $valorVat = $valorVat + round(($itemInvoice->getPrdServicePrice() * 0.21), 2, PHP_ROUND_HALF_UP);
  3458.                         $valorVat $valorVat round(($itemInvoice->getPrdSubTotalPrice() * 0.21), 2PHP_ROUND_HALF_UP);
  3459.                     }
  3460.                 }
  3461.             }
  3462.             if (!empty($arrayBools['service'])) {
  3463.                 foreach ($arrayBools['service'] as $key => $item) {
  3464.                     if ($item == 'true') {
  3465.                         $boolMakeInvoice true;
  3466.                         $servicio $em->getRepository(AveServices::class)->findOneById($key);
  3467.                         $itemInvoice = new AveDocInvoiceItems();
  3468.                         $itemInvoice->setFileId($id);
  3469.                         $itemInvoice->setInvoiceId($invoiceId);
  3470.                         $itemInvoice->setItemType('SERVICE');
  3471.                         $itemInvoice->setSrvControlId($key);
  3472.                         $itemInvoice->setSrvSupplierId($servicio->getSupplierId());
  3473.                         $itemInvoice->setSrvServiceId($servicio->getServiceId());
  3474.                         $itemInvoice->setSrvServiceCatId($servicio->getServiceCatId());
  3475.                         $itemInvoice->setSrvServiceCatName($servicio->getServiceCatName());
  3476.                         $itemInvoice->setSrvPrice($servicio->getPrice());
  3477.                         $itemInvoice->setSrvCurrency($servicio->getCurrency());
  3478.                         $itemInvoice->setSrvUnits($servicio->getUnits());
  3479.                         $itemInvoice->setSrvOpCommission($servicio->getOpCommission());
  3480.                         $itemInvoice->setSrvCommission($servicio->getCommission());
  3481.                         $itemInvoice->setSrvOpOver($servicio->getOpOver());
  3482.                         $itemInvoice->setSrvOver($servicio->getOver());
  3483.                         $itemInvoice->setSrvOpIva($servicio->getOpIva());
  3484.                         $itemInvoice->setSrvIva($servicio->getIva());
  3485.                         $itemInvoice->setSrvPax($servicio->getPax());
  3486.                         $itemInvoice->setSrvHour($servicio->getHour());
  3487.                         $itemInvoice->setSrvDateInAt($servicio->getDateInAt());
  3488.                         $itemInvoice->setSrvDateOutAt($servicio->getDateOutAt());
  3489.                         $itemInvoice->setSrvContcolor($servicio->getContcolor());
  3490.                         $itemInvoice->setSrvRankQuote($servicio->getRankQuote());
  3491.                         $itemInvoice->setSrvAssistantId($servicio->getAssistantId());
  3492.                         $itemInvoice->setSrvActivityId($servicio->getActivityId());
  3493.                         $itemInvoice->setSrvPay($servicio->getPay());
  3494.                         $itemInvoice->setCreatedAt(new DateTime('now'));
  3495.                         $itemInvoice->setUpdatedAt(new DateTime('now'));
  3496.                         $itemInvoice->setCreatedId($user_id);
  3497.                         $itemInvoice->setUpdatedId($user_id);
  3498.                         $em->persist($itemInvoice);
  3499.                         $em->flush();
  3500.                         //Acumulamos neto e iva para la factura
  3501.                         if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())) {
  3502.                             $subtotal 0;
  3503.                             $neto 0;
  3504.                             $subtotalService 0;
  3505.                         } else {
  3506.                             $subtotalService $itemInvoice->getSrvPrice();
  3507.                             $subneto $itemInvoice->getSrvPrice();
  3508.                             // Commission
  3509.                             if ($itemInvoice->getSrvOpCommission() == '1') {
  3510.                                 $subtotalService $subtotalService * (+ ($itemInvoice->getSrvCommission() / 100));
  3511.                                 $subneto $subneto * (+ ($itemInvoice->getSrvCommission() / 100));
  3512.                             } else {
  3513.                                 $subtotalService $subtotalService * (- ($itemInvoice->getSrvCommission() / 100));
  3514.                                 $subneto $subneto * (- ($itemInvoice->getSrvCommission() / 100));
  3515.                             }
  3516.                             // Over
  3517.                             if ($itemInvoice->getSrvOpOver() == '1') {
  3518.                                 $subtotalService $subtotalService $itemInvoice->getSrvOver();
  3519.                                 $subneto $subneto $itemInvoice->getSrvOver();
  3520.                             } else {
  3521.                                 $subtotalService $subtotalService $itemInvoice->getSrvOver();
  3522.                                 $subneto $subneto $itemInvoice->getSrvOver();
  3523.                             }
  3524.                             // IVA
  3525.                             if ($itemInvoice->getSrvOpIva() == '1') {
  3526.                                 $subtotalService $subtotalService * (+ ($itemInvoice->getSrvIva() / 100));
  3527.                             } else {
  3528.                                 $subtotalService $itemInvoice->getSrvPrice();
  3529.                                 $subneto = ($subneto 100) / (100 $itemInvoice->getSrvIva());
  3530.                             }
  3531.                             switch ($itemInvoice->getSrvServiceCatId()) {
  3532.                                 case 1// Alojamiento
  3533.                                     // el numero de noches $numNoches; precio unitario $subneto
  3534.                                     $numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
  3535.                                     // La personas no afectan este calculo
  3536.                                     $subtotal $subtotalService $numNoches $itemInvoice->getSrvUnits();
  3537.                                     $subnetoUnit $subneto;
  3538.                                     $subneto $subneto $numNoches $itemInvoice->getSrvUnits();
  3539.                                     break;
  3540.                                 case 2//Actividades
  3541.                                     // El nĂºmero de personas es considerado en el calculo
  3542.                                     $pax $itemInvoice->getSrvPax();
  3543.                                     if (empty($pax) or $pax == "0") {
  3544.                                         $pax 1;
  3545.                                     }
  3546.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3547.                                     if ($days 1) {
  3548.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3549.                                     } else {
  3550.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3551.                                     }
  3552.                                     $subtotal $subtotalService $days $itemInvoice->getSrvUnits();
  3553.                                     $subnetoUnit $subneto;
  3554.                                     $subneto $subneto $days $itemInvoice->getSrvUnits();
  3555.                                     break;
  3556.                                 case 3// AV
  3557.                                     $pax $itemInvoice->getSrvPax();
  3558.                                     if (empty($pax) or $pax == "0") {
  3559.                                         $pax 1;
  3560.                                     }
  3561.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3562.                                     if ($days 1) {
  3563.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3564.                                     } else {
  3565.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3566.                                     }
  3567.                                     $unitsServ $itemInvoice->getSrvUnits();
  3568.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3569.                                         $unitsServ 1;
  3570.                                     }
  3571.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3572.                                     $subnetoUnit $subneto;
  3573.                                     $subneto $subneto $days $unitsServ $pax;
  3574.                                     break;
  3575.                                 case 4//Creative
  3576.                                     $pax $itemInvoice->getSrvPax();
  3577.                                     if (empty($pax) or $pax == "0") {
  3578.                                         $pax 1;
  3579.                                     }
  3580.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3581.                                     if ($days 1) {
  3582.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3583.                                     } else {
  3584.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3585.                                     }
  3586.                                     $unitsServ $itemInvoice->getSrvUnits();
  3587.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3588.                                         $unitsServ 1;
  3589.                                     }
  3590.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3591.                                     $subnetoUnit $subneto;
  3592.                                     $subneto $subneto $days $unitsServ $pax;
  3593.                                     break;
  3594.                                 case 5//Cruise
  3595.                                     $pax $itemInvoice->getSrvPax();
  3596.                                     if (empty($pax) or $pax == "0") {
  3597.                                         $pax 1;
  3598.                                     }
  3599.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
  3600.                                     if ($days 1) {
  3601.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3602.                                     } else {
  3603.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3604.                                     }
  3605.                                     $unitsServ $itemInvoice->getSrvUnits();
  3606.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3607.                                         $unitsServ 1;
  3608.                                     }
  3609.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3610.                                     $subnetoUnit $subneto;
  3611.                                     $subneto $subneto $days $unitsServ $pax;
  3612.                                     break;
  3613.                                 case 6//Entertaiment
  3614.                                     $pax $itemInvoice->getSrvPax();
  3615.                                     if (empty($pax) or $pax == "0") {
  3616.                                         $pax 1;
  3617.                                     }
  3618.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3619.                                     if ($days 1) {
  3620.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3621.                                     } else {
  3622.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3623.                                     }
  3624.                                     $unitsServ $itemInvoice->getSrvUnits();
  3625.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3626.                                         $unitsServ 1;
  3627.                                     }
  3628.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3629.                                     $subnetoUnit $subneto;
  3630.                                     $subneto $subneto $days $unitsServ $pax;
  3631.                                     break;
  3632.                                 case 7// Gifts
  3633.                                     $pax $itemInvoice->getSrvPax();
  3634.                                     if (empty($pax) or $pax == "0") {
  3635.                                         $pax 1;
  3636.                                     }
  3637.                                     $days 1;
  3638.                                     if ($days 1) {
  3639.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3640.                                     } else {
  3641.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3642.                                     }
  3643.                                     $unitsServ $itemInvoice->getSrvUnits();
  3644.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3645.                                         $unitsServ 1;
  3646.                                     }
  3647.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3648.                                     $subnetoUnit $subneto;
  3649.                                     $subneto $subneto $days $unitsServ $pax;
  3650.                                     break;
  3651.                                 case 8//Guide
  3652.                                     $pax $itemInvoice->getSrvPax();
  3653.                                     if (empty($pax) or $pax == "0") {
  3654.                                         $pax 1;
  3655.                                     }
  3656.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3657.                                     if ($days 1) {
  3658.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3659.                                     } else {
  3660.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3661.                                     }
  3662.                                     $unitsServ $itemInvoice->getSrvUnits();
  3663.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3664.                                         $unitsServ 1;
  3665.                                     }
  3666.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3667.                                     $subnetoUnit $subneto;
  3668.                                     $subneto $subneto $days $unitsServ $pax;
  3669.                                     break;
  3670.                                 case 9//Itineraries
  3671.                                     $pax $itemInvoice->getSrvPax();
  3672.                                     if (empty($pax) or $pax == "0") {
  3673.                                         $pax 1;
  3674.                                     }
  3675.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3676.                                     if ($days 1) {
  3677.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3678.                                     } else {
  3679.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3680.                                     }
  3681.                                     $unitsServ $itemInvoice->getSrvUnits();
  3682.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3683.                                         $unitsServ 1;
  3684.                                     }
  3685.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3686.                                     $subnetoUnit $subneto;
  3687.                                     $subneto $subneto $days $unitsServ $pax;
  3688.                                     break;
  3689.                                 case 10//Lounge  -- No Aplica
  3690.                                     break;
  3691.                                 case 11//Menu
  3692.                                     $pax $itemInvoice->getSrvPax();
  3693.                                     if (empty($pax) or $pax == "0") {
  3694.                                         $pax 1;
  3695.                                     }
  3696.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3697.                                     if ($days 1) {
  3698.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3699.                                     } else {
  3700.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3701.                                     }
  3702.                                     $unitsServ $itemInvoice->getSrvUnits();
  3703.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3704.                                         $unitsServ 1;
  3705.                                     }
  3706.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3707.                                     $subnetoUnit $subneto;
  3708.                                     $subneto $subneto $days $unitsServ $pax;
  3709.                                     break;
  3710.                                 case 12//Others
  3711.                                     $pax $itemInvoice->getSrvPax();
  3712.                                     if (empty($pax) or $pax == "0") {
  3713.                                         $pax 1;
  3714.                                     }
  3715.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3716.                                     if ($days 1) {
  3717.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3718.                                     } else {
  3719.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3720.                                     }
  3721.                                     $unitsServ $itemInvoice->getSrvUnits();
  3722.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3723.                                         $unitsServ 1;
  3724.                                     }
  3725.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3726.                                     $subnetoUnit $subneto;
  3727.                                     $subneto $subneto $days $unitsServ $pax;
  3728.                                     break;
  3729.                                 case 13//Transport
  3730.                                     $pax $itemInvoice->getSrvPax();
  3731.                                     if (empty($pax) or $pax == "0") {
  3732.                                         $pax 1;
  3733.                                     }
  3734.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3735.                                     if ($days 1) {
  3736.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3737.                                     } else {
  3738.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3739.                                     }
  3740.                                     $unitsServ $itemInvoice->getSrvUnits();
  3741.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3742.                                         $unitsServ 1;
  3743.                                     }
  3744.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3745.                                     $subnetoUnit $subneto;
  3746.                                     $subneto $subneto $days $unitsServ $pax;
  3747.                                     break;
  3748.                                 case 14//Technology
  3749.                                     $pax $itemInvoice->getSrvPax();
  3750.                                     if (empty($pax) or $pax == "0") {
  3751.                                         $pax 1;
  3752.                                     }
  3753.                                     $days 1;
  3754.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3755.                                     $unitsServ $itemInvoice->getSrvUnits();
  3756.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3757.                                         $unitsServ 1;
  3758.                                     }
  3759.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3760.                                     $subnetoUnit $subneto;
  3761.                                     $subneto $subneto $days $unitsServ $pax;
  3762.                                     break;
  3763.                                 case 15//Assisstant
  3764.                                     $pax $itemInvoice->getSrvPax();
  3765.                                     if (empty($pax) or $pax == "0") {
  3766.                                         $pax 1;
  3767.                                     }
  3768.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3769.                                     if ($days 1) {
  3770.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3771.                                     } else {
  3772.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3773.                                     }
  3774.                                     $unitsServ $itemInvoice->getSrvUnits();
  3775.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3776.                                         $unitsServ 1;
  3777.                                     }
  3778.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3779.                                     $subnetoUnit $subneto;
  3780.                                     $subneto $subneto $days $unitsServ $pax;
  3781.                                     break;
  3782.                                 case 16//DDR
  3783.                                     $pax $itemInvoice->getSrvPax();
  3784.                                     if (empty($pax) or $pax == "0") {
  3785.                                         $pax 1;
  3786.                                     }
  3787.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3788.                                     if ($days 1) {
  3789.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3790.                                     } else {
  3791.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3792.                                     }
  3793.                                     $unitsServ $itemInvoice->getSrvUnits();
  3794.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3795.                                         $unitsServ 1;
  3796.                                     }
  3797.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3798.                                     $subnetoUnit $subneto;
  3799.                                     $subneto $subneto $days $unitsServ $pax;
  3800.                                     break;
  3801.                                 default:
  3802.                                     break;
  3803.                             }
  3804.                             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  3805.                             $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  3806.                             $neto round($subneto2PHP_ROUND_HALF_UP);
  3807.                             $valorTotalNet $valorTotalNet $neto;
  3808.                             $valorVat $valorVat + ($subtotal $neto);
  3809.                         }
  3810.                     }
  3811.                 }
  3812.             }
  3813.             if (!empty($arrayBools['payment'])) {
  3814.                 foreach ($arrayBools['payment'] as $key => $item) {
  3815.                     if ($item == 'true') {
  3816.                         $boolMakeInvoice true;
  3817.                         $pago $em->getRepository(AvePaymentsClient::class)->findOneById($key);
  3818.                         $itemInvoice = new AveDocInvoiceItems();
  3819.                         $itemInvoice->setFileId($id);
  3820.                         $itemInvoice->setInvoiceId($invoiceId);
  3821.                         $itemInvoice->setItemType('PAYMENT');
  3822.                         $itemInvoice->setPayControlId($key);
  3823.                         $itemInvoice->setPayAmount($pago->getAmount());
  3824.                         $itemInvoice->setPayVat($pago->getVat());
  3825.                         $itemInvoice->setPayAmountTotal($pago->getAmountTotal());
  3826.                         $itemInvoice->setPayDatePayAt($pago->getDatePayAt());
  3827.                         $itemInvoice->setPayWayToPay($pago->getWayToPay());
  3828.                         $itemInvoice->setCreatedAt(new DateTime('now'));
  3829.                         $itemInvoice->setUpdatedAt(new DateTime('now'));
  3830.                         $itemInvoice->setCreatedId($user_id);
  3831.                         $itemInvoice->setUpdatedId($user_id);
  3832.                         $em->persist($itemInvoice);
  3833.                         $em->flush();
  3834.                         //Acumulamos neto e iva para la factura
  3835.                         //$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();    // El pago no puede afectar el neto de la factura
  3836.                     }
  3837.                 }
  3838.             }
  3839.             //FIN: Creamos los items de la factura
  3840.             $valorTotal $valorTotalNet $valorVat;
  3841.             //INICIO: Creamos la factura
  3842.             $newInvoice = new AveDocInvoice();
  3843.             $newInvoice->setAccessKey(md5(rand() * time()));
  3844.             $newInvoice->setNumber('AVE-' date('dmy') . "-" $id);
  3845.             $newInvoice->setDateAt(new DateTime('now'));
  3846.             $newInvoice->setType('Invoice');
  3847.             $newInvoice->setFileId($id);
  3848.             $newInvoice->setTotalNet($valorTotalNet);
  3849.             $newInvoice->setVat($valorVat);
  3850.             $newInvoice->setTotal($valorTotal);
  3851.             $newInvoice->setCreatedAt(new DateTime('now'));
  3852.             $newInvoice->setCreatedId($user_id);
  3853.             $newInvoice->setUpdatedAt(new DateTime('now'));
  3854.             $newInvoice->setUpdatedId($user_id);
  3855.             $newInvoice->setMaster('master');
  3856.             if ($boolMakeInvoice) {
  3857.                 // Solo se debe crear factura si hay un elemento
  3858.                 $em->persist($newInvoice);
  3859.                 $em->flush();
  3860.                 $newInvoice->setNumber($newInvoice->getNumber() . '-' $newInvoice->getId());
  3861.                 $em->persist($newInvoice);
  3862.                 $em->flush();
  3863.             } else {
  3864.                 // Se llama a la vista de facturas del expediente
  3865.                 return $this->redirectToRoute('ave_view_invoice', array('id' => $id));
  3866.             }
  3867.             //FIN: Creamos la factura
  3868.             $data = array();
  3869.             $data $this->baseInvoiceSelectedFile($id$arrayBools'I' $newInvoice->getId());
  3870.             $paymentsClient = new AvePaymentsClient();
  3871.             $paymentsClient->setFileId($id);
  3872.             $file $em->getRepository(AveFiles::class)->findOneById($id);
  3873.             $payments $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  3874.             $services $em->getRepository(AveServices::class)->findByFileId($id);
  3875.             $proforma $em->getRepository(AveDocProforma::class)->findOneByFileId($id);
  3876.             $reservaInv = new AveDocInvoice();
  3877.             $reservaInv->setAccessKey(md5(rand() * time()));
  3878.             $reservaInv->setFileId($id);
  3879.             $idProducts = array();
  3880.             $productsBoolToInvoice = array();
  3881.             if (array_key_exists('lounge'$data['datasupplier'])) {
  3882.                 foreach ($data['datasupplier']['lounge'] as $item) {
  3883.                     $idProducts[] = $item['id'];
  3884.                     $productsBoolToInvoice[] = 1;
  3885.                 }
  3886.                 $idProducts implode(','$idProducts);
  3887.                 $productsBoolToInvoice implode(','$productsBoolToInvoice);
  3888.             } else {
  3889.                 $idProducts '0';
  3890.                 $productsBoolToInvoice '0';
  3891.             }
  3892.             $idPayments = array();
  3893.             $paymentsBoolToInvoice = array();
  3894.             if (array_key_exists('payment'$data['datasupplier'])) {
  3895.                 foreach ($data['datasupplier']['payment'] as $item) {
  3896.                     $idPayments[] = $item['id'];
  3897.                     $paymentsBoolToInvoice[] = 1;
  3898.                 }
  3899.                 $idPayments implode(','$idPayments);
  3900.                 $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  3901.                 // Se han generado dos arreglos, cada uno dividido en 2 strings
  3902.                 // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  3903.                 // Para manipularlos entre la vista y el JS
  3904.             } else {
  3905.                 $idPayments '0';
  3906.                 $paymentsBoolToInvoice '0';
  3907.             }
  3908.             // Una factura solo se puede rectificar una vez
  3909.             $rectf $em->getRepository(AveDocInvoiceRec::class)->findBy(array('number' => 'REC-' $newInvoice->getNumber()));
  3910.             $boolToRec = empty($rectf);
  3911.             $allInvoices $em->getRepository(AveDocInvoice::class)->findByFileId($id);
  3912.             $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($id);
  3913.             foreach ($allInvoicesRec as $item) {
  3914.                 array_push($allInvoices$item);
  3915.             }
  3916.             $allProformas $em->getRepository(AveDocProforma::class)->findByFileId($id);
  3917.             if (empty($data['type'])) {
  3918.                 $data['type'] = 'Invoice';
  3919.             }
  3920.             if (array_key_exists('paymentSubTotal'$data['datasupplier'])) {
  3921.                 $paymentInvoice $data['datasupplier']['paymentSubTotal']['sumSubT'];
  3922.             } else {
  3923.                 $paymentInvoice 0;
  3924.             }
  3925.             return $this->redirectToRoute(
  3926.                 'ave_view_invoice',
  3927.                 array(
  3928.                     'id' => $newInvoice->getId()
  3929.                 )
  3930.             );
  3931.         }
  3932.     }
  3933.     /**
  3934.      * @Route("/viewinvoice/{id}",  name="ave_view_invoice")
  3935.      * Ver una factura
  3936.      */
  3937.     public function viewNewInvoiceAction($idRequest $request)
  3938.     {
  3939.         $em $this->getDoctrine()->getManager();
  3940.         // Se genera y muestra en nueva pantalla la nueva proforma
  3941.         $arrayBools = array(
  3942.             'product' => null,
  3943.             'service' => null,
  3944.             'payment' => null,
  3945.         );
  3946.         $arrayBools['product'] = $request->request->get('inv_lounge_hidden_bool');
  3947.         $arrayBools['service'] = $request->request->get('inv_service_hidden_bool');
  3948.         $arrayBools['payment'] = $request->request->get('inv_payment_hidden_bool');
  3949.         /* Obtengo usuario logueado */
  3950.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  3951.         $user_id $user_logueado->getId();
  3952.         //Acumuladores de datos globales de la factura
  3953.         $valorTotalNet $valorVat 0;
  3954.         //INICIO: Creamos los items de la factura
  3955.         $arrayInvoicedItems $em->getRepository(AveDocInvoiceItems::class)->findByInvoiceId($id);
  3956.         if (!empty($arrayInvoicedItems)) {
  3957.             foreach ($arrayInvoicedItems as $itemInvoice) {
  3958.                 if ($itemInvoice->getItemType() == 'PRODUCT') {
  3959.                     //Buscamos el iva
  3960.                     $zProductFile $em->getRepository(AveProductFile::class)->findOneById($itemInvoice->getPrdControlId());
  3961.                     if (empty($zProductFile)) {
  3962.                         $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $itemInvoice->getPrdControlId());
  3963.                     }
  3964.                     $ivaFactor = empty($zProductFile) ? 0.21 : ($zProductFile->getIva() / 100);
  3965.                     if (!empty($itemInvoice->getPrdIva()) or ($itemInvoice->getPrdIva() == 0)) {
  3966.                         $ivaFactor = ($itemInvoice->getPrdIva()) / 100;
  3967.                     }        // El iva se incorporo en la entidad despues del año 2024 por eso las lineas anteriores del iva
  3968.                     //Acumulamos neto e iva para la factura
  3969.                     //                    $valorTotalNet = $valorTotalNet + $itemInvoice->getPrdServicePrice();
  3970.                     $valorTotalNet $valorTotalNet $itemInvoice->getPrdSubTotalPrice();
  3971.                     //                    $valorVat = $valorVat + round(($itemInvoice->getPrdServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
  3972.                     $valorVat $valorVat round(($itemInvoice->getPrdSubTotalPrice() * $ivaFactor), 2PHP_ROUND_HALF_UP);
  3973.                 }
  3974.             }
  3975.         }
  3976.         if (!empty($arrayInvoicedItems)) {
  3977.             foreach ($arrayInvoicedItems as $itemInvoice) {
  3978.                 if ($itemInvoice->getItemType() == 'SERVICE') {
  3979.                     //Acumulamos neto e iva para la factura
  3980.                     if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())) {
  3981.                         $subtotal 0;
  3982.                         $neto 0;
  3983.                         $subtotalService 0;
  3984.                     } else {
  3985.                         $subtotalService $itemInvoice->getSrvPrice();
  3986.                         $subneto $itemInvoice->getSrvPrice();
  3987.                         // Commission
  3988.                         if ($itemInvoice->getSrvOpCommission() == '1') {
  3989.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvCommission() / 100));
  3990.                             $subneto $subneto  * (+ ($itemInvoice->getSrvCommission() / 100));
  3991.                         } else {
  3992.                             $subtotalService $subtotalService * (- ($itemInvoice->getSrvCommission() / 100));
  3993.                             $subneto $subneto * (- ($itemInvoice->getSrvCommission() / 100));
  3994.                         }
  3995.                         // Over
  3996.                         if ($itemInvoice->getSrvOpOver() == '1') {
  3997.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  3998.                             $subneto $subneto $itemInvoice->getSrvOver();
  3999.                         } else {
  4000.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  4001.                             $subneto $subneto $itemInvoice->getSrvOver();
  4002.                         }
  4003.                         // IVA
  4004.                         if ($itemInvoice->getSrvOpIva() == '1') {
  4005.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvIva() / 100));
  4006.                         } else {
  4007.                             $subtotalService $itemInvoice->getSrvPrice();
  4008.                             $subneto = ($subneto 100) / (100 $itemInvoice->getSrvIva());
  4009.                         }
  4010.                         switch ($itemInvoice->getSrvServiceCatId()) {
  4011.                             case 1// Alojamiento
  4012.                                 // el numero de noches $numNoches; precio unitario $subneto
  4013.                                 $numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
  4014.                                 // La personas no afectan este calculo
  4015.                                 $subtotal $subtotalService $numNoches $itemInvoice->getSrvUnits();
  4016.                                 $subnetoUnit $subneto;
  4017.                                 $subneto $subneto $numNoches $itemInvoice->getSrvUnits();
  4018.                                 break;
  4019.                             case 2//Actividades
  4020.                                 // El nĂºmero de personas es considerado en el calculo
  4021.                                 $pax $itemInvoice->getSrvPax();
  4022.                                 if (empty($pax) or $pax == "0") {
  4023.                                     $pax 1;
  4024.                                 }
  4025.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4026.                                 if ($days 1) {
  4027.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4028.                                 } else {
  4029.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4030.                                 }
  4031.                                 $subtotal $subtotalService $days $itemInvoice->getSrvUnits();
  4032.                                 $subnetoUnit $subneto;
  4033.                                 $subneto $subneto $days $itemInvoice->getSrvUnits();
  4034.                                 break;
  4035.                             case 3// AV
  4036.                                 $pax $itemInvoice->getSrvPax();
  4037.                                 if (empty($pax) or $pax == "0") {
  4038.                                     $pax 1;
  4039.                                 }
  4040.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4041.                                 if ($days 1) {
  4042.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4043.                                 } else {
  4044.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4045.                                 }
  4046.                                 $unitsServ $itemInvoice->getSrvUnits();
  4047.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4048.                                     $unitsServ 1;
  4049.                                 }
  4050.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4051.                                 $subnetoUnit $subneto;
  4052.                                 $subneto $subneto $days $unitsServ $pax;
  4053.                                 break;
  4054.                             case 4//Creative
  4055.                                 $pax $itemInvoice->getSrvPax();
  4056.                                 if (empty($pax) or $pax == "0") {
  4057.                                     $pax 1;
  4058.                                 }
  4059.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4060.                                 if ($days 1) {
  4061.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4062.                                 } else {
  4063.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4064.                                 }
  4065.                                 $unitsServ $itemInvoice->getSrvUnits();
  4066.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4067.                                     $unitsServ 1;
  4068.                                 }
  4069.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4070.                                 $subnetoUnit $subneto;
  4071.                                 $subneto $subneto $days $unitsServ $pax;
  4072.                                 break;
  4073.                             case 5//Cruise
  4074.                                 $pax $itemInvoice->getSrvPax();
  4075.                                 if (empty($pax) or $pax == "0") {
  4076.                                     $pax 1;
  4077.                                 }
  4078.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
  4079.                                 if ($days 1) {
  4080.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4081.                                 } else {
  4082.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4083.                                 }
  4084.                                 $unitsServ $itemInvoice->getSrvUnits();
  4085.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4086.                                     $unitsServ 1;
  4087.                                 }
  4088.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4089.                                 $subnetoUnit $subneto;
  4090.                                 $subneto $subneto $days $unitsServ $pax;
  4091.                                 break;
  4092.                             case 6//Entertaiment
  4093.                                 $pax $itemInvoice->getSrvPax();
  4094.                                 if (empty($pax) or $pax == "0") {
  4095.                                     $pax 1;
  4096.                                 }
  4097.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4098.                                 if ($days 1) {
  4099.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4100.                                 } else {
  4101.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4102.                                 }
  4103.                                 $unitsServ $itemInvoice->getSrvUnits();
  4104.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4105.                                     $unitsServ 1;
  4106.                                 }
  4107.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4108.                                 $subnetoUnit $subneto;
  4109.                                 $subneto $subneto $days $unitsServ $pax;
  4110.                                 break;
  4111.                             case 7// Gifts
  4112.                                 $pax $itemInvoice->getSrvPax();
  4113.                                 if (empty($pax) or $pax == "0") {
  4114.                                     $pax 1;
  4115.                                 }
  4116.                                 $days 1;
  4117.                                 if ($days 1) {
  4118.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4119.                                 } else {
  4120.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4121.                                 }
  4122.                                 $unitsServ $itemInvoice->getSrvUnits();
  4123.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4124.                                     $unitsServ 1;
  4125.                                 }
  4126.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4127.                                 $subnetoUnit $subneto;
  4128.                                 $subneto $subneto $days $unitsServ $pax;
  4129.                                 break;
  4130.                             case 8//Guide
  4131.                                 $pax $itemInvoice->getSrvPax();
  4132.                                 if (empty($pax) or $pax == "0") {
  4133.                                     $pax 1;
  4134.                                 }
  4135.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4136.                                 if ($days 1) {
  4137.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4138.                                 } else {
  4139.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4140.                                 }
  4141.                                 $unitsServ $itemInvoice->getSrvUnits();
  4142.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4143.                                     $unitsServ 1;
  4144.                                 }
  4145.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4146.                                 $subnetoUnit $subneto;
  4147.                                 $subneto $subneto $days $unitsServ $pax;
  4148.                                 break;
  4149.                             case 9//Itineraries
  4150.                                 $pax $itemInvoice->getSrvPax();
  4151.                                 if (empty($pax) or $pax == "0") {
  4152.                                     $pax 1;
  4153.                                 }
  4154.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4155.                                 if ($days 1) {
  4156.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4157.                                 } else {
  4158.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4159.                                 }
  4160.                                 $unitsServ $itemInvoice->getSrvUnits();
  4161.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4162.                                     $unitsServ 1;
  4163.                                 }
  4164.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4165.                                 $subnetoUnit $subneto;
  4166.                                 $subneto $subneto $days $unitsServ $pax;
  4167.                                 break;
  4168.                             case 10//Lounge  -- No Aplica
  4169.                                 break;
  4170.                             case 11//Menu
  4171.                                 $pax $itemInvoice->getSrvPax();
  4172.                                 if (empty($pax) or $pax == "0") {
  4173.                                     $pax 1;
  4174.                                 }
  4175.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4176.                                 if ($days 1) {
  4177.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4178.                                 } else {
  4179.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4180.                                 }
  4181.                                 $unitsServ $itemInvoice->getSrvUnits();
  4182.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4183.                                     $unitsServ 1;
  4184.                                 }
  4185.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4186.                                 $subnetoUnit $subneto;
  4187.                                 $subneto $subneto $days $unitsServ $pax;
  4188.                                 break;
  4189.                             case 12//Others
  4190.                                 $pax $itemInvoice->getSrvPax();
  4191.                                 if (empty($pax) or $pax == "0") {
  4192.                                     $pax 1;
  4193.                                 }
  4194.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4195.                                 if ($days 1) {
  4196.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4197.                                 } else {
  4198.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4199.                                 }
  4200.                                 $unitsServ $itemInvoice->getSrvUnits();
  4201.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4202.                                     $unitsServ 1;
  4203.                                 }
  4204.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4205.                                 $subnetoUnit $subneto;
  4206.                                 $subneto $subneto $days $unitsServ $pax;
  4207.                                 break;
  4208.                             case 13//Transport
  4209.                                 $pax $itemInvoice->getSrvPax();
  4210.                                 if (empty($pax) or $pax == "0") {
  4211.                                     $pax 1;
  4212.                                 }
  4213.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4214.                                 if ($days 1) {
  4215.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4216.                                 } else {
  4217.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4218.                                 }
  4219.                                 $unitsServ $itemInvoice->getSrvUnits();
  4220.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4221.                                     $unitsServ 1;
  4222.                                 }
  4223.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4224.                                 $subnetoUnit $subneto;
  4225.                                 $subneto $subneto $days $unitsServ $pax;
  4226.                                 break;
  4227.                             case 14//Technology
  4228.                                 $pax $itemInvoice->getSrvPax();
  4229.                                 if (empty($pax) or $pax == "0") {
  4230.                                     $pax 1;
  4231.                                 }
  4232.                                 $days 1;
  4233.                                 $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4234.                                 $unitsServ $itemInvoice->getSrvUnits();
  4235.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4236.                                     $unitsServ 1;
  4237.                                 }
  4238.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4239.                                 $subnetoUnit $subneto;
  4240.                                 $subneto $subneto $days $unitsServ $pax;
  4241.                                 break;
  4242.                             case 15//Assisstant
  4243.                                 $pax $itemInvoice->getSrvPax();
  4244.                                 if (empty($pax) or $pax == "0") {
  4245.                                     $pax 1;
  4246.                                 }
  4247.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4248.                                 if ($days 1) {
  4249.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4250.                                 } else {
  4251.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4252.                                 }
  4253.                                 $unitsServ $itemInvoice->getSrvUnits();
  4254.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4255.                                     $unitsServ 1;
  4256.                                 }
  4257.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4258.                                 $subnetoUnit $subneto;
  4259.                                 $subneto $subneto $days $unitsServ $pax;
  4260.                                 break;
  4261.                             case 16//DDR
  4262.                                 $pax $itemInvoice->getSrvPax();
  4263.                                 if (empty($pax) or $pax == "0") {
  4264.                                     $pax 1;
  4265.                                 }
  4266.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4267.                                 if ($days 1) {
  4268.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4269.                                 } else {
  4270.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4271.                                 }
  4272.                                 $unitsServ $itemInvoice->getSrvUnits();
  4273.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4274.                                     $unitsServ 1;
  4275.                                 }
  4276.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4277.                                 $subnetoUnit $subneto;
  4278.                                 $subneto $subneto $days $unitsServ $pax;
  4279.                                 break;
  4280.                             default:
  4281.                                 break;
  4282.                         }
  4283.                         // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  4284.                         $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  4285.                         $neto round($subneto2PHP_ROUND_HALF_UP);
  4286.                         $valorTotalNet $valorTotalNet $neto;
  4287.                         $valorVat $valorVat + ($subtotal $neto);
  4288.                     }
  4289.                 }
  4290.             }
  4291.         }
  4292.         if (!empty($arrayInvoicedItems)) {
  4293.             foreach ($arrayInvoicedItems as $itemInvoice) {
  4294.                 if ($itemInvoice->getItemType() == 'PAYMENT') {
  4295.                     //                    $pago = $em->getRepository(ReservationPaymentsClient::class)->findOneById($key);
  4296.                     //
  4297.                     //                    $itemInvoice = new ReservationInvoiceItems();
  4298.                     //                    $itemInvoice->setReservationId($id);
  4299.                     //                    $itemInvoice->setInvoiceId($invoiceId);
  4300.                     //                    $itemInvoice->setItemType('PAYMENT');
  4301.                     //                    $itemInvoice->setPayControlId($key);
  4302.                     //                    $itemInvoice->setPayAmount($pago->getAmount());
  4303.                     //                    $itemInvoice->setPayDatePayAt($pago->getDatePayAt());
  4304.                     //                    $itemInvoice->setPayWayToPay($pago->getWayToPay());
  4305.                     //                    $itemInvoice->setCreatedAt(new DateTime('now'));
  4306.                     //                    $itemInvoice->setUpdatedAt(new DateTime('now'));
  4307.                     //                    $itemInvoice->setCreatedId($user_id);
  4308.                     //                    $itemInvoice->setUpdatedId($user_id);
  4309.                     //
  4310.                     //                    $em->persist($itemInvoice);
  4311.                     //                    $em->flush();
  4312.                     //Acumulamos neto e iva para la factura
  4313.                     //$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();    // El pago no puede afectar el neto de la factura
  4314.                 }
  4315.             }
  4316.         }
  4317.         //FIN: Creamos los items de la factura
  4318.         $valorTotal $valorTotalNet $valorVat;
  4319.         $newInvoice $em->getRepository(AveDocInvoice::class)->findOneById($id);
  4320.         if (!$newInvoice) {
  4321.             $newInvoice $em->getRepository(AveDocProforma::class)->findOneById($id);
  4322.             if (!$newInvoice) {
  4323.                 throw $this->createNotFoundException('No se encontrĂ³ el documento con ID: ' $id);
  4324.             }
  4325.         }
  4326.         $data = [];
  4327.         $data $this->baseInvoiceDoneFile($newInvoice->getFileId(), $id'I');
  4328.         $paymentsClient = new AvePaymentsClient();
  4329.         $paymentsClient->setFileId($id);
  4330.         $fileInv = new AveDocInvoice();
  4331.         $fileInv->setAccessKey(md5(rand() * time()));
  4332.         $fileInv->setFileId($id);
  4333.         $idProducts = [];
  4334.         $productsBoolToInvoice = [];
  4335.         if (array_key_exists('product'$data['datasupplier'])) {
  4336.             foreach ($data['datasupplier']['product'] as $item) {
  4337.                 $idProducts[] = $item['id'];
  4338.                 $productsBoolToInvoice[] = 1;
  4339.             }
  4340.             $idProducts implode(','$idProducts);
  4341.             $productsBoolToInvoice implode(','$productsBoolToInvoice);
  4342.         } else {
  4343.             $idProducts '0';
  4344.             $productsBoolToInvoice '0';
  4345.         }
  4346.         $idPayments = [];
  4347.         $paymentsBoolToInvoice = [];
  4348.         if (array_key_exists('payment'$data['datasupplier'])) {
  4349.             foreach ($data['datasupplier']['payment'] as $item) {
  4350.                 $idPayments[] = $item['id'];
  4351.                 $paymentsBoolToInvoice[] = 1;
  4352.             }
  4353.             $idPayments implode(','$idPayments);
  4354.             $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  4355.             // Se han generado dos arreglos, cada uno dividido en 2 strings
  4356.             // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  4357.             // Para manipularlos entre la vista y el JS
  4358.         } else {
  4359.             $idPayments '0';
  4360.             $paymentsBoolToInvoice '0';
  4361.         }
  4362.         // Una factura solo se puede rectificar una vez
  4363.         $rectf $em->getRepository(AveDocInvoiceRec::class)->findBy(array('number' => 'REC-' $newInvoice->getNumber()));
  4364.         $boolToRec = empty($rectf);
  4365.         // Solo pueden rectificar desde el departamento de administracion y Salva
  4366.         $boolToRec = ($boolToRec and ($user_logueado->getSettingsRol()->getMadmin() or $user_logueado->getId() == 14));
  4367.         $allInvoices $em->getRepository(AveDocInvoice::class)->findByFileId($newInvoice->getFileId());
  4368.         $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($newInvoice->getFileId());
  4369.         foreach ($allInvoicesRec as $item) {
  4370.             array_push($allInvoices$item);
  4371.         }
  4372.         $allProformas $em->getRepository(AveDocProforma::class)->findByFileId($newInvoice->getFileId());
  4373.         if (empty($data['type'])) {
  4374.             $data['type'] = 'Invoice';
  4375.         }
  4376.         $commentsBool false;
  4377.         $comments null;
  4378.         $fileAv $em->getRepository(AveFiles::class)->findOneById($newInvoice->getFileId());
  4379.         if ($fileAv->getCommentsInInv()) { $commentsBool true; }
  4380.         if ($commentsBool) { $comments $fileAv->getComments(); }
  4381.         // Campos extras - Actualizamos las entidades InvoiceProformaExtraField y las asociamos con la factura
  4382.         $company $em->getRepository(SettingsCompany::class)->findOneByBusinessType(['businessType' => BusinessTypeSettingsCompanyConstants::AUDIOVISUAL]);
  4383.         $billingSerie = empty($newInvoice->getPrefix()) ? null $newInvoice->getPrefix();
  4384.         $companyId = empty($company) ? null $company->getId();
  4385.         $numberInvFromLine $this->extraFieldService->extractInvoiceNumber($newInvoice->getNumber(), $billingSerie);
  4386.         $extraFields $this->extraFieldService->getExtraFieldsIndexedByPosition($companyIdInvoiceProformaExtraFieldConstants::TYPE_INVOICE$id$billingSerie);
  4387.         return $this->render(
  4388.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
  4389.             array(
  4390.                 'id' => $newInvoice->getFileId(),
  4391.                 'cid' => '',
  4392.                 'fid' => $id,
  4393.                 'invoice' => $newInvoice,
  4394.                 'facturas' => $allInvoices,
  4395.                 'proformas' => $allProformas,
  4396.                 'boolToRec' => $boolToRec,
  4397.                 'numberadmin' => '',
  4398.                 'type' => $data['type'],
  4399.                 'docType' => 'Factura',
  4400.                 'number' => $newInvoice->getId(),
  4401.                 'prefix' => $data['prefix'],
  4402.                 'date' => $data['date'],
  4403.                 'token' =>  $data['token'],
  4404.                 'file' => $data['file'],
  4405.                 'company' => $data['company'],
  4406.                 'clients' => $data['clients'],
  4407.                 'user' => $user_logueado,
  4408.                 'invoicedeposititems' => '',
  4409.                 'arrayItems' => $data['arrayItems'],
  4410.                 'datasupplier' => $data['datasupplier'],
  4411.                 'totales_neto' => $data['totales_neto'],
  4412.                 'totales_iva' => '',
  4413.                 'totales' => $data['totales'],
  4414.                 'bases_imponibles' => $data['bases_imponibles'],
  4415.                 'balance' => $data['balance'],
  4416.                 'paymentInvoice' => $data['paymentInvoice'],
  4417.                 'currency' => $data['currency'],
  4418.                 'comments' => $comments,
  4419.                 'extraFields' => $extraFields,
  4420.             )
  4421.         );
  4422.     }
  4423.     /**
  4424.      * @Route("/avexternal/printinvoice/{id}",  name="ave_print_invoice")
  4425.      * Imprimir una factura
  4426.      */
  4427.     public function printInvoiceAction($idRequest $request)
  4428.     {
  4429.         $em $this->getDoctrine()->getManager();
  4430.         // Se genera y muestra en nueva pantalla la nueva proforma
  4431.         $arrayBools = array(
  4432.             'product' => null,
  4433.             'service' => null,
  4434.             'payment' => null,
  4435.         );
  4436.         $arrayBools['product'] = $request->request->get('inv_lounge_hidden_bool');
  4437.         $arrayBools['service'] = $request->request->get('inv_service_hidden_bool');
  4438.         $arrayBools['payment'] = $request->request->get('inv_payment_hidden_bool');
  4439.         //Acumuladores de datos globales de la factura
  4440.         $valorTotalNet 0;
  4441.         $valorVat 0;
  4442.         //INICIO: Creamos los items de la factura
  4443.         $arrayInvoicedItems $em->getRepository(AveDocInvoiceItems::class)->findByInvoiceId($id);
  4444.         if (!empty($arrayInvoicedItems)) {
  4445.             foreach ($arrayInvoicedItems as $itemInvoice) {
  4446.                 if ($itemInvoice->getItemType() == 'PRODUCT') {
  4447.                     //Acumulamos neto e iva para la factura
  4448.                     $valorTotalNet $valorTotalNet $itemInvoice->getPrdServicePrice();
  4449.                     $valorVat $valorVat round(($itemInvoice->getPrdServicePrice() * 0.21), 2PHP_ROUND_HALF_UP);
  4450.                 }
  4451.             }
  4452.         }
  4453.         if (!empty($arrayInvoicedItems)) {
  4454.             foreach ($arrayInvoicedItems as $itemInvoice) {
  4455.                 if ($itemInvoice->getItemType() == 'SERVICE') {
  4456.                     //Acumulamos neto e iva para la factura
  4457.                     if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())) {
  4458.                         $subtotal 0;
  4459.                         $neto 0;
  4460.                         $subtotalService 0;
  4461.                     } else {
  4462.                         $subtotalService $itemInvoice->getSrvPrice();
  4463.                         $subneto $itemInvoice->getSrvPrice();
  4464.                         // Commission
  4465.                         if ($itemInvoice->getSrvOpCommission() == '1') {
  4466.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvCommission() / 100));
  4467.                             $subneto $subneto  * (+ ($itemInvoice->getSrvCommission() / 100));
  4468.                         } else {
  4469.                             $subtotalService $subtotalService * (- ($itemInvoice->getSrvCommission() / 100));
  4470.                             $subneto $subneto * (- ($itemInvoice->getSrvCommission() / 100));
  4471.                         }
  4472.                         // Over
  4473.                         if ($itemInvoice->getSrvOpOver() == '1') {
  4474.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  4475.                             $subneto $subneto $itemInvoice->getSrvOver();
  4476.                         } else {
  4477.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  4478.                             $subneto $subneto $itemInvoice->getSrvOver();
  4479.                         }
  4480.                         // IVA
  4481.                         if ($itemInvoice->getSrvOpIva() == '1') {
  4482.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvIva() / 100));
  4483.                         } else {
  4484.                             $subtotalService $itemInvoice->getSrvPrice();
  4485.                             $subneto = ($subneto 100) / (100 $itemInvoice->getSrvIva());
  4486.                         }
  4487.                         switch ($itemInvoice->getSrvServiceCatId()) {
  4488.                             case 1// Alojamiento
  4489.                                 // el numero de noches $numNoches; precio unitario $subneto
  4490.                                 $numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
  4491.                                 // La personas no afectan este calculo
  4492.                                 $subtotal $subtotalService $numNoches $itemInvoice->getSrvUnits();
  4493.                                 $subnetoUnit $subneto;
  4494.                                 $subneto $subneto $numNoches $itemInvoice->getSrvUnits();
  4495.                                 break;
  4496.                             case 2//Actividades
  4497.                                 // El nĂºmero de personas es considerado en el calculo
  4498.                                 $pax $itemInvoice->getSrvPax();
  4499.                                 if (empty($pax) or $pax == "0") {
  4500.                                     $pax 1;
  4501.                                 }
  4502.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4503.                                 if ($days 1) {
  4504.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4505.                                 } else {
  4506.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4507.                                 }
  4508.                                 $subtotal $subtotalService $days $itemInvoice->getSrvUnits();
  4509.                                 $subnetoUnit $subneto;
  4510.                                 $subneto $subneto $days $itemInvoice->getSrvUnits();
  4511.                                 break;
  4512.                             case 3// AV
  4513.                                 $pax $itemInvoice->getSrvPax();
  4514.                                 if (empty($pax) or $pax == "0") {
  4515.                                     $pax 1;
  4516.                                 }
  4517.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4518.                                 if ($days 1) {
  4519.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4520.                                 } else {
  4521.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4522.                                 }
  4523.                                 $unitsServ $itemInvoice->getSrvUnits();
  4524.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4525.                                     $unitsServ 1;
  4526.                                 }
  4527.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4528.                                 $subnetoUnit $subneto;
  4529.                                 $subneto $subneto $days $unitsServ $pax;
  4530.                                 break;
  4531.                             case 4//Creative
  4532.                                 $pax $itemInvoice->getSrvPax();
  4533.                                 if (empty($pax) or $pax == "0") {
  4534.                                     $pax 1;
  4535.                                 }
  4536.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4537.                                 if ($days 1) {
  4538.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4539.                                 } else {
  4540.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4541.                                 }
  4542.                                 $unitsServ $itemInvoice->getSrvUnits();
  4543.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4544.                                     $unitsServ 1;
  4545.                                 }
  4546.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4547.                                 $subnetoUnit $subneto;
  4548.                                 $subneto $subneto $days $unitsServ $pax;
  4549.                                 break;
  4550.                             case 5//Cruise
  4551.                                 $pax $itemInvoice->getSrvPax();
  4552.                                 if (empty($pax) or $pax == "0") {
  4553.                                     $pax 1;
  4554.                                 }
  4555.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
  4556.                                 if ($days 1) {
  4557.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4558.                                 } else {
  4559.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4560.                                 }
  4561.                                 $unitsServ $itemInvoice->getSrvUnits();
  4562.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4563.                                     $unitsServ 1;
  4564.                                 }
  4565.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4566.                                 $subnetoUnit $subneto;
  4567.                                 $subneto $subneto $days $unitsServ $pax;
  4568.                                 break;
  4569.                             case 6//Entertaiment
  4570.                                 $pax $itemInvoice->getSrvPax();
  4571.                                 if (empty($pax) or $pax == "0") {
  4572.                                     $pax 1;
  4573.                                 }
  4574.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4575.                                 if ($days 1) {
  4576.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4577.                                 } else {
  4578.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4579.                                 }
  4580.                                 $unitsServ $itemInvoice->getSrvUnits();
  4581.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4582.                                     $unitsServ 1;
  4583.                                 }
  4584.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4585.                                 $subnetoUnit $subneto;
  4586.                                 $subneto $subneto $days $unitsServ $pax;
  4587.                                 break;
  4588.                             case 7// Gifts
  4589.                                 $pax $itemInvoice->getSrvPax();
  4590.                                 if (empty($pax) or $pax == "0") {
  4591.                                     $pax 1;
  4592.                                 }
  4593.                                 $days 1;
  4594.                                 if ($days 1) {
  4595.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4596.                                 } else {
  4597.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4598.                                 }
  4599.                                 $unitsServ $itemInvoice->getSrvUnits();
  4600.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4601.                                     $unitsServ 1;
  4602.                                 }
  4603.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4604.                                 $subnetoUnit $subneto;
  4605.                                 $subneto $subneto $days $unitsServ $pax;
  4606.                                 break;
  4607.                             case 8//Guide
  4608.                                 $pax $itemInvoice->getSrvPax();
  4609.                                 if (empty($pax) or $pax == "0") {
  4610.                                     $pax 1;
  4611.                                 }
  4612.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4613.                                 if ($days 1) {
  4614.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4615.                                 } else {
  4616.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4617.                                 }
  4618.                                 $unitsServ $itemInvoice->getSrvUnits();
  4619.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4620.                                     $unitsServ 1;
  4621.                                 }
  4622.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4623.                                 $subnetoUnit $subneto;
  4624.                                 $subneto $subneto $days $unitsServ $pax;
  4625.                                 break;
  4626.                             case 9//Itineraries
  4627.                                 $pax $itemInvoice->getSrvPax();
  4628.                                 if (empty($pax) or $pax == "0") {
  4629.                                     $pax 1;
  4630.                                 }
  4631.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4632.                                 if ($days 1) {
  4633.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4634.                                 } else {
  4635.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4636.                                 }
  4637.                                 $unitsServ $itemInvoice->getSrvUnits();
  4638.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4639.                                     $unitsServ 1;
  4640.                                 }
  4641.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4642.                                 $subnetoUnit $subneto;
  4643.                                 $subneto $subneto $days $unitsServ $pax;
  4644.                                 break;
  4645.                             case 10//Lounge  -- No Aplica
  4646.                                 break;
  4647.                             case 11//Menu
  4648.                                 $pax $itemInvoice->getSrvPax();
  4649.                                 if (empty($pax) or $pax == "0") {
  4650.                                     $pax 1;
  4651.                                 }
  4652.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4653.                                 if ($days 1) {
  4654.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4655.                                 } else {
  4656.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4657.                                 }
  4658.                                 $unitsServ $itemInvoice->getSrvUnits();
  4659.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4660.                                     $unitsServ 1;
  4661.                                 }
  4662.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4663.                                 $subnetoUnit $subneto;
  4664.                                 $subneto $subneto $days $unitsServ $pax;
  4665.                                 break;
  4666.                             case 12//Others
  4667.                                 $pax $itemInvoice->getSrvPax();
  4668.                                 if (empty($pax) or $pax == "0") {
  4669.                                     $pax 1;
  4670.                                 }
  4671.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4672.                                 if ($days 1) {
  4673.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4674.                                 } else {
  4675.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4676.                                 }
  4677.                                 $unitsServ $itemInvoice->getSrvUnits();
  4678.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4679.                                     $unitsServ 1;
  4680.                                 }
  4681.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4682.                                 $subnetoUnit $subneto;
  4683.                                 $subneto $subneto $days $unitsServ $pax;
  4684.                                 break;
  4685.                             case 13//Transport
  4686.                                 $pax $itemInvoice->getSrvPax();
  4687.                                 if (empty($pax) or $pax == "0") {
  4688.                                     $pax 1;
  4689.                                 }
  4690.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4691.                                 if ($days 1) {
  4692.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4693.                                 } else {
  4694.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4695.                                 }
  4696.                                 $unitsServ $itemInvoice->getSrvUnits();
  4697.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4698.                                     $unitsServ 1;
  4699.                                 }
  4700.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4701.                                 $subnetoUnit $subneto;
  4702.                                 $subneto $subneto $days $unitsServ $pax;
  4703.                                 break;
  4704.                             case 14//Technology
  4705.                                 $pax $itemInvoice->getSrvPax();
  4706.                                 if (empty($pax) or $pax == "0") {
  4707.                                     $pax 1;
  4708.                                 }
  4709.                                 $days 1;
  4710.                                 $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4711.                                 $unitsServ $itemInvoice->getSrvUnits();
  4712.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4713.                                     $unitsServ 1;
  4714.                                 }
  4715.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4716.                                 $subnetoUnit $subneto;
  4717.                                 $subneto $subneto $days $unitsServ $pax;
  4718.                                 break;
  4719.                             case 15//Assisstant
  4720.                                 $pax $itemInvoice->getSrvPax();
  4721.                                 if (empty($pax) or $pax == "0") {
  4722.                                     $pax 1;
  4723.                                 }
  4724.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4725.                                 if ($days 1) {
  4726.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4727.                                 } else {
  4728.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4729.                                 }
  4730.                                 $unitsServ $itemInvoice->getSrvUnits();
  4731.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4732.                                     $unitsServ 1;
  4733.                                 }
  4734.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4735.                                 $subnetoUnit $subneto;
  4736.                                 $subneto $subneto $days $unitsServ $pax;
  4737.                                 break;
  4738.                             case 16//DDR
  4739.                                 $pax $itemInvoice->getSrvPax();
  4740.                                 if (empty($pax) or $pax == "0") {
  4741.                                     $pax 1;
  4742.                                 }
  4743.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4744.                                 if ($days 1) {
  4745.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4746.                                 } else {
  4747.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4748.                                 }
  4749.                                 $unitsServ $itemInvoice->getSrvUnits();
  4750.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4751.                                     $unitsServ 1;
  4752.                                 }
  4753.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4754.                                 $subnetoUnit $subneto;
  4755.                                 $subneto $subneto $days $unitsServ $pax;
  4756.                                 break;
  4757.                             default:
  4758.                                 break;
  4759.                         }
  4760.                         // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  4761.                         $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  4762.                         $neto round($subneto2PHP_ROUND_HALF_UP);
  4763.                         $valorTotalNet $valorTotalNet $neto;
  4764.                         $valorVat $valorVat + ($subtotal $neto);
  4765.                     }
  4766.                 }
  4767.             }
  4768.         }
  4769.         if (!empty($arrayInvoicedItems)) {
  4770.             foreach ($arrayInvoicedItems as $itemInvoice) {
  4771.                 if ($itemInvoice->getItemType() == 'PAYMENT') {
  4772.                     //                    $pago = $em->getRepository(ReservationPaymentsClient::class)->findOneById($key);
  4773.                     //
  4774.                     //                    $itemInvoice = new ReservationInvoiceItems();
  4775.                     //                    $itemInvoice->setReservationId($id);
  4776.                     //                    $itemInvoice->setInvoiceId($invoiceId);
  4777.                     //                    $itemInvoice->setItemType('PAYMENT');
  4778.                     //                    $itemInvoice->setPayControlId($key);
  4779.                     //                    $itemInvoice->setPayAmount($pago->getAmount());
  4780.                     //                    $itemInvoice->setPayDatePayAt($pago->getDatePayAt());
  4781.                     //                    $itemInvoice->setPayWayToPay($pago->getWayToPay());
  4782.                     //                    $itemInvoice->setCreatedAt(new DateTime('now'));
  4783.                     //                    $itemInvoice->setUpdatedAt(new DateTime('now'));
  4784.                     //                    $itemInvoice->setCreatedId($user_id);
  4785.                     //                    $itemInvoice->setUpdatedId($user_id);
  4786.                     //
  4787.                     //                    $em->persist($itemInvoice);
  4788.                     //                    $em->flush();
  4789.                     //Acumulamos neto e iva para la factura
  4790.                     //$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();    // El pago no puede afectar el neto de la factura
  4791.                 }
  4792.             }
  4793.         }
  4794.         //FIN: Creamos los items de la factura
  4795.         $valorTotal $valorTotalNet $valorVat;
  4796.         //INICIO: Buscamos la factura
  4797.         $newInvoice $em->getRepository(AveDocInvoice::class)->findOneById($id);
  4798.         //FIN: Buscamos la factura
  4799.         $data = array();
  4800.         $data $this->baseInvoiceDoneFile($newInvoice->getFileId(), $id'I');
  4801.         $paymentsClient = new AvePaymentsClient();
  4802.         $paymentsClient->setFileId($id);
  4803.         $fileInv = new AveDocInvoice();
  4804.         $fileInv->setAccessKey(md5(rand() * time()));
  4805.         $fileInv->setFileId($id);
  4806.         $idProducts = array();
  4807.         $productsBoolToInvoice = array();
  4808.         if (array_key_exists('product'$data['datasupplier'])) {
  4809.             foreach ($data['datasupplier']['product'] as $item) {
  4810.                 $idProducts[] = $item['id'];
  4811.                 $productsBoolToInvoice[] = 1;
  4812.             }
  4813.             $idProducts implode(','$idProducts);
  4814.             $productsBoolToInvoice implode(','$productsBoolToInvoice);
  4815.         } else {
  4816.             $idProducts '0';
  4817.             $productsBoolToInvoice '0';
  4818.         }
  4819.         $idPayments = array();
  4820.         $paymentsBoolToInvoice = array();
  4821.         if (array_key_exists('payment'$data['datasupplier'])) {
  4822.             foreach ($data['datasupplier']['payment'] as $item) {
  4823.                 $idPayments[] = $item['id'];
  4824.                 $paymentsBoolToInvoice[] = 1;
  4825.             }
  4826.             $idPayments implode(','$idPayments);
  4827.             $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  4828.             // Se han generado dos arreglos, cada uno dividido en 2 strings
  4829.             // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  4830.             // Para manipularlos entre la vista y el JS
  4831.         } else {
  4832.             $idPayments '0';
  4833.             $paymentsBoolToInvoice '0';
  4834.         }
  4835.         // Una factura solo se puede rectificar una vez
  4836.         $rectf $em->getRepository(AveDocInvoiceRec::class)->findBy(array('number' => 'REC-' $newInvoice->getNumber()));
  4837.         $boolToRec = empty($rectf);
  4838.         $allInvoices $em->getRepository(AveDocInvoice::class)->findByFileId($newInvoice->getFileId());
  4839.         $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($newInvoice->getFileId());
  4840.         foreach ($allInvoicesRec as $item) {
  4841.             array_push($allInvoices$item);
  4842.         }
  4843.         $allProformas $em->getRepository(AveDocProforma::class)->findByFileId($newInvoice->getFileId());
  4844.         if (empty($data['type'])) {
  4845.             $data['type'] = 'Invoice';
  4846.         }
  4847.         $commentsBool false;
  4848.         $comments null;
  4849.         $fileAv $em->getRepository(AveFiles::class)->findOneById($newInvoice->getFileId());
  4850.         if ($fileAv->getCommentsInInv()) {
  4851.             $commentsBool true;
  4852.         }
  4853.         if ($commentsBool) {
  4854.             $comments $fileAv->getComments();
  4855.         }
  4856.         // Campos extras - Actualizamos las entidades InvoiceProformaExtraField y las asociamos con la factura
  4857.         $company $em->getRepository(SettingsCompany::class)->findOneByBusinessType(['businessType' => BusinessTypeSettingsCompanyConstants::AUDIOVISUAL]);
  4858.         $billingSerie = empty($newInvoice->getPrefix()) ? null $newInvoice->getPrefix();
  4859.         $companyId = empty($company) ? null $company->getId();
  4860.         $numberInvFromLine $this->extraFieldService->extractInvoiceNumber($newInvoice->getNumber(), $billingSerie);
  4861.         $extraFields $this->extraFieldService->getExtraFieldsIndexedByPosition($companyIdInvoiceProformaExtraFieldConstants::TYPE_INVOICE$id$billingSerie);
  4862.         return $this->render(
  4863.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
  4864.             array(
  4865.                 'id' => $newInvoice->getFileId(),
  4866.                 'cid' => '',
  4867.                 'fid' => $id,
  4868.                 'invoice' => $newInvoice,
  4869.                 'facturas' => $allInvoices,
  4870.                 'proformas' => $allProformas,
  4871.                 'boolToRec' => $boolToRec,
  4872.                 'numberadmin' => '',
  4873.                 'type' => $data['type'],
  4874.                 'docType' => 'Factura',
  4875.                 'number' => $newInvoice->getId(),
  4876.                 'prefix' => $data['prefix'],
  4877.                 'date' => $data['date'],
  4878.                 'token' =>  $data['token'],
  4879.                 'file' => $data['file'],
  4880.                 'company' => $data['company'],
  4881.                 'clients' => $data['clients'],
  4882.                 'user' => '',
  4883.                 'invoicedeposititems' => '',
  4884.                 'arrayItems' => $data['arrayItems'],
  4885.                 'datasupplier' => $data['datasupplier'],
  4886.                 'totales_neto' => $data['totales_neto'],
  4887.                 'totales_iva' => '',
  4888.                 'totales' => $data['totales'],
  4889.                 'bases_imponibles' => $data['bases_imponibles'],
  4890.                 'balance' => $data['balance'],
  4891.                 'paymentInvoice' => $data['paymentInvoice'],
  4892.                 'currency' => $data['currency'],
  4893.                 'comments' => $comments,
  4894.                 'extraFields' => $extraFields,
  4895.             )
  4896.         );
  4897.     }
  4898.     /**
  4899.      * @Route("/newinvoicerec/{id}", name="ave_new_invoice_rec")
  4900.      * Crear una factura rectificativa
  4901.      */
  4902.     public function generateNewInvoiceRecAction($idRequest $request)
  4903.     {
  4904.         $em $this->getDoctrine()->getManager();
  4905.         $invoice $em->getRepository(AveDocInvoice::class)->findOneById($id);
  4906.         if (!empty($invoice)) {
  4907.             $invoiceComAvGp $em->getRepository(ReservationInvoice::class)->findOneByNumber('GPF-Automatic commission invoice-Av_File-' $invoice->getFileId() . '-Invoice-' $invoice->getId());
  4908.         } else {
  4909.             $invoiceComAvGp null;
  4910.         }
  4911. //        
  4912. //        }
  4913.         // Verificamos que no exista una factura rectificativa previa sobre la misma factura
  4914.         $previusInvoiceRec $em->getRepository(AveDocInvoiceRec::class)->findOneByInvoiceToRec($id);
  4915.         if (!empty($previusInvoiceRec)) { return $this->redirectToRoute('ave_view_invoice_rec', array('id' => $previusInvoiceRec->getId())); }
  4916.         $now = new DateTime();
  4917.         /* Obtengo usuario logueado */
  4918.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  4919.         $user_id $user_logueado->getId();
  4920.         $invoiceRec = new AveDocInvoiceRec();
  4921.         $invoiceRec->setInvoiceToRec($id);
  4922.         $invoiceRec->setCreatedAt($now);
  4923.         $invoiceRec->setUpdatedAt($now);
  4924.         $invoiceRec->setCreatedId($user_id);
  4925.         $invoiceRec->setUpdatedId($user_id);
  4926.         $invoiceRec->setDateAt($now);
  4927.         $invoiceRec->setMaster($invoice->getMaster());
  4928.         $invoiceRec->setNumber('REC-' $invoice->getNumber());
  4929.         $invoiceRec->setPrefix('R');
  4930.         $invoiceRec->setFileId($invoice->getFileId());
  4931.         $invoiceRec->setTotal($invoice->getTotal() * (-1));
  4932.         $invoiceRec->setTotalNet($invoice->getTotalNet() * (-1));
  4933.         $invoiceRec->setType('Invoice Rec');
  4934.         $invoiceRec->setVat($invoice->getVat() * (-1));
  4935.         $invoiceRec->setBalance($invoice->getBalance() * (-1));
  4936.         $em->persist($invoiceRec);
  4937.         $em->flush();
  4938.         $invoiceItems $em->getRepository(AveDocInvoiceItems::class)->findByInvoiceId($id);
  4939.         // Cada elemento se duplica en ItemsRec y se libera asignando ID = 0
  4940.         foreach ($invoiceItems as $item) {
  4941.             $itemRec = new AveDocInvoiceRecItems();
  4942.             $itemRec->setFileId($item->getFileId());
  4943.             $itemRec->setInvoiceId($item->getInvoiceId());
  4944.             $itemRec->setItemType($item->getItemType());
  4945.             $itemRec->setInvoiceRecId($invoiceRec->getId());
  4946.             $itemRec->setLocation($item->getLocation());
  4947.             $itemRec->setRankQuoteAv($item->getRankQuoteAv());
  4948.             $itemRec->setPrdControlId($item->getPrdControlId());
  4949.             $itemRec->setPrdName($item->getPrdName());
  4950.             $itemRec->setPrdProductId($item->getPrdProductId());
  4951.             $itemRec->setPrdDateStart($item->getPrdDateStart());
  4952.             $itemRec->setPrdDateEnd($item->getPrdDateEnd());
  4953.             $itemRec->setPrdServicePrice($item->getPrdServicePrice() * (-1));
  4954.             $itemRec->setPrdSubTotalPrice($item->getPrdSubTotalPrice() * (-1));
  4955.             $itemRec->setPrdQty($item->getPrdQty());
  4956.             $itemRec->setPrdDays($item->getPrdDays());
  4957.             $itemRec->setPrdPax($item->getPrdPax());
  4958.             $itemRec->setPrdType($item->getPrdType());
  4959.             $itemRec->setPrdHourStart($item->getPrdHourStart());
  4960.             $itemRec->setPrdMinStart($item->getPrdMinStart());
  4961.             $itemRec->setPrdHourEnd($item->getPrdHourEnd());
  4962.             $itemRec->setPrdMinEnd($item->getPrdMinEnd());
  4963.             $itemRec->setPrdIva($item->getPrdIva());
  4964.             $itemRec->setPrdOpIva($item->getPrdOpIva());
  4965.             $itemRec->setSrvControlId($item->getSrvControlId());
  4966.             $itemRec->setSrvSupplierId($item->getSrvSupplierId());
  4967.             $itemRec->setSrvServiceId($item->getSrvServiceId());
  4968.             $itemRec->setSrvServiceCatId($item->getSrvServiceCatId());
  4969.             $itemRec->setSrvServiceCatName($item->getSrvServiceCatName());
  4970.             $itemRec->setSrvPrice($item->getSrvPrice() * (-1));
  4971.             $itemRec->setSrvCurrency($item->getSrvCurrency());
  4972.             $itemRec->setSrvUnits($item->getSrvUnits());
  4973.             $itemRec->setSrvOpCommission($item->getSrvOpCommission());
  4974.             $itemRec->setSrvCommission($item->getSrvCommission());
  4975.             $itemRec->setSrvOpOver($item->getSrvOpOver());
  4976.             $itemRec->setSrvOver($item->getSrvOver());
  4977.             $itemRec->setSrvOpIva($item->getSrvOpIva());
  4978.             $itemRec->setSrvIva($item->getSrvIva());
  4979.             $itemRec->setSrvPax($item->getSrvPax());
  4980.             $itemRec->setSrvHour($item->getSrvHour());
  4981.             $itemRec->setSrvDateInAt($item->getSrvDateInAt());
  4982.             $itemRec->setSrvDateOutAt($item->getSrvDateOutAt());
  4983.             $itemRec->setSrvContcolor($item->getSrvContcolor());
  4984.             $itemRec->setSrvRankQuote($item->getSrvRankQuote());
  4985.             $itemRec->setSrvAssistantId($item->getSrvAssistantId());
  4986.             $itemRec->setSrvActivityId($item->getSrvActivityId());
  4987.             $itemRec->setSrvPay($item->getSrvPay());
  4988.             $itemRec->setPayControlId($item->getPayControlId());
  4989.             $itemRec->setPayAmount($item->getPayAmount() * (-1));
  4990.             $itemRec->setPayDatePayAt($item->getPayDatePayAt());
  4991.             $itemRec->setPayWayToPay($item->getPayWayToPay());
  4992.             $itemRec->setPayAmountTotal($item->getPayAmountTotal() * (-1));
  4993.             $itemRec->setPayVat($item->getPayVat());
  4994.             $itemRec->setCreatedId($user_id);
  4995.             $itemRec->setCreatedAt(new DateTime('now'));
  4996.             $itemRec->setUpdatedId($user_id);
  4997.             $itemRec->setUpdatedAt(new DateTime('now'));
  4998.             $em->persist($itemRec);
  4999.             $em->flush();
  5000.             $item->setPrdControlId((-1) * $item->getPrdControlId());
  5001.             $item->setSrvControlId((-1) * $item->getSrvControlId());
  5002.             $item->setPayControlId((-1) * $item->getPayControlId());
  5003.             $em->persist($item);
  5004.             $em->flush();
  5005.         }
  5006.         $allInvoices $em->getRepository(AveDocInvoice::class)->findByFileId($invoice->getFileId());
  5007.         $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($invoice->getFileId());
  5008.         foreach ($allInvoicesRec as $item) { array_push($allInvoices$item); }
  5009.         $file $em->getRepository(AveFiles::class)->findOneById($invoice->getFileId());
  5010.         $client $em->getRepository(Client::class)->findOneById($file->getClient());
  5011.         $data = array();
  5012.         $data $this->baseInvoiceDoneFile($invoiceRec->getFileId(), $invoiceRec->getId(), 'R');
  5013.         $data['clients'][0] = $client;
  5014.         $data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  5015.         // Se elimina la ComisiĂ³n de AV a GreenPatio y la factura de comision
  5016.         $aveFile $em->getRepository(AveFiles::class)->findOneById($invoice->getFileId());
  5017.         $reserva $em->getRepository(Reservation::class)->findOneById($aveFile->getReservation());
  5018.         $description $id.' - ComisiĂ³n MANTE de Green Patio (Generado automaticamente)';
  5019.         $benSup $em->getRepository(AveBenefitsSupplier::class)->findOneByDescription($description);     // Beneficio de Green Patio sobre una factura
  5020.         if(!empty($benSup)){
  5021.             $em->remove($benSup);
  5022.             $em->flush();
  5023.         }
  5024.         if(!empty($invoiceComAvGp)){
  5025.             $dataService $this->commisionEnterpriseService->rectCommissionAvExpressGreenPatio($invoice->getId(), $user_id);
  5026.         }
  5027.         $this->calculoBeneficiosDocumento($invoiceRec->getId(), 'Invoice Rec');
  5028.         return $this->redirectToRoute'ave_view_invoice_rec', array('id' => $invoiceRec->getId()));
  5029.     }
  5030.     /**
  5031.      * @Route("/viewinvoicerec/{id}",  name="ave_view_invoice_rec")
  5032.      * Ver una factura rectificativa
  5033.      */
  5034.     public function viewInvoiceRecAction($idRequest $request)
  5035.     {
  5036.         $em $this->getDoctrine()->getManager();
  5037.         $invoiceRec $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
  5038.         /* Obtengo usuario logueado */
  5039.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5040.         $user_id $user_logueado->getId();
  5041.         $invoiceItems $em->getRepository(AveDocInvoiceRecItems::class)->findByInvoiceId($id);
  5042.         // Cada elemento se duplica en ItemsRec y se libera asignando ID = 0
  5043.         $allInvoices $em->getRepository(AveDocInvoice::class)->findByFileId($invoiceRec->getFileId());
  5044.         $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($invoiceRec->getFileId());
  5045.         foreach ($allInvoicesRec as $item) { array_push($allInvoices$item); }
  5046.         $file $em->getRepository(AveFiles::class)->findOneById($invoiceRec->getFileId());
  5047.         $client $em->getRepository(Client::class)->findById($file->getClient());
  5048.         if (empty($client)) {
  5049.             $client[0] = new Client();
  5050.             $client[0]->setName('');
  5051.             $client[0]->setTitle('');
  5052.             $client[0]->setIdDocument('');
  5053.             $client[0]->setPopulation('');
  5054.             $client[0]->setRegion('');
  5055.             $client[0]->setCountry('');
  5056.             $clientNew = array(
  5057.                 'name' => '',
  5058.                 'title' => '',
  5059.                 'idDocument' => '',
  5060.                 'population' => '',
  5061.                 'region' => '',
  5062.                 'country' => '',
  5063.                 'address' => '',
  5064.                 'addressNumber' => '',
  5065.                 'zipCode' => '',
  5066.                 'typeDocument' => '',
  5067.             );
  5068.         } else {
  5069.             $clientNew = array(
  5070.                 'name' => $client[0]->getName(),
  5071.                 'title' => $client[0]->getTitle(),
  5072.                 'idDocument' => $client[0]->getIdDocument(),
  5073.                 'population' => '',
  5074.                 'region' => '',
  5075.                 'country' => '',
  5076.                 'address' => $client[0]->getAddress(),
  5077.                 'addressNumber' => $client[0]->getAddressNumber(),
  5078.                 'zipCode' => $client[0]->getZipCode(),
  5079.                 'typeDocument' => $client[0]->getTypeDocument(),
  5080.             );
  5081.             if (is_numeric($client[0]->getPopulation())) {
  5082.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  5083.                 $clientNew['population'] = $city->getCity();
  5084.             }
  5085.             if (is_numeric($client[0]->getRegion())) {
  5086.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  5087.                 $clientNew['region'] = $region->getRegion();
  5088.             }
  5089.             if (is_numeric($client[0]->getCountry())) {
  5090.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  5091.                 $clientNew['country'] = $country->getCountry();
  5092.             }
  5093.         }
  5094.         $data = array();
  5095.         $data $this->baseInvoiceDoneFile($invoiceRec->getFileId(), $id'R');
  5096.         $data['clients'] = $client;
  5097.         $data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  5098.         // Una factura solo se puede rectificar una vez
  5099.         //        $rectf = $em->getRepository(ReservationInvoiceRec::class)->findBy( array('number' => 'REC-'.$invoice->getNumber()));
  5100.         $boolToRec false;
  5101.         $commentsBool false;
  5102.         $comments null;
  5103.         $fileAv $em->getRepository(AveFiles::class)->findOneById($invoiceRec->getFileId());
  5104.         if ($fileAv->getCommentsInInv()) { $commentsBool true; }
  5105.         if ($commentsBool) { $comments $fileAv->getComments(); }
  5106.         // Campos extras - Actualizamos las entidades InvoiceProformaExtraField y las asociamos con la factura
  5107.         $company $em->getRepository(SettingsCompany::class)->findOneByBusinessType(['businessType' => BusinessTypeSettingsCompanyConstants::AUDIOVISUAL]);
  5108.         $billingSerie = empty($invoiceRec->getPrefix()) ? null $invoiceRec->getPrefix();
  5109.         $companyId = empty($company) ? null $company->getId();
  5110.         // $numberInvFromLine = $this->extraFieldService->extractInvoiceNumber($invoiceRec->getId(), $billingSerie);
  5111.         $extraFields $this->extraFieldService->getExtraFieldsIndexedByPosition($companyIdInvoiceProformaExtraFieldConstants::TYPE_RECTIFICATIVE$id$billingSerie);
  5112.         return $this->render(
  5113.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
  5114.             array(
  5115.                 'id' => $invoiceRec->getFileId(),
  5116.                 'cid' => '',
  5117.                 'fid' => $invoiceRec->getId(),
  5118.                 'invoice' => $invoiceRec,
  5119.                 'facturas' => $allInvoices,
  5120.                 'boolToRec' => $boolToRec,
  5121.                 'numberadmin' => '',
  5122.                 'type' => 'Invoice Rec',
  5123.                 'docType' => 'Factura Rectificativa',
  5124.                 'number' => $invoiceRec->getId(),
  5125.                 'prefix' => '',
  5126.                 'date' => $invoiceRec->getDateAt(),
  5127.                 'invoiceIdToRec' => $invoiceRec->getInvoiceToRec(),
  5128.                 'token' => '',
  5129.                 'file' => $file,
  5130.                 'company' => $data['company'],
  5131.                 'clients' => $clientNew,
  5132.                 'user' => $user_logueado,
  5133.                 'invoicedeposititems' => '',
  5134.                 'datasupplier' => $data['datasupplier'],
  5135.                 'totales_neto' => $data['totales_neto'],
  5136.                 'totales_iva' => '',
  5137.                 'totales' => $data['totales'],
  5138.                 'bases_imponibles' => $data['bases_imponibles'],
  5139.                 'balance' => $data['balance'],
  5140.                 'paymentInvoice' => $data['paymentInvoice'],
  5141.                 'currency' => $data['currency'],
  5142.                 'comments' => $comments,
  5143.                 'extraFields' => $extraFields,
  5144.             )
  5145.         );
  5146.     }
  5147.     /**
  5148.      * @Route("/avexternal/printinvoicerec/{id}",  name="ave_print_invoice_rec")
  5149.      * Imprimir una factura rectificativa
  5150.      */
  5151.     public function printInvoiceRecAction($idRequest $request)
  5152.     {
  5153.         $em $this->getDoctrine()->getManager();
  5154.         $invoiceRec $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
  5155.         $invoiceItems $em->getRepository(AveDocInvoiceRecItems::class)->findByInvoiceId($id);
  5156.         $allInvoices $em->getRepository(AveDocInvoice::class)->findByFileId($invoiceRec->getFileId());
  5157.         $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($invoiceRec->getFileId());
  5158.         foreach ($allInvoicesRec as $item) {
  5159.             array_push($allInvoices$item);
  5160.         }
  5161.         $file $em->getRepository(AveFiles::class)->findOneById($invoiceRec->getFileId());
  5162.         $client $em->getRepository(Client::class)->findOneById($file->getClient());
  5163.         $data = array();
  5164.         $data $this->baseInvoiceDoneFile($invoiceRec->getFileId(), $invoiceRec->getId(), 'R');
  5165.         $data['clients'][0] = $client;
  5166.         $data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  5167.         // Una factura solo se puede rectificar una vez
  5168.         //        $rectf = $em->getRepository(ReservationInvoiceRec::class)->findBy( array('number' => 'REC-'.$invoice->getNumber()));
  5169.         $boolToRec false;
  5170.         $commentsBool false;
  5171.         $comments null;
  5172.         $fileAv $em->getRepository(AveFiles::class)->findOneById($invoiceRec->getFileId());
  5173.         if ($fileAv->getCommentsInPro()) {
  5174.             $commentsBool true;
  5175.         }
  5176.         if ($commentsBool) {
  5177.             $comments $fileAv->getComments();
  5178.         }
  5179.         return $this->render(
  5180.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
  5181.             array(
  5182.                 'id' => $invoiceRec->getFileId(),
  5183.                 'cid' => '',
  5184.                 'fid' => $invoiceRec->getId(),
  5185.                 'invoice' => $invoiceRec,
  5186.                 'facturas' => $allInvoices,
  5187.                 'boolToRec' => $boolToRec,
  5188.                 'numberadmin' => '',
  5189.                 'type' => 'Invoice Rec',
  5190.                 'docType' => 'Factura Rectificativa',
  5191.                 'number' => $invoiceRec->getId(),
  5192.                 'prefix' => '',
  5193.                 'date' => $invoiceRec->getDateAt(),
  5194.                 'invoiceIdToRec' => $invoiceRec->getInvoiceToRec(),
  5195.                 'token' => '',
  5196.                 'file' => $file,
  5197.                 'company' => $data['company'],
  5198.                 'clients' => $data['clients'],
  5199.                 'user' => '',
  5200.                 'invoicedeposititems' => '',
  5201.                 'datasupplier' => $data['datasupplier'],
  5202.                 'totales_neto' => $data['totales_neto'],
  5203.                 'totales_iva' => '',
  5204.                 'totales' => $data['totales'],
  5205.                 'bases_imponibles' => $data['bases_imponibles'],
  5206.                 'balance' => $data['balance'],
  5207.                 'paymentInvoice' => $data['paymentInvoice'],
  5208.                 'currency' => $data['currency'],
  5209.                 'comments' => $comments,
  5210.             )
  5211.         );
  5212.     }
  5213.     /**
  5214.      * @Route("/listinvoice/",  name="ave_list_invoices")
  5215.      * Listar facturas
  5216.      */
  5217.     public function listInvoicesAction(Request $request)
  5218.     {
  5219.         $em $this->getDoctrine()->getManager();
  5220.         $invoiced $em->getRepository(AveDocInvoice::class)->findAll();
  5221.         $invoicedRec $em->getRepository(AveDocInvoiceRec::class)->findAll();
  5222.         // Agregamos las rectificativas al arreglo de facturas con el indice "R(id)"
  5223.         foreach ($invoicedRec as $item) {
  5224.             $invoiced['R' $item->getId()] = $item;
  5225.         }
  5226.         $sumatoriaTotalNet 0;
  5227.         $sumatoriaTotalVat 0;
  5228.         $sumatoriaTotal 0;
  5229.         // OptimizaciĂ³n N+1: Recolectar IDs para consultas masivas
  5230.         $fileIds = [];
  5231.         $invoiceDepositIds = [];
  5232.         $masterIds = [];
  5233.         foreach ($invoiced as $item) {
  5234.             if ($item->getFileId()) {
  5235.                 $fileIds[$item->getFileId()] = $item->getFileId();
  5236.             }
  5237.             if ($item->getType() === 'Invoice Deposit') {
  5238.                 $invoiceDepositIds[] = $item->getId();
  5239.                 if ($item->getMaster()) {
  5240.                     $masterIds[] = $item->getMaster();
  5241.                 }
  5242.             }
  5243.         }
  5244.         // 1. Obtener Files en bloque
  5245.         $files = [];
  5246.         if (!empty($fileIds)) {
  5247.             foreach (array_chunk($fileIds500) as $chunk) {
  5248.                 $filesResult $em->getRepository(AveFiles::class)->findBy(['id' => $chunk]);
  5249.                 foreach ($filesResult as $f) {
  5250.                     $files[$f->getId()] = $f;
  5251.                 }
  5252.             }
  5253.         }
  5254.         // 2. Obtener Clientes en bloque
  5255.         $clientIds = [];
  5256.         foreach ($files as $f) {
  5257.             if ($f->getClient()) {
  5258.                 $clientIds[$f->getClient()] = $f->getClient();
  5259.             }
  5260.         }
  5261.         $clients = [];
  5262.         if (!empty($clientIds)) {
  5263.             foreach (array_chunk($clientIds500) as $chunk) {
  5264.                 $clientsResult $em->getRepository(Client::class)->findBy(['id' => $chunk]);
  5265.                 foreach ($clientsResult as $c) {
  5266.                     $clients[$c->getId()] = $c;
  5267.                 }
  5268.             }
  5269.         }
  5270.         // 3. Obtener Pagos de DepĂ³sito en bloque
  5271.         $payments = [];
  5272.         $paymentIds = [];
  5273.         if (!empty($invoiceDepositIds)) {
  5274.             foreach (array_chunk($invoiceDepositIds500) as $chunk) {
  5275.                 $paymentsResult $em->getRepository(AvePaymentsClient::class)->findBy(['invoiceId' => $chunk]);
  5276.                 foreach ($paymentsResult as $p) {
  5277.                     $payments[$p->getInvoiceId()] = $p;
  5278.                     $paymentIds[] = $p->getId();
  5279.                 }
  5280.             }
  5281.         }
  5282.         // 4. Obtener Items e Items Rectificativos por PayControlId en bloque
  5283.         $itemsByPayControl = [];
  5284.         $itemsRecByPayControl = [];
  5285.         if (!empty($paymentIds)) {
  5286.             foreach (array_chunk($paymentIds500) as $chunk) {
  5287.                 $itemsResult $em->getRepository(AveDocInvoiceItems::class)->findBy(['payControlId' => $chunk]);
  5288.                 foreach ($itemsResult as $it) {
  5289.                     $itemsByPayControl[$it->getPayControlId()] = $it;
  5290.                 }
  5291.                 $itemsRecResult $em->getRepository(AveDocInvoiceRecItems::class)->findBy(['payControlId' => $chunk]);
  5292.                 foreach ($itemsRecResult as $it) {
  5293.                     $itemsRecByPayControl[$it->getPayControlId()] = $it;
  5294.                 }
  5295.             }
  5296.         }
  5297.         // 5. Obtener Items por ControlId (para sumar en deposit) en bloque
  5298.         $itemsByControlId = [];
  5299.         if (!empty($masterIds)) {
  5300.             foreach (array_chunk($masterIds500) as $chunk) {
  5301.                 $itemsMasterResult $em->getRepository(AveDocInvoiceItems::class)->findBy(['controlId' => $chunk]);
  5302.                 foreach ($itemsMasterResult as $it) {
  5303.                     $itemsByControlId[$it->getControlId()][] = $it;
  5304.                 }
  5305.             }
  5306.         }
  5307.         // IteraciĂ³n principal optimizada - Construyendo las dependencias desde memoria
  5308.         foreach ($invoiced as $idArray => $item) {
  5309.             $file $files[$item->getFileId()] ?? null;
  5310.             $invoiced[$idArray]->setNumber($file $file->getTitle() : 0);
  5311.             $clientId $file $file->getClient() : null;
  5312.             $client $clientId ? ($clients[$clientId] ?? null) : null;
  5313.             $invoiced[$idArray]->setPrefix($client $client->getName() : '');
  5314.             $estaEnFactura false;
  5315.             $estaEnFacturaRectificativa false;
  5316.             if ($item->getType() === 'Invoice Deposit') {
  5317.                 $payOfInvoiceDeposit $payments[$item->getId()] ?? null;
  5318.                 if ($payOfInvoiceDeposit) {
  5319.                     $payId $payOfInvoiceDeposit->getId();
  5320.                     
  5321.                     // Verificamos si el depĂ³sito estĂ¡ dentro de una factura
  5322.                     $itemInv $itemsByPayControl[$payId] ?? null;
  5323.                     if ($itemInv) {
  5324.                         $estaEnFactura true;
  5325.                     } else {
  5326.                         // Verificamos que el control Id no haya sido seteado a 0 por rectificar la factura
  5327.                         $itemInvRec $itemsRecByPayControl[$payId] ?? null;
  5328.                         if ($itemInvRec) {
  5329.                             $estaEnFactura true;
  5330.                         }
  5331.                     }
  5332.                     // Verificamos si el depĂ³sito estĂ¡ dentro de una factura rectificativa
  5333.                     $itemInvRecCheck $itemsRecByPayControl[$payId] ?? null;
  5334.                     if ($itemInvRecCheck) {
  5335.                         $estaEnFacturaRectificativa true;
  5336.                     }
  5337.                 }
  5338.                 $invoicedDepositItems $itemsByControlId[$item->getMaster()] ?? [];
  5339.                 
  5340.                 foreach ($invoicedDepositItems as $itemDep) {
  5341.                     $invoiced[$idArray]->setTotalNet($invoiced[$idArray]->getTotalNet() + $itemDep->getAmount());
  5342.                     $invoiced[$idArray]->setVat($invoiced[$idArray]->getVat() + (($itemDep->getAmount() * $itemDep->getIva()) / 100));
  5343.                     $invoiced[$idArray]->setTotal($invoiced[$idArray]->getTotal() + ($itemDep->getAmount() + (($itemDep->getAmount() * $itemDep->getIva()) / 100)));
  5344.                 }
  5345.             }
  5346.             // SumarĂ¡ cuando ambos estĂ©n en false (no estĂ¡ en factura ni en fact. rectif.)
  5347.             // o en true en ambas (fue facturado pero luego rectificado)
  5348.             if ((!$estaEnFactura && !$estaEnFacturaRectificativa) || ($estaEnFactura && $estaEnFacturaRectificativa)) {
  5349.                 $sumatoriaTotalNet += $item->getTotalNet();
  5350.                 $sumatoriaTotalVat += $item->getVat();
  5351.                 $sumatoriaTotal += $item->getTotal();
  5352.             }
  5353.         }
  5354.         return $this->render(
  5355.             'MDS/AvexpressBundle/Avexpress/invoice-list.html.twig',
  5356.             [
  5357.                 'invocied' => $invoiced,
  5358.                 'sumatoriaTotalNet' => $sumatoriaTotalNet,
  5359.                 'sumatoriaTotalVat' => $sumatoriaTotalVat,
  5360.                 'sumatoriaTotal' => $sumatoriaTotal,
  5361.             ]
  5362.         );
  5363.     }
  5364.     /**
  5365.      * @Route("/listpendingbud/", name="ave_list_pending_bud")
  5366.      * Listar presupuestos pendientes para aprobar y los pendientes por facturar
  5367.      */
  5368.     public function listPendingBudgetsAction(Request $request)
  5369.     {
  5370.         $em $this->getDoctrine()->getManager();
  5371.         $pendingBuds $em->getRepository(AveBudgetPending::class)->findAll();
  5372.         $pBuds = array();
  5373.         $budInPro = array();
  5374.         // Creamos la agrupacion por proposal
  5375.         foreach ($pendingBuds as $item) {
  5376.             if (!(array_key_exists($item->getProposalId(), $pBuds))) {
  5377.                 if (!empty($item->getOriginId())) {    // Los vacios solo contienen briefings
  5378.                     $pBuds[$item->getProposalId()] = null;
  5379.                 }
  5380.             }
  5381.         }
  5382.         // Metemos los items en el arreglo clasificado por proposal
  5383.         foreach ($pendingBuds as $item) {
  5384.             if (!empty($item->getOriginId())) {    // Los vacios solo contienen briefings
  5385.                 $pBuds[$item->getProposalId()][] = $item;
  5386.             }
  5387.         }
  5388.         ksort($pBuds);
  5389.         $keysPbuds array_keys($pBuds);
  5390.         $budToProforma $em->getRepository(AveBudgetToProforma::class)->findBy(
  5391.             array(
  5392.                 'status' => 'Confirmed',                                         // Pending -> Tosend -> Confirmed -> Invoiced
  5393.             )
  5394.         );
  5395.         $budToInvoice = array();
  5396.         foreach ($budToProforma as $item) {
  5397.             if (!array_key_exists($item->getFileId(), $budToInvoice)) {
  5398.                 $budToInvoice[$item->getFileId()] = null;
  5399.             }
  5400.         }
  5401.         foreach ($budToProforma as $item) {
  5402.             $budToInvoice[$item->getFileId()]['file'] = $em->getRepository(AveFiles::class)->findOneById($item->getFileId());
  5403.             // INICIO: Agrupamos las proformas y dentro ponemos los items de cada una
  5404.             //Obtenemos el Id de la proforma que contiene el producto
  5405.             $idPro =  $em->getRepository(AveDocProformaItems::class)->findOneByControlId($item->getProductFileId());
  5406.             $idPro $idPro->getProformaId();
  5407.             // Guardamos la info del agente
  5408.             $budToInvoice[$item->getFileId()]['agente'] = $item->getUserConfirmedFullName();
  5409.             $budToInvoice[$item->getFileId()]['idAgente'] = $item->getUserConfirmedId();
  5410.             //Buscamos el elemento que va dentro de la proforma
  5411.             $elemento $em->getRepository(AveProductFile::class)->findOneById($item->getProductFileId());
  5412.             $budToInvoice[$item->getFileId()]['proformas'][$idPro][] = $elemento;
  5413.             // FIN: Agrupamos las proformas y dentro ponemos los items de cada una
  5414.         }
  5415.         ksort($budToInvoice);
  5416.         //INICIO: Buscamos los budgets que ya se han metido en proformas
  5417.         $budInProforma $em->getRepository(AveBudgetToProforma::class)->findBy(
  5418.             array(
  5419.                 'status' => 'Tosend',                                         // Pending -> Tosend -> Confirmed -> Invoiced
  5420.             )
  5421.         );
  5422.         $budInPro = array();
  5423.         foreach ($budInProforma as $item) {
  5424.             $budInPro[$item->getFileId()]['file'] = $em->getRepository(AveFiles::class)->findOneById($item->getFileId());
  5425.             // INICIO: Agrupamos las proformas y dentro ponemos los items de cada una
  5426.             //Obtenemos el Id de la proforma que contiene el producto
  5427.             $idPro =  $em->getRepository(AveDocProformaItems::class)->findOneByControlId($item->getProductFileId());
  5428.             $idPro $idPro->getProformaId();
  5429.             // Guardamos la info del agente
  5430.             $budInPro[$item->getFileId()]['agente'] = $item->getUserConfirmedFullName();
  5431.             $budInPro[$item->getFileId()]['idAgente'] = $item->getUserConfirmedId();
  5432.             //Buscamos el elemento que va dentro de la proforma
  5433.             $elemento $em->getRepository(AveProductFile::class)->findOneById($item->getProductFileId());
  5434.             if (!empty($elemento)) {
  5435.                 $budInPro[$item->getFileId()]['proformas'][$idPro][] = $elemento;
  5436.                 if (empty($budInPro[$item->getFileId()]['proformasMontos'][$idPro])) {
  5437.                     $budInPro[$item->getFileId()]['proformasMontos'][$idPro] = $elemento->getServicePrice() * 1.21;
  5438.                 } else {
  5439.                     $budInPro[$item->getFileId()]['proformasMontos'][$idPro] = $budInPro[$item->getFileId()]['proformasMontos'][$idPro] + $elemento->getServicePrice() * 1.21;
  5440.                 }
  5441.             }
  5442.             // FIN: Agrupamos las proformas y dentro ponemos los items de cada una
  5443.         }
  5444.         ksort($budInPro);
  5445.         //Verificamos que no haya expedientes sin elementos (proformas)
  5446.         foreach ($budInPro as $key => $item) {
  5447.             if (!array_key_exists('proformas'$item)) {
  5448.                 if (sizeof($budInPro) == 1) {
  5449.                     unset($budInPro$key);
  5450.                     $budInPro = array();
  5451.                 } else {
  5452.                     unset($budInPro$key);
  5453.                 }
  5454.             }
  5455.         }
  5456.         //FIN: Buscamos los budgets que ya se han metido en proformas
  5457.         //Buscamos los budgets que solo contienen Briefing
  5458.         $briefings $em->getRepository(AveBudgetPending::class)->findBy(
  5459.             array(
  5460.                 'serviceId' => null,                                         // Pending -> Tosend -> Confirmed -> Invoiced
  5461.             )
  5462.         );
  5463.         return $this->render(
  5464.             'MDS/AvexpressBundle/Avexpress/list-budgets-pending.html.twig',
  5465.             array(
  5466.                 'pendingBudgets' => $pBuds,
  5467.                 'keysPendingBudgets' => $keysPbuds,
  5468.                 'budToInvoice' => $budToInvoice,
  5469.                 'budInProforma' => $budInPro,
  5470.                 'briefings' => $briefings,
  5471.             )
  5472.         );
  5473.     }
  5474.     /**
  5475.      * @Route("/budgetadd/", name="ave_list_budget_add")
  5476.      * Crear los presupuestos (proformas) y los expedientes (si es necesario)
  5477.      */
  5478.     public function budgetsAddAction(Request $request)
  5479.     {
  5480.         $services $request->request->get('services_hidden');
  5481.         $backToEditFile $request->request->get('backToEditFile');
  5482.         $logTelegram false;
  5483.         //Modificar precios en Eventos (si es necesario)
  5484.         foreach ($services as $item) {
  5485.             $em $this->getDoctrine()->getManager();
  5486.             $pendingBud $em->getRepository(AveBudgetPending::class)->findOneById($item['id']);
  5487.             //INICIO: Creamos el expediente de AVEXPRESS (en caso de ser necesario)
  5488.             $file $em->getRepository(AveFiles::class)->findOneByIdProposal($pendingBud->getProposalId());
  5489.             if (empty($file)) {
  5490.                 $file = new AveFiles();
  5491.                 if (array_key_exists('proposalTitle'$item)) {
  5492.                     $file->setTitle($pendingBud->getProposalId() . ' -- ' $item['proposalTitle']);
  5493.                 } else {
  5494.                     if (array_key_exists('title'$item)) {
  5495.                         $file->setTitle($item['title']);
  5496.                     } else {
  5497.                         $file->setTitle($pendingBud->getProposalId() . ' - ');
  5498.                     }
  5499.                 }
  5500.                 $file->setClient('262');                                            // 262 es In Out Travel & Events
  5501.                 $file->setPriority(null);
  5502.                 $file->setSupplier(null);
  5503.                 $file->setStatus('Confirmed');
  5504.                 $file->setDaysBlock(null);
  5505.                 $file->setAdvancePayment(null);
  5506.                 $file->setIdProposal($pendingBud->getProposalId());
  5507.                 $file->setCateringName(null);
  5508.                 $file->setBoolCatering(null);
  5509.                 $file->setDateStart(null);
  5510.                 $file->setDateEnd(null);
  5511.                 $file->setPax(null);
  5512.                 $file->setDeposit(null);
  5513.                 $file->setAccessKey(null);
  5514.                 $file->setDescription(null);
  5515.                 $file->setCreatedAt(new DateTime('now'));
  5516.                 $file->setCreatedId(14);                                             // Usuario de Salvador Guerrero
  5517.                 $file->setUpdatedAt(new DateTime('now'));
  5518.                 $file->setUpdatedId(14);                                             // Usuario de Salvador Guerrero
  5519.                 $em->persist($file);
  5520.                 $em->flush();
  5521.                 //Actualizamos los Briefings que esten en FileId null con el recien generado fileId en base al proposalId
  5522.                 $allBriefings $em->getRepository(AveBriefings::class)->findByProposalId($file->getIdProposal());
  5523.                 foreach ($allBriefings as $itemBrief) {
  5524.                     if (empty($itemBrief->getFileId())) {
  5525.                         $itemBrief->setFileId($file->getId());
  5526.                         $em->persist($itemBrief);
  5527.                         $em->flush();
  5528.                     }
  5529.                 }
  5530.             }
  5531.             //FIN: Creamos el expediente de AVEXPRESS (en caso de ser necesario)
  5532.             //INICIO: Creamos el producto dentro del expediente
  5533.             /* Obtengo usuario logueado */
  5534.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5535.             $user_id $user_logueado->getId();
  5536.             $newProductFile = new AveProductFile();
  5537.             if (!($pendingBud->getStatusinternal() == 'AV TEMPLATE')) {
  5538.                 $aveProductSelected $em->getRepository(AveProduct::class)->findOneById($pendingBud->getServiceId());
  5539.                 $newProductFile->setProductName($aveProductSelected->getName());
  5540.                 if (!empty($item['price'])) {
  5541.                     $newProductFile->setServicePrice($item['price']);
  5542.                     if (!($item['price'] == $aveProductSelected->getPrice())) {
  5543.                         // Se ha modificado el precio en el presupuesto y se debe cambiar en el origen (Proposal de eventos)
  5544.                         $itemOrigin $em->getRepository(ProposalSupplierServices::class)->findOneById($pendingBud->getOriginId());
  5545.                         if (!empty($itemOrigin)) {
  5546.                             $itemOrigin->setPrice($item['price']);
  5547.                             $em->persist($itemOrigin);
  5548.                             $em->flush();
  5549.                         }
  5550.                     }
  5551.                 } else {
  5552.                     // Si el precio viene vacio tomamos el valor por defecto del producto
  5553.                     $newProductFile->setServicePrice($aveProductSelected->getPrice());
  5554.                 }
  5555.                 //Unidades
  5556.                 if (!empty($item['units'])) {
  5557.                     $newProductFile->setUnits($item['units']);
  5558.                     if (!($item['units'] == 1)) {
  5559.                         // Se ha modificado el numero de unidades en el presupuesto y se debe cambiar en el origen (Proposal de eventos)
  5560.                         $itemOrigin $em->getRepository(ProposalSupplierServices::class)->findOneById($pendingBud->getOriginId());
  5561.                         if (!empty($itemOrigin)) {
  5562.                             $itemOrigin->setUnits($item['units']);
  5563.                             $itemOrigin->setUnits(1);
  5564.                             $em->persist($itemOrigin);
  5565.                             $em->flush();
  5566.                         }
  5567.                     }
  5568.                 } else {
  5569.                     // Si las unidades viene vacio tomamos el valor por defecto del producto
  5570.                     $newProductFile->setUnits('1');
  5571.                 }
  5572.                 $newProductFile->setSubTotalPrice($newProductFile->getServicePrice() * $newProductFile->getUnits());
  5573.             } else {
  5574.                 // Es un Template
  5575.                 $aveProductSelected $em->getRepository(AveTemplateItems::class)->findOneById($pendingBud->getServiceId());
  5576.                 //                d($pendingBud,$pendingBud->getServiceId(),$aveProductSelected);
  5577.                 $newProductFile->setProductName($aveProductSelected->getProductName());
  5578.                 $newProductFile->setServicePrice($aveProductSelected->getServicePrice());
  5579.                 $newProductFile->setUnits($aveProductSelected->getUnits());
  5580.                 $newProductFile->setSubTotalPrice($aveProductSelected->getSubTotalPrice());
  5581.                 $newProductFile->setSupplierExt($aveProductSelected->getSupplierExt());
  5582.                 $newProductFile->setSupplierExtId($aveProductSelected->getSupplierExtId());
  5583.                 $newProductFile->setUnits($aveProductSelected->getUnits());
  5584.                 $newProductFile->setOpCommission($aveProductSelected->getOpCommission());
  5585.                 $newProductFile->setCommission($aveProductSelected->getCommission());
  5586.                 $newProductFile->setOpOver($aveProductSelected->getOpOver());
  5587.                 $newProductFile->setOver($aveProductSelected->getOver());
  5588.                 $newProductFile->setOpIva($aveProductSelected->getOpIva());
  5589.                 $newProductFile->setIva($aveProductSelected->getIva());
  5590.                 $newProductFile->setDays($aveProductSelected->getDays());
  5591.             }
  5592.             $newProductFile->setProductId($aveProductSelected->getId());
  5593.             $newProductFile->setOriginId($pendingBud->getOriginId());
  5594.             $newProductFile->setDescription($aveProductSelected->getDescription());
  5595.             $newProductFile->setFileId($file->getId());
  5596.             if (true) { // No recibimos fechas // (!empty($newRequest['dateStart'])) {
  5597.                 $newProductFile->setDateStart(new DateTime('now')); //$newRequest['dateStart'].' '.$newRequest['hourStart']));
  5598.             }
  5599.             if (true) { // No recibimos fechas // (!empty($newRequest['dateEnd'])) {
  5600.                 $newProductFile->setDateEnd(new DateTime('now')); // (new \DateTime($newRequest['dateStart'].' '.$newRequest['hourEnd']));
  5601.             }
  5602.             $newProductFile->setCreatedId($user_id);
  5603.             $newProductFile->setUpdatedId($user_id);
  5604.             $newProductFile->setCreatedAt(new DateTime('now'));
  5605.             $newProductFile->setUpdatedAt(new DateTime('now'));
  5606.             $em->persist($newProductFile);
  5607.             $em->flush();
  5608.             $logTelegram true;
  5609.             //FIN: Creamos el producto dentro del expediente
  5610.             //INICIO: Creamos una orden de hacer proforma
  5611.             $order = new AveBudgetToProforma();
  5612.             $order->setStatus('Pending');
  5613.             $order->setFileId($file->getId());
  5614.             $order->setProductFileId($newProductFile->getId());
  5615.             $order->setUserConfirmedId($pendingBud->getUserConfirmedId());
  5616.             $order->setUserConfirmedFullName($pendingBud->getUserConfirmedFullName());
  5617.             $order->setProposalTitle($pendingBud->getProposalTitle());
  5618.             $em->persist($order);
  5619.             $em->flush();
  5620.             //FIN: Creamos una orden de hacer proforma
  5621.             // Se elimina el presupuesto pendiente
  5622.             $em->remove($pendingBud);
  5623.             $em->flush();
  5624.         }
  5625.         //INICIO: Creamos el presupuesto (proforma)
  5626.         $budToPro $em->getRepository(AveBudgetToProforma::class)->findByStatus('Pending');
  5627.         /* Obtengo usuario logueado */
  5628.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5629.         $user_id $user_logueado->getId();
  5630.         //        $arrayIdPro = array();          // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  5631.         //INICIO: Se agrupan por expediente (fileId)
  5632.         $proformas = array();
  5633.         foreach ($budToPro as $item) {
  5634.             $proformas[$item->getFileId()][] = $item;
  5635.         }
  5636.         //FIN: Se agrupan por expediente (fileId)
  5637.         if (empty($backToEditFile)) {                   // Las proforma no se creara si venimos de editar file
  5638.             if (!empty($budToPro)) {
  5639.                 foreach ($proformas as $key => $elemento) {
  5640.                     //INICIO: Creamos las proformas
  5641.                     //INICIO: Calculamos el ID de la proforma
  5642.                     $numberToPrefix $em->getRepository(AveDocProforma::class)->findAll();
  5643.                     if (empty($numberToPrefix)) {
  5644.                         $numberToPrefix 0;
  5645.                     } else {
  5646.                         $numberToPrefix end($numberToPrefix)->getId();
  5647.                     }
  5648.                     $numberToPrefix++;
  5649.                     //FIN: Calculamos el ID de la proforma
  5650.                     $proforma_prefix $request->request->get('proforma_prefix') . $proforma_number '-' $id;
  5651. // PĂ©galo aquĂ­:
  5652.                     $newProforma = new AveDocProforma();
  5653.                     $newProforma->setPrefix($proforma_prefix);
  5654.                     $newProforma->setDateAt(new DateTime('now'));
  5655.                     $newProforma->setFileId($id);
  5656.                     $newProforma->setCreatedAt(new DateTime('now'));
  5657.                     $newProforma->setCreatedId($user_id);
  5658.                     $newProforma->setUpdatedAt(new DateTime('now'));
  5659.                     $newProforma->setUpdatedId($user_id);
  5660.                     $em->persist($newProforma);
  5661.                     $em->flush(); // Esto genera el ID real en la base de datos
  5662.                     //FIN: Creamos las proformas
  5663.                     foreach ($elemento as $item) {
  5664.                         //$key es el id del expediente
  5665.                         //                    $arrayIdPro[$numberToPrefix] = $item->getUserConfirmedId();             // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  5666.                         //INICIO: Creamos los elemento que iran dentro de las proformas
  5667.                         $itemProforma = new AveDocProformaItems();
  5668.                         $itemProforma->setType('PRODUCT');
  5669.                         $itemProforma->setFileId($key);
  5670.                         $itemProforma->setProformaId($newProforma->getId());
  5671.                         $itemProforma->setControlId($item->getProductFileId());
  5672.                         $em->persist($itemProforma);
  5673.                         $em->flush();
  5674.                         //INICIO: Confirmamos el BudToProforma
  5675.                         $item->setStatus('Tosend');              // El elemento se ha pasado a la proforma, solo falta enviar
  5676.                         $item->setProformaId($newProforma->getId());
  5677.                         $em->persist($item);
  5678.                         $em->flush();
  5679.                         //FIN: Confirmamos el BudToProforma
  5680.                         //FIN: Creamos los elemento que iran dentro de las proformas
  5681.                     }
  5682.                 }
  5683.             }
  5684.         }
  5685.         //INICIO: Notificamos al agente por Telegram
  5686.         if ($logTelegram) {
  5687.             //Buscamos todos los agentes del proposal
  5688.             $proposalAgents $em->getRepository(ProposalAgents::class)->findOneByIdProp($file->getIdProposal());
  5689.             //Buscamos el Destino
  5690.             //            $proposalDestino = $em->getRepository(Destination::class)->findOneById($control->getDestinoId());
  5691.             //Buscamos el agente de Develup
  5692.             $userData $em->getRepository(User::class)->findOneById($user_id);
  5693.             if (!empty($proposalAgents)) {
  5694.                 if ((!empty($proposalAgents->getAgOne())) and (!($proposalAgents->getAgOne() == 0))) {
  5695.                     $this->sendTelegram($proposalAgents->getAgOne(), '1. PRESUPUESTO APROBADO DESDE AVEXPRESS __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5696.                 }
  5697.                 if ((!empty($proposalAgents->getAgTwo())) and (!($proposalAgents->getAgTwo() == 0))) {
  5698.                     $this->sendTelegram($proposalAgents->getAgTwo(), '2. PRESUPUESTO APROBADO DESDE AVEXPRESS __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5699.                 }
  5700.                 if ((!empty($proposalAgents->getAgThree())) and (!($proposalAgents->getAgThree() == 0))) {
  5701.                     $this->sendTelegram($proposalAgents->getAgThree(), '3. PRESUPUESTO APROBADO DESDE AVEXPRESS __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5702.                 }
  5703.                 if ((!empty($proposalAgents->getAgFour())) and (!($proposalAgents->getAgFour() == 0))) {
  5704.                     $this->sendTelegram($proposalAgents->getAgFour(), '4. PRESUPUESTO APROBADO DESDE AVEXPRESS __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5705.                 }
  5706.             }
  5707.         }
  5708.         //FIN: Notificamos al agente por Telegram
  5709.         //FIN: Creamos el presupuesto (proforma)
  5710.         if (!empty($backToEditFile)) {
  5711.             return $this->redirectToRoute('ave_edit_file', array('id' => $backToEditFile));
  5712.         }
  5713.         return $this->redirectToRoute('ave_list_pending_bud');
  5714.     }
  5715.     /**
  5716.      * @Route("/budgetsend/", name="ave_budget_send")
  5717.      * Envio automatico de los presupuestos forzado por usuario
  5718.      */
  5719.     public function budgetSendAction(Request $request)
  5720.     {
  5721.         $em $this->getDoctrine()->getManager();
  5722.         $budToPro $em->getRepository(AveBudgetToProforma::class)->findByStatus('Tosend');
  5723.         $logTelegram false;
  5724.         /* Obtengo usuario logueado */
  5725.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5726.         $user_id $user_logueado->getId();
  5727.         $arrayIdPro = array();          // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  5728.         //INICIO: Se agrupan por expediente (fileId)
  5729.         $proformas = array();
  5730.         foreach ($budToPro as $item) {
  5731.             $proformas[$item->getFileId()][] = $item;
  5732.             //            $fileDevelup = $item->getFileId();
  5733.         }
  5734.         //FIN: Se agrupan por expediente (fileId)
  5735.         if (!empty($budToPro)) {
  5736.             foreach ($proformas as $key => $elemento) {
  5737.                 //INICIO: Creamos las proformas
  5738.                 foreach ($elemento as $item) {
  5739.                     //$key es el id del expediente
  5740.                     if (!empty($item->getProformaId())) {
  5741.                         $arrayIdPro[$item->getProformaId()] = $item->getUserConfirmedId();             // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  5742.                     }
  5743.                     //INICIO: Confirmamos el BudToProforma
  5744.                     $item->setStatus('Confirmed');              // El elemento se ha pasado a confirmado porque se enviara por correo
  5745.                     $em->persist($item);
  5746.                     $em->flush();
  5747.                     //FIN: Confirmamos el BudToProforma
  5748.                     //FIN: Creamos los elemento que iran dentro de las proformas
  5749.                 }
  5750.             }
  5751.         }
  5752.         //INICIO: Notificamos de todos los presupuestos (proformas) que se han creado
  5753.         foreach ($arrayIdPro as $key => $item) {
  5754.             $logTelegram true;
  5755.             //Buscamos los agentes a notificar
  5756.             // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  5757.             $agent $em->getRepository(User::class)->findOneById($item);
  5758.             $agentMail $agent->getEmail();
  5759.             $mailAgent $agentMail;
  5760.             //            $mailAgent = 'gustavo.ayala@develup.solutions';
  5761.             //Se prepara el correo con los agentes a notificar
  5762.             $firmGmail $agent->getFirmGmail();
  5763.             $data = array(
  5764.                 '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>',
  5765.                 'firm' => $firmGmail,
  5766.             );
  5767.             // EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
  5768.             $transporter = new Swift_SmtpTransport();
  5769.             $transporter->setHost('smtp.gmail.com')
  5770.                 ->setEncryption('ssl'//ssl / tls
  5771.                 ->setPort(465// 465 / 587
  5772.                 ->setUsername('desarrollo@develup.solutions')
  5773.                 ->setPassword('utvh hzoi wfdo ztjs');
  5774.             $mailer = new Swift_Mailer($transporter);
  5775.             $message = new Swift_Message();
  5776.             $message->setSubject('Presupuesto #' $key ', NotificaciĂ³n de nuevo presupuesto')
  5777.                 ->setSender($agentMail)
  5778.                 ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  5779.                 ->setReplyTo($agentMail)
  5780.                 ->setTo($mailAgent)
  5781.                 ->setBody(
  5782.                     $this->renderView(
  5783.                         'mail/structure-mail.html.twig',
  5784.                         array('data' => $data)
  5785.                     ),
  5786.                     'text/html'
  5787.                 );
  5788.             $mailer->send($message);
  5789.             //INICIO: Notificamos al agente por Telegram
  5790.             if ($logTelegram) {
  5791.                 //Buscamos el id proposal a partir del id de la proforma
  5792.                 $prof $em->getRepository(AveDocProforma::class)->findOneById($key);
  5793.                 $file $em->getRepository(AveFiles::class)->findOneById($prof->getFileId());
  5794.                 //Buscamos todos los agentes del proposal
  5795.                 $proposalAgents $em->getRepository(ProposalAgents::class)->findOneByIdProp($file->getIdProposal());
  5796.                 //Buscamos el Destino
  5797.                 //            $proposalDestino = $em->getRepository(Destination::class)->findOneById($control->getDestinoId());
  5798.                 //Buscamos el agente de AvExpress
  5799.                 $userData $em->getRepository(User::class)->findOneById($user_id);
  5800.                 if (!empty($proposalAgents)) {
  5801.                     if ((!empty($proposalAgents->getAgOne())) and (!($proposalAgents->getAgOne() == 0))) {
  5802.                         $this->sendTelegram($proposalAgents->getAgOne(), '1. PRESUPUESTO DE AVEXPRESS ENVIADO POR CORREO __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5803.                     }
  5804.                     if ((!empty($proposalAgents->getAgTwo())) and (!($proposalAgents->getAgTwo() == 0))) {
  5805.                         $this->sendTelegram($proposalAgents->getAgTwo(), '2. PRESUPUESTO DE AVEXPRESS ENVIADO POR CORREO __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5806.                     }
  5807.                     if ((!empty($proposalAgents->getAgThree())) and (!($proposalAgents->getAgThree() == 0))) {
  5808.                         $this->sendTelegram($proposalAgents->getAgThree(), '3. PRESUPUESTO DE AVEXPRESS ENVIADO POR CORREO __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5809.                     }
  5810.                     if ((!empty($proposalAgents->getAgFour())) and (!($proposalAgents->getAgFour() == 0))) {
  5811.                         $this->sendTelegram($proposalAgents->getAgFour(), '4. PRESUPUESTO DE AVEXPRESS ENVIADO POR CORREO __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5812.                     }
  5813.                 }
  5814.             }
  5815.             //FIN: Notificamos al agente por Telegram
  5816.         }
  5817.         //FIN: Notificamos de todos los presupuestos (proformas) que se han creado
  5818.         return $this->redirectToRoute('ave_list_pending_bud');
  5819.     }
  5820.     /**
  5821.      * @Route("/budgetdel/{id}", name="ave_list_budget_del")
  5822.      * Eliminar el producto de la solicitud de presupuesto
  5823.      */
  5824.     public function budgetsDeleteAction($idRequest $request)
  5825.     {
  5826.         $em $this->getDoctrine()->getManager();
  5827.         $budget $em->getRepository(AveBudgetPending::class)->findOneById($id);
  5828.         $proposal_services_supplier $em->getRepository(ProposalSupplierServices::class)->findOneById($budget->getOriginId());
  5829.         // Se elimina el servicio de In Out
  5830.         if (!empty($proposal_services_supplier)) {
  5831.             $em->remove($proposal_services_supplier);
  5832.             $em->flush();
  5833.         }
  5834.         // Se elimina el servicio del presupuesto
  5835.         $em->remove($budget);
  5836.         $em->flush();
  5837.         return $this->redirectToRoute('ave_list_pending_bud');
  5838.     }
  5839.     /**
  5840.      * @Route("/newinvoicefrombudget/{id}", name="ave_new_invoice_from_budget")
  5841.      * Crear nueva factura desde un presupuesto (proforma)
  5842.      */
  5843.     public function generateNewInvoiceFromBudgetAction($idRequest $request)
  5844.     {
  5845.         // Antes de redirigir a la funcion que crea presupuesto a partir de proformas se deben modificar las tablas de los presupuestos
  5846.         $em $this->getDoctrine()->getManager();
  5847.         //  Buscamos los elementos de la proforma
  5848.         $elemProf $em->getRepository(AveDocProformaItems::class)->findByProformaId($id);
  5849.         $fileId $elemProf[0]->getFileId();
  5850.         //  Buscamos los elementos de budgetToProforma para cambiar su status a Invoiced
  5851.         // los que pertenezcan a la proforma y a Discard los que pertenezcan a otra proforma
  5852.         $elemBudToProf $em->getRepository(AveBudgetToProforma::class)->findByFileId($fileId);
  5853.         foreach ($elemBudToProf as $key => $item) {
  5854.             //con los $item busco en $elemBudToProf para poner invoiced
  5855.             foreach ($elemProf as $elem) {
  5856.                 if ($elem->getControlId() == $item->getProductFileId()) {
  5857.                     // Se debe poner en Invoiced
  5858.                     $item->setStatus('Invoiced');
  5859.                 }
  5860.             }
  5861.             // Si al terminar de revisar el status sigue en Confirmado, lo pasaremos
  5862.             // a descartado, es un elemento de un presupuesto que no fue aprobado
  5863.             // mientras que otro presupuesto si fue aprobado y paso a facturacion.
  5864.             // Al estar descartado no se muestra mas el presupuesto en los listados
  5865.             // aunque la proforma sigue existiendo.
  5866.             if ($item->getStatus() == 'Confirmed') {
  5867.                 $item->setStatus('Discarded');
  5868.             }
  5869.             $em->persist($item);
  5870.             $em->flush();
  5871.         }
  5872.         return $this->redirectToRoute('ave_new_invoice_from_proforma', array('id' => $id));
  5873.     }
  5874.     /**
  5875.      * @Route("/budgetdiscard/{id}", name="ave_budget_discard")
  5876.      * Crear nueva factura desde un presupuesto (proforma)
  5877.      */
  5878.     public function discardBudgetAction($idRequest $request)
  5879.     {
  5880.         $em $this->getDoctrine()->getManager();
  5881.         //  Buscamos los elementos de la proforma
  5882.         $elemProf $em->getRepository(MdvDocProformaItems::class)->findByProformaId($id);
  5883.         foreach ($elemProf as $item) {
  5884.             //  Buscamos los elementos de budgetToProforma para cambiar su status a Discarded
  5885.             $elemBudToProf $em->getRepository(AveBudgetToProforma::class)->findOneByProductFileId($item->getControlId());
  5886.             $elemBudToProf->setStatus('Discarded');
  5887.             $em->persist($item);
  5888.             $em->flush();
  5889.         }
  5890.         return $this->redirectToRoute('ave_list_pending_bud');
  5891.     }
  5892.     /**
  5893.      * @Route("/updateinvoicedate/", name="ave_update_invoice_date")
  5894.      * Actualizar servicios develup desde inout events (Controlador inaccesible)
  5895.      */
  5896.     public function updateInvoiceDateAction(Request $request)
  5897.     {
  5898.         $em $this->getDoctrine()->getManager();
  5899.         $invoiceId $request->request->get('invoice_id');
  5900.         $invoiceNewDate $request->request->get('new_invoice_date');
  5901.         /* Obtengo usuario logueado */
  5902.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5903.         $user_id $user_logueado->getId();
  5904.         $invoice $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
  5905.         $newDate = new DateTime($invoiceNewDate);
  5906.         $invoice->setDateAt($newDate);
  5907.         // Modificamos el number para que se adapte a la nueva fecha
  5908.         $invoice->setNumber('AVE-' $newDate->format('dmy') . substr($invoice->getNumber(), 10));
  5909.         $invoice->setUpdatedId($user_id);
  5910.         $invoice->setUpdatedAt(new DateTime('now'));
  5911.         $em->persist($invoice);
  5912.         $em->flush();
  5913.         return $this->redirectToRoute('ave_list_invoices');
  5914.     }
  5915.     /**
  5916.      * @Route("/budgetbriefdiscard/{id}", name="ave_budget_briefing_discard")
  5917.      * Eliminar un budget que es de tipo Briefing
  5918.      */
  5919.     public function budgetBriefDiscardAction($idRequest $request)
  5920.     {
  5921.         $em $this->getDoctrine()->getManager();
  5922.         $pendingBud $em->getRepository(AveBudgetPending::class)->findOneById($id);
  5923.         // Se elimina el presupuesto pendiente
  5924.         $em->remove($pendingBud);
  5925.         $em->flush();
  5926.         return $this->redirectToRoute('ave_list_pending_bud');
  5927.     }
  5928.     /**
  5929.      * @Route("/sendinvoicemail/", name="ave_send_invoice_mail")
  5930.      * Enviar enlace de la factura al cliente con copia
  5931.      */
  5932.     public function sendInvoiceMailAction(Request $request)
  5933.     {
  5934.         $fileId $request->request->get('fileId');
  5935.         $invoiceId $request->request->get('invoiceId');
  5936.         $ccToMail $request->request->get('ccToMail');
  5937.         /* Obtengo usuario logueado */
  5938.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5939.         $user_id $user_logueado->getId();
  5940.         $mailArrayTo = array();
  5941.         $mailArrayTo['salvador@avexpress.tv'] = 'salvador@avexpress.tv';
  5942.         $em $this->getDoctrine()->getManager();
  5943.         $file $em->getRepository(AveFiles::class)->findOneById($fileId);
  5944.         $invoice $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
  5945.         if (!empty($file->getClient())) {
  5946.             $client $em->getRepository(Client::class)->findOneById($file->getClient());
  5947.             if (!empty($client->getEmail())) {
  5948.                 $mailArrayTo[$client->getEmail()] = $client->getEmail();
  5949.             }
  5950.         }
  5951.         if (!empty($ccToMail)) {
  5952.             $mailArrayTo[$ccToMail] = $ccToMail;
  5953.         }
  5954.         $agente $em->getRepository(User::class)->findOneById($user_id);
  5955.         $mailAddressFrom $agente->getEmail();
  5956.         $mailSubject 'Factura del expediente: ' $file->getTitle();
  5957.         $mailBody 'Estimado cliente,' .
  5958.             '<br><br> En el siguiente enlace ponemos a su disposiciĂ³n la factura del expediente: ' .
  5959.             '<br><br><a href="https://mantevenues.mante.solutions/pdf/avexpressinvoiceext/' $invoice->getAccessKey() . '">Ver la factura</a>' .
  5960.             '<br><br>Muchas gracias por confiar en nuestros servicios.<br><br>';
  5961.         $this->sendMailLot($mailAddressFrom$mailArrayTo$mailSubject$mailBody);
  5962.         return $this->redirectToRoute('ave_edit_file', array('id' => $fileId));
  5963.     }
  5964.     /**
  5965.      * @Route("/filltokens/", name="ave_fill_tokens")
  5966.      * Llenar el campo token
  5967.      */
  5968.     public function fillTokensAction(Request $request)
  5969.     {
  5970.         $em $this->getDoctrine()->getManager();
  5971.         $invoices $em->getRepository(AveDocInvoice::class)->findAll();
  5972.         foreach ($invoices as $item) {
  5973.             if (empty($item->getAccessKey())) {
  5974.                 $item->setAccessKey(md5(rand() * time()));
  5975.                 $em->persist($item);
  5976.                 $em->flush();
  5977.             }
  5978.         }
  5979.         exit();
  5980.     }
  5981.     /**
  5982.      * @Route("/sendatch/", name="ave_sendatch")
  5983.      * prueba de envio de correo con datos adjuntos
  5984.      */
  5985.     public function sendAtchAction(Request $request)
  5986.     {
  5987.         $em $this->getDoctrine()->getManager();
  5988.         $mailBody 'Mensaje del correo';
  5989.         $mailArrayTo = array();
  5990.         $mailAddressFrom 'gustavo.ayala@develup.solutions';
  5991.         $mailSubject 'Asunto del correo';
  5992.         $agent $em->getRepository(User::class)->findOneByEmail($mailAddressFrom);
  5993.         $replyTo = array();
  5994.         foreach ($mailArrayTo as $item) {
  5995.             // Verificamos que los correos sean validos
  5996.             if (filter_var($itemFILTER_VALIDATE_EMAIL)) {
  5997.                 $replyTo[$item] = $item;
  5998.             }
  5999.         }
  6000.         $agentMail $mailAddressFrom;
  6001.         $mailAgent $agentMail;
  6002.         //Se prepara el correo con los agentes a notificar
  6003.         $firmGmail $agent->getFirmGmail();
  6004.         $data = array(
  6005.             'body' => $mailBody,
  6006.             'firm' => $firmGmail,
  6007.         );
  6008.         // EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
  6009.         $transporter = new Swift_SmtpTransport();
  6010.         $transporter->setHost('smtp.gmail.com')
  6011.             ->setEncryption('ssl'//ssl / tls
  6012.             ->setPort(465// 465 / 587
  6013.             ->setUsername('desarrollo@develup.solutions')
  6014.             ->setPassword('utvh hzoi wfdo ztjs');
  6015.         $mailer = new Swift_Mailer($transporter);
  6016.         $message = new Swift_Message();
  6017.         $message->setSubject($mailSubject)
  6018.             ->setSender($agentMail)
  6019.             ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  6020.             ->setReplyTo($agentMail)
  6021.             ->setTo($replyTo)
  6022.             ->setBody(
  6023.                 $this->renderView(
  6024.                     'mail/structure-mail.html.twig',
  6025.                     array('data' => $data)
  6026.                 ),
  6027.                 'text/html'
  6028.             );
  6029.         $message->attach(Swift_Attachment::fromPath('http://site.tld/logo.png'));
  6030.         $mailer->send($message);
  6031.         exit();
  6032.     }
  6033.     /**
  6034.      * @Route("/maketableinfo/", name="ave_make_table_info")
  6035.      * crea la info de la tabla AveBenefitsInvoiceInvoiceRec
  6036.      */
  6037.     public function aveBenefitsAction(Request $request)
  6038.     {
  6039.         $em $this->getDoctrine()->getManager();
  6040.         if (true) {
  6041.             //Buscamos todas las facturas
  6042.             $invoices $em->getRepository(AveDocInvoice::class)->findAll();
  6043.             foreach ($invoices as $invoice) {
  6044.                 // Verificamos si esta ya en la tabla
  6045.                 $isInTable $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneBy(array('docId' => $invoice->getId(), 'docType' => 'Invoice'));
  6046.                 // Solo se hace en facturas, se descartan facturas de deposito ya que estas no se consideran ventas reales (Isa)
  6047.                 if ($invoice->getType() == 'Invoice') {
  6048.                     // Solo creamos si no existe en la tabla
  6049.                     if (empty($isInTable)) {
  6050.                         $this->calculoBeneficiosDocumento($invoice->getId(), 'Invoice');
  6051.                     }
  6052.                 }
  6053.             }
  6054.         }
  6055.         if (true) {
  6056.             //Buscamos todas las facturas rectificativas
  6057.             $invoices $em->getRepository(AveDocInvoiceRec::class)->findAll();
  6058.             foreach ($invoices as $invoice) {
  6059.                 // Verificamos si esta ya en la tabla
  6060.                 //                $isInTable = $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneByDocId($invoice->getId());
  6061.                 $isInTable $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneBy(array('docId' => $invoice->getId(), 'docType' => 'Invoice Rec'));
  6062.                 // Solo se hace en facturas, se descartan facturas de deposito ya que estas no se consideran ventas reales (Isa)
  6063.                 if ($invoice->getType() == 'Invoice Rec') {
  6064.                     // Solo creamos si no existe en la tabla
  6065.                     if (empty($isInTable)) {
  6066.                         $this->calculoBeneficiosDocumento($invoice->getId(), 'Invoice Rec');
  6067.                     }
  6068.                 }
  6069.             }
  6070.         }
  6071.         d('Fin del procesamiento');
  6072.         exit();
  6073.     }
  6074.     /**
  6075.      * @Route("/openbenefitssuppliers/{id}", name="ave_open_benefits_suppliers")
  6076.      * abre el expediente para permitir escritura AveBenefitsInvoiceInvoiceRec
  6077.      */
  6078.     public function aveOpenBenefitsSuppliersAction($idRequest $request)
  6079.     {
  6080.         $em $this->getDoctrine()->getManager();
  6081.         /* Obtengo usuario logueado */
  6082.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  6083.         $user_id $user_logueado->getId();
  6084.         $benefits $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneByFileId($id);
  6085.         if (!empty($benefits)) {
  6086.             $benefits->setBenefitEuro(0);
  6087.             $benefits->setBenefitPerc(0);
  6088.             $em->persist($benefits);
  6089.             $em->flush();
  6090.         }
  6091.         $benefitsPer $em->getRepository(AveBenefitsPermissions::class)->findOneByFileId($id);
  6092.         if (empty($benefitsPer)) {
  6093.             $benefitsPer = new AveBenefitsPermissions();
  6094.             $benefitsPer->setCreatedId($user_id);
  6095.             $benefitsPer->setCreatedAt(new \DateTime("now"));
  6096.         }
  6097.         $benefitsPer->setStatus('Open');
  6098.         $benefitsPer->setFileId($id);
  6099.         $benefitsPer->setUpdatedId($user_id);
  6100.         $benefitsPer->setUpdatedAt(new \DateTime("now"));
  6101.         $em->persist($benefitsPer);
  6102.         $em->flush();
  6103.         return $this->redirectToRoute('ave_supplier_list', array('id' => $id));
  6104.     }
  6105.     /**
  6106.      * @Route("/closebenefitssuppliers/{id}", name="ave_close_benefits_suppliers")
  6107.      * cierra el expediente para crear su AveBenefitsInvoiceInvoiceRec
  6108.      */
  6109.     public function aveCloseBenefitsSuppliersAction($idRequest $request)
  6110.     {
  6111.         $em $this->getDoctrine()->getManager();
  6112.         /* Obtengo usuario logueado */
  6113.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  6114.         $user_id $user_logueado->getId();
  6115.         $benefitsOLD $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findBy(
  6116.             array(
  6117.                 'fileId' => $id,
  6118.                 'docType' => 'Invoice',
  6119.             )
  6120.         );
  6121.         if (!empty($benefitsOLD)) {
  6122.             if (!(($benefitsOLD[0]->getClientName() == 'Green Patio') and ($benefitsOLD[0]->getClientId() == 2556))) {
  6123.                 $this->calculoBeneficiosDocumento($benefitsOLD[0]->getDocId(), $benefitsOLD[0]->getDocType());
  6124.                 $em->remove($benefitsOLD[0]);
  6125.                 $em->flush();
  6126.             }
  6127.         }
  6128.         $benefitsPer $em->getRepository(AveBenefitsPermissions::class)->findOneByFileId($id);
  6129.         if (!empty($benefitsPer)) {
  6130.             $benefitsPer->setStatus('Close');
  6131.             $benefitsPer->setUpdatedId($user_id);
  6132.             $benefitsPer->setUpdatedAt(new \DateTime("now"));
  6133.             $em->persist($benefitsPer);
  6134.             $em->flush();
  6135.         }
  6136.         return $this->redirectToRoute('ave_supplier_list', array('id' => $id));
  6137.     }
  6138.     private function baseInvoiceFile($id$type$number$prefix$date)
  6139.     {
  6140.         $em $this->getDoctrine()->getManager();
  6141.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  6142.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  6143.         $client $em->getRepository(Client::class)->findById($file->getClient());
  6144.         if (empty($client)) {
  6145.             $client[0] = new Client();
  6146.             $client[0]->setName('');
  6147.             $client[0]->setTitle('');
  6148.             $client[0]->setIdDocument('');
  6149.             $client[0]->setPopulation('');
  6150.             $client[0]->setRegion('');
  6151.             $client[0]->setCountry('');
  6152.         } else {
  6153.             if (is_numeric($client[0]->getPopulation())) {
  6154.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  6155. //                $client[0]->setPopulation($city->getCity());
  6156.             }
  6157.             if (is_numeric($client[0]->getRegion())) {
  6158.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  6159. //                $client[0]->setRegion($region->getRegion());
  6160.             }
  6161.             if (is_numeric($client[0]->getCountry())) {
  6162.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  6163. //                $client[0]->setCountry($country->getCountry());
  6164.             }
  6165.         }
  6166.         if (empty($client)) {
  6167.             $client[0] = new Client();
  6168.             $client[0]->setName('');
  6169.             $client[0]->setTitle('');
  6170.             $client[0]->setIdDocument('');
  6171.             $client[0]->setPopulation('');
  6172.             $client[0]->setRegion('');
  6173.             $client[0]->setCountry('');
  6174.             $clientNew = array(
  6175.                 'name' => '',
  6176.                 'title' => '',
  6177.                 'idDocument' => '',
  6178.                 'population' => '',
  6179.                 'region' => '',
  6180.                 'country' => '',
  6181.                 'address' => '',
  6182.                 'addressNumber' => '',
  6183.                 'zipCode' => '',
  6184.                 'typeDocument' => '',
  6185.             );
  6186.         } else {
  6187.             $clientNew = array(
  6188.                 'name' => $client[0]->getName(),
  6189.                 'title' => $client[0]->getTitle(),
  6190.                 'idDocument' => $client[0]->getIdDocument(),
  6191.                 'population' => '',
  6192.                 'region' => '',
  6193.                 'country' => '',
  6194.                 'address' => $client[0]->getAddress(),
  6195.                 'addressNumber' => $client[0]->getAddressNumber(),
  6196.                 'zipCode' => $client[0]->getZipCode(),
  6197.                 'typeDocument' => $client[0]->getTypeDocument(),
  6198.             );
  6199.             if (is_numeric($client[0]->getPopulation())) {
  6200.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  6201.                 $clientNew['population'] = $city->getCity();
  6202.             }
  6203.             if (is_numeric($client[0]->getRegion())) {
  6204.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  6205.                 $clientNew['region'] = $region->getRegion();
  6206.             }
  6207.             if (is_numeric($client[0]->getCountry())) {
  6208.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  6209.                 $clientNew['country'] = $country->getCountry();
  6210.             }
  6211.         }
  6212.         // Acumuladores de los calculos
  6213.         $totales_neto_all 0;
  6214.         $data_iva = array(
  6215.             'iva' => 21,
  6216.             'ivaMontoVeintiUno' => 0,
  6217.             'ivaMontoDiez' => 0,
  6218.             'ivaMontoCero' => null,
  6219.         );
  6220.         // Buscamos las salas reservadas, pagos y servicios para el evento
  6221.         // Salvador Guerrero indico, el orden de los productos en la factura o proforma serĂ¡ (Video - Sonido - Iluminacion - Otros)
  6222.         $allProductFile $em->getRepository(AveProductFile::class)->findByFileId($id);
  6223.         $arrayLocation = array();
  6224.         $arrayLocationWithNull false;
  6225.         foreach ($allProductFile as $item) {
  6226.             if (!empty($item->getLocation())) {
  6227.                 $arrayLocation[$item->getLocation()] = $item->getLocation();
  6228.             } else {
  6229.                 $arrayLocationWithNull true;
  6230.             }
  6231.         }
  6232.         if ($arrayLocationWithNull) {
  6233.             $arrayLocation['null'] = 'null';
  6234.         }
  6235.         $productsInFile = [];
  6236.         foreach ($arrayLocation as $item) {
  6237.             // VIDEO
  6238.             $parameters = array(
  6239.                 'fileId' => $id,
  6240.                 'type' => 'VĂ­deo',
  6241.                 'location' => $item,
  6242.             );
  6243.             $dql 'SELECT i
  6244.                     FROM AvexpressBundle:AveProductFile i
  6245.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location
  6246.                     ORDER BY i.rankquoteAv ASC';
  6247.             $query $em->createQuery($dql)->setParameters($parameters);
  6248.             $productsInFileVid $query->getResult();
  6249.             // SONIDO
  6250.             $parameters = array(
  6251.                 'fileId' => $id,
  6252.                 'type' => 'Sonido',
  6253.                 'location' => $item,
  6254.             );
  6255.             $dql 'SELECT i
  6256.                     FROM AvexpressBundle:AveProductFile i
  6257.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location
  6258.                     ORDER BY i.rankquoteAv ASC';
  6259.             $query $em->createQuery($dql)->setParameters($parameters);
  6260.             $productsInFileSound $query->getResult();
  6261.             // ILUMINACION
  6262.             $parameters = array(
  6263.                 'fileId' => $id,
  6264.                 'type' => 'IluminaciĂ³n',
  6265.                 'location' => $item,
  6266.             );
  6267.             $dql 'SELECT i
  6268.                     FROM AvexpressBundle:AveProductFile i
  6269.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location
  6270.                     ORDER BY i.rankquoteAv ASC';
  6271.             $query $em->createQuery($dql)->setParameters($parameters);
  6272.             $productsInFileLights $query->getResult();
  6273.             // PAQUETE
  6274.             $parameters = array(
  6275.                 'fileId' => $id,
  6276.                 'type' => 'Paquete',
  6277.                 'location' => $item,
  6278.             );
  6279.             $dql 'SELECT i
  6280.                     FROM AvexpressBundle:AveProductFile i
  6281.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location
  6282.                     ORDER BY i.rankquoteAv ASC';
  6283.             $query $em->createQuery($dql)->setParameters($parameters);
  6284.             $productsInFilePackage $query->getResult();
  6285.             // OTROS
  6286.             $parameters = array(
  6287.                 'fileId' => $id,
  6288.                 'typeV' => 'VĂ­deo',
  6289.                 'typeS' => 'Sonido',
  6290.                 'typeI' => 'IluminaciĂ³n',
  6291.                 'typeP' => 'Paquete',
  6292.                 'location' => $item,
  6293.             );
  6294.             $dql 'SELECT i
  6295.                     FROM AvexpressBundle:AveProductFile i
  6296.                     WHERE (i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND i.type != :typeP AND i.location = :location)
  6297.                     ORDER BY i.rankquoteAv ASC';
  6298.             $query $em->createQuery($dql)->setParameters($parameters);
  6299.             $productsInFileOther $query->getResult();
  6300.             // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  6301.             $parameters = array(
  6302.                 'fileId' => $id,
  6303.                 'location' => $item,
  6304.             );
  6305.             $dql 'SELECT i
  6306.                     FROM AvexpressBundle:AveProductFile i
  6307.                     WHERE (i.fileId = :fileId AND i.type IS NULL AND i.location = :location)
  6308.                     ORDER BY i.rankquoteAv ASC';
  6309.             $query $em->createQuery($dql)->setParameters($parameters);
  6310.             $productsInFileNull $query->getResult();
  6311.             // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  6312.             if ($item == 'null') {
  6313.                 // VIDEO
  6314.                 $parameters = array(
  6315.                     'fileId' => $id,
  6316.                     'type' => 'VĂ­deo',
  6317.                     'location' => '',
  6318.                 );
  6319.                 $dql 'SELECT i
  6320.                         FROM AvexpressBundle:AveProductFile i
  6321.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location)
  6322.                         ORDER BY i.rankquoteAv ASC';
  6323.                 $query $em->createQuery($dql)->setParameters($parameters);
  6324.                 $productsInFileVid $query->getResult();
  6325.                 // SONIDO
  6326.                 $parameters = array(
  6327.                     'fileId' => $id,
  6328.                     'type' => 'Sonido',
  6329.                     'location' => '',
  6330.                 );
  6331.                 $dql 'SELECT i
  6332.                         FROM AvexpressBundle:AveProductFile i
  6333.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) 
  6334.                         ORDER BY i.rankquoteAv ASC';
  6335.                 $query $em->createQuery($dql)->setParameters($parameters);
  6336.                 $productsInFileSound $query->getResult();
  6337.                 // ILUMINACION
  6338.                 $parameters = array(
  6339.                     'fileId' => $id,
  6340.                     'type' => 'IluminaciĂ³n',
  6341.                     'location' => '',
  6342.                 );
  6343.                 $dql 'SELECT i
  6344.                         FROM AvexpressBundle:AveProductFile i
  6345.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location)
  6346.                         ORDER BY i.rankquoteAv ASC';
  6347.                 $query $em->createQuery($dql)->setParameters($parameters);
  6348.                 $productsInFileLights $query->getResult();
  6349.                 // PAQUETE
  6350.                 $parameters = array(
  6351.                     'fileId' => $id,
  6352.                     'type' => 'Paquete',
  6353.                     'location' => '',
  6354.                 );
  6355.                 $dql 'SELECT i
  6356.                         FROM AvexpressBundle:AveProductFile i
  6357.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location)
  6358.                         ORDER BY i.rankquoteAv ASC';
  6359.                 $query $em->createQuery($dql)->setParameters($parameters);
  6360.                 $productsInFilePackage $query->getResult();
  6361.                 // OTROS
  6362.                 $parameters = array(
  6363.                     'fileId' => $id,
  6364.                     'typeV' => 'VĂ­deo',
  6365.                     'typeS' => 'Sonido',
  6366.                     'typeI' => 'IluminaciĂ³n',
  6367.                     'typeP' => 'Paquete',
  6368.                     'location' => '',
  6369.                 );
  6370.                 $dql 'SELECT i
  6371.                         FROM AvexpressBundle:AveProductFile i
  6372.                         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))
  6373.                         ORDER BY i.rankquoteAv ASC';
  6374.                 $query $em->createQuery($dql)->setParameters($parameters);
  6375.                 $productsInFileOther $query->getResult();
  6376.                 // CASO NULL DEL TIPO (Los casos EMPTY estan considerados en las consultas previas)
  6377.                 $parameters = array(
  6378.                     'fileId' => $id,
  6379.                     'location' => '',
  6380.                 );
  6381.                 $dql 'SELECT i
  6382.                         FROM AvexpressBundle:AveProductFile i
  6383.                         WHERE (i.fileId = :fileId AND i.type IS NULL AND (i.location IS NULL OR i.location = :location))
  6384.                         ORDER BY i.rankquoteAv ASC';
  6385.                 $query $em->createQuery($dql)->setParameters($parameters);
  6386.                 $productsInFileNull $query->getResult();
  6387.             }
  6388.             $productsInFile array_merge($productsInFile$productsInFileVid$productsInFileSound$productsInFileLights$productsInFilePackage$productsInFileOther$productsInFileNull);
  6389.         }
  6390.         $payments $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  6391.         $services $em->getRepository(AveServices::class)->findByFileId($id);
  6392.         $data_supplier = [];
  6393.         $i 0;
  6394.         $iva '21';            // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
  6395.         $pax '1';
  6396.         $qty '1';
  6397.         $product = array(
  6398.             'neto' => 0,
  6399.             'sumSubT' => 0,
  6400.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  6401.         $service = array(
  6402.             'neto' => 0,
  6403.             'sumSubT' => 0,
  6404.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  6405.         foreach ($productsInFile as $item) {
  6406.             //            $days = '1';
  6407.             //            $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  6408.             $days = ((($item->getDateEnd())->diff($item->getDateStart()))->days 1);
  6409.             // Verificamos que el producto no se encuentre ya en una factura
  6410.             $existe $em->getRepository(AveDocInvoiceItems::class)->findByPrdControlId($item->getId());
  6411.             $pax $item->getPax();
  6412.             $qty $item->getUnits();
  6413.             if (!empty($item->getDays())) {
  6414.                 $days $item->getDays();
  6415.             }
  6416.             if (is_null($item->getServicePrice()) or empty($item->getServicePrice()) or !empty($existe)) {
  6417.                 $subtotal 0;
  6418.                 $neto 0;
  6419.                 $subtotalProduct 0;
  6420.             } else {
  6421.                 $subtotalProduct 0;
  6422.                 if ($item->getIva() == '21') {
  6423.                     $subtotalProduct $item->getSubTotalPrice() * 1.21;
  6424.                 } // Iva a 21%
  6425.                 if ($item->getIva() == '10') {
  6426.                     $subtotalProduct $item->getSubTotalPrice() * 1.1;
  6427.                 } // Iva a 10%
  6428.                 if ($item->getIva() == '0') {
  6429.                     $subtotalProduct $item->getSubTotalPrice() * 1;
  6430.                 } // Iva a 0%
  6431.                 $subneto $item->getSubTotalPrice();
  6432.                 $subtotal =  $subtotalProduct;
  6433.                 $neto =  $subneto;
  6434.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  6435.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  6436.                 $neto round($neto2PHP_ROUND_HALF_UP);
  6437.             }
  6438.             // Acumula netos totales e IVA
  6439.             $totales_neto_all $totales_neto_all $neto;
  6440.             if ($item->getIva() == '21') {
  6441.                 $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  6442.             } // Iva a 21%
  6443.             if ($item->getIva() == '10') {
  6444.                 $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1);
  6445.             } // Iva a 10%
  6446.             if ($item->getIva() == '0') {
  6447.                 $data_iva['ivaMontoCero'] = $neto 0;
  6448.             } // Iva a 0%, estaba inicializado en null para que aparezca en la factura solo si estĂ¡ a cero
  6449.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6450.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  6451.             if ($item->getIva() == '21') {
  6452.                 $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  6453.             } // Iva a 21%
  6454.             if ($item->getIva() == '10') {
  6455.                 $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  6456.             } // Iva a 10%
  6457.             if ($item->getIva() == '0') {
  6458.                 $data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2PHP_ROUND_HALF_UP);
  6459.             } // Iva a 0%
  6460.             // Acumula netos totales e IVA
  6461.             $product['neto'] = $product['neto'] + $neto;
  6462.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  6463.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6464.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  6465.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  6466.             // Calculo del precio unitario despues de aplicar Over y Comision
  6467.             $multiplo = (float)$qty * (float)$days;
  6468.             $item->setServicePrice($item->getSubTotalPrice() / $multiplo);
  6469.             $data_supplier['product'][$i] = array(
  6470.                 'id' => $item->getId(),
  6471.                 'productName' => $item->getProductName(),
  6472.                 'productId' => $item->getProductId(),
  6473.                 'dateStart' => $item->getDateStart(),
  6474.                 'dateEnd' => $item->getDateEnd(),
  6475.                 'location' => $item->getLocation(),
  6476.                 'servicePrice' => $item->getServicePrice(),
  6477.                 'subTotalPrice' => $item->getSubTotalPrice(),
  6478.                 'subtotalProduct' => $subtotalProduct,
  6479.                 'iva' => $item->getIva(),
  6480.                 'pax' => $pax,
  6481.                 'qty' => $qty,
  6482.                 'days' => $days,
  6483.                 'type' => $item->getType(),
  6484.                 'subtotal' => $subtotal,
  6485.             );
  6486.             $i++;
  6487.         }
  6488.         $data_supplier['productSubTotal'] = array(
  6489.             'neto' => $product['neto'],
  6490.             'sumSubT' => $product['sumSubT'],
  6491.         );
  6492.         $payment = array(
  6493.             'sumSubT' => 0,
  6494.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  6495.         $i 0;
  6496.         foreach ($payments as $item) {
  6497.             // Verificamos que el pago no se encuentre ya en una factura
  6498.             $existe $em->getRepository(AveDocInvoiceItems::class)->findByPayControlId($item->getId());
  6499.             if (!empty($existe)) {
  6500.                 $payment['sumSubT'] = $payment['sumSubT'] + 0;
  6501.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6502.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  6503.             } else {
  6504.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  6505.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6506.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  6507.             }
  6508.             $data_supplier['payment'][$i] = array(
  6509.                 'id' => $item->getId(),
  6510.                 'amount' => $item->getAmount(),
  6511.                 'datePayAt' => $item->getDatePayAt(),
  6512.                 'wayToPay' => $item->getWayToPay(),
  6513.                 'amountTotal' => $item->getAmountTotal(),
  6514.                 'vat' => $item->getVat(),
  6515.             );
  6516.             $i++;
  6517.         }
  6518.         if (!empty($payments)) {
  6519.             $data_supplier['paymentSubTotal'] = array(
  6520.                 'sumSubT' => $payment['sumSubT'],
  6521.             );
  6522.         }
  6523.         foreach ($services as $item) {
  6524.             // Verificamos que el servicio no se encuentre ya en una factura
  6525.             $existe $em->getRepository(AveDocInvoiceItems::class)->findBySrvControlId($item->getId());
  6526.             if (is_null($item->getPrice()) or empty($item->getPrice()) or !empty($existe)) {
  6527.                 $subtotal 0;
  6528.                 $neto 0;
  6529.                 $subtotalService 0;
  6530.                 $subneto 0;
  6531.                 switch ($item->getServiceCatId()) {
  6532.                     case 1// Alojamiento
  6533.                         // el numero de noches $numNoches; precio unitario $subneto
  6534.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  6535.                         // La personas no afectan este calculo
  6536.                         $subtotal $subtotalService $numNoches $item->getUnits();
  6537.                         $subnetoUnit $subneto;
  6538.                         $subneto $subneto $numNoches $item->getUnits();
  6539.                         $data_supplier['service'][$i] = array(
  6540.                             'id' => $item->getId(),
  6541.                             'serviceCatId' => $item->getServiceCatId(),
  6542.                             'serviceName' => $item->getName(),
  6543.                             'serviceType' => 'Hotel',
  6544.                             'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  6545.                             'qty' => $item->getUnits(),
  6546.                             'iva' => $item->getIva(),
  6547.                             'pax' => '-',
  6548.                             'precioUnit' => $subnetoUnit,
  6549.                             'subneto' => $subneto,
  6550.                             'subtotal' => $subtotal,
  6551.                         );
  6552.                         break;
  6553.                     case 2//Actividades
  6554.                         // El nĂºmero de personas es considerado en el calculo
  6555.                         $pax $item->getPax();
  6556.                         if (empty($pax) or $pax == "0") {
  6557.                             $pax 1;
  6558.                         }
  6559.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6560.                         if ($days 1) {
  6561.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6562.                         } else {
  6563.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6564.                         }
  6565.                         $subtotal $subtotalService $days $item->getUnits();
  6566.                         $subnetoUnit $subneto;
  6567.                         $subneto $subneto $days $item->getUnits();
  6568.                         $data_supplier['service'][$i] = array(
  6569.                             'id' => $item->getId(),
  6570.                             'serviceCatId' => $item->getServiceCatId(),
  6571.                             'serviceName' => $item->getName(),
  6572.                             'serviceType' => 'Actividad',
  6573.                             'date' => $dateServ,
  6574.                             'qty' => $item->getUnits(),
  6575.                             'iva' => $item->getIva(),
  6576.                             'pax' => $item->getPax(),
  6577.                             'precioUnit' => $subnetoUnit,
  6578.                             'subneto' => $subneto,
  6579.                             'subtotal' => $subtotal,
  6580.                         );
  6581.                         break;
  6582.                     case 3// AV
  6583.                         $pax $item->getPax();
  6584.                         if (empty($pax) or $pax == "0") {
  6585.                             $pax 1;
  6586.                         }
  6587.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6588.                         if ($days 1) {
  6589.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6590.                         } else {
  6591.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6592.                         }
  6593.                         $unitsServ $item->getUnits();
  6594.                         if (empty($unitsServ) or $unitsServ == "0") {
  6595.                             $unitsServ 1;
  6596.                         }
  6597.                         $subtotal $subtotalService $days $unitsServ $pax;
  6598.                         $subnetoUnit $subneto;
  6599.                         $subneto $subneto $days $unitsServ $pax;
  6600.                         $data_supplier['service'][$i] = array(
  6601.                             'id' => $item->getId(),
  6602.                             'serviceCatId' => $item->getServiceCatId(),
  6603.                             'serviceName' => $item->getName(),
  6604.                             'serviceType' => 'AV',
  6605.                             'date' => $dateServ,
  6606.                             'qty' => $unitsServ,
  6607.                             'iva' => $item->getIva(),
  6608.                             'pax' => $item->getPax(),
  6609.                             'precioUnit' => $subnetoUnit,
  6610.                             'subneto' => $subneto,
  6611.                             'subtotal' => $subtotal,
  6612.                         );
  6613.                         break;
  6614.                     case 4//Creative
  6615.                         $pax $item->getPax();
  6616.                         if (empty($pax) or $pax == "0") {
  6617.                             $pax 1;
  6618.                         }
  6619.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6620.                         if ($days 1) {
  6621.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6622.                         } else {
  6623.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6624.                         }
  6625.                         $unitsServ $item->getUnits();
  6626.                         if (empty($unitsServ) or $unitsServ == "0") {
  6627.                             $unitsServ 1;
  6628.                         }
  6629.                         $subtotal $subtotalService $days $unitsServ $pax;
  6630.                         $subnetoUnit $subneto;
  6631.                         $subneto $subneto $days $unitsServ $pax;
  6632.                         $data_supplier['service'][$i] = array(
  6633.                             'id' => $item->getId(),
  6634.                             'serviceCatId' => $item->getServiceCatId(),
  6635.                             'serviceName' => $item->getName(),
  6636.                             'serviceType' => 'Creativo',
  6637.                             'date' => $dateServ,
  6638.                             'qty' => $unitsServ,
  6639.                             'iva' => $item->getIva(),
  6640.                             'pax' => $item->getPax(),
  6641.                             'precioUnit' => $subnetoUnit,
  6642.                             'subneto' => $subneto,
  6643.                             'subtotal' => $subtotal,
  6644.                         );
  6645.                         break;
  6646.                     case 5//Cruise
  6647.                         $pax $item->getPax();
  6648.                         if (empty($pax) or $pax == "0") {
  6649.                             $pax 1;
  6650.                         }
  6651.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  6652.                         if ($days 1) {
  6653.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6654.                         } else {
  6655.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6656.                         }
  6657.                         $unitsServ $item->getUnits();
  6658.                         if (empty($unitsServ) or $unitsServ == "0") {
  6659.                             $unitsServ 1;
  6660.                         }
  6661.                         $subtotal $subtotalService $days $unitsServ $pax;
  6662.                         $subnetoUnit $subneto;
  6663.                         $subneto $subneto $days $unitsServ $pax;
  6664.                         $data_supplier['service'][$i] = array(
  6665.                             'id' => $item->getId(),
  6666.                             'serviceCatId' => $item->getServiceCatId(),
  6667.                             'serviceName' => $item->getName(),
  6668.                             'serviceType' => 'Crucero',
  6669.                             'date' => $dateServ,
  6670.                             'qty' => $unitsServ,
  6671.                             'iva' => $item->getIva(),
  6672.                             'pax' => $item->getPax(),
  6673.                             'precioUnit' => $subnetoUnit,
  6674.                             'subneto' => $subneto,
  6675.                             'subtotal' => $subtotal,
  6676.                         );
  6677.                         break;
  6678.                     case 6//Entertaiment
  6679.                         $pax $item->getPax();
  6680.                         if (empty($pax) or $pax == "0") {
  6681.                             $pax 1;
  6682.                         }
  6683.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6684.                         if ($days 1) {
  6685.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6686.                         } else {
  6687.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6688.                         }
  6689.                         $unitsServ $item->getUnits();
  6690.                         if (empty($unitsServ) or $unitsServ == "0") {
  6691.                             $unitsServ 1;
  6692.                         }
  6693.                         $subtotal $subtotalService $days $unitsServ $pax;
  6694.                         $subnetoUnit $subneto;
  6695.                         $subneto $subneto $days $unitsServ $pax;
  6696.                         $data_supplier['service'][$i] = array(
  6697.                             'id' => $item->getId(),
  6698.                             'serviceCatId' => $item->getServiceCatId(),
  6699.                             'serviceName' => $item->getName(),
  6700.                             'serviceType' => 'Entretenimiento',
  6701.                             'date' => $dateServ,
  6702.                             'qty' => $unitsServ,
  6703.                             'iva' => $item->getIva(),
  6704.                             'pax' => $item->getPax(),
  6705.                             'precioUnit' => $subnetoUnit,
  6706.                             'subneto' => $subneto,
  6707.                             'subtotal' => $subtotal,
  6708.                         );
  6709.                         break;
  6710.                     case 7// Gifts
  6711.                         $pax $item->getPax();
  6712.                         if (empty($pax) or $pax == "0") {
  6713.                             $pax 1;
  6714.                         }
  6715.                         $days 1;
  6716.                         if ($days 1) {
  6717.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6718.                         } else {
  6719.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6720.                         }
  6721.                         $unitsServ $item->getUnits();
  6722.                         if (empty($unitsServ) or $unitsServ == "0") {
  6723.                             $unitsServ 1;
  6724.                         }
  6725.                         $subtotal $subtotalService $days $unitsServ $pax;
  6726.                         $subnetoUnit $subneto;
  6727.                         $subneto $subneto $days $unitsServ $pax;
  6728.                         $data_supplier['service'][$i] = array(
  6729.                             'id' => $item->getId(),
  6730.                             'serviceCatId' => $item->getServiceCatId(),
  6731.                             'serviceName' => $item->getName(),
  6732.                             'serviceType' => 'Regalos',
  6733.                             'date' => $dateServ,
  6734.                             'qty' => $unitsServ,
  6735.                             'iva' => $item->getIva(),
  6736.                             'pax' => $item->getPax(),
  6737.                             'precioUnit' => $subnetoUnit,
  6738.                             'subneto' => $subneto,
  6739.                             'subtotal' => $subtotal,
  6740.                         );
  6741.                         break;
  6742.                     case 8//Guide
  6743.                         $pax $item->getPax();
  6744.                         if (empty($pax) or $pax == "0") {
  6745.                             $pax 1;
  6746.                         }
  6747.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6748.                         if ($days 1) {
  6749.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6750.                         } else {
  6751.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6752.                         }
  6753.                         $unitsServ $item->getUnits();
  6754.                         if (empty($unitsServ) or $unitsServ == "0") {
  6755.                             $unitsServ 1;
  6756.                         }
  6757.                         $subtotal $subtotalService $days $unitsServ $pax;
  6758.                         $subnetoUnit $subneto;
  6759.                         $subneto $subneto $days $unitsServ $pax;
  6760.                         $data_supplier['service'][$i] = array(
  6761.                             'id' => $item->getId(),
  6762.                             'serviceCatId' => $item->getServiceCatId(),
  6763.                             'serviceName' => $item->getName(),
  6764.                             'serviceType' => 'Regalos',
  6765.                             'date' => $dateServ,
  6766.                             'qty' => $unitsServ,
  6767.                             'iva' => $item->getIva(),
  6768.                             'pax' => $item->getPax(),
  6769.                             'precioUnit' => $subnetoUnit,
  6770.                             'subneto' => $subneto,
  6771.                             'subtotal' => $subtotal,
  6772.                         );
  6773.                         break;
  6774.                     case 9//Itineraries
  6775.                         $pax $item->getPax();
  6776.                         if (empty($pax) or $pax == "0") {
  6777.                             $pax 1;
  6778.                         }
  6779.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6780.                         if ($days 1) {
  6781.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6782.                         } else {
  6783.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6784.                         }
  6785.                         $unitsServ $item->getUnits();
  6786.                         if (empty($unitsServ) or $unitsServ == "0") {
  6787.                             $unitsServ 1;
  6788.                         }
  6789.                         $subtotal $subtotalService $days $unitsServ $pax;
  6790.                         $subnetoUnit $subneto;
  6791.                         $subneto $subneto $days $unitsServ $pax;
  6792.                         $data_supplier['service'][$i] = array(
  6793.                             'id' => $item->getId(),
  6794.                             'serviceCatId' => $item->getServiceCatId(),
  6795.                             'serviceName' => $item->getName(),
  6796.                             'serviceType' => 'Itinerarios',
  6797.                             'date' => $dateServ,
  6798.                             'qty' => $unitsServ,
  6799.                             'iva' => $item->getIva(),
  6800.                             'pax' => $item->getPax(),
  6801.                             'precioUnit' => $subnetoUnit,
  6802.                             'subneto' => $subneto,
  6803.                             'subtotal' => $subtotal,
  6804.                         );
  6805.                         break;
  6806.                     case 10//Lounge  -- No Aplica
  6807.                         //                        $pax = $item->getPax();
  6808.                         //                        if (empty($pax) or $pax == "0") {
  6809.                         //                            $pax = 1;
  6810.                         //                        }
  6811.                         //
  6812.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  6813.                         //                        if ($days > 1){
  6814.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  6815.                         //                        } else {
  6816.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6817.                         //                        }
  6818.                         //
  6819.                         //                        $unitsServ = $item->getUnits();
  6820.                         //                        if (empty($unitsServ) or $unitsServ == "0") {
  6821.                         //                            $unitsServ = 1;
  6822.                         //                        }
  6823.                         //
  6824.                         //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  6825.                         //                        $subnetoUnit = $subneto;
  6826.                         //                        $subneto = $subneto * $days * $unitsServ * $pax;
  6827.                         //
  6828.                         //                        $data_supplier['service'][$i] = array (
  6829.                         //                            'id' => $item->getId(),
  6830.                         //                            'serviceCatId' => $item->getServiceCatId(),
  6831.                         //                            'serviceName' => $item->getName(),
  6832.                         //                            'serviceType' => 'Itinerarios',
  6833.                         //                            'date' => $dateServ,
  6834.                         //                            'qty' => $unitsServ,
  6835.                         //                            'iva' => $item->getIva(),
  6836.                         //                            'pax' => $item->getPax(),
  6837.                         //                            'precioUnit' => $subnetoUnit,
  6838.                         //                            'subneto' => $subneto,
  6839.                         //                            'subtotal' => $subtotal,
  6840.                         //                        );
  6841.                         break;
  6842.                     case 11//Menu
  6843.                         $pax $item->getPax();
  6844.                         if (empty($pax) or $pax == "0") {
  6845.                             $pax 1;
  6846.                         }
  6847.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6848.                         if ($days 1) {
  6849.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6850.                         } else {
  6851.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6852.                         }
  6853.                         $unitsServ $item->getUnits();
  6854.                         if (empty($unitsServ) or $unitsServ == "0") {
  6855.                             $unitsServ 1;
  6856.                         }
  6857.                         $subtotal $subtotalService $days $unitsServ $pax;
  6858.                         $subnetoUnit $subneto;
  6859.                         $subneto $subneto $days $unitsServ $pax;
  6860.                         $data_supplier['service'][$i] = array(
  6861.                             'id' => $item->getId(),
  6862.                             'serviceCatId' => $item->getServiceCatId(),
  6863.                             'serviceName' => $item->getName(),
  6864.                             'serviceType' => 'MenĂº',
  6865.                             'date' => $dateServ,
  6866.                             'qty' => $unitsServ,
  6867.                             'iva' => $item->getIva(),
  6868.                             'pax' => $item->getPax(),
  6869.                             'precioUnit' => $subnetoUnit,
  6870.                             'subneto' => $subneto,
  6871.                             'subtotal' => $subtotal,
  6872.                         );
  6873.                         break;
  6874.                     case 12//Others
  6875.                         $pax $item->getPax();
  6876.                         if (empty($pax) or $pax == "0") {
  6877.                             $pax 1;
  6878.                         }
  6879.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6880.                         if ($days 1) {
  6881.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6882.                         } else {
  6883.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6884.                         }
  6885.                         $unitsServ $item->getUnits();
  6886.                         if (empty($unitsServ) or $unitsServ == "0") {
  6887.                             $unitsServ 1;
  6888.                         }
  6889.                         $subtotal $subtotalService $days $unitsServ $pax;
  6890.                         $subnetoUnit $subneto;
  6891.                         $subneto $subneto $days $unitsServ $pax;
  6892.                         $data_supplier['service'][$i] = array(
  6893.                             'id' => $item->getId(),
  6894.                             'serviceCatId' => $item->getServiceCatId(),
  6895.                             'serviceName' => $item->getName(),
  6896.                             'serviceType' => 'Otros',
  6897.                             'date' => $dateServ,
  6898.                             'qty' => $unitsServ,
  6899.                             'iva' => $item->getIva(),
  6900.                             'pax' => $item->getPax(),
  6901.                             'precioUnit' => $subnetoUnit,
  6902.                             'subneto' => $subneto,
  6903.                             'subtotal' => $subtotal,
  6904.                         );
  6905.                         break;
  6906.                     case 13//Transport
  6907.                         $pax $item->getPax();
  6908.                         if (empty($pax) or $pax == "0") {
  6909.                             $pax 1;
  6910.                         }
  6911.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6912.                         if ($days 1) {
  6913.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6914.                         } else {
  6915.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6916.                         }
  6917.                         $unitsServ $item->getUnits();
  6918.                         if (empty($unitsServ) or $unitsServ == "0") {
  6919.                             $unitsServ 1;
  6920.                         }
  6921.                         $subtotal $subtotalService $days $unitsServ $pax;
  6922.                         $subnetoUnit $subneto;
  6923.                         $subneto $subneto $days $unitsServ $pax;
  6924.                         $data_supplier['service'][$i] = array(
  6925.                             'id' => $item->getId(),
  6926.                             'serviceCatId' => $item->getServiceCatId(),
  6927.                             'serviceName' => $item->getName(),
  6928.                             'serviceType' => 'Transporte',
  6929.                             'date' => $dateServ,
  6930.                             'qty' => $unitsServ,
  6931.                             'iva' => $item->getIva(),
  6932.                             'pax' => $item->getPax(),
  6933.                             'precioUnit' => $subnetoUnit,
  6934.                             'subneto' => $subneto,
  6935.                             'subtotal' => $subtotal,
  6936.                         );
  6937.                         break;
  6938.                     case 14//Technology
  6939.                         $pax $item->getPax();
  6940.                         if (empty($pax) or $pax == "0") {
  6941.                             $pax 1;
  6942.                         }
  6943.                         $days 1;
  6944.                         $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6945.                         $unitsServ $item->getUnits();
  6946.                         if (empty($unitsServ) or $unitsServ == "0") {
  6947.                             $unitsServ 1;
  6948.                         }
  6949.                         $subtotal $subtotalService $days $unitsServ $pax;
  6950.                         $subnetoUnit $subneto;
  6951.                         $subneto $subneto $days $unitsServ $pax;
  6952.                         $data_supplier['service'][$i] = array(
  6953.                             'id' => $item->getId(),
  6954.                             'serviceCatId' => $item->getServiceCatId(),
  6955.                             'serviceName' => $item->getName(),
  6956.                             'serviceType' => 'TecnologĂ­a',
  6957.                             'date' => $dateServ,
  6958.                             'qty' => $unitsServ,
  6959.                             'iva' => $item->getIva(),
  6960.                             'pax' => $item->getPax(),
  6961.                             'precioUnit' => $subnetoUnit,
  6962.                             'subneto' => $subneto,
  6963.                             'subtotal' => $subtotal,
  6964.                         );
  6965.                         break;
  6966.                     case 15//Assisstant
  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.                         $unitsServ $item->getUnits();
  6978.                         if (empty($unitsServ) or $unitsServ == "0") {
  6979.                             $unitsServ 1;
  6980.                         }
  6981.                         $subtotal $subtotalService $days $unitsServ $pax;
  6982.                         $subnetoUnit $subneto;
  6983.                         $subneto $subneto $days $unitsServ $pax;
  6984.                         $data_supplier['service'][$i] = array(
  6985.                             'id' => $item->getId(),
  6986.                             'serviceCatId' => $item->getServiceCatId(),
  6987.                             'serviceName' => $item->getName(),
  6988.                             'serviceType' => 'Asistente',
  6989.                             'date' => $dateServ,
  6990.                             'qty' => $unitsServ,
  6991.                             'iva' => $item->getIva(),
  6992.                             'pax' => $item->getPax(),
  6993.                             'precioUnit' => $subnetoUnit,
  6994.                             'subneto' => $subneto,
  6995.                             'subtotal' => $subtotal,
  6996.                         );
  6997.                         break;
  6998.                     case 16//DDR
  6999.                         $pax $item->getPax();
  7000.                         if (empty($pax) or $pax == "0") {
  7001.                             $pax 1;
  7002.                         }
  7003.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7004.                         if ($days 1) {
  7005.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7006.                         } else {
  7007.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7008.                         }
  7009.                         $unitsServ $item->getUnits();
  7010.                         if (empty($unitsServ) or $unitsServ == "0") {
  7011.                             $unitsServ 1;
  7012.                         }
  7013.                         $subtotal $subtotalService $days $unitsServ $pax;
  7014.                         $subnetoUnit $subneto;
  7015.                         $subneto $subneto $days $unitsServ $pax;
  7016.                         $data_supplier['service'][$i] = array(
  7017.                             'id' => $item->getId(),
  7018.                             'serviceCatId' => $item->getServiceCatId(),
  7019.                             'serviceName' => $item->getName(),
  7020.                             'serviceType' => 'DDR',
  7021.                             'date' => $dateServ,
  7022.                             'qty' => $unitsServ,
  7023.                             'iva' => $item->getIva(),
  7024.                             'pax' => $item->getPax(),
  7025.                             'precioUnit' => $subnetoUnit,
  7026.                             'subneto' => $subneto,
  7027.                             'subtotal' => $subtotal,
  7028.                         );
  7029.                         break;
  7030.                     default:
  7031.                         break;
  7032.                 }
  7033.             } else {
  7034.                 $subtotalService $item->getPrice();
  7035.                 $subneto $item->getPrice();
  7036.                 // Commission
  7037.                 if ($item->getOpCommission() == '1') {
  7038.                     $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  7039.                     $subneto $subneto  * (+ ($item->getCommission() / 100));
  7040.                 } else {
  7041.                     $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  7042.                     $subneto $subneto * (- ($item->getCommission() / 100));
  7043.                 }
  7044.                 // Over
  7045.                 if ($item->getOpOver() == '1') {
  7046.                     $subtotalService $subtotalService $item->getOver();
  7047.                     $subneto $subneto $item->getOver();
  7048.                 } else {
  7049.                     $subtotalService $subtotalService $item->getOver();
  7050.                     $subneto $subneto $item->getOver();
  7051.                 }
  7052.                 // IVA
  7053.                 if ($item->getOpIva() == '1') {
  7054.                     $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  7055.                 } else {
  7056.                     $subtotalService $item->getPrice();
  7057.                     $subneto = ($subneto 100) / (100 $item->getIva());
  7058.                 }
  7059.                 switch ($item->getServiceCatId()) {
  7060.                     case 1// Alojamiento
  7061.                         // el numero de noches $numNoches; precio unitario $subneto
  7062.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  7063.                         // La personas no afectan este calculo
  7064.                         $subtotal $subtotalService $numNoches $item->getUnits();
  7065.                         $subnetoUnit $subneto;
  7066.                         $subneto $subneto $numNoches $item->getUnits();
  7067.                         $data_supplier['service'][$i] = array(
  7068.                             'id' => $item->getId(),
  7069.                             'serviceCatId' => $item->getServiceCatId(),
  7070.                             'serviceName' => $item->getName(),
  7071.                             'serviceType' => 'Hotel',
  7072.                             'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  7073.                             'qty' => $item->getUnits(),
  7074.                             'iva' => $item->getIva(),
  7075.                             'pax' => '-',
  7076.                             'precioUnit' => $subnetoUnit,
  7077.                             'subneto' => $subneto,
  7078.                             'subtotal' => $subtotal,
  7079.                         );
  7080.                         break;
  7081.                     case 2//Actividades
  7082.                         // El nĂºmero de personas es considerado en el calculo
  7083.                         $pax $item->getPax();
  7084.                         if (empty($pax) or $pax == "0") {
  7085.                             $pax 1;
  7086.                         }
  7087.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7088.                         if ($days 1) {
  7089.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7090.                         } else {
  7091.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7092.                         }
  7093.                         $subtotal $subtotalService $days $item->getUnits();
  7094.                         $subnetoUnit $subneto;
  7095.                         $subneto $subneto $days $item->getUnits();
  7096.                         $data_supplier['service'][$i] = array(
  7097.                             'id' => $item->getId(),
  7098.                             'serviceCatId' => $item->getServiceCatId(),
  7099.                             'serviceName' => $item->getName(),
  7100.                             'serviceType' => 'Actividad',
  7101.                             'date' => $dateServ,
  7102.                             'qty' => $item->getUnits(),
  7103.                             'iva' => $item->getIva(),
  7104.                             'pax' => $item->getPax(),
  7105.                             'precioUnit' => $subnetoUnit,
  7106.                             'subneto' => $subneto,
  7107.                             'subtotal' => $subtotal,
  7108.                         );
  7109.                         break;
  7110.                     case 3// AV
  7111.                         $pax $item->getPax();
  7112.                         if (empty($pax) or $pax == "0") {
  7113.                             $pax 1;
  7114.                         }
  7115.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7116.                         if ($days 1) {
  7117.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7118.                         } else {
  7119.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7120.                         }
  7121.                         $unitsServ $item->getUnits();
  7122.                         if (empty($unitsServ) or $unitsServ == "0") {
  7123.                             $unitsServ 1;
  7124.                         }
  7125.                         $subtotal $subtotalService $days $unitsServ $pax;
  7126.                         $subnetoUnit $subneto;
  7127.                         $subneto $subneto $days $unitsServ $pax;
  7128.                         $data_supplier['service'][$i] = array(
  7129.                             'id' => $item->getId(),
  7130.                             'serviceCatId' => $item->getServiceCatId(),
  7131.                             'serviceName' => $item->getName(),
  7132.                             'serviceType' => 'AV',
  7133.                             'date' => $dateServ,
  7134.                             'qty' => $unitsServ,
  7135.                             'iva' => $item->getIva(),
  7136.                             'pax' => $item->getPax(),
  7137.                             'precioUnit' => $subnetoUnit,
  7138.                             'subneto' => $subneto,
  7139.                             'subtotal' => $subtotal,
  7140.                         );
  7141.                         break;
  7142.                     case 4//Creative
  7143.                         $pax $item->getPax();
  7144.                         if (empty($pax) or $pax == "0") {
  7145.                             $pax 1;
  7146.                         }
  7147.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7148.                         if ($days 1) {
  7149.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7150.                         } else {
  7151.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7152.                         }
  7153.                         $unitsServ $item->getUnits();
  7154.                         if (empty($unitsServ) or $unitsServ == "0") {
  7155.                             $unitsServ 1;
  7156.                         }
  7157.                         $subtotal $subtotalService $days $unitsServ $pax;
  7158.                         $subnetoUnit $subneto;
  7159.                         $subneto $subneto $days $unitsServ $pax;
  7160.                         $data_supplier['service'][$i] = array(
  7161.                             'id' => $item->getId(),
  7162.                             'serviceCatId' => $item->getServiceCatId(),
  7163.                             'serviceName' => $item->getName(),
  7164.                             'serviceType' => 'Creativo',
  7165.                             'date' => $dateServ,
  7166.                             'qty' => $unitsServ,
  7167.                             'iva' => $item->getIva(),
  7168.                             'pax' => $item->getPax(),
  7169.                             'precioUnit' => $subnetoUnit,
  7170.                             'subneto' => $subneto,
  7171.                             'subtotal' => $subtotal,
  7172.                         );
  7173.                         break;
  7174.                     case 5//Cruise
  7175.                         $pax $item->getPax();
  7176.                         if (empty($pax) or $pax == "0") {
  7177.                             $pax 1;
  7178.                         }
  7179.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  7180.                         if ($days 1) {
  7181.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7182.                         } else {
  7183.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7184.                         }
  7185.                         $unitsServ $item->getUnits();
  7186.                         if (empty($unitsServ) or $unitsServ == "0") {
  7187.                             $unitsServ 1;
  7188.                         }
  7189.                         $subtotal $subtotalService $days $unitsServ $pax;
  7190.                         $subnetoUnit $subneto;
  7191.                         $subneto $subneto $days $unitsServ $pax;
  7192.                         $data_supplier['service'][$i] = array(
  7193.                             'id' => $item->getId(),
  7194.                             'serviceCatId' => $item->getServiceCatId(),
  7195.                             'serviceName' => $item->getName(),
  7196.                             'serviceType' => 'Crucero',
  7197.                             'date' => $dateServ,
  7198.                             'qty' => $unitsServ,
  7199.                             'iva' => $item->getIva(),
  7200.                             'pax' => $item->getPax(),
  7201.                             'precioUnit' => $subnetoUnit,
  7202.                             'subneto' => $subneto,
  7203.                             'subtotal' => $subtotal,
  7204.                         );
  7205.                         break;
  7206.                     case 6//Entertaiment
  7207.                         $pax $item->getPax();
  7208.                         if (empty($pax) or $pax == "0") {
  7209.                             $pax 1;
  7210.                         }
  7211.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7212.                         if ($days 1) {
  7213.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7214.                         } else {
  7215.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7216.                         }
  7217.                         $unitsServ $item->getUnits();
  7218.                         if (empty($unitsServ) or $unitsServ == "0") {
  7219.                             $unitsServ 1;
  7220.                         }
  7221.                         $subtotal $subtotalService $days $unitsServ $pax;
  7222.                         $subnetoUnit $subneto;
  7223.                         $subneto $subneto $days $unitsServ $pax;
  7224.                         $data_supplier['service'][$i] = array(
  7225.                             'id' => $item->getId(),
  7226.                             'serviceCatId' => $item->getServiceCatId(),
  7227.                             'serviceName' => $item->getName(),
  7228.                             'serviceType' => 'Entretenimiento',
  7229.                             'date' => $dateServ,
  7230.                             'qty' => $unitsServ,
  7231.                             'iva' => $item->getIva(),
  7232.                             'pax' => $item->getPax(),
  7233.                             'precioUnit' => $subnetoUnit,
  7234.                             'subneto' => $subneto,
  7235.                             'subtotal' => $subtotal,
  7236.                         );
  7237.                         break;
  7238.                     case 7// Gifts
  7239.                         $pax $item->getPax();
  7240.                         if (empty($pax) or $pax == "0") {
  7241.                             $pax 1;
  7242.                         }
  7243.                         $days 1;
  7244.                         if ($days 1) {
  7245.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7246.                         } else {
  7247.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7248.                         }
  7249.                         $unitsServ $item->getUnits();
  7250.                         if (empty($unitsServ) or $unitsServ == "0") {
  7251.                             $unitsServ 1;
  7252.                         }
  7253.                         $subtotal $subtotalService $days $unitsServ $pax;
  7254.                         $subnetoUnit $subneto;
  7255.                         $subneto $subneto $days $unitsServ $pax;
  7256.                         $data_supplier['service'][$i] = array(
  7257.                             'id' => $item->getId(),
  7258.                             'serviceCatId' => $item->getServiceCatId(),
  7259.                             'serviceName' => $item->getName(),
  7260.                             'serviceType' => 'Regalos',
  7261.                             'date' => $dateServ,
  7262.                             'qty' => $unitsServ,
  7263.                             'iva' => $item->getIva(),
  7264.                             'pax' => $item->getPax(),
  7265.                             'precioUnit' => $subnetoUnit,
  7266.                             'subneto' => $subneto,
  7267.                             'subtotal' => $subtotal,
  7268.                         );
  7269.                         break;
  7270.                     case 8//Guide
  7271.                         $pax $item->getPax();
  7272.                         if (empty($pax) or $pax == "0") {
  7273.                             $pax 1;
  7274.                         }
  7275.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7276.                         if ($days 1) {
  7277.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7278.                         } else {
  7279.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7280.                         }
  7281.                         $unitsServ $item->getUnits();
  7282.                         if (empty($unitsServ) or $unitsServ == "0") {
  7283.                             $unitsServ 1;
  7284.                         }
  7285.                         $subtotal $subtotalService $days $unitsServ $pax;
  7286.                         $subnetoUnit $subneto;
  7287.                         $subneto $subneto $days $unitsServ $pax;
  7288.                         $data_supplier['service'][$i] = array(
  7289.                             'id' => $item->getId(),
  7290.                             'serviceCatId' => $item->getServiceCatId(),
  7291.                             'serviceName' => $item->getName(),
  7292.                             'serviceType' => 'Regalos',
  7293.                             'date' => $dateServ,
  7294.                             'qty' => $unitsServ,
  7295.                             'iva' => $item->getIva(),
  7296.                             'pax' => $item->getPax(),
  7297.                             'precioUnit' => $subnetoUnit,
  7298.                             'subneto' => $subneto,
  7299.                             'subtotal' => $subtotal,
  7300.                         );
  7301.                         break;
  7302.                     case 9//Itineraries
  7303.                         $pax $item->getPax();
  7304.                         if (empty($pax) or $pax == "0") {
  7305.                             $pax 1;
  7306.                         }
  7307.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7308.                         if ($days 1) {
  7309.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7310.                         } else {
  7311.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7312.                         }
  7313.                         $unitsServ $item->getUnits();
  7314.                         if (empty($unitsServ) or $unitsServ == "0") {
  7315.                             $unitsServ 1;
  7316.                         }
  7317.                         $subtotal $subtotalService $days $unitsServ $pax;
  7318.                         $subnetoUnit $subneto;
  7319.                         $subneto $subneto $days $unitsServ $pax;
  7320.                         $data_supplier['service'][$i] = array(
  7321.                             'id' => $item->getId(),
  7322.                             'serviceCatId' => $item->getServiceCatId(),
  7323.                             'serviceName' => $item->getName(),
  7324.                             'serviceType' => 'Itinerarios',
  7325.                             'date' => $dateServ,
  7326.                             'qty' => $unitsServ,
  7327.                             'iva' => $item->getIva(),
  7328.                             'pax' => $item->getPax(),
  7329.                             'precioUnit' => $subnetoUnit,
  7330.                             'subneto' => $subneto,
  7331.                             'subtotal' => $subtotal,
  7332.                         );
  7333.                         break;
  7334.                     case 10//Lounge  -- No Aplica
  7335.                         //                        $pax = $item->getPax();
  7336.                         //                        if (empty($pax) or $pax == "0") {
  7337.                         //                            $pax = 1;
  7338.                         //                        }
  7339.                         //
  7340.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  7341.                         //                        if ($days > 1){
  7342.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  7343.                         //                        } else {
  7344.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7345.                         //                        }
  7346.                         //
  7347.                         //                        $unitsServ = $item->getUnits();
  7348.                         //                        if (empty($unitsServ) or $unitsServ == "0") {
  7349.                         //                            $unitsServ = 1;
  7350.                         //                        }
  7351.                         //
  7352.                         //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  7353.                         //                        $subnetoUnit = $subneto;
  7354.                         //                        $subneto = $subneto * $days * $unitsServ * $pax;
  7355.                         //
  7356.                         //                        $data_supplier['service'][$i] = array (
  7357.                         //                            'id' => $item->getId(),
  7358.                         //                            'serviceCatId' => $item->getServiceCatId(),
  7359.                         //                            'serviceName' => $item->getName(),
  7360.                         //                            'serviceType' => 'Itinerarios',
  7361.                         //                            'date' => $dateServ,
  7362.                         //                            'qty' => $unitsServ,
  7363.                         //                            'iva' => $item->getIva(),
  7364.                         //                            'pax' => $item->getPax(),
  7365.                         //                            'precioUnit' => $subnetoUnit,
  7366.                         //                            'subneto' => $subneto,
  7367.                         //                            'subtotal' => $subtotal,
  7368.                         //                        );
  7369.                         break;
  7370.                     case 11//Menu
  7371.                         $pax $item->getPax();
  7372.                         if (empty($pax) or $pax == "0") {
  7373.                             $pax 1;
  7374.                         }
  7375.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7376.                         if ($days 1) {
  7377.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7378.                         } else {
  7379.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7380.                         }
  7381.                         $unitsServ $item->getUnits();
  7382.                         if (empty($unitsServ) or $unitsServ == "0") {
  7383.                             $unitsServ 1;
  7384.                         }
  7385.                         $subtotal $subtotalService $days $unitsServ $pax;
  7386.                         $subnetoUnit $subneto;
  7387.                         $subneto $subneto $days $unitsServ $pax;
  7388.                         $data_supplier['service'][$i] = array(
  7389.                             'id' => $item->getId(),
  7390.                             'serviceCatId' => $item->getServiceCatId(),
  7391.                             'serviceName' => $item->getName(),
  7392.                             'serviceType' => 'MenĂº',
  7393.                             'date' => $dateServ,
  7394.                             'qty' => $unitsServ,
  7395.                             'iva' => $item->getIva(),
  7396.                             'pax' => $item->getPax(),
  7397.                             'precioUnit' => $subnetoUnit,
  7398.                             'subneto' => $subneto,
  7399.                             'subtotal' => $subtotal,
  7400.                         );
  7401.                         break;
  7402.                     case 12//Others
  7403.                         $pax $item->getPax();
  7404.                         if (empty($pax) or $pax == "0") {
  7405.                             $pax 1;
  7406.                         }
  7407.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7408.                         if ($days 1) {
  7409.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7410.                         } else {
  7411.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7412.                         }
  7413.                         $unitsServ $item->getUnits();
  7414.                         if (empty($unitsServ) or $unitsServ == "0") {
  7415.                             $unitsServ 1;
  7416.                         }
  7417.                         $subtotal $subtotalService $days $unitsServ $pax;
  7418.                         $subnetoUnit $subneto;
  7419.                         $subneto $subneto $days $unitsServ $pax;
  7420.                         $data_supplier['service'][$i] = array(
  7421.                             'id' => $item->getId(),
  7422.                             'serviceCatId' => $item->getServiceCatId(),
  7423.                             'serviceName' => $item->getName(),
  7424.                             'serviceType' => 'Otros',
  7425.                             'date' => $dateServ,
  7426.                             'qty' => $unitsServ,
  7427.                             'iva' => $item->getIva(),
  7428.                             'pax' => $item->getPax(),
  7429.                             'precioUnit' => $subnetoUnit,
  7430.                             'subneto' => $subneto,
  7431.                             'subtotal' => $subtotal,
  7432.                         );
  7433.                         break;
  7434.                     case 13//Transport
  7435.                         $pax $item->getPax();
  7436.                         if (empty($pax) or $pax == "0") {
  7437.                             $pax 1;
  7438.                         }
  7439.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7440.                         if ($days 1) {
  7441.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7442.                         } else {
  7443.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7444.                         }
  7445.                         $unitsServ $item->getUnits();
  7446.                         if (empty($unitsServ) or $unitsServ == "0") {
  7447.                             $unitsServ 1;
  7448.                         }
  7449.                         $subtotal $subtotalService $days $unitsServ $pax;
  7450.                         $subnetoUnit $subneto;
  7451.                         $subneto $subneto $days $unitsServ $pax;
  7452.                         $data_supplier['service'][$i] = array(
  7453.                             'id' => $item->getId(),
  7454.                             'serviceCatId' => $item->getServiceCatId(),
  7455.                             'serviceName' => $item->getName(),
  7456.                             'serviceType' => 'Transporte',
  7457.                             'date' => $dateServ,
  7458.                             'qty' => $unitsServ,
  7459.                             'iva' => $item->getIva(),
  7460.                             'pax' => $item->getPax(),
  7461.                             'precioUnit' => $subnetoUnit,
  7462.                             'subneto' => $subneto,
  7463.                             'subtotal' => $subtotal,
  7464.                         );
  7465.                         break;
  7466.                     case 14//Technology
  7467.                         $pax $item->getPax();
  7468.                         if (empty($pax) or $pax == "0") {
  7469.                             $pax 1;
  7470.                         }
  7471.                         $days 1;
  7472.                         $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7473.                         $unitsServ $item->getUnits();
  7474.                         if (empty($unitsServ) or $unitsServ == "0") {
  7475.                             $unitsServ 1;
  7476.                         }
  7477.                         $subtotal $subtotalService $days $unitsServ $pax;
  7478.                         $subnetoUnit $subneto;
  7479.                         $subneto $subneto $days $unitsServ $pax;
  7480.                         $data_supplier['service'][$i] = array(
  7481.                             'id' => $item->getId(),
  7482.                             'serviceCatId' => $item->getServiceCatId(),
  7483.                             'serviceName' => $item->getName(),
  7484.                             'serviceType' => 'TecnologĂ­a',
  7485.                             'date' => $dateServ,
  7486.                             'qty' => $unitsServ,
  7487.                             'iva' => $item->getIva(),
  7488.                             'pax' => $item->getPax(),
  7489.                             'precioUnit' => $subnetoUnit,
  7490.                             'subneto' => $subneto,
  7491.                             'subtotal' => $subtotal,
  7492.                         );
  7493.                         break;
  7494.                     case 15//Assisstant
  7495.                         $pax $item->getPax();
  7496.                         if (empty($pax) or $pax == "0") {
  7497.                             $pax 1;
  7498.                         }
  7499.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7500.                         if ($days 1) {
  7501.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7502.                         } else {
  7503.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7504.                         }
  7505.                         $unitsServ $item->getUnits();
  7506.                         if (empty($unitsServ) or $unitsServ == "0") {
  7507.                             $unitsServ 1;
  7508.                         }
  7509.                         $subtotal $subtotalService $days $unitsServ $pax;
  7510.                         $subnetoUnit $subneto;
  7511.                         $subneto $subneto $days $unitsServ $pax;
  7512.                         $data_supplier['service'][$i] = array(
  7513.                             'id' => $item->getId(),
  7514.                             'serviceCatId' => $item->getServiceCatId(),
  7515.                             'serviceName' => $item->getName(),
  7516.                             'serviceType' => 'Asistente',
  7517.                             'date' => $dateServ,
  7518.                             'qty' => $unitsServ,
  7519.                             'iva' => $item->getIva(),
  7520.                             'pax' => $item->getPax(),
  7521.                             'precioUnit' => $subnetoUnit,
  7522.                             'subneto' => $subneto,
  7523.                             'subtotal' => $subtotal,
  7524.                         );
  7525.                         break;
  7526.                     case 16//DDR
  7527.                         $pax $item->getPax();
  7528.                         if (empty($pax) or $pax == "0") {
  7529.                             $pax 1;
  7530.                         }
  7531.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7532.                         if ($days 1) {
  7533.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7534.                         } else {
  7535.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7536.                         }
  7537.                         $unitsServ $item->getUnits();
  7538.                         if (empty($unitsServ) or $unitsServ == "0") {
  7539.                             $unitsServ 1;
  7540.                         }
  7541.                         $subtotal $subtotalService $days $unitsServ $pax;
  7542.                         $subnetoUnit $subneto;
  7543.                         $subneto $subneto $days $unitsServ $pax;
  7544.                         $data_supplier['service'][$i] = array(
  7545.                             'id' => $item->getId(),
  7546.                             'serviceCatId' => $item->getServiceCatId(),
  7547.                             'serviceName' => $item->getName(),
  7548.                             'serviceType' => 'DDR',
  7549.                             'date' => $dateServ,
  7550.                             'qty' => $unitsServ,
  7551.                             'iva' => $item->getIva(),
  7552.                             'pax' => $item->getPax(),
  7553.                             'precioUnit' => $subnetoUnit,
  7554.                             'subneto' => $subneto,
  7555.                             'subtotal' => $subtotal,
  7556.                         );
  7557.                         break;
  7558.                     default:
  7559.                         break;
  7560.                 }
  7561.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  7562.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  7563.                 $neto round($subneto2PHP_ROUND_HALF_UP);
  7564.             }
  7565.             switch ($item->getIva()) {
  7566.                     // Acumula IVA
  7567.                 case 21:
  7568.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  7569.                     break;
  7570.                 case 10:
  7571.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  7572.                     break;
  7573.                 case 0:
  7574.                     break;
  7575.                 default:
  7576.                     break;
  7577.             }
  7578.             $totales_neto_all $totales_neto_all $neto;
  7579.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7580.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  7581.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  7582.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  7583.             // Acumula netos totales e IVA
  7584.             $service['neto'] = $service['neto'] + $neto;
  7585.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  7586.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7587.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  7588.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  7589.             $i++;
  7590.         }
  7591.         $data_supplier['serviceSubTotal'] = array(
  7592.             'neto' => $service['neto'],
  7593.             'sumSubT' => $service['sumSubT'],
  7594.         );
  7595.         $currency '€';
  7596.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  7597.         if (!empty($payments)) {
  7598.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  7599.         } else {
  7600.             $amount_pay 0;
  7601.         }
  7602.         $totales_all $totales_total $amount_pay;
  7603.         $data = array(
  7604.             'id' => $id,
  7605.             'type' => $type,
  7606.             'number' => $number,
  7607.             'prefix' => $prefix,
  7608.             'date' => $date,
  7609.             'file' => $file,
  7610.             'token' => ''// $file->getAccessKey(),
  7611.             'company' => $company,
  7612.             'clients' => $clientNew,
  7613.             'datasupplier' => $data_supplier,
  7614.             'currency' => $currency,
  7615.             'totales_neto' => $totales_neto_all,
  7616.             'bases_imponibles' => $data_iva,
  7617.             'totales' => $totales_total,
  7618.             'balance' => $totales_all,
  7619.             'paymentInvoice' => $amount_pay,
  7620.         );
  7621.         return $data;
  7622.     }
  7623.     private function baseInvoiceSelectedFile($id$arrayBools$number)
  7624.     {
  7625.         $em $this->getDoctrine()->getManager();
  7626.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  7627.         $items $em->getRepository(AveDocProformaItems::class)->findByFileId($file->getId());
  7628.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  7629.         $client $em->getRepository(Client::class)->findById($file->getClient());
  7630.         if (empty($client)) {
  7631.             $client[0] = new Client();
  7632.             $client[0]->setName('');
  7633.             $client[0]->setTitle('');
  7634.             $client[0]->setIdDocument('');
  7635.             $client[0]->setPopulation('');
  7636.             $client[0]->setRegion('');
  7637.             $client[0]->setCountry('');
  7638.         } else {
  7639.             if (is_numeric($client[0]->getPopulation())) {
  7640.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  7641. //                $client[0]->setPopulation($city->getCity());
  7642.             }
  7643.             if (is_numeric($client[0]->getRegion())) {
  7644.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  7645. //                $client[0]->setRegion($region->getRegion());
  7646.             }
  7647.             if (is_numeric($client[0]->getCountry())) {
  7648.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  7649. //                $client[0]->setCountry($country->getCountry());
  7650.             }
  7651.         }
  7652.         if (empty($client)) {
  7653.             $client[0] = new Client();
  7654.             $client[0]->setName('');
  7655.             $client[0]->setTitle('');
  7656.             $client[0]->setIdDocument('');
  7657.             $client[0]->setPopulation('');
  7658.             $client[0]->setRegion('');
  7659.             $client[0]->setCountry('');
  7660.             $clientNew = array(
  7661.                 'name' => '',
  7662.                 'title' => '',
  7663.                 'idDocument' => '',
  7664.                 'population' => '',
  7665.                 'region' => '',
  7666.                 'country' => '',
  7667.                 'address' => '',
  7668.                 'addressNumber' => '',
  7669.                 'zipCode' => '',
  7670.                 'typeDocument' => '',
  7671.             );
  7672.         } else {
  7673.             $clientNew = array(
  7674.                 'name' => $client[0]->getName(),
  7675.                 'title' => $client[0]->getTitle(),
  7676.                 'idDocument' => $client[0]->getIdDocument(),
  7677.                 'population' => '',
  7678.                 'region' => '',
  7679.                 'country' => '',
  7680.                 'address' => $client[0]->getAddress(),
  7681.                 'addressNumber' => $client[0]->getAddressNumber(),
  7682.                 'zipCode' => $client[0]->getZipCode(),
  7683.                 'typeDocument' => $client[0]->getTypeDocument(),
  7684.             );
  7685.             if (is_numeric($client[0]->getPopulation())) {
  7686.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  7687.                 $clientNew['population'] = $city->getCity();
  7688.             }
  7689.             if (is_numeric($client[0]->getRegion())) {
  7690.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  7691.                 $clientNew['region'] = $region->getRegion();
  7692.             }
  7693.             if (is_numeric($client[0]->getCountry())) {
  7694.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  7695.                 $clientNew['country'] = $country->getCountry();
  7696.             }
  7697.         }
  7698.         // Acumuladores de los calculos
  7699.         $totales_neto_all 0;
  7700.         $data_iva = array(
  7701.             'iva' => 21,
  7702.             'ivaMontoVeintiUno' => 0,
  7703.             'ivaMontoDiez' => 0,
  7704.             'ivaMontoCero' => null,                                     // Si toma el valor de cero, indica que hay un iva en 0 y se pone en la factura de resto no
  7705.         );
  7706.         //INICIO: Determinamos el numero de factura o proforma
  7707.         if (substr($number01) == 'I') {
  7708.             // Es una Factura
  7709.             $numberInvoiceOrProforma substr($number1);
  7710.             $number $numberInvoiceOrProforma;
  7711.             $number $em->getRepository(AveDocInvoice::class)->findOneById($number);
  7712.             $number $number->getNumber();
  7713.             $type 'Invoice';
  7714.         } else {
  7715.             // Es una Proforma
  7716.             $numberInvoiceOrProforma substr($number1);
  7717.             $number $numberInvoiceOrProforma;
  7718.             $number $em->getRepository(AveDocProforma::class)->findOneById($number);
  7719.             $number $number->getPrefix() . $number->getFileId();
  7720.             $type 'Proforma';
  7721.         }
  7722.         //FIN: Determinamos el numero de factura o proforma
  7723.         // Buscamos las salas reservadas, pagos y servicios para el evento
  7724.         $arrayItems = array();
  7725.         $fileProducts = array();
  7726.         if (!empty($arrayBools['product'])) {
  7727.             foreach ($arrayBools['product'] as $key => $item) {
  7728.                 if ($item == 'true') {
  7729.                     $fileProducts[] = $em->getRepository(AveProductFile::class)->findOneById($key);
  7730.                     ///***---
  7731.                 }
  7732.             }
  7733.         }
  7734.         $payments = array();
  7735.         if (!empty($arrayBools['payment'])) {
  7736.             foreach ($arrayBools['payment'] as $key => $item) {
  7737.                 if ($item == 'true') {
  7738.                     $payments[] = $em->getRepository(AvePaymentsClient::class)->findOneById($key);
  7739.                 }
  7740.             }
  7741.         }
  7742.         $services = array();
  7743.         if (!empty($arrayBools['service'])) {
  7744.             foreach ($arrayBools['service'] as $key => $item) {
  7745.                 if ($item == 'true') {
  7746.                     $services[] = $em->getRepository(AveServices::class)->findOneById($key);
  7747.                 }
  7748.             }
  7749.         }
  7750.         $data_supplier = array();
  7751.         $i 0;
  7752.         $iva '21';            // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
  7753.         $pax '1';
  7754.         $qty '1';
  7755.         $product = array(
  7756.             'neto' => 0,
  7757.             'sumSubT' => 0,
  7758.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  7759.         $service = array(
  7760.             'neto' => 0,
  7761.             'sumSubT' => 0,
  7762.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  7763.         foreach ($fileProducts as $item) {
  7764.             if (is_null($item->getServicePrice()) or empty($item->getServicePrice())) {
  7765.                 $subtotal 0;
  7766.                 $neto 0;
  7767.                 $subtotalProduct 0;
  7768.             } else {
  7769.                 //                $subtotalProduct = $item->getServicePrice() * 1.21;
  7770.                 $subtotalProduct $item->getSubTotalPrice() * (+ ($item->getIva() / 100));
  7771.                 //                $subneto = $item->getServicePrice();
  7772.                 $subneto $item->getSubTotalPrice();
  7773.                 $subtotal =  $subtotalProduct;
  7774.                 $neto =  $subneto;
  7775.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  7776.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  7777.                 $neto round($neto2PHP_ROUND_HALF_UP);
  7778.                 $arrayItems[] = array(
  7779.                     'type' => 'Product',
  7780.                     'name' => $item->getProductName(),
  7781.                     'amount' => $neto,
  7782.                     'iva' => $item->getIva(),
  7783.                     'total' => $subtotal,
  7784.                 );
  7785.             }
  7786.             // Acumula netos totales e IVA
  7787.             $totales_neto_all $totales_neto_all $neto;
  7788.             switch ($item->getIva()) {
  7789.                 case 21:
  7790.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  7791.                     $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  7792.                     break;
  7793.                 case 10:
  7794.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1);
  7795.                     $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  7796.                     break;
  7797.                 case 0:
  7798.                     $data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto 0);
  7799.                     $data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2PHP_ROUND_HALF_UP);
  7800.                     break;
  7801.                 default:
  7802.                     $data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
  7803.                     $data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2PHP_ROUND_HALF_UP);
  7804.                     break;
  7805.             }
  7806.             //            $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * 0.21);
  7807.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7808.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  7809.             // Acumula netos totales e IVA
  7810.             $product['neto'] = $product['neto'] + $neto;
  7811.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  7812.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7813.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  7814.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  7815.             // Calculo del precio unitario despues de aplicar Over y Comision
  7816.             $multiplo $qty $item->getDays();
  7817.             $item->setServicePrice($item->getSubTotalPrice() / $multiplo);
  7818.             $data_supplier['product'][$i] = array(
  7819.                 'id' => $item->getId(),
  7820.                 'productName' => $item->getProductName(),
  7821.                 'productId' => $item->getProductId(),
  7822.                 'dateStart' => $item->getDateStart(),
  7823.                 'dateEnd' => $item->getDateEnd(),
  7824.                 'servicePrice' => $item->getServicePrice(),
  7825.                 'subtotalProduct' => $subtotalProduct,
  7826.                 'iva' => $item->getIva(),
  7827.                 'pax' => $pax,
  7828.                 'qty' => $qty,
  7829.                 'type' => $item->getType(),
  7830.                 'subtotal' => $subtotal,
  7831.             );
  7832.             $i++;
  7833.         }
  7834.         $data_supplier['productSubTotal'] = array(
  7835.             'neto' => $product['neto'],
  7836.             'sumSubT' => $product['sumSubT'],
  7837.         );
  7838.         $payment = array(
  7839.             'sumSubT' => 0,
  7840.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  7841.         $i 0;
  7842.         foreach ($payments as $item) {
  7843.             $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  7844.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7845.             $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  7846.             $data_supplier['payment'][$i] = array(
  7847.                 'id' => $item->getId(),
  7848.                 'amount' => $item->getAmount(),
  7849.                 'amountTotal' => $item->getAmountTotal(),
  7850.                 'vat' => $item->getVat(),
  7851.                 'datePayAt' => $item->getDatePayAt(),
  7852.                 'wayToPay' => $item->getWayToPay(),
  7853.             );
  7854.             $arrayItems[] = array(
  7855.                 'type' => 'Payment',
  7856.                 'name' => $item->getWayToPay(),
  7857.                 'amount' => $item->getAmount(),
  7858.                 'total' => $item->getAmountTotal(),
  7859.                 'iva' => $item->getVat(),
  7860.             );
  7861.             $i++;
  7862.         }
  7863.         if (!empty($payments)) {
  7864.             $data_supplier['paymentSubTotal'] = array(
  7865.                 'sumSubT' => $payment['sumSubT'],
  7866.             );
  7867.         }
  7868.         foreach ($services as $item) {
  7869.             if (is_null($item->getPrice()) or empty($item->getPrice())) {
  7870.                 $subtotal 0;
  7871.                 $neto 0;
  7872.                 $subtotalService 0;
  7873.             } else {
  7874.                 $subtotalService $item->getPrice();
  7875.                 $subneto $item->getPrice();
  7876.                 // Commission
  7877.                 if ($item->getOpCommission() == '1') {
  7878.                     $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  7879.                     $subneto $subneto  * (+ ($item->getCommission() / 100));
  7880.                 } else {
  7881.                     $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  7882.                     $subneto $subneto * (- ($item->getCommission() / 100));
  7883.                 }
  7884.                 // Over
  7885.                 if ($item->getOpOver() == '1') {
  7886.                     $subtotalService $subtotalService $item->getOver();
  7887.                     $subneto $subneto $item->getOver();
  7888.                 } else {
  7889.                     $subtotalService $subtotalService $item->getOver();
  7890.                     $subneto $subneto $item->getOver();
  7891.                 }
  7892.                 // IVA
  7893.                 if ($item->getOpIva() == '1') {
  7894.                     $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  7895.                 } else {
  7896.                     $subtotalService $item->getPrice();
  7897.                     $subneto = ($subneto 100) / (100 $item->getIva());
  7898.                 }
  7899.                 switch ($item->getServiceCatId()) {
  7900.                     case 1// Alojamiento
  7901.                         // el numero de noches $numNoches; precio unitario $subneto
  7902.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  7903.                         // La personas no afectan este calculo
  7904.                         $subtotal $subtotalService $numNoches $item->getUnits();
  7905.                         $subnetoUnit $subneto;
  7906.                         $subneto $subneto $numNoches $item->getUnits();
  7907.                         $data_supplier['service'][$i] = array(
  7908.                             'id' => $item->getId(),
  7909.                             'serviceCatId' => $item->getServiceCatId(),
  7910.                             'serviceName' => $item->getName(),
  7911.                             'serviceType' => 'Hotel',
  7912.                             'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  7913.                             'qty' => $item->getUnits(),
  7914.                             'iva' => $item->getIva(),
  7915.                             'pax' => '-',
  7916.                             'precioUnit' => $subnetoUnit,
  7917.                             'subneto' => $subneto,
  7918.                             'subtotal' => $subtotal,
  7919.                         );
  7920.                         break;
  7921.                     case 2//Actividades
  7922.                         // El nĂºmero de personas es considerado en el calculo
  7923.                         $pax $item->getPax();
  7924.                         if (empty($pax) or $pax == "0") {
  7925.                             $pax 1;
  7926.                         }
  7927.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7928.                         if ($days 1) {
  7929.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7930.                         } else {
  7931.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7932.                         }
  7933.                         $subtotal $subtotalService $days $item->getUnits();
  7934.                         $subnetoUnit $subneto;
  7935.                         $subneto $subneto $days $item->getUnits();
  7936.                         $data_supplier['service'][$i] = array(
  7937.                             'id' => $item->getId(),
  7938.                             'serviceCatId' => $item->getServiceCatId(),
  7939.                             'serviceName' => $item->getName(),
  7940.                             'serviceType' => 'Actividad',
  7941.                             'date' => $dateServ,
  7942.                             'qty' => $item->getUnits(),
  7943.                             'iva' => $item->getIva(),
  7944.                             'pax' => $item->getPax(),
  7945.                             'precioUnit' => $subnetoUnit,
  7946.                             'subneto' => $subneto,
  7947.                             'subtotal' => $subtotal,
  7948.                         );
  7949.                         break;
  7950.                     case 3// AV
  7951.                         $pax $item->getPax();
  7952.                         if (empty($pax) or $pax == "0") {
  7953.                             $pax 1;
  7954.                         }
  7955.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7956.                         if ($days 1) {
  7957.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7958.                         } else {
  7959.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7960.                         }
  7961.                         $unitsServ $item->getUnits();
  7962.                         if (empty($unitsServ) or $unitsServ == "0") {
  7963.                             $unitsServ 1;
  7964.                         }
  7965.                         $subtotal $subtotalService $days $unitsServ $pax;
  7966.                         $subnetoUnit $subneto;
  7967.                         $subneto $subneto $days $unitsServ $pax;
  7968.                         $data_supplier['service'][$i] = array(
  7969.                             'id' => $item->getId(),
  7970.                             'serviceCatId' => $item->getServiceCatId(),
  7971.                             'serviceName' => $item->getName(),
  7972.                             'serviceType' => 'AV',
  7973.                             'date' => $dateServ,
  7974.                             'qty' => $unitsServ,
  7975.                             'iva' => $item->getIva(),
  7976.                             'pax' => $item->getPax(),
  7977.                             'precioUnit' => $subnetoUnit,
  7978.                             'subneto' => $subneto,
  7979.                             'subtotal' => $subtotal,
  7980.                         );
  7981.                         break;
  7982.                     case 4//Creative
  7983.                         $pax $item->getPax();
  7984.                         if (empty($pax) or $pax == "0") {
  7985.                             $pax 1;
  7986.                         }
  7987.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7988.                         if ($days 1) {
  7989.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7990.                         } else {
  7991.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7992.                         }
  7993.                         $unitsServ $item->getUnits();
  7994.                         if (empty($unitsServ) or $unitsServ == "0") {
  7995.                             $unitsServ 1;
  7996.                         }
  7997.                         $subtotal $subtotalService $days $unitsServ $pax;
  7998.                         $subnetoUnit $subneto;
  7999.                         $subneto $subneto $days $unitsServ $pax;
  8000.                         $data_supplier['service'][$i] = array(
  8001.                             'id' => $item->getId(),
  8002.                             'serviceCatId' => $item->getServiceCatId(),
  8003.                             'serviceName' => $item->getName(),
  8004.                             'serviceType' => 'Creativo',
  8005.                             'date' => $dateServ,
  8006.                             'qty' => $unitsServ,
  8007.                             'iva' => $item->getIva(),
  8008.                             'pax' => $item->getPax(),
  8009.                             'precioUnit' => $subnetoUnit,
  8010.                             'subneto' => $subneto,
  8011.                             'subtotal' => $subtotal,
  8012.                         );
  8013.                         break;
  8014.                     case 5//Cruise
  8015.                         $pax $item->getPax();
  8016.                         if (empty($pax) or $pax == "0") {
  8017.                             $pax 1;
  8018.                         }
  8019.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  8020.                         if ($days 1) {
  8021.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8022.                         } else {
  8023.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8024.                         }
  8025.                         $unitsServ $item->getUnits();
  8026.                         if (empty($unitsServ) or $unitsServ == "0") {
  8027.                             $unitsServ 1;
  8028.                         }
  8029.                         $subtotal $subtotalService $days $unitsServ $pax;
  8030.                         $subnetoUnit $subneto;
  8031.                         $subneto $subneto $days $unitsServ $pax;
  8032.                         $data_supplier['service'][$i] = array(
  8033.                             'id' => $item->getId(),
  8034.                             'serviceCatId' => $item->getServiceCatId(),
  8035.                             'serviceName' => $item->getName(),
  8036.                             'serviceType' => 'Crucero',
  8037.                             'date' => $dateServ,
  8038.                             'qty' => $unitsServ,
  8039.                             'iva' => $item->getIva(),
  8040.                             'pax' => $item->getPax(),
  8041.                             'precioUnit' => $subnetoUnit,
  8042.                             'subneto' => $subneto,
  8043.                             'subtotal' => $subtotal,
  8044.                         );
  8045.                         break;
  8046.                     case 6//Entertaiment
  8047.                         $pax $item->getPax();
  8048.                         if (empty($pax) or $pax == "0") {
  8049.                             $pax 1;
  8050.                         }
  8051.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8052.                         if ($days 1) {
  8053.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8054.                         } else {
  8055.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8056.                         }
  8057.                         $unitsServ $item->getUnits();
  8058.                         if (empty($unitsServ) or $unitsServ == "0") {
  8059.                             $unitsServ 1;
  8060.                         }
  8061.                         $subtotal $subtotalService $days $unitsServ $pax;
  8062.                         $subnetoUnit $subneto;
  8063.                         $subneto $subneto $days $unitsServ $pax;
  8064.                         $data_supplier['service'][$i] = array(
  8065.                             'id' => $item->getId(),
  8066.                             'serviceCatId' => $item->getServiceCatId(),
  8067.                             'serviceName' => $item->getName(),
  8068.                             'serviceType' => 'Entretenimiento',
  8069.                             'date' => $dateServ,
  8070.                             'qty' => $unitsServ,
  8071.                             'iva' => $item->getIva(),
  8072.                             'pax' => $item->getPax(),
  8073.                             'precioUnit' => $subnetoUnit,
  8074.                             'subneto' => $subneto,
  8075.                             'subtotal' => $subtotal,
  8076.                         );
  8077.                         break;
  8078.                     case 7// Gifts
  8079.                         $pax $item->getPax();
  8080.                         if (empty($pax) or $pax == "0") {
  8081.                             $pax 1;
  8082.                         }
  8083.                         $days 1;
  8084.                         if ($days 1) {
  8085.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8086.                         } else {
  8087.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8088.                         }
  8089.                         $unitsServ $item->getUnits();
  8090.                         if (empty($unitsServ) or $unitsServ == "0") {
  8091.                             $unitsServ 1;
  8092.                         }
  8093.                         $subtotal $subtotalService $days $unitsServ $pax;
  8094.                         $subnetoUnit $subneto;
  8095.                         $subneto $subneto $days $unitsServ $pax;
  8096.                         $data_supplier['service'][$i] = array(
  8097.                             'id' => $item->getId(),
  8098.                             'serviceCatId' => $item->getServiceCatId(),
  8099.                             'serviceName' => $item->getName(),
  8100.                             'serviceType' => 'Regalos',
  8101.                             'date' => $dateServ,
  8102.                             'qty' => $unitsServ,
  8103.                             'iva' => $item->getIva(),
  8104.                             'pax' => $item->getPax(),
  8105.                             'precioUnit' => $subnetoUnit,
  8106.                             'subneto' => $subneto,
  8107.                             'subtotal' => $subtotal,
  8108.                         );
  8109.                         break;
  8110.                     case 8//Guide
  8111.                         $pax $item->getPax();
  8112.                         if (empty($pax) or $pax == "0") {
  8113.                             $pax 1;
  8114.                         }
  8115.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8116.                         if ($days 1) {
  8117.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8118.                         } else {
  8119.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8120.                         }
  8121.                         $unitsServ $item->getUnits();
  8122.                         if (empty($unitsServ) or $unitsServ == "0") {
  8123.                             $unitsServ 1;
  8124.                         }
  8125.                         $subtotal $subtotalService $days $unitsServ $pax;
  8126.                         $subnetoUnit $subneto;
  8127.                         $subneto $subneto $days $unitsServ $pax;
  8128.                         $data_supplier['service'][$i] = array(
  8129.                             'id' => $item->getId(),
  8130.                             'serviceCatId' => $item->getServiceCatId(),
  8131.                             'serviceName' => $item->getName(),
  8132.                             'serviceType' => 'Regalos',
  8133.                             'date' => $dateServ,
  8134.                             'qty' => $unitsServ,
  8135.                             'iva' => $item->getIva(),
  8136.                             'pax' => $item->getPax(),
  8137.                             'precioUnit' => $subnetoUnit,
  8138.                             'subneto' => $subneto,
  8139.                             'subtotal' => $subtotal,
  8140.                         );
  8141.                         break;
  8142.                     case 9//Itineraries
  8143.                         $pax $item->getPax();
  8144.                         if (empty($pax) or $pax == "0") {
  8145.                             $pax 1;
  8146.                         }
  8147.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8148.                         if ($days 1) {
  8149.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8150.                         } else {
  8151.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8152.                         }
  8153.                         $unitsServ $item->getUnits();
  8154.                         if (empty($unitsServ) or $unitsServ == "0") {
  8155.                             $unitsServ 1;
  8156.                         }
  8157.                         $subtotal $subtotalService $days $unitsServ $pax;
  8158.                         $subnetoUnit $subneto;
  8159.                         $subneto $subneto $days $unitsServ $pax;
  8160.                         $data_supplier['service'][$i] = array(
  8161.                             'id' => $item->getId(),
  8162.                             'serviceCatId' => $item->getServiceCatId(),
  8163.                             'serviceName' => $item->getName(),
  8164.                             'serviceType' => 'Itinerarios',
  8165.                             'date' => $dateServ,
  8166.                             'qty' => $unitsServ,
  8167.                             'iva' => $item->getIva(),
  8168.                             'pax' => $item->getPax(),
  8169.                             'precioUnit' => $subnetoUnit,
  8170.                             'subneto' => $subneto,
  8171.                             'subtotal' => $subtotal,
  8172.                         );
  8173.                         break;
  8174.                     case 10//Lounge  -- No Aplica
  8175.                         //                        $pax = $item->getPax();
  8176.                         //                        if (empty($pax) or $pax == "0") {
  8177.                         //                            $pax = 1;
  8178.                         //                        }
  8179.                         //
  8180.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  8181.                         //                        if ($days > 1){
  8182.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  8183.                         //                        } else {
  8184.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8185.                         //                        }
  8186.                         //
  8187.                         //                        $unitsServ = $item->getUnits();
  8188.                         //                        if (empty($unitsServ) or $unitsServ == "0") {
  8189.                         //                            $unitsServ = 1;
  8190.                         //                        }
  8191.                         //
  8192.                         //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  8193.                         //                        $subnetoUnit = $subneto;
  8194.                         //                        $subneto = $subneto * $days * $unitsServ * $pax;
  8195.                         //
  8196.                         //                        $data_supplier['service'][$i] = array (
  8197.                         //                            'id' => $item->getId(),
  8198.                         //                            'serviceCatId' => $item->getServiceCatId(),
  8199.                         //                            'serviceName' => $item->getName(),
  8200.                         //                            'serviceType' => 'Itinerarios',
  8201.                         //                            'date' => $dateServ,
  8202.                         //                            'qty' => $unitsServ,
  8203.                         //                            'iva' => $item->getIva(),
  8204.                         //                            'pax' => $item->getPax(),
  8205.                         //                            'precioUnit' => $subnetoUnit,
  8206.                         //                            'subneto' => $subneto,
  8207.                         //                            'subtotal' => $subtotal,
  8208.                         //                        );
  8209.                         break;
  8210.                     case 11//Menu
  8211.                         $pax $item->getPax();
  8212.                         if (empty($pax) or $pax == "0") {
  8213.                             $pax 1;
  8214.                         }
  8215.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8216.                         if ($days 1) {
  8217.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8218.                         } else {
  8219.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8220.                         }
  8221.                         $unitsServ $item->getUnits();
  8222.                         if (empty($unitsServ) or $unitsServ == "0") {
  8223.                             $unitsServ 1;
  8224.                         }
  8225.                         $subtotal $subtotalService $days $unitsServ $pax;
  8226.                         $subnetoUnit $subneto;
  8227.                         $subneto $subneto $days $unitsServ $pax;
  8228.                         $data_supplier['service'][$i] = array(
  8229.                             'id' => $item->getId(),
  8230.                             'serviceCatId' => $item->getServiceCatId(),
  8231.                             'serviceName' => $item->getName(),
  8232.                             'serviceType' => 'MenĂº',
  8233.                             'date' => $dateServ,
  8234.                             'qty' => $unitsServ,
  8235.                             'iva' => $item->getIva(),
  8236.                             'pax' => $item->getPax(),
  8237.                             'precioUnit' => $subnetoUnit,
  8238.                             'subneto' => $subneto,
  8239.                             'subtotal' => $subtotal,
  8240.                         );
  8241.                         break;
  8242.                     case 12//Others
  8243.                         $pax $item->getPax();
  8244.                         if (empty($pax) or $pax == "0") {
  8245.                             $pax 1;
  8246.                         }
  8247.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8248.                         if ($days 1) {
  8249.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8250.                         } else {
  8251.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8252.                         }
  8253.                         $unitsServ $item->getUnits();
  8254.                         if (empty($unitsServ) or $unitsServ == "0") {
  8255.                             $unitsServ 1;
  8256.                         }
  8257.                         $subtotal $subtotalService $days $unitsServ $pax;
  8258.                         $subnetoUnit $subneto;
  8259.                         $subneto $subneto $days $unitsServ $pax;
  8260.                         $data_supplier['service'][$i] = array(
  8261.                             'id' => $item->getId(),
  8262.                             'serviceCatId' => $item->getServiceCatId(),
  8263.                             'serviceName' => $item->getName(),
  8264.                             'serviceType' => 'Otros',
  8265.                             'date' => $dateServ,
  8266.                             'qty' => $unitsServ,
  8267.                             'iva' => $item->getIva(),
  8268.                             'pax' => $item->getPax(),
  8269.                             'precioUnit' => $subnetoUnit,
  8270.                             'subneto' => $subneto,
  8271.                             'subtotal' => $subtotal,
  8272.                         );
  8273.                         break;
  8274.                     case 13//Transport
  8275.                         $pax $item->getPax();
  8276.                         if (empty($pax) or $pax == "0") {
  8277.                             $pax 1;
  8278.                         }
  8279.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8280.                         if ($days 1) {
  8281.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8282.                         } else {
  8283.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8284.                         }
  8285.                         $unitsServ $item->getUnits();
  8286.                         if (empty($unitsServ) or $unitsServ == "0") {
  8287.                             $unitsServ 1;
  8288.                         }
  8289.                         $subtotal $subtotalService $days $unitsServ $pax;
  8290.                         $subnetoUnit $subneto;
  8291.                         $subneto $subneto $days $unitsServ $pax;
  8292.                         $data_supplier['service'][$i] = array(
  8293.                             'id' => $item->getId(),
  8294.                             'serviceCatId' => $item->getServiceCatId(),
  8295.                             'serviceName' => $item->getName(),
  8296.                             'serviceType' => 'Transporte',
  8297.                             'date' => $dateServ,
  8298.                             'qty' => $unitsServ,
  8299.                             'iva' => $item->getIva(),
  8300.                             'pax' => $item->getPax(),
  8301.                             'precioUnit' => $subnetoUnit,
  8302.                             'subneto' => $subneto,
  8303.                             'subtotal' => $subtotal,
  8304.                         );
  8305.                         break;
  8306.                     case 14//Technology
  8307.                         $pax $item->getPax();
  8308.                         if (empty($pax) or $pax == "0") {
  8309.                             $pax 1;
  8310.                         }
  8311.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  8312.                         $days 1;
  8313.                         //                        if ($days > 1){
  8314.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  8315.                         //                        } else {
  8316.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8317.                         //                        }
  8318.                         $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8319.                         $unitsServ $item->getUnits();
  8320.                         if (empty($unitsServ) or $unitsServ == "0") {
  8321.                             $unitsServ 1;
  8322.                         }
  8323.                         $subtotal $subtotalService $days $unitsServ $pax;
  8324.                         $subnetoUnit $subneto;
  8325.                         $subneto $subneto $days $unitsServ $pax;
  8326.                         $data_supplier['service'][$i] = array(
  8327.                             'id' => $item->getId(),
  8328.                             'serviceCatId' => $item->getServiceCatId(),
  8329.                             'serviceName' => $item->getName(),
  8330.                             'serviceType' => 'TecnologĂ­a',
  8331.                             'date' => $dateServ,
  8332.                             'qty' => $unitsServ,
  8333.                             'iva' => $item->getIva(),
  8334.                             'pax' => $item->getPax(),
  8335.                             'precioUnit' => $subnetoUnit,
  8336.                             'subneto' => $subneto,
  8337.                             'subtotal' => $subtotal,
  8338.                         );
  8339.                         break;
  8340.                     case 15//Assisstant
  8341.                         $pax $item->getPax();
  8342.                         if (empty($pax) or $pax == "0") {
  8343.                             $pax 1;
  8344.                         }
  8345.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8346.                         if ($days 1) {
  8347.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8348.                         } else {
  8349.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8350.                         }
  8351.                         $unitsServ $item->getUnits();
  8352.                         if (empty($unitsServ) or $unitsServ == "0") {
  8353.                             $unitsServ 1;
  8354.                         }
  8355.                         $subtotal $subtotalService $days $unitsServ $pax;
  8356.                         $subnetoUnit $subneto;
  8357.                         $subneto $subneto $days $unitsServ $pax;
  8358.                         $data_supplier['service'][$i] = array(
  8359.                             'id' => $item->getId(),
  8360.                             'serviceCatId' => $item->getServiceCatId(),
  8361.                             'serviceName' => $item->getName(),
  8362.                             'serviceType' => 'Asistente',
  8363.                             'date' => $dateServ,
  8364.                             'qty' => $unitsServ,
  8365.                             'iva' => $item->getIva(),
  8366.                             'pax' => $item->getPax(),
  8367.                             'precioUnit' => $subnetoUnit,
  8368.                             'subneto' => $subneto,
  8369.                             'subtotal' => $subtotal,
  8370.                         );
  8371.                         break;
  8372.                     case 16//DDR
  8373.                         $pax $item->getPax();
  8374.                         if (empty($pax) or $pax == "0") {
  8375.                             $pax 1;
  8376.                         }
  8377.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8378.                         if ($days 1) {
  8379.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8380.                         } else {
  8381.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8382.                         }
  8383.                         $unitsServ $item->getUnits();
  8384.                         if (empty($unitsServ) or $unitsServ == "0") {
  8385.                             $unitsServ 1;
  8386.                         }
  8387.                         $subtotal $subtotalService $days $unitsServ $pax;
  8388.                         $subnetoUnit $subneto;
  8389.                         $subneto $subneto $days $unitsServ $pax;
  8390.                         $data_supplier['service'][$i] = array(
  8391.                             'id' => $item->getId(),
  8392.                             'serviceCatId' => $item->getServiceCatId(),
  8393.                             'serviceName' => $item->getName(),
  8394.                             'serviceType' => 'DDR',
  8395.                             'date' => $dateServ,
  8396.                             'qty' => $unitsServ,
  8397.                             'iva' => $item->getIva(),
  8398.                             'pax' => $item->getPax(),
  8399.                             'precioUnit' => $subnetoUnit,
  8400.                             'subneto' => $subneto,
  8401.                             'subtotal' => $subtotal,
  8402.                         );
  8403.                         break;
  8404.                     default:
  8405.                         break;
  8406.                 }
  8407.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  8408.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  8409.                 $neto round($subneto2PHP_ROUND_HALF_UP);
  8410.                 $arrayItems[] = array(
  8411.                     'type' => 'Service',
  8412.                     'name' => $item->getName(),
  8413.                     'amount' => $neto,
  8414.                     'iva' => $item->getIva(),
  8415.                     'total' => $subtotal,
  8416.                 );
  8417.             }
  8418.             switch ($item->getIva()) {
  8419.                     // Acumula IVA
  8420.                 case 21:
  8421.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  8422.                     $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  8423.                     break;
  8424.                 case 10:
  8425.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  8426.                     $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  8427.                     break;
  8428.                 case 0:
  8429.                     $data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto * ($item->getIva() / 100));
  8430.                     break;
  8431.                 default:
  8432.                     $data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
  8433.                     $data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2PHP_ROUND_HALF_UP);
  8434.                     break;
  8435.             }
  8436.             $totales_neto_all $totales_neto_all $neto;
  8437.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  8438.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  8439.             // Acumula netos totales e IVA
  8440.             $service['neto'] = $service['neto'] + $neto;
  8441.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  8442.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  8443.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  8444.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  8445.             $i++;
  8446.         }
  8447.         $data_supplier['serviceSubTotal'] = array(
  8448.             'neto' => $service['neto'],
  8449.             'sumSubT' => $service['sumSubT'],
  8450.         );
  8451.         $currency '€';
  8452.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  8453.         if (!empty($payments)) {
  8454.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  8455.         } else {
  8456.             $amount_pay 0;
  8457.         }
  8458.         $totales_all $totales_total $amount_pay;
  8459.         if ($type == 'Invoice') {
  8460.             $em->clear();   // sin este clear se producia error al guardar
  8461.             $newInvoice $em->getRepository(AveDocInvoice::class)->findOneById($numberInvoiceOrProforma);
  8462.             $newInvoice->setBalance($totales_all);
  8463.             $em->persist($newInvoice);
  8464.             $em->flush();
  8465.         }
  8466.         $data = array(
  8467.             'id' => $id,
  8468.             'type' => $type,
  8469.             'number' => $number,
  8470.             'prefix' => $number,
  8471.             'date' => new DateTime('now'),
  8472.             'file' => $file,
  8473.             'company' => $company,
  8474.             'clients' => $clientNew,
  8475.             'arrayItems' => $arrayItems,
  8476.             'datasupplier' => $data_supplier,
  8477.             'currency' => $currency,
  8478.             'totales_neto' => $totales_neto_all,
  8479.             'bases_imponibles' => $data_iva,
  8480.             'totales' => $totales_total,
  8481.             'balance' => $totales_all,
  8482.             'paymentInvoice' => $amount_pay,
  8483.         );
  8484.         return $data;
  8485.     }
  8486.     private function baseInvoiceDoneDocument($fileId$invoiceId$typeBase)
  8487.     {
  8488.         $em $this->getDoctrine()->getManager();
  8489.         $file $em->getRepository(AveFiles::class)->findOneById($fileId);
  8490.         $dateDocument null;                                                                           //Fecha final del documento
  8491.         if (($typeBase == 'I') or ($typeBase == 'P')) {
  8492.             if ($typeBase == 'I') {
  8493.                 // Es una factura
  8494.                 $items $em->getRepository(AveDocInvoiceItems::class)->findBy(array('fileId' => $fileId'invoiceId' => $invoiceId));
  8495.                 // Salvador Guerrero indico, el orden de los productos en la factura o proforma serĂ¡ (Video - Sonido - Iluminacion - Otros)
  8496.                 $allProductFile $em->getRepository(AveProductFile::class)->findBy(array('fileId' => $fileId));
  8497.                 $arrayLocation = array();
  8498.                 $arrayLocationWithNull false;
  8499.                 foreach ($allProductFile as $item) {
  8500.                     if (!empty($item->getLocation())) {
  8501.                         $arrayLocation[$item->getLocation()] = $item->getLocation();
  8502.                     } else {
  8503.                         $arrayLocationWithNull true;
  8504.                     }
  8505.                 }
  8506.                 if ($arrayLocationWithNull) {
  8507.                     $arrayLocation['null'] = 'null';
  8508.                 }
  8509.                 $arrayItemsSorted = array();
  8510.                 $productsInFile = array();
  8511.                 foreach ($arrayLocation as $item) {
  8512.                     // VIDEO
  8513.                     $parameters = array(
  8514.                         'fileId' => $fileId,
  8515.                         'proformaId' => $invoiceId,
  8516.                         'type' => 'VĂ­deo',
  8517.                         'location' => $item,
  8518.                     );
  8519.                     $dql 'SELECT i
  8520.                             FROM AvexpressBundle:AveProductFile i
  8521.                             INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8522.                             WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8523.                             ORDER BY i.rankquoteAv ASC';
  8524.                     $query $em->createQuery($dql)->setParameters($parameters);
  8525.                     $productsInFileVid $query->getResult();
  8526.                     // SONIDO
  8527.                     $parameters = array(
  8528.                         'fileId' => $fileId,
  8529.                         'proformaId' => $invoiceId,
  8530.                         'type' => 'Sonido',
  8531.                         'location' => $item,
  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 = :type AND i.location = :location AND c.proformaId =:proformaId
  8537.                     ORDER BY i.rankquoteAv ASC';
  8538.                     $query $em->createQuery($dql)->setParameters($parameters);
  8539.                     $productsInFileSound $query->getResult();
  8540.                     // ILUMINACION
  8541.                     $parameters = array(
  8542.                         'fileId' => $fileId,
  8543.                         'proformaId' => $invoiceId,
  8544.                         'type' => 'IluminaciĂ³n',
  8545.                         'location' => $item,
  8546.                     );
  8547.                     $dql 'SELECT i
  8548.                     FROM AvexpressBundle:AveProductFile i                    
  8549.                     INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id                  
  8550.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8551.                     ORDER BY i.rankquoteAv ASC';
  8552.                     $query $em->createQuery($dql)->setParameters($parameters);
  8553.                     $productsInFileLights $query->getResult();
  8554.                     // OTROS
  8555.                     $parameters = array(
  8556.                         'fileId' => $fileId,
  8557.                         'proformaId' => $invoiceId,
  8558.                         'typeV' => 'VĂ­deo',
  8559.                         'typeS' => 'Sonido',
  8560.                         'typeI' => 'IluminaciĂ³n',
  8561.                         'location' => $item,
  8562.                     );
  8563.                     $dql 'SELECT i
  8564.                     FROM AvexpressBundle:AveProductFile i                    
  8565.                     INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8566.                     WHERE i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND i.location = :location AND c.proformaId =:proformaId
  8567.                     ORDER BY i.rankquoteAv ASC';
  8568.                     $query $em->createQuery($dql)->setParameters($parameters);
  8569.                     $productsInFileOther $query->getResult();
  8570.                     // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  8571.                     $parameters = array(
  8572.                         'fileId' => $fileId,
  8573.                         'proformaId' => $invoiceId,
  8574.                         'location' => $item,
  8575.                     );
  8576.                     $dql 'SELECT i
  8577.                     FROM AvexpressBundle:AveProductFile i                    
  8578.                     INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8579.                     WHERE i.fileId = :fileId AND i.type IS NULL AND i.location = :location AND c.proformaId =:proformaId
  8580.                     ORDER BY i.rankquoteAv ASC';
  8581.                     $query $em->createQuery($dql)->setParameters($parameters);
  8582.                     $productsInFileNull $query->getResult();
  8583.                     // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  8584.                     if ($item == 'null') {
  8585.                         // VIDEO
  8586.                         $parameters = array(
  8587.                             'fileId' => $fileId,
  8588.                             'proformaId' => $invoiceId,
  8589.                             'type' => 'VĂ­deo',
  8590.                             'location' => '',
  8591.                         );
  8592.                         $dql 'SELECT i
  8593.                         FROM AvexpressBundle:AveProductFile i                        
  8594.                         INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8595.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8596.                         ORDER BY i.rankquoteAv ASC';
  8597.                         $query $em->createQuery($dql)->setParameters($parameters);
  8598.                         $productsInFileVid $query->getResult();
  8599.                         // SONIDO
  8600.                         $parameters = array(
  8601.                             'fileId' => $fileId,
  8602.                             'proformaId' => $invoiceId,
  8603.                             'type' => 'Sonido',
  8604.                             'location' => '',
  8605.                         );
  8606.                         $dql 'SELECT i
  8607.                         FROM AvexpressBundle:AveProductFile i
  8608.                         INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8609.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8610.                         ORDER BY i.rankquoteAv ASC';
  8611.                         $query $em->createQuery($dql)->setParameters($parameters);
  8612.                         $productsInFileSound $query->getResult();
  8613.                         // ILUMINACION
  8614.                         $parameters = array(
  8615.                             'fileId' => $fileId,
  8616.                             'proformaId' => $invoiceId,
  8617.                             'type' => 'IluminaciĂ³n',
  8618.                             'location' => '',
  8619.                         );
  8620.                         $dql 'SELECT i
  8621.                         FROM AvexpressBundle:AveProductFile i
  8622.                         INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8623.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8624.                         ORDER BY i.rankquoteAv ASC';
  8625.                         $query $em->createQuery($dql)->setParameters($parameters);
  8626.                         $productsInFileLights $query->getResult();
  8627.                         // OTROS
  8628.                         $parameters = array(
  8629.                             'fileId' => $fileId,
  8630.                             'proformaId' => $invoiceId,
  8631.                             'typeV' => 'VĂ­deo',
  8632.                             'typeS' => 'Sonido',
  8633.                             'typeI' => 'IluminaciĂ³n',
  8634.                             'location' => '',
  8635.                         );
  8636.                         $dql 'SELECT i
  8637.                         FROM AvexpressBundle:AveProductFile i                        
  8638.                         INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8639.                         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
  8640.                         ORDER BY i.rankquoteAv ASC';
  8641.                         $query $em->createQuery($dql)->setParameters($parameters);
  8642.                         $productsInFileOther $query->getResult();
  8643.                         // CASO NULL DEL TIPO (Los casos EMPTY estan considerados en las consultas previas)
  8644.                         $parameters = array(
  8645.                             'fileId' => $fileId,
  8646.                             'proformaId' => $invoiceId,
  8647.                             'location' => '',
  8648.                         );
  8649.                         $dql 'SELECT i
  8650.                         FROM AvexpressBundle:AveProductFile i                        
  8651.                         INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8652.                         WHERE i.fileId = :fileId AND i.type IS NULL AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8653.                         ORDER BY i.rankquoteAv ASC';
  8654.                         $query $em->createQuery($dql)->setParameters($parameters);
  8655.                         $productsInFileNull $query->getResult();
  8656.                     }
  8657.                     $arrayItemsSorted array_merge($arrayItemsSorted$productsInFileVid$productsInFileSound$productsInFileLights$productsInFileOther$productsInFileNull);
  8658.                 }
  8659.                 $items = array();
  8660.                 foreach ($arrayItemsSorted as $elem) {
  8661.                     $items[] = $em->getRepository(AveDocInvoiceItems::class)->findOneBy(array('fileId' => $fileId'invoiceId' => $invoiceId'prdControlId' => $elem->getId()));
  8662.                 }
  8663.             } else {
  8664.                 // Es una proforma
  8665.                 //                $items = $em->getRepository(AveDocProformaItems::class)->findBy(array('fileId' => $fileId, 'proformaId' => $invoiceId));
  8666.                 // Salvador Guerrero indico, el orden de los productos en la factura o proforma serĂ¡ (Video - Sonido - Iluminacion - Otros)
  8667.                 $allProductFile $em->getRepository(AveProductFile::class)->findBy(array('fileId' => $fileId));
  8668.                 $arrayLocation = array();
  8669.                 $arrayLocationWithNull false;
  8670.                 foreach ($allProductFile as $item) {
  8671.                     if (!empty($item->getLocation())) {
  8672.                         $arrayLocation[$item->getLocation()] = $item->getLocation();
  8673.                     } else {
  8674.                         $arrayLocationWithNull true;
  8675.                     }
  8676.                 }
  8677.                 if ($arrayLocationWithNull) {
  8678.                     $arrayLocation['null'] = 'null';
  8679.                 }
  8680.                 $arrayItemsSorted = array();
  8681.                 $productsInFile = array();
  8682.                 foreach ($arrayLocation as $item) {
  8683.                     // VIDEO
  8684.                     $parameters = array(
  8685.                         'fileId' => $fileId,
  8686.                         'proformaId' => $invoiceId,
  8687.                         'type' => 'VĂ­deo',
  8688.                         'location' => $item,
  8689.                     );
  8690.                     $dql 'SELECT i
  8691.                     FROM AvexpressBundle:AveProductFile i
  8692.                     INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  8693.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8694.                     ORDER BY i.rankquoteAv ASC';
  8695.                     $query $em->createQuery($dql)->setParameters($parameters);
  8696.                     $productsInFileVid $query->getResult();
  8697.                     // SONIDO
  8698.                     $parameters = array(
  8699.                         'fileId' => $fileId,
  8700.                         'proformaId' => $invoiceId,
  8701.                         'type' => 'Sonido',
  8702.                         'location' => $item,
  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 = :type AND i.location = :location AND c.proformaId =:proformaId
  8708.                     ORDER BY i.rankquoteAv ASC';
  8709.                     $query $em->createQuery($dql)->setParameters($parameters);
  8710.                     $productsInFileSound $query->getResult();
  8711.                     // ILUMINACION
  8712.                     $parameters = array(
  8713.                         'fileId' => $fileId,
  8714.                         'proformaId' => $invoiceId,
  8715.                         'type' => 'IluminaciĂ³n',
  8716.                         'location' => $item,
  8717.                     );
  8718.                     $dql 'SELECT i
  8719.                     FROM AvexpressBundle:AveProductFile i                    
  8720.                     INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                  
  8721.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8722.                     ORDER BY i.rankquoteAv ASC';
  8723.                     $query $em->createQuery($dql)->setParameters($parameters);
  8724.                     $productsInFileLights $query->getResult();
  8725.                     // OTROS
  8726.                     $parameters = array(
  8727.                         'fileId' => $fileId,
  8728.                         'proformaId' => $invoiceId,
  8729.                         'typeV' => 'VĂ­deo',
  8730.                         'typeS' => 'Sonido',
  8731.                         'typeI' => 'IluminaciĂ³n',
  8732.                         'location' => $item,
  8733.                     );
  8734.                     $dql 'SELECT i
  8735.                     FROM AvexpressBundle:AveProductFile i                    
  8736.                     INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                                        
  8737.                     WHERE i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND i.location = :location AND c.proformaId =:proformaId
  8738.                     ORDER BY i.rankquoteAv ASC';
  8739.                     $query $em->createQuery($dql)->setParameters($parameters);
  8740.                     $productsInFileOther $query->getResult();
  8741.                     // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  8742.                     $parameters = array(
  8743.                         'fileId' => $fileId,
  8744.                         'proformaId' => $invoiceId,
  8745.                         'location' => $item,
  8746.                     );
  8747.                     $dql 'SELECT i
  8748.                     FROM AvexpressBundle:AveProductFile i                    
  8749.                     INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                    
  8750.                     WHERE i.fileId = :fileId AND i.type IS NULL AND i.location = :location AND c.proformaId =:proformaId
  8751.                     ORDER BY i.rankquoteAv ASC';
  8752.                     $query $em->createQuery($dql)->setParameters($parameters);
  8753.                     $productsInFileNull $query->getResult();
  8754.                     // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  8755.                     if ($item == 'null') {
  8756.                         // VIDEO
  8757.                         $parameters = array(
  8758.                             'fileId' => $fileId,
  8759.                             'proformaId' => $invoiceId,
  8760.                             'type' => 'VĂ­deo',
  8761.                             'location' => '',
  8762.                         );
  8763.                         $dql 'SELECT i
  8764.                         FROM AvexpressBundle:AveProductFile i                        
  8765.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                  
  8766.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8767.                         ORDER BY i.rankquoteAv ASC';
  8768.                         $query $em->createQuery($dql)->setParameters($parameters);
  8769.                         $productsInFileVid $query->getResult();
  8770.                         // SONIDO
  8771.                         $parameters = array(
  8772.                             'fileId' => $fileId,
  8773.                             'proformaId' => $invoiceId,
  8774.                             'type' => 'Sonido',
  8775.                             'location' => '',
  8776.                         );
  8777.                         $dql 'SELECT i
  8778.                         FROM AvexpressBundle:AveProductFile i
  8779.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                        
  8780.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8781.                         ORDER BY i.rankquoteAv ASC';
  8782.                         $query $em->createQuery($dql)->setParameters($parameters);
  8783.                         $productsInFileSound $query->getResult();
  8784.                         // ILUMINACION
  8785.                         $parameters = array(
  8786.                             'fileId' => $fileId,
  8787.                             'proformaId' => $invoiceId,
  8788.                             'type' => 'IluminaciĂ³n',
  8789.                             'location' => '',
  8790.                         );
  8791.                         $dql 'SELECT i
  8792.                         FROM AvexpressBundle:AveProductFile i
  8793.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                        
  8794.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8795.                         ORDER BY i.rankquoteAv ASC';
  8796.                         $query $em->createQuery($dql)->setParameters($parameters);
  8797.                         $productsInFileLights $query->getResult();
  8798.                         // OTROS
  8799.                         $parameters = array(
  8800.                             'fileId' => $fileId,
  8801.                             'proformaId' => $invoiceId,
  8802.                             'typeV' => 'VĂ­deo',
  8803.                             'typeS' => 'Sonido',
  8804.                             'typeI' => 'IluminaciĂ³n',
  8805.                             'location' => '',
  8806.                         );
  8807.                         $dql 'SELECT i
  8808.                         FROM AvexpressBundle:AveProductFile i                        
  8809.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                        
  8810.                         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
  8811.                         ORDER BY i.rankquoteAv ASC';
  8812.                         $query $em->createQuery($dql)->setParameters($parameters);
  8813.                         $productsInFileOther $query->getResult();
  8814.                         // CASO NULL DEL TIPO (Los casos EMPTY estan considerados en las consultas previas)
  8815.                         $parameters = array(
  8816.                             'fileId' => $fileId,
  8817.                             'proformaId' => $invoiceId,
  8818.                             'location' => '',
  8819.                         );
  8820.                         $dql 'SELECT i
  8821.                         FROM AvexpressBundle:AveProductFile i                        
  8822.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                        
  8823.                         WHERE i.fileId = :fileId AND i.type IS NULL AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8824.                         ORDER BY i.rankquoteAv ASC';
  8825.                         $query $em->createQuery($dql)->setParameters($parameters);
  8826.                         $productsInFileNull $query->getResult();
  8827.                     }
  8828.                     $arrayItemsSorted array_merge($arrayItemsSorted$productsInFileVid$productsInFileSound$productsInFileLights$productsInFileOther$productsInFileNull);
  8829.                 }
  8830.                 $items = array();
  8831.                 foreach ($arrayItemsSorted as $elem) {
  8832.                     $items[] = $em->getRepository(AveDocProformaItems::class)->findOneBy(array('fileId' => $fileId'proformaId' => $invoiceId'controlId' => $elem->getId()));
  8833.                 }
  8834.             }
  8835.         } else {
  8836.             // No es factura ni proforma, es una rectificativa
  8837.             $items $em->getRepository(ReservationInvoiceRecItems::class)->findBy(array('reservationId' => $fileId'invoiceRecId' => $invoiceId));
  8838.         }
  8839.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  8840.         $client $em->getRepository(Client::class)->findById($file->getClient());
  8841.         if (empty($client)) {
  8842.             $client[0] = new Client();
  8843.             $client[0]->setName('');
  8844.             $client[0]->setTitle('');
  8845.             $client[0]->setIdDocument('');
  8846.             $client[0]->setPopulation('');
  8847.             $client[0]->setRegion('');
  8848.             $client[0]->setCountry('');
  8849.         } else {
  8850.             if (is_numeric($client[0]->getPopulation())) {
  8851.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  8852. //                $client[0]->setPopulation($city->getCity());
  8853.             }
  8854.             if (is_numeric($client[0]->getRegion())) {
  8855.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  8856. //                $client[0]->setRegion($region->getRegion());
  8857.             }
  8858.             if (is_numeric($client[0]->getCountry())) {
  8859.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  8860. //                $client[0]->setCountry($country->getCountry());
  8861.             }
  8862.         }
  8863.         if (empty($client)) {
  8864.             $client[0] = new Client();
  8865.             $client[0]->setName('');
  8866.             $client[0]->setTitle('');
  8867.             $client[0]->setIdDocument('');
  8868.             $client[0]->setPopulation('');
  8869.             $client[0]->setRegion('');
  8870.             $client[0]->setCountry('');
  8871.             $clientNew = array(
  8872.                 'name' => '',
  8873.                 'title' => '',
  8874.                 'idDocument' => '',
  8875.                 'population' => '',
  8876.                 'region' => '',
  8877.                 'country' => '',
  8878.                 'address' => '',
  8879.                 'addressNumber' => '',
  8880.                 'zipCode' => '',
  8881.                 'typeDocument' => '',
  8882.             );
  8883.         } else {
  8884.             $clientNew = array(
  8885.                 'name' => $client[0]->getName(),
  8886.                 'title' => $client[0]->getTitle(),
  8887.                 'idDocument' => $client[0]->getIdDocument(),
  8888.                 'population' => '',
  8889.                 'region' => '',
  8890.                 'country' => '',
  8891.                 'address' => $client[0]->getAddress(),
  8892.                 'addressNumber' => $client[0]->getAddressNumber(),
  8893.                 'zipCode' => $client[0]->getZipCode(),
  8894.                 'typeDocument' => $client[0]->getTypeDocument(),
  8895.             );
  8896.             if (is_numeric($client[0]->getPopulation())) {
  8897.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  8898.                 $clientNew['population'] = $city->getCity();
  8899.             }
  8900.             if (is_numeric($client[0]->getRegion())) {
  8901.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  8902.                 $clientNew['region'] = $region->getRegion();
  8903.             }
  8904.             if (is_numeric($client[0]->getCountry())) {
  8905.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  8906.                 $clientNew['country'] = $country->getCountry();
  8907.             }
  8908.         }
  8909.         // Acumuladores de los calculos
  8910.         $totales_neto_all 0;
  8911.         $data_iva = array(
  8912.             'iva' => 21,
  8913.             'ivaMontoVeintiUno' => 0,
  8914.             'ivaMontoDiez' => 0,
  8915.             'ivaMontoCero' => null,
  8916.         );
  8917.         //INICIO: Determinamos el numero de factura o proforma
  8918.         if ($typeBase == 'I') {
  8919.             // Es una Factura
  8920.             $number $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
  8921.             $dateDocument $number->getDateAt();
  8922.             $number $number->getNumber();
  8923.             $type 'Invoice';
  8924.         } else {
  8925.             if ($typeBase == 'R') {
  8926.                 // Es una factura rectificativa
  8927.                 $number $em->getRepository(AveDocInvoiceRec::class)->findOneById($invoiceId);
  8928.                 $dateDocument $number->getDateAt();
  8929.                 $type 'Invoice Rec';
  8930.             } else {
  8931.                 // Es una Proforma
  8932.                 //                $number = $em->getRepository('DevelupBundle:ReservationProforma')->findOneById($invoiceId);
  8933.                 //                $number = $number->getNumber();
  8934.                 $number $invoiceId;
  8935.                 //                $number = $number->getPrefix().$number->getReservationId();
  8936.                 $type 'Proforma';
  8937.             }
  8938.         }
  8939.         //FIN: Determinamos el numero de factura o proforma
  8940.         // Buscamos las salas reservadas, pagos y servicios para el evento
  8941.         $arrayItems = array();
  8942.         $fileProducts = array();
  8943.         $payments = array();
  8944.         $services = array();
  8945.         if (!empty($items)) {
  8946.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  8947.                 foreach ($items as $item) {
  8948.                     switch ($item->getItemType()) {
  8949.                         case 'PRODUCT'// Salon
  8950.                             $fileProducts[] = $item;
  8951.                             break;
  8952.                         case 'PAYMENT'// Pago
  8953.                             $payments[] = $item;
  8954.                             break;
  8955.                         case 'SERVICE'// Servicio
  8956.                             $services[] = $item;
  8957.                             break;
  8958.                         default:
  8959.                             break;
  8960.                     }
  8961.                 }
  8962.             } else {
  8963.                 // Es una proforma
  8964.                 foreach ($items as $item) {
  8965.                     switch ($item->getType()) {
  8966.                         case 'PRODUCT'// Producto
  8967.                             $productPro $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
  8968.                             if (!empty($productPro)) {
  8969.                                 $fileProducts[] = $productPro;
  8970.                             }
  8971.                             break;
  8972.                         case 'PAYMENT'// Pago
  8973.                             $paymentPro $em->getRepository(AvePaymentsClient::class)->findOneById($item->getControlId());
  8974.                             if (!empty($paymentPro)) {
  8975.                                 $payments[] = $paymentPro;
  8976.                             }
  8977.                             break;
  8978.                         case 'SERVICE'// Servicio
  8979.                             $servicePro $em->getRepository(AveServices::class)->findOneById($item->getControlId());
  8980.                             if (!empty($servicePro)) {
  8981.                                 $services[] = $servicePro;
  8982.                             }
  8983.                             break;
  8984.                         default:
  8985.                             break;
  8986.                     }
  8987.                 }
  8988.             }
  8989.         }
  8990.         $data_supplier = array();
  8991.         $i 0;
  8992.         $iva '21';            // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
  8993.         $pax '1';
  8994.         $qty '1';
  8995.         $product = array(
  8996.             'neto' => 0,
  8997.             'sumSubT' => 0,
  8998.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  8999.         $service = array(
  9000.             'neto' => 0,
  9001.             'sumSubT' => 0,
  9002.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  9003.         foreach ($fileProducts as $item) {
  9004.             //            $days = '1';
  9005.             $days = ((($item->getDateEnd())->diff($item->getDateStart()))->days 1);
  9006.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  9007.                 if (is_null($item->getSubTotalPrice()) or empty($item->getSubTotalPrice())) {
  9008.                     $subtotal 0;
  9009.                     $neto 0;
  9010.                     $subnetoMounting 0;
  9011.                     $subtotalLounge 0;
  9012.                     $subnetoRemoval 0;
  9013.                 } else {
  9014.                     if ($item->getIva() == '21') {
  9015.                         $subtotalLounge $item->getSubTotalPrice() * 1.21;
  9016.                     }
  9017.                     if ($item->getIva() == '10') {
  9018.                         $subtotalLounge $item->getSubTotalPrice() * 1.1;
  9019.                     }
  9020.                     if ($item->getIva() == '0') {
  9021.                         $subtotalLounge $item->getSubTotalPrice() * 1;
  9022.                     }
  9023.                     $subneto $item->getSubTotalPrice();
  9024.                     $subtotal =  $subtotalLounge;
  9025.                     $neto =  $subneto;
  9026.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  9027.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  9028.                     $neto round($neto2PHP_ROUND_HALF_UP);
  9029.                     $arrayItems[] = array(
  9030.                         'type' => 'Product',
  9031.                         'name' => $item->getLngLoungeName(),
  9032.                         'amount' => $item->getServicePrice(),
  9033.                         'iva' => $item->getIva(),
  9034.                         'amountSubTotal' => $neto,
  9035.                         //                        'iva' => '21',
  9036.                         'total' => $subtotal,
  9037.                     );
  9038.                 }
  9039.             } else {
  9040.                 // Es proforma
  9041.                 if (is_null($item->getSubTotalPrice()) or empty($item->getSubTotalPrice())) {
  9042.                     $subtotal 0;
  9043.                     $neto 0;
  9044.                     $subtotalProduct 0;
  9045.                 } else {
  9046.                     if ($item->getIva() == '21') {
  9047.                         $subtotalProduct $item->getSubTotalPrice() * 1.21;
  9048.                     }
  9049.                     if ($item->getIva() == '10') {
  9050.                         $subtotalProduct $item->getSubTotalPrice() * 1.1;
  9051.                     }
  9052.                     if ($item->getIva() == '0') {
  9053.                         $subtotalProduct $item->getSubTotalPrice() * 1;
  9054.                     }
  9055.                     $subneto $item->getSubTotalPrice();
  9056.                     $subtotal =  $subtotalProduct;
  9057.                     $neto =  $subneto;
  9058.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  9059.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  9060.                     $neto round($neto2PHP_ROUND_HALF_UP);
  9061.                     $arrayItems[] = array(
  9062.                         'type' => 'Product',
  9063.                         'name' => $item->getProductName(),
  9064.                         'amount' => $item->getServicePrice(),
  9065.                         'amountSubTotal' => $neto,
  9066.                         //                        'iva' => '21',
  9067.                         'iva' => $item->getIva(),
  9068.                         'total' => $subtotal,
  9069.                     );
  9070.                 }
  9071.             }
  9072.             // Acumula netos totales e IVA
  9073.             $totales_neto_all $totales_neto_all $neto;
  9074.             if ($item->getIva() == '21') {
  9075.                 $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  9076.             }
  9077.             if ($item->getIva() == '10') {
  9078.                 $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1);
  9079.             }
  9080.             if ($item->getIva() == '0') {
  9081.                 $data_iva['ivaMontoCero'] = $neto 0;
  9082.             }
  9083.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  9084.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  9085.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  9086.             // Acumula netos totales e IVA
  9087.             $product['neto'] = $product['neto'] + $neto;
  9088.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  9089.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  9090.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  9091.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  9092.             $pax $item->getPax();
  9093.             $qty $item->getUnits();
  9094.             if (!empty($item->getDays())) {
  9095.                 $days $item->getDays();
  9096.             }
  9097.             // Calculo del precio unitario despues de aplicar Over y Comision
  9098.             $multiplo = (float)$qty * (float)$days;
  9099.             $item->setServicePrice($item->getSubTotalPrice() / $multiplo);
  9100.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  9101.                 $data_supplier['product'][$i] = array(
  9102.                     'id' => $item->getId(),
  9103.                     'loungeName' => $item->getLngLoungeName(),
  9104.                     'idLounge' => $item->getLngIdLounge(),
  9105.                     'dateStart' => $item->getLngDateStart(),
  9106.                     'dateEnd' => $item->getLngDateEnd(),
  9107.                     //                    'servicePrice' => $item->getLngServicePrice(),
  9108.                     'servicePrice' => $item->getServicePrice(),
  9109.                     'serviceSubTotalPrice' => $item->getSubTotalPrice(),
  9110.                     'subtotalLounge' => $subtotalLounge,
  9111.                     // 'iva' => $iva,
  9112.                     'iva' => $item->getIva(),
  9113.                     'pax' => $pax,
  9114.                     'qty' => $qty,
  9115.                     'days' => $days,
  9116.                     'type' => $item->getLngType(),
  9117.                     'subtotal' => $subtotal,
  9118.                 );
  9119.             } else {
  9120.                 // Es proforma
  9121.                 $data_supplier['product'][$i] = array(
  9122.                     'id' => $item->getId(),
  9123.                     'productName' => $item->getProductName(),
  9124.                     'productId' => $item->getProductId(),
  9125.                     'dateStart' => $item->getDateStart(),
  9126.                     'dateEnd' => $item->getDateEnd(),
  9127.                     'location' => $item->getLocation(),
  9128.                     //                    'servicePrice' => $item->getServicePrice(),
  9129.                     'servicePrice' => $item->getServicePrice(),
  9130.                     'serviceSubTotalPrice' => $item->getSubTotalPrice(),
  9131.                     'subtotalProduct' => $subtotalProduct,
  9132.                     // 'iva' => $iva,
  9133.                     'iva' => $item->getIva(),
  9134.                     'pax' => $pax,
  9135.                     'qty' => $qty,
  9136.                     'days' => $days,
  9137.                     'type' => $item->getType(),
  9138.                     'subtotal' => $subtotal,
  9139.                 );
  9140.             }
  9141.             $i++;
  9142.         }
  9143.         $data_supplier['productSubTotal'] = array(
  9144.             'neto' => $product['neto'],
  9145.             'sumSubT' => $product['sumSubT'],
  9146.         );
  9147.         $payment = array(
  9148.             'sumSubT' => 0,
  9149.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  9150.         $i 0;
  9151.         foreach ($payments as $item) {
  9152.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  9153.                 //                $payment['sumSubT'] = $payment['sumSubT'] + $item->getPayAmount();
  9154.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getPayAmountTotal();
  9155.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  9156.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  9157.                 $data_supplier['payment'][$i] = array(
  9158.                     'id' => $item->getId(),
  9159.                     'amount' => $item->getPayAmount(),
  9160.                     'amountTotal' => $item->getPayAmountTotal(),
  9161.                     'vat' => $item->getPayVat(),
  9162.                     'datePayAt' => $item->getPayDatePayAt(),
  9163.                     'wayToPay' => $item->getPayWayToPay(),
  9164.                 );
  9165.                 $arrayItems[] = array(
  9166.                     'type' => 'Payment',
  9167.                     'name' => $item->getPayWayToPay(),
  9168.                     'amount' => $item->getPayAmount(),
  9169.                     'total' => $item->getPayAmountTotal(),
  9170.                     'iva' => $item->getPayVat(),
  9171.                     //                    'iva' => '',
  9172.                     //                    'total' => $item->getPayAmount(),
  9173.                 );
  9174.             } else {
  9175.                 // Es una proforma
  9176.                 //                $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmount();
  9177.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  9178.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  9179.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  9180.                 $data_supplier['payment'][$i] = array(
  9181.                     'id' => $item->getId(),
  9182.                     'amount' => $item->getAmount(),
  9183.                     'amountTotal' => $item->getAmountTotal(),
  9184.                     'vat' => $item->getVat(),
  9185.                     'datePayAt' => $item->getDatePayAt(),
  9186.                     'wayToPay' => $item->getWayToPay(),
  9187.                 );
  9188.                 $arrayItems[] = array(
  9189.                     'type' => 'Payment',
  9190.                     'name' => $item->getWayToPay(),
  9191.                     'amount' => $item->getAmount(),
  9192.                     'total' => $item->getAmountTotal(),
  9193.                     'iva' => $item->getVat(),
  9194.                     //                    'iva' => '',
  9195.                     //                    'total' => $item->getAmount(),
  9196.                 );
  9197.             }
  9198.             $i++;
  9199.         }
  9200.         if (!empty($payments)) {
  9201.             $data_supplier['paymentSubTotal'] = array(
  9202.                 'sumSubT' => $payment['sumSubT'],
  9203.             );
  9204.         }
  9205.         foreach ($services as $item) {
  9206.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  9207.                 if (is_null($item->getSrvPrice()) or empty($item->getSrvPrice())) {
  9208.                     $subtotal 0;
  9209.                     $neto 0;
  9210.                     $subtotalService 0;
  9211.                 } else {
  9212.                     $subtotalService $item->getSrvPrice();
  9213.                     $subneto $item->getSrvPrice();
  9214.                     // Commission
  9215.                     if ($item->getSrvOpCommission() == '1') {
  9216.                         $subtotalService $subtotalService * (+ ($item->getSrvCommission() / 100));
  9217.                         $subneto $subneto * (+ ($item->getSrvCommission() / 100));
  9218.                     } else {
  9219.                         $subtotalService $subtotalService * (- ($item->getSrvCommission() / 100));
  9220.                         $subneto $subneto * (- ($item->getSrvCommission() / 100));
  9221.                     }
  9222.                     // Over
  9223.                     if ($item->getSrvOpOver() == '1') {
  9224.                         $subtotalService $subtotalService $item->getSrvOver();
  9225.                         $subneto $subneto $item->getSrvOver();
  9226.                     } else {
  9227.                         $subtotalService $subtotalService $item->getSrvOver();
  9228.                         $subneto $subneto $item->getSrvOver();
  9229.                     }
  9230.                     // IVA
  9231.                     if ($item->getSrvOpIva() == '1') {
  9232.                         $subtotalService $subtotalService * (+ ($item->getSrvIva() / 100));
  9233.                     } else {
  9234.                         $subtotalService $item->getSrvPrice();
  9235.                         $subneto = ($subneto 100) / (100 $item->getSrvIva());
  9236.                     }
  9237.                     switch ($item->getSrvServiceCatId()) {
  9238.                         case 1// Alojamiento
  9239.                             // el numero de noches $numNoches; precio unitario $subneto
  9240.                             $numNoches = (($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days;
  9241.                             // La personas no afectan este calculo
  9242.                             $subtotal $subtotalService $numNoches $item->getSrvUnits();
  9243.                             $subnetoUnit $subneto;
  9244.                             $subneto $subneto $numNoches $item->getSrvUnits();
  9245.                             $data_supplier['service'][$i] = array(
  9246.                                 'id' => $item->getId(),
  9247.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9248.                                 'serviceName' => $item->getSrvName(),
  9249.                                 'serviceType' => 'Hotel',
  9250.                                 'date' => ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y'),
  9251.                                 'qty' => $item->getSrvUnits(),
  9252.                                 'iva' => $item->getSrvIva(),
  9253.                                 'pax' => '-',
  9254.                                 'precioUnit' => $subnetoUnit,
  9255.                                 'subneto' => $subneto,
  9256.                                 'subtotal' => $subtotal,
  9257.                             );
  9258.                             break;
  9259.                         case 2//Actividades
  9260.                             // El nĂºmero de personas es considerado en el calculo
  9261.                             $pax $item->getSrvPax();
  9262.                             if (empty($pax) or $pax == "0") {
  9263.                                 $pax 1;
  9264.                             }
  9265.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9266.                             if ($days 1) {
  9267.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9268.                             } else {
  9269.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9270.                             }
  9271.                             $subtotal $subtotalService $days $item->getSrvUnits();
  9272.                             $subnetoUnit $subneto;
  9273.                             $subneto $subneto $days $item->getSrvUnits();
  9274.                             $data_supplier['service'][$i] = array(
  9275.                                 'id' => $item->getId(),
  9276.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9277.                                 'serviceName' => $item->getSrvName(),
  9278.                                 'serviceType' => 'Actividad',
  9279.                                 'date' => $dateServ,
  9280.                                 'qty' => $item->getSrvUnits(),
  9281.                                 'iva' => $item->getSrvIva(),
  9282.                                 'pax' => $item->getSrvPax(),
  9283.                                 'precioUnit' => $subnetoUnit,
  9284.                                 'subneto' => $subneto,
  9285.                                 'subtotal' => $subtotal,
  9286.                             );
  9287.                             break;
  9288.                         case 3// AV
  9289.                             $pax $item->getSrvPax();
  9290.                             if (empty($pax) or $pax == "0") {
  9291.                                 $pax 1;
  9292.                             }
  9293.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9294.                             if ($days 1) {
  9295.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9296.                             } else {
  9297.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9298.                             }
  9299.                             $unitsServ $item->getSrvUnits();
  9300.                             if (empty($unitsServ) or $unitsServ == "0") {
  9301.                                 $unitsServ 1;
  9302.                             }
  9303.                             $subtotal $subtotalService $days $unitsServ $pax;
  9304.                             $subnetoUnit $subneto;
  9305.                             $subneto $subneto $days $unitsServ $pax;
  9306.                             $data_supplier['service'][$i] = array(
  9307.                                 'id' => $item->getId(),
  9308.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9309.                                 'serviceName' => $item->getSrvName(),
  9310.                                 'serviceType' => 'AV',
  9311.                                 'date' => $dateServ,
  9312.                                 'qty' => $unitsServ,
  9313.                                 'iva' => $item->getSrvIva(),
  9314.                                 'pax' => $item->getSrvPax(),
  9315.                                 'precioUnit' => $subnetoUnit,
  9316.                                 'subneto' => $subneto,
  9317.                                 'subtotal' => $subtotal,
  9318.                             );
  9319.                             break;
  9320.                         case 4//Creative
  9321.                             $pax $item->getSrvPax();
  9322.                             if (empty($pax) or $pax == "0") {
  9323.                                 $pax 1;
  9324.                             }
  9325.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9326.                             if ($days 1) {
  9327.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9328.                             } else {
  9329.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9330.                             }
  9331.                             $unitsServ $item->getSrvUnits();
  9332.                             if (empty($unitsServ) or $unitsServ == "0") {
  9333.                                 $unitsServ 1;
  9334.                             }
  9335.                             $subtotal $subtotalService $days $unitsServ $pax;
  9336.                             $subnetoUnit $subneto;
  9337.                             $subneto $subneto $days $unitsServ $pax;
  9338.                             $data_supplier['service'][$i] = array(
  9339.                                 'id' => $item->getId(),
  9340.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9341.                                 'serviceName' => $item->getSrvName(),
  9342.                                 'serviceType' => 'Creativo',
  9343.                                 'date' => $dateServ,
  9344.                                 'qty' => $unitsServ,
  9345.                                 'iva' => $item->getSrvIva(),
  9346.                                 'pax' => $item->getSrvPax(),
  9347.                                 'precioUnit' => $subnetoUnit,
  9348.                                 'subneto' => $subneto,
  9349.                                 'subtotal' => $subtotal,
  9350.                             );
  9351.                             break;
  9352.                         case 5//Cruise
  9353.                             $pax $item->getSrvPax();
  9354.                             if (empty($pax) or $pax == "0") {
  9355.                                 $pax 1;
  9356.                             }
  9357.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days);
  9358.                             if ($days 1) {
  9359.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9360.                             } else {
  9361.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9362.                             }
  9363.                             $unitsServ $item->getSrvUnits();
  9364.                             if (empty($unitsServ) or $unitsServ == "0") {
  9365.                                 $unitsServ 1;
  9366.                             }
  9367.                             $subtotal $subtotalService $days $unitsServ $pax;
  9368.                             $subnetoUnit $subneto;
  9369.                             $subneto $subneto $days $unitsServ $pax;
  9370.                             $data_supplier['service'][$i] = array(
  9371.                                 'id' => $item->getId(),
  9372.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9373.                                 'serviceName' => $item->getSrvName(),
  9374.                                 'serviceType' => 'Crucero',
  9375.                                 'date' => $dateServ,
  9376.                                 'qty' => $unitsServ,
  9377.                                 'iva' => $item->getSrvIva(),
  9378.                                 'pax' => $item->getSrvPax(),
  9379.                                 'precioUnit' => $subnetoUnit,
  9380.                                 'subneto' => $subneto,
  9381.                                 'subtotal' => $subtotal,
  9382.                             );
  9383.                             break;
  9384.                         case 6//Entertaiment
  9385.                             $pax $item->getSrvPax();
  9386.                             if (empty($pax) or $pax == "0") {
  9387.                                 $pax 1;
  9388.                             }
  9389.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9390.                             if ($days 1) {
  9391.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9392.                             } else {
  9393.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9394.                             }
  9395.                             $unitsServ $item->getSrvUnits();
  9396.                             if (empty($unitsServ) or $unitsServ == "0") {
  9397.                                 $unitsServ 1;
  9398.                             }
  9399.                             $subtotal $subtotalService $days $unitsServ $pax;
  9400.                             $subnetoUnit $subneto;
  9401.                             $subneto $subneto $days $unitsServ $pax;
  9402.                             $data_supplier['service'][$i] = array(
  9403.                                 'id' => $item->getId(),
  9404.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9405.                                 'serviceName' => $item->getSrvName(),
  9406.                                 'serviceType' => 'Entretenimiento',
  9407.                                 'date' => $dateServ,
  9408.                                 'qty' => $unitsServ,
  9409.                                 'iva' => $item->getSrvIva(),
  9410.                                 'pax' => $item->getSrvPax(),
  9411.                                 'precioUnit' => $subnetoUnit,
  9412.                                 'subneto' => $subneto,
  9413.                                 'subtotal' => $subtotal,
  9414.                             );
  9415.                             break;
  9416.                         case 7// Gifts
  9417.                             $pax $item->getSrvPax();
  9418.                             if (empty($pax) or $pax == "0") {
  9419.                                 $pax 1;
  9420.                             }
  9421.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  9422.                             $days 1;
  9423.                             if ($days 1) {
  9424.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9425.                             } else {
  9426.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9427.                             }
  9428.                             $unitsServ $item->getSrvUnits();
  9429.                             if (empty($unitsServ) or $unitsServ == "0") {
  9430.                                 $unitsServ 1;
  9431.                             }
  9432.                             $subtotal $subtotalService $days $unitsServ $pax;
  9433.                             $subnetoUnit $subneto;
  9434.                             $subneto $subneto $days $unitsServ $pax;
  9435.                             $data_supplier['service'][$i] = array(
  9436.                                 'id' => $item->getId(),
  9437.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9438.                                 'serviceName' => $item->getSrvName(),
  9439.                                 'serviceType' => 'Regalos',
  9440.                                 'date' => $dateServ,
  9441.                                 'qty' => $unitsServ,
  9442.                                 'iva' => $item->getSrvIva(),
  9443.                                 'pax' => $item->getSrvPax(),
  9444.                                 'precioUnit' => $subnetoUnit,
  9445.                                 'subneto' => $subneto,
  9446.                                 'subtotal' => $subtotal,
  9447.                             );
  9448.                             break;
  9449.                         case 8//Guide
  9450.                             $pax $item->getSrvPax();
  9451.                             if (empty($pax) or $pax == "0") {
  9452.                                 $pax 1;
  9453.                             }
  9454.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9455.                             if ($days 1) {
  9456.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9457.                             } else {
  9458.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9459.                             }
  9460.                             $unitsServ $item->getSrvUnits();
  9461.                             if (empty($unitsServ) or $unitsServ == "0") {
  9462.                                 $unitsServ 1;
  9463.                             }
  9464.                             $subtotal $subtotalService $days $unitsServ $pax;
  9465.                             $subnetoUnit $subneto;
  9466.                             $subneto $subneto $days $unitsServ $pax;
  9467.                             $data_supplier['service'][$i] = array(
  9468.                                 'id' => $item->getId(),
  9469.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9470.                                 'serviceName' => $item->getSrvName(),
  9471.                                 'serviceType' => 'Regalos',
  9472.                                 'date' => $dateServ,
  9473.                                 'qty' => $unitsServ,
  9474.                                 'iva' => $item->getSrvIva(),
  9475.                                 'pax' => $item->getSrvPax(),
  9476.                                 'precioUnit' => $subnetoUnit,
  9477.                                 'subneto' => $subneto,
  9478.                                 'subtotal' => $subtotal,
  9479.                             );
  9480.                             break;
  9481.                         case 9//Itineraries
  9482.                             $pax $item->getSrvPax();
  9483.                             if (empty($pax) or $pax == "0") {
  9484.                                 $pax 1;
  9485.                             }
  9486.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9487.                             if ($days 1) {
  9488.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9489.                             } else {
  9490.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9491.                             }
  9492.                             $unitsServ $item->getSrvUnits();
  9493.                             if (empty($unitsServ) or $unitsServ == "0") {
  9494.                                 $unitsServ 1;
  9495.                             }
  9496.                             $subtotal $subtotalService $days $unitsServ $pax;
  9497.                             $subnetoUnit $subneto;
  9498.                             $subneto $subneto $days $unitsServ $pax;
  9499.                             $data_supplier['service'][$i] = array(
  9500.                                 'id' => $item->getId(),
  9501.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9502.                                 'serviceName' => $item->getSrvName(),
  9503.                                 'serviceType' => 'Itinerarios',
  9504.                                 'date' => $dateServ,
  9505.                                 'qty' => $unitsServ,
  9506.                                 'iva' => $item->getSrvIva(),
  9507.                                 'pax' => $item->getSrvPax(),
  9508.                                 'precioUnit' => $subnetoUnit,
  9509.                                 'subneto' => $subneto,
  9510.                                 'subtotal' => $subtotal,
  9511.                             );
  9512.                             break;
  9513.                         case 10//Lounge  -- No Aplica
  9514.                             //                        $pax = $item->getPax();
  9515.                             //                        if (empty($pax) or $pax == "0") {
  9516.                             //                            $pax = 1;
  9517.                             //                        }
  9518.                             //
  9519.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  9520.                             //                        if ($days > 1){
  9521.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  9522.                             //                        } else {
  9523.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9524.                             //                        }
  9525.                             //
  9526.                             //                        $unitsServ = $item->getUnits();
  9527.                             //                        if (empty($unitsServ) or $unitsServ == "0") {
  9528.                             //                            $unitsServ = 1;
  9529.                             //                        }
  9530.                             //
  9531.                             //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  9532.                             //                        $subnetoUnit = $subneto;
  9533.                             //                        $subneto = $subneto * $days * $unitsServ * $pax;
  9534.                             //
  9535.                             //                        $data_supplier['service'][$i] = array (
  9536.                             //                            'id' => $item->getId(),
  9537.                             //                            'serviceCatId' => $item->getServiceCatId(),
  9538.                             //                            'serviceName' => $item->getName(),
  9539.                             //                            'serviceType' => 'Itinerarios',
  9540.                             //                            'date' => $dateServ,
  9541.                             //                            'qty' => $unitsServ,
  9542.                             //                            'iva' => $item->getIva(),
  9543.                             //                            'pax' => $item->getPax(),
  9544.                             //                            'precioUnit' => $subnetoUnit,
  9545.                             //                            'subneto' => $subneto,
  9546.                             //                            'subtotal' => $subtotal,
  9547.                             //                        );
  9548.                             break;
  9549.                         case 11//Menu
  9550.                             $pax $item->getSrvPax();
  9551.                             if (empty($pax) or $pax == "0") {
  9552.                                 $pax 1;
  9553.                             }
  9554.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9555.                             if ($days 1) {
  9556.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9557.                             } else {
  9558.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9559.                             }
  9560.                             $unitsServ $item->getSrvUnits();
  9561.                             if (empty($unitsServ) or $unitsServ == "0") {
  9562.                                 $unitsServ 1;
  9563.                             }
  9564.                             $subtotal $subtotalService $days $unitsServ $pax;
  9565.                             $subnetoUnit $subneto;
  9566.                             $subneto $subneto $days $unitsServ $pax;
  9567.                             $data_supplier['service'][$i] = array(
  9568.                                 'id' => $item->getId(),
  9569.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9570.                                 'serviceName' => $item->getSrvName(),
  9571.                                 'serviceType' => 'MenĂº',
  9572.                                 'date' => $dateServ,
  9573.                                 'qty' => $unitsServ,
  9574.                                 'iva' => $item->getSrvIva(),
  9575.                                 'pax' => $item->getSrvPax(),
  9576.                                 'precioUnit' => $subnetoUnit,
  9577.                                 'subneto' => $subneto,
  9578.                                 'subtotal' => $subtotal,
  9579.                             );
  9580.                             break;
  9581.                         case 12//Others
  9582.                             $pax $item->getSrvPax();
  9583.                             if (empty($pax) or $pax == "0") {
  9584.                                 $pax 1;
  9585.                             }
  9586.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9587.                             if ($days 1) {
  9588.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9589.                             } else {
  9590.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9591.                             }
  9592.                             $unitsServ $item->getSrvUnits();
  9593.                             if (empty($unitsServ) or $unitsServ == "0") {
  9594.                                 $unitsServ 1;
  9595.                             }
  9596.                             $subtotal $subtotalService $days $unitsServ $pax;
  9597.                             $subnetoUnit $subneto;
  9598.                             $subneto $subneto $days $unitsServ $pax;
  9599.                             $data_supplier['service'][$i] = array(
  9600.                                 'id' => $item->getId(),
  9601.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9602.                                 'serviceName' => $item->getSrvName(),
  9603.                                 'serviceType' => 'Otros',
  9604.                                 'date' => $dateServ,
  9605.                                 'qty' => $unitsServ,
  9606.                                 'iva' => $item->getSrvIva(),
  9607.                                 'pax' => $item->getSrvPax(),
  9608.                                 'precioUnit' => $subnetoUnit,
  9609.                                 'subneto' => $subneto,
  9610.                                 'subtotal' => $subtotal,
  9611.                             );
  9612.                             break;
  9613.                         case 13//Transport
  9614.                             $pax $item->getSrvPax();
  9615.                             if (empty($pax) or $pax == "0") {
  9616.                                 $pax 1;
  9617.                             }
  9618.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9619.                             if ($days 1) {
  9620.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9621.                             } else {
  9622.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9623.                             }
  9624.                             $unitsServ $item->getSrvUnits();
  9625.                             if (empty($unitsServ) or $unitsServ == "0") {
  9626.                                 $unitsServ 1;
  9627.                             }
  9628.                             $subtotal $subtotalService $days $unitsServ $pax;
  9629.                             $subnetoUnit $subneto;
  9630.                             $subneto $subneto $days $unitsServ $pax;
  9631.                             $data_supplier['service'][$i] = array(
  9632.                                 'id' => $item->getId(),
  9633.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9634.                                 'serviceName' => $item->getSrvName(),
  9635.                                 'serviceType' => 'Transporte',
  9636.                                 'date' => $dateServ,
  9637.                                 'qty' => $unitsServ,
  9638.                                 'iva' => $item->getSrvIva(),
  9639.                                 'pax' => $item->getSrvPax(),
  9640.                                 'precioUnit' => $subnetoUnit,
  9641.                                 'subneto' => $subneto,
  9642.                                 'subtotal' => $subtotal,
  9643.                             );
  9644.                             break;
  9645.                         case 14//Technology
  9646.                             $pax $item->getSrvPax();
  9647.                             if (empty($pax) or $pax == "0") {
  9648.                                 $pax 1;
  9649.                             }
  9650.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  9651.                             $days 1;
  9652.                             //                        if ($days > 1){
  9653.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  9654.                             //                        } else {
  9655.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9656.                             //                        }
  9657.                             $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9658.                             $unitsServ $item->getSrvUnits();
  9659.                             if (empty($unitsServ) or $unitsServ == "0") {
  9660.                                 $unitsServ 1;
  9661.                             }
  9662.                             $subtotal $subtotalService $days $unitsServ $pax;
  9663.                             $subnetoUnit $subneto;
  9664.                             $subneto $subneto $days $unitsServ $pax;
  9665.                             $data_supplier['service'][$i] = array(
  9666.                                 'id' => $item->getId(),
  9667.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9668.                                 'serviceName' => $item->getSrvName(),
  9669.                                 'serviceType' => 'TecnologĂ­a',
  9670.                                 'date' => $dateServ,
  9671.                                 'qty' => $unitsServ,
  9672.                                 'iva' => $item->getSrvIva(),
  9673.                                 'pax' => $item->getSrvPax(),
  9674.                                 'precioUnit' => $subnetoUnit,
  9675.                                 'subneto' => $subneto,
  9676.                                 'subtotal' => $subtotal,
  9677.                             );
  9678.                             break;
  9679.                         case 15//Assisstant
  9680.                             $pax $item->getSrvPax();
  9681.                             if (empty($pax) or $pax == "0") {
  9682.                                 $pax 1;
  9683.                             }
  9684.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9685.                             if ($days 1) {
  9686.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9687.                             } else {
  9688.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9689.                             }
  9690.                             $unitsServ $item->getSrvUnits();
  9691.                             if (empty($unitsServ) or $unitsServ == "0") {
  9692.                                 $unitsServ 1;
  9693.                             }
  9694.                             $subtotal $subtotalService $days $unitsServ $pax;
  9695.                             $subnetoUnit $subneto;
  9696.                             $subneto $subneto $days $unitsServ $pax;
  9697.                             $data_supplier['service'][$i] = array(
  9698.                                 'id' => $item->getId(),
  9699.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9700.                                 'serviceName' => $item->getSrvName(),
  9701.                                 'serviceType' => 'Asistente',
  9702.                                 'date' => $dateServ,
  9703.                                 'qty' => $unitsServ,
  9704.                                 'iva' => $item->getSrvIva(),
  9705.                                 'pax' => $item->getSrvPax(),
  9706.                                 'precioUnit' => $subnetoUnit,
  9707.                                 'subneto' => $subneto,
  9708.                                 'subtotal' => $subtotal,
  9709.                             );
  9710.                             break;
  9711.                         case 16//DDR
  9712.                             $pax $item->getSrvPax();
  9713.                             if (empty($pax) or $pax == "0") {
  9714.                                 $pax 1;
  9715.                             }
  9716.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9717.                             if ($days 1) {
  9718.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9719.                             } else {
  9720.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9721.                             }
  9722.                             $unitsServ $item->getSrvUnits();
  9723.                             if (empty($unitsServ) or $unitsServ == "0") {
  9724.                                 $unitsServ 1;
  9725.                             }
  9726.                             $subtotal $subtotalService $days $unitsServ $pax;
  9727.                             $subnetoUnit $subneto;
  9728.                             $subneto $subneto $days $unitsServ $pax;
  9729.                             $data_supplier['service'][$i] = array(
  9730.                                 'id' => $item->getId(),
  9731.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9732.                                 'serviceName' => $item->getSrvName(),
  9733.                                 'serviceType' => 'DDR',
  9734.                                 'date' => $dateServ,
  9735.                                 'qty' => $unitsServ,
  9736.                                 'iva' => $item->getSrvIva(),
  9737.                                 'pax' => $item->getSrvPax(),
  9738.                                 'precioUnit' => $subnetoUnit,
  9739.                                 'subneto' => $subneto,
  9740.                                 'subtotal' => $subtotal,
  9741.                             );
  9742.                             break;
  9743.                         default:
  9744.                             break;
  9745.                     }
  9746.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  9747.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  9748.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  9749.                     $arrayItems[] = array(
  9750.                         'type' => 'Service',
  9751.                         'name' => $item->getSrvName(),
  9752.                         'amount' => $neto,
  9753.                         'iva' => $item->getSrvIva(),
  9754.                         'total' => $subtotal,
  9755.                     );
  9756.                 }
  9757.                 switch ($item->getSrvIva()) {
  9758.                         // Acumula IVA
  9759.                     case 21:
  9760.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getSrvIva() / 100));
  9761.                         break;
  9762.                     case 10:
  9763.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getSrvIva() / 100));
  9764.                         break;
  9765.                     case 0:
  9766.                         break;
  9767.                     default:
  9768.                         break;
  9769.                 }
  9770.             } else {
  9771.                 // Es una proforma
  9772.                 if (is_null($item->getPrice()) or empty($item->getPrice())) {
  9773.                     $subtotal 0;
  9774.                     $neto 0;
  9775.                     $subtotalService 0;
  9776.                 } else {
  9777.                     $subtotalService $item->getPrice();
  9778.                     $subneto $item->getPrice();
  9779.                     // Commission
  9780.                     if ($item->getOpCommission() == '1') {
  9781.                         $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  9782.                         $subneto $subneto * (+ ($item->getCommission() / 100));
  9783.                     } else {
  9784.                         $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  9785.                         $subneto $subneto * (- ($item->getCommission() / 100));
  9786.                     }
  9787.                     // Over
  9788.                     if ($item->getOpOver() == '1') {
  9789.                         $subtotalService $subtotalService $item->getOver();
  9790.                         $subneto $subneto $item->getOver();
  9791.                     } else {
  9792.                         $subtotalService $subtotalService $item->getOver();
  9793.                         $subneto $subneto $item->getOver();
  9794.                     }
  9795.                     // IVA
  9796.                     if ($item->getOpIva() == '1') {
  9797.                         $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  9798.                     } else {
  9799.                         $subtotalService $item->getPrice();
  9800.                         $subneto = ($subneto 100) / (100 $item->getIva());
  9801.                     }
  9802.                     switch ($item->getServiceCatId()) {
  9803.                         case 1// Alojamiento
  9804.                             // el numero de noches $numNoches; precio unitario $subneto
  9805.                             $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  9806.                             // La personas no afectan este calculo
  9807.                             $subtotal $subtotalService $numNoches $item->getUnits();
  9808.                             $subnetoUnit $subneto;
  9809.                             $subneto $subneto $numNoches $item->getUnits();
  9810.                             $data_supplier['service'][$i] = array(
  9811.                                 'id' => $item->getId(),
  9812.                                 'serviceCatId' => $item->getServiceCatId(),
  9813.                                 'serviceName' => $item->getName(),
  9814.                                 'serviceType' => 'Hotel',
  9815.                                 'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  9816.                                 'qty' => $item->getUnits(),
  9817.                                 'iva' => $item->getIva(),
  9818.                                 'pax' => '-',
  9819.                                 'precioUnit' => $subnetoUnit,
  9820.                                 'subneto' => $subneto,
  9821.                                 'subtotal' => $subtotal,
  9822.                             );
  9823.                             break;
  9824.                         case 2//Actividades
  9825.                             // El nĂºmero de personas es considerado en el calculo
  9826.                             $pax $item->getPax();
  9827.                             if (empty($pax) or $pax == "0") {
  9828.                                 $pax 1;
  9829.                             }
  9830.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9831.                             if ($days 1) {
  9832.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9833.                             } else {
  9834.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9835.                             }
  9836.                             $subtotal $subtotalService $days $item->getUnits();
  9837.                             $subnetoUnit $subneto;
  9838.                             $subneto $subneto $days $item->getUnits();
  9839.                             $data_supplier['service'][$i] = array(
  9840.                                 'id' => $item->getId(),
  9841.                                 'serviceCatId' => $item->getServiceCatId(),
  9842.                                 'serviceName' => $item->getName(),
  9843.                                 'serviceType' => 'Actividad',
  9844.                                 'date' => $dateServ,
  9845.                                 'qty' => $item->getUnits(),
  9846.                                 'iva' => $item->getIva(),
  9847.                                 'pax' => $item->getPax(),
  9848.                                 'precioUnit' => $subnetoUnit,
  9849.                                 'subneto' => $subneto,
  9850.                                 'subtotal' => $subtotal,
  9851.                             );
  9852.                             break;
  9853.                         case 3// AV
  9854.                             $pax $item->getPax();
  9855.                             if (empty($pax) or $pax == "0") {
  9856.                                 $pax 1;
  9857.                             }
  9858.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9859.                             if ($days 1) {
  9860.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9861.                             } else {
  9862.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9863.                             }
  9864.                             $unitsServ $item->getUnits();
  9865.                             if (empty($unitsServ) or $unitsServ == "0") {
  9866.                                 $unitsServ 1;
  9867.                             }
  9868.                             $subtotal $subtotalService $days $unitsServ $pax;
  9869.                             $subnetoUnit $subneto;
  9870.                             $subneto $subneto $days $unitsServ $pax;
  9871.                             $data_supplier['service'][$i] = array(
  9872.                                 'id' => $item->getId(),
  9873.                                 'serviceCatId' => $item->getServiceCatId(),
  9874.                                 'serviceName' => $item->getName(),
  9875.                                 'serviceType' => 'AV',
  9876.                                 'date' => $dateServ,
  9877.                                 'qty' => $unitsServ,
  9878.                                 'iva' => $item->getIva(),
  9879.                                 'pax' => $item->getPax(),
  9880.                                 'precioUnit' => $subnetoUnit,
  9881.                                 'subneto' => $subneto,
  9882.                                 'subtotal' => $subtotal,
  9883.                             );
  9884.                             break;
  9885.                         case 4//Creative
  9886.                             $pax $item->getPax();
  9887.                             if (empty($pax) or $pax == "0") {
  9888.                                 $pax 1;
  9889.                             }
  9890.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9891.                             if ($days 1) {
  9892.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9893.                             } else {
  9894.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9895.                             }
  9896.                             $unitsServ $item->getUnits();
  9897.                             if (empty($unitsServ) or $unitsServ == "0") {
  9898.                                 $unitsServ 1;
  9899.                             }
  9900.                             $subtotal $subtotalService $days $unitsServ $pax;
  9901.                             $subnetoUnit $subneto;
  9902.                             $subneto $subneto $days $unitsServ $pax;
  9903.                             $data_supplier['service'][$i] = array(
  9904.                                 'id' => $item->getId(),
  9905.                                 'serviceCatId' => $item->getServiceCatId(),
  9906.                                 'serviceName' => $item->getName(),
  9907.                                 'serviceType' => 'Creativo',
  9908.                                 'date' => $dateServ,
  9909.                                 'qty' => $unitsServ,
  9910.                                 'iva' => $item->getIva(),
  9911.                                 'pax' => $item->getPax(),
  9912.                                 'precioUnit' => $subnetoUnit,
  9913.                                 'subneto' => $subneto,
  9914.                                 'subtotal' => $subtotal,
  9915.                             );
  9916.                             break;
  9917.                         case 5//Cruise
  9918.                             $pax $item->getPax();
  9919.                             if (empty($pax) or $pax == "0") {
  9920.                                 $pax 1;
  9921.                             }
  9922.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  9923.                             if ($days 1) {
  9924.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9925.                             } else {
  9926.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9927.                             }
  9928.                             $unitsServ $item->getUnits();
  9929.                             if (empty($unitsServ) or $unitsServ == "0") {
  9930.                                 $unitsServ 1;
  9931.                             }
  9932.                             $subtotal $subtotalService $days $unitsServ $pax;
  9933.                             $subnetoUnit $subneto;
  9934.                             $subneto $subneto $days $unitsServ $pax;
  9935.                             $data_supplier['service'][$i] = array(
  9936.                                 'id' => $item->getId(),
  9937.                                 'serviceCatId' => $item->getServiceCatId(),
  9938.                                 'serviceName' => $item->getName(),
  9939.                                 'serviceType' => 'Crucero',
  9940.                                 'date' => $dateServ,
  9941.                                 'qty' => $unitsServ,
  9942.                                 'iva' => $item->getIva(),
  9943.                                 'pax' => $item->getPax(),
  9944.                                 'precioUnit' => $subnetoUnit,
  9945.                                 'subneto' => $subneto,
  9946.                                 'subtotal' => $subtotal,
  9947.                             );
  9948.                             break;
  9949.                         case 6//Entertaiment
  9950.                             $pax $item->getPax();
  9951.                             if (empty($pax) or $pax == "0") {
  9952.                                 $pax 1;
  9953.                             }
  9954.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9955.                             if ($days 1) {
  9956.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9957.                             } else {
  9958.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9959.                             }
  9960.                             $unitsServ $item->getUnits();
  9961.                             if (empty($unitsServ) or $unitsServ == "0") {
  9962.                                 $unitsServ 1;
  9963.                             }
  9964.                             $subtotal $subtotalService $days $unitsServ $pax;
  9965.                             $subnetoUnit $subneto;
  9966.                             $subneto $subneto $days $unitsServ $pax;
  9967.                             $data_supplier['service'][$i] = array(
  9968.                                 'id' => $item->getId(),
  9969.                                 'serviceCatId' => $item->getServiceCatId(),
  9970.                                 'serviceName' => $item->getName(),
  9971.                                 'serviceType' => 'Entretenimiento',
  9972.                                 'date' => $dateServ,
  9973.                                 'qty' => $unitsServ,
  9974.                                 'iva' => $item->getIva(),
  9975.                                 'pax' => $item->getPax(),
  9976.                                 'precioUnit' => $subnetoUnit,
  9977.                                 'subneto' => $subneto,
  9978.                                 'subtotal' => $subtotal,
  9979.                             );
  9980.                             break;
  9981.                         case 7// Gifts
  9982.                             $pax $item->getPax();
  9983.                             if (empty($pax) or $pax == "0") {
  9984.                                 $pax 1;
  9985.                             }
  9986.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  9987.                             $days 1;
  9988.                             if ($days 1) {
  9989.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9990.                             } else {
  9991.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9992.                             }
  9993.                             $unitsServ $item->getUnits();
  9994.                             if (empty($unitsServ) or $unitsServ == "0") {
  9995.                                 $unitsServ 1;
  9996.                             }
  9997.                             $subtotal $subtotalService $days $unitsServ $pax;
  9998.                             $subnetoUnit $subneto;
  9999.                             $subneto $subneto $days $unitsServ $pax;
  10000.                             $data_supplier['service'][$i] = array(
  10001.                                 'id' => $item->getId(),
  10002.                                 'serviceCatId' => $item->getServiceCatId(),
  10003.                                 'serviceName' => $item->getName(),
  10004.                                 'serviceType' => 'Regalos',
  10005.                                 'date' => $dateServ,
  10006.                                 'qty' => $unitsServ,
  10007.                                 'iva' => $item->getIva(),
  10008.                                 'pax' => $item->getPax(),
  10009.                                 'precioUnit' => $subnetoUnit,
  10010.                                 'subneto' => $subneto,
  10011.                                 'subtotal' => $subtotal,
  10012.                             );
  10013.                             break;
  10014.                         case 8//Guide
  10015.                             $pax $item->getPax();
  10016.                             if (empty($pax) or $pax == "0") {
  10017.                                 $pax 1;
  10018.                             }
  10019.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10020.                             if ($days 1) {
  10021.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10022.                             } else {
  10023.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10024.                             }
  10025.                             $unitsServ $item->getUnits();
  10026.                             if (empty($unitsServ) or $unitsServ == "0") {
  10027.                                 $unitsServ 1;
  10028.                             }
  10029.                             $subtotal $subtotalService $days $unitsServ $pax;
  10030.                             $subnetoUnit $subneto;
  10031.                             $subneto $subneto $days $unitsServ $pax;
  10032.                             $data_supplier['service'][$i] = array(
  10033.                                 'id' => $item->getId(),
  10034.                                 'serviceCatId' => $item->getServiceCatId(),
  10035.                                 'serviceName' => $item->getName(),
  10036.                                 'serviceType' => 'Regalos',
  10037.                                 'date' => $dateServ,
  10038.                                 'qty' => $unitsServ,
  10039.                                 'iva' => $item->getIva(),
  10040.                                 'pax' => $item->getPax(),
  10041.                                 'precioUnit' => $subnetoUnit,
  10042.                                 'subneto' => $subneto,
  10043.                                 'subtotal' => $subtotal,
  10044.                             );
  10045.                             break;
  10046.                         case 9//Itineraries
  10047.                             $pax $item->getPax();
  10048.                             if (empty($pax) or $pax == "0") {
  10049.                                 $pax 1;
  10050.                             }
  10051.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10052.                             if ($days 1) {
  10053.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10054.                             } else {
  10055.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10056.                             }
  10057.                             $unitsServ $item->getUnits();
  10058.                             if (empty($unitsServ) or $unitsServ == "0") {
  10059.                                 $unitsServ 1;
  10060.                             }
  10061.                             $subtotal $subtotalService $days $unitsServ $pax;
  10062.                             $subnetoUnit $subneto;
  10063.                             $subneto $subneto $days $unitsServ $pax;
  10064.                             $data_supplier['service'][$i] = array(
  10065.                                 'id' => $item->getId(),
  10066.                                 'serviceCatId' => $item->getServiceCatId(),
  10067.                                 'serviceName' => $item->getName(),
  10068.                                 'serviceType' => 'Itinerarios',
  10069.                                 'date' => $dateServ,
  10070.                                 'qty' => $unitsServ,
  10071.                                 'iva' => $item->getIva(),
  10072.                                 'pax' => $item->getPax(),
  10073.                                 'precioUnit' => $subnetoUnit,
  10074.                                 'subneto' => $subneto,
  10075.                                 'subtotal' => $subtotal,
  10076.                             );
  10077.                             break;
  10078.                         case 10//Lounge  -- No Aplica
  10079.                             //                        $pax = $item->getPax();
  10080.                             //                        if (empty($pax) or $pax == "0") {
  10081.                             //                            $pax = 1;
  10082.                             //                        }
  10083.                             //
  10084.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  10085.                             //                        if ($days > 1){
  10086.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  10087.                             //                        } else {
  10088.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10089.                             //                        }
  10090.                             //
  10091.                             //                        $unitsServ = $item->getUnits();
  10092.                             //                        if (empty($unitsServ) or $unitsServ == "0") {
  10093.                             //                            $unitsServ = 1;
  10094.                             //                        }
  10095.                             //
  10096.                             //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  10097.                             //                        $subnetoUnit = $subneto;
  10098.                             //                        $subneto = $subneto * $days * $unitsServ * $pax;
  10099.                             //
  10100.                             //                        $data_supplier['service'][$i] = array (
  10101.                             //                            'id' => $item->getId(),
  10102.                             //                            'serviceCatId' => $item->getServiceCatId(),
  10103.                             //                            'serviceName' => $item->getName(),
  10104.                             //                            'serviceType' => 'Itinerarios',
  10105.                             //                            'date' => $dateServ,
  10106.                             //                            'qty' => $unitsServ,
  10107.                             //                            'iva' => $item->getIva(),
  10108.                             //                            'pax' => $item->getPax(),
  10109.                             //                            'precioUnit' => $subnetoUnit,
  10110.                             //                            'subneto' => $subneto,
  10111.                             //                            'subtotal' => $subtotal,
  10112.                             //                        );
  10113.                             break;
  10114.                         case 11//Menu
  10115.                             $pax $item->getPax();
  10116.                             if (empty($pax) or $pax == "0") {
  10117.                                 $pax 1;
  10118.                             }
  10119.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10120.                             if ($days 1) {
  10121.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10122.                             } else {
  10123.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10124.                             }
  10125.                             $unitsServ $item->getUnits();
  10126.                             if (empty($unitsServ) or $unitsServ == "0") {
  10127.                                 $unitsServ 1;
  10128.                             }
  10129.                             $subtotal $subtotalService $days $unitsServ $pax;
  10130.                             $subnetoUnit $subneto;
  10131.                             $subneto $subneto $days $unitsServ $pax;
  10132.                             $data_supplier['service'][$i] = array(
  10133.                                 'id' => $item->getId(),
  10134.                                 'serviceCatId' => $item->getServiceCatId(),
  10135.                                 'serviceName' => $item->getName(),
  10136.                                 'serviceType' => 'MenĂº',
  10137.                                 'date' => $dateServ,
  10138.                                 'qty' => $unitsServ,
  10139.                                 'iva' => $item->getIva(),
  10140.                                 'pax' => $item->getPax(),
  10141.                                 'precioUnit' => $subnetoUnit,
  10142.                                 'subneto' => $subneto,
  10143.                                 'subtotal' => $subtotal,
  10144.                             );
  10145.                             break;
  10146.                         case 12//Others
  10147.                             $pax $item->getPax();
  10148.                             if (empty($pax) or $pax == "0") {
  10149.                                 $pax 1;
  10150.                             }
  10151.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10152.                             if ($days 1) {
  10153.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10154.                             } else {
  10155.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10156.                             }
  10157.                             $unitsServ $item->getUnits();
  10158.                             if (empty($unitsServ) or $unitsServ == "0") {
  10159.                                 $unitsServ 1;
  10160.                             }
  10161.                             $subtotal $subtotalService $days $unitsServ $pax;
  10162.                             $subnetoUnit $subneto;
  10163.                             $subneto $subneto $days $unitsServ $pax;
  10164.                             $data_supplier['service'][$i] = array(
  10165.                                 'id' => $item->getId(),
  10166.                                 'serviceCatId' => $item->getServiceCatId(),
  10167.                                 'serviceName' => $item->getName(),
  10168.                                 'serviceType' => 'Otros',
  10169.                                 'date' => $dateServ,
  10170.                                 'qty' => $unitsServ,
  10171.                                 'iva' => $item->getIva(),
  10172.                                 'pax' => $item->getPax(),
  10173.                                 'precioUnit' => $subnetoUnit,
  10174.                                 'subneto' => $subneto,
  10175.                                 'subtotal' => $subtotal,
  10176.                             );
  10177.                             break;
  10178.                         case 13//Transport
  10179.                             $pax $item->getPax();
  10180.                             if (empty($pax) or $pax == "0") {
  10181.                                 $pax 1;
  10182.                             }
  10183.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10184.                             if ($days 1) {
  10185.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10186.                             } else {
  10187.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10188.                             }
  10189.                             $unitsServ $item->getUnits();
  10190.                             if (empty($unitsServ) or $unitsServ == "0") {
  10191.                                 $unitsServ 1;
  10192.                             }
  10193.                             $subtotal $subtotalService $days $unitsServ $pax;
  10194.                             $subnetoUnit $subneto;
  10195.                             $subneto $subneto $days $unitsServ $pax;
  10196.                             $data_supplier['service'][$i] = array(
  10197.                                 'id' => $item->getId(),
  10198.                                 'serviceCatId' => $item->getServiceCatId(),
  10199.                                 'serviceName' => $item->getName(),
  10200.                                 'serviceType' => 'Transporte',
  10201.                                 'date' => $dateServ,
  10202.                                 'qty' => $unitsServ,
  10203.                                 'iva' => $item->getIva(),
  10204.                                 'pax' => $item->getPax(),
  10205.                                 'precioUnit' => $subnetoUnit,
  10206.                                 'subneto' => $subneto,
  10207.                                 'subtotal' => $subtotal,
  10208.                             );
  10209.                             break;
  10210.                         case 14//Technology
  10211.                             $pax $item->getPax();
  10212.                             if (empty($pax) or $pax == "0") {
  10213.                                 $pax 1;
  10214.                             }
  10215.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  10216.                             $days 1;
  10217.                             //                        if ($days > 1){
  10218.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  10219.                             //                        } else {
  10220.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10221.                             //                        }
  10222.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10223.                             $unitsServ $item->getUnits();
  10224.                             if (empty($unitsServ) or $unitsServ == "0") {
  10225.                                 $unitsServ 1;
  10226.                             }
  10227.                             $subtotal $subtotalService $days $unitsServ $pax;
  10228.                             $subnetoUnit $subneto;
  10229.                             $subneto $subneto $days $unitsServ $pax;
  10230.                             $data_supplier['service'][$i] = array(
  10231.                                 'id' => $item->getId(),
  10232.                                 'serviceCatId' => $item->getServiceCatId(),
  10233.                                 'serviceName' => $item->getName(),
  10234.                                 'serviceType' => 'TecnologĂ­a',
  10235.                                 'date' => $dateServ,
  10236.                                 'qty' => $unitsServ,
  10237.                                 'iva' => $item->getIva(),
  10238.                                 'pax' => $item->getPax(),
  10239.                                 'precioUnit' => $subnetoUnit,
  10240.                                 'subneto' => $subneto,
  10241.                                 'subtotal' => $subtotal,
  10242.                             );
  10243.                             break;
  10244.                         case 15//Assisstant
  10245.                             $pax $item->getPax();
  10246.                             if (empty($pax) or $pax == "0") {
  10247.                                 $pax 1;
  10248.                             }
  10249.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10250.                             if ($days 1) {
  10251.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10252.                             } else {
  10253.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10254.                             }
  10255.                             $unitsServ $item->getUnits();
  10256.                             if (empty($unitsServ) or $unitsServ == "0") {
  10257.                                 $unitsServ 1;
  10258.                             }
  10259.                             $subtotal $subtotalService $days $unitsServ $pax;
  10260.                             $subnetoUnit $subneto;
  10261.                             $subneto $subneto $days $unitsServ $pax;
  10262.                             $data_supplier['service'][$i] = array(
  10263.                                 'id' => $item->getId(),
  10264.                                 'serviceCatId' => $item->getServiceCatId(),
  10265.                                 'serviceName' => $item->getName(),
  10266.                                 'serviceType' => 'Asistente',
  10267.                                 'date' => $dateServ,
  10268.                                 'qty' => $unitsServ,
  10269.                                 'iva' => $item->getIva(),
  10270.                                 'pax' => $item->getPax(),
  10271.                                 'precioUnit' => $subnetoUnit,
  10272.                                 'subneto' => $subneto,
  10273.                                 'subtotal' => $subtotal,
  10274.                             );
  10275.                             break;
  10276.                         case 16//DDR
  10277.                             $pax $item->getPax();
  10278.                             if (empty($pax) or $pax == "0") {
  10279.                                 $pax 1;
  10280.                             }
  10281.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10282.                             if ($days 1) {
  10283.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10284.                             } else {
  10285.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10286.                             }
  10287.                             $unitsServ $item->getUnits();
  10288.                             if (empty($unitsServ) or $unitsServ == "0") {
  10289.                                 $unitsServ 1;
  10290.                             }
  10291.                             $subtotal $subtotalService $days $unitsServ $pax;
  10292.                             $subnetoUnit $subneto;
  10293.                             $subneto $subneto $days $unitsServ $pax;
  10294.                             $data_supplier['service'][$i] = array(
  10295.                                 'id' => $item->getId(),
  10296.                                 'serviceCatId' => $item->getServiceCatId(),
  10297.                                 'serviceName' => $item->getName(),
  10298.                                 'serviceType' => 'DDR',
  10299.                                 'date' => $dateServ,
  10300.                                 'qty' => $unitsServ,
  10301.                                 'iva' => $item->getIva(),
  10302.                                 'pax' => $item->getPax(),
  10303.                                 'precioUnit' => $subnetoUnit,
  10304.                                 'subneto' => $subneto,
  10305.                                 'subtotal' => $subtotal,
  10306.                             );
  10307.                             break;
  10308.                         default:
  10309.                             break;
  10310.                     }
  10311.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  10312.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  10313.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  10314.                     $arrayItems[] = array(
  10315.                         'type' => 'Service',
  10316.                         'name' => $item->getName(),
  10317.                         'amount' => $neto,
  10318.                         'iva' => $item->getIva(),
  10319.                         'total' => $subtotal,
  10320.                     );
  10321.                 }
  10322.                 switch ($item->getIva()) {
  10323.                         // Acumula IVA
  10324.                     case 21:
  10325.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  10326.                         break;
  10327.                     case 10:
  10328.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  10329.                         break;
  10330.                     case 0:
  10331.                         break;
  10332.                     default:
  10333.                         break;
  10334.                 }
  10335.             }
  10336.             $totales_neto_all $totales_neto_all $neto;
  10337.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10338.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  10339.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  10340.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  10341.             // Acumula netos totales e IVA
  10342.             $service['neto'] = $service['neto'] + $neto;
  10343.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  10344.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10345.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  10346.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  10347.             $i++;
  10348.         }
  10349.         $data_supplier['serviceSubTotal'] = array(
  10350.             'neto' => $service['neto'],
  10351.             'sumSubT' => $service['sumSubT'],
  10352.         );
  10353.         $currency '€';
  10354.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  10355.         if (!empty($payments)) {
  10356.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  10357.         } else {
  10358.             $amount_pay 0;
  10359.         }
  10360.         $totales_all $totales_total $amount_pay;
  10361.         if (empty($dateDocument)) {
  10362.             $dateDocument = new DateTime('now');
  10363.         }
  10364.         $data = array(
  10365.             'id' => $fileId,
  10366.             'type' => $type,
  10367.             'number' => $number,
  10368.             'prefix' => 'AVE-' . (new DateTime('now'))->format('dmy') . '-' $fileId,
  10369.             'date' => $dateDocument,
  10370.             'file' => $file,
  10371.             'company' => $company,
  10372.             'clients' => $clientNew,
  10373.             'arrayItems' => $arrayItems,
  10374.             'datasupplier' => $data_supplier,
  10375.             'currency' => $currency,
  10376.             'totales_neto' => $totales_neto_all,
  10377.             'bases_imponibles' => $data_iva,
  10378.             'totales' => $totales_total,
  10379.             'balance' => $totales_all,
  10380.             'paymentInvoice' => $amount_pay,
  10381.         );
  10382.         return $data;
  10383.     }
  10384.     private function baseInvoiceDoneFile($fileId$invoiceId$typeBase)
  10385.     {
  10386.         $em $this->getDoctrine()->getManager();
  10387.         $file $em->getRepository(AveFiles::class)->findOneById($fileId);
  10388.         $dateDocument null;                                                                           //Fecha final del documento
  10389.         $subneto 0;
  10390.         if (($typeBase == 'I') or ($typeBase == 'P')) {
  10391.             if ($typeBase == 'I') {
  10392.                 $items $em->getRepository(AveDocInvoiceItems::class)->findBy(array('fileId' => $fileId'invoiceId' => $invoiceId));
  10393.                 $arrayLocation = array();
  10394.                 $arrayLocationWithNull false;
  10395.                 foreach ($items as $item) {
  10396.                     if (!empty($item->getLocation())) {
  10397.                         $arrayLocation[$item->getLocation()] = $item->getLocation();
  10398.                     } else {
  10399.                         $arrayLocationWithNull true;
  10400.                     }
  10401.                 }
  10402.                 if ($arrayLocationWithNull) {
  10403.                     $arrayLocation['null'] = 'null';
  10404.                 }
  10405.                 $productsInFile = array();
  10406.                 foreach ($arrayLocation as $item) {
  10407.                     // VIDEO
  10408.                     $parameters = array(
  10409.                         'fileId' => $fileId,
  10410.                         'type' => 'VĂ­deo',
  10411.                         'location' => $item,
  10412.                         'invoiceId' => $invoiceId,
  10413.                     );
  10414.                     $dql 'SELECT i
  10415.                             FROM AvexpressBundle:AveDocInvoiceItems i
  10416.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceId = :invoiceId
  10417.                             ORDER BY i.rankquoteAv ASC';
  10418.                     $query $em->createQuery($dql)->setParameters($parameters);
  10419.                     $productsInFileVid $query->getResult();
  10420.                     // SONIDO
  10421.                     $parameters = array(
  10422.                         'fileId' => $fileId,
  10423.                         'type' => 'Sonido',
  10424.                         'location' => $item,
  10425.                         'invoiceId' => $invoiceId,
  10426.                     );
  10427.                     $dql 'SELECT i
  10428.                             FROM AvexpressBundle:AveDocInvoiceItems i
  10429.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceId = :invoiceId
  10430.                             ORDER BY i.rankquoteAv ASC';
  10431.                     $query $em->createQuery($dql)->setParameters($parameters);
  10432.                     $productsInFileSound $query->getResult();
  10433.                     // ILUMINACION
  10434.                     $parameters = array(
  10435.                         'fileId' => $fileId,
  10436.                         'type' => 'IluminaciĂ³n',
  10437.                         'location' => $item,
  10438.                         'invoiceId' => $invoiceId,
  10439.                     );
  10440.                     $dql 'SELECT i
  10441.                             FROM AvexpressBundle:AveDocInvoiceItems i
  10442.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceId = :invoiceId
  10443.                             ORDER BY i.rankquoteAv ASC';
  10444.                     $query $em->createQuery($dql)->setParameters($parameters);
  10445.                     $productsInFileLights $query->getResult();
  10446.                     // OTROS
  10447.                     $parameters = array(
  10448.                         'fileId' => $fileId,
  10449.                         'typeV' => 'VĂ­deo',
  10450.                         'typeS' => 'Sonido',
  10451.                         'typeI' => 'IluminaciĂ³n',
  10452.                         'location' => $item,
  10453.                         'invoiceId' => $invoiceId,
  10454.                     );
  10455.                     $dql 'SELECT i
  10456.                             FROM AvexpressBundle:AveDocInvoiceItems i
  10457.                             WHERE (i.fileId = :fileId AND i.prdType != :typeV AND i.prdType != :typeS AND i.prdType != :typeI AND i.location = :location AND i.invoiceId = :invoiceId)
  10458.                             ORDER BY i.rankquoteAv ASC';
  10459.                     $query $em->createQuery($dql)->setParameters($parameters);
  10460.                     $productsInFileOther $query->getResult();
  10461.                     // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  10462.                     $parameters = array(
  10463.                         'fileId' => $fileId,
  10464.                         'location' => $item,
  10465.                         'invoiceId' => $invoiceId,
  10466.                     );
  10467.                     $dql 'SELECT i
  10468.                             FROM AvexpressBundle:AveDocInvoiceItems i
  10469.                             WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location = :location AND i.invoiceId = :invoiceId)
  10470.                             ORDER BY i.rankquoteAv ASC';
  10471.                     $query $em->createQuery($dql)->setParameters($parameters);
  10472.                     $productsInFileNull $query->getResult();
  10473.                     // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  10474.                     if ($item == 'null') {
  10475.                         // VIDEO
  10476.                         $parameters = array(
  10477.                             'fileId' => $fileId,
  10478.                             'type' => 'VĂ­deo',
  10479.                             'invoiceId' => $invoiceId,
  10480.                         );
  10481.                         $dql 'SELECT i
  10482.                                 FROM AvexpressBundle:AveDocInvoiceItems i
  10483.                                 WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceId = :invoiceId
  10484.                                 ORDER BY i.rankquoteAv ASC';
  10485.                         $query $em->createQuery($dql)->setParameters($parameters);
  10486.                         $productsInFileVid $query->getResult();
  10487.                         // SONIDO
  10488.                         $parameters = array(
  10489.                             'fileId' => $fileId,
  10490.                             'type' => 'Sonido',
  10491.                             'invoiceId' => $invoiceId,
  10492.                         );
  10493.                         $dql 'SELECT i
  10494.                                 FROM AvexpressBundle:AveDocInvoiceItems i
  10495.                                 WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceId = :invoiceId
  10496.                                 ORDER BY i.rankquoteAv ASC';
  10497.                         $query $em->createQuery($dql)->setParameters($parameters);
  10498.                         $productsInFileSound $query->getResult();
  10499.                         // ILUMINACION
  10500.                         $parameters = array(
  10501.                             'fileId' => $fileId,
  10502.                             'type' => 'IluminaciĂ³n',
  10503.                             'invoiceId' => $invoiceId,
  10504.                         );
  10505.                         $dql 'SELECT i
  10506.                                 FROM AvexpressBundle:AveDocInvoiceItems i
  10507.                                 WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceId = :invoiceId
  10508.                                 ORDER BY i.rankquoteAv ASC';
  10509.                         $query $em->createQuery($dql)->setParameters($parameters);
  10510.                         $productsInFileLights $query->getResult();
  10511.                         // OTROS
  10512.                         $parameters = array(
  10513.                             'fileId' => $fileId,
  10514.                             'typeV' => 'VĂ­deo',
  10515.                             'typeS' => 'Sonido',
  10516.                             'typeI' => 'IluminaciĂ³n',
  10517.                             'invoiceId' => $invoiceId,
  10518.                         );
  10519.                         $dql 'SELECT i
  10520.                                 FROM AvexpressBundle:AveDocInvoiceItems i
  10521.                                 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)
  10522.                                 ORDER BY i.rankquoteAv ASC';
  10523.                         $query $em->createQuery($dql)->setParameters($parameters);
  10524.                         $productsInFileOther $query->getResult();
  10525.                         // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  10526.                         $parameters = array(
  10527.                             'fileId' => $fileId,
  10528.                             'invoiceId' => $invoiceId,
  10529.                         );
  10530.                         $dql 'SELECT i
  10531.                                 FROM AvexpressBundle:AveDocInvoiceItems i
  10532.                                 WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location IS NULL AND i.invoiceId = :invoiceId)
  10533.                                 ORDER BY i.rankquoteAv ASC';
  10534.                         $query $em->createQuery($dql)->setParameters($parameters);
  10535.                         $productsInFileNull $query->getResult();
  10536.                     }
  10537.                     $productsInFile array_merge($productsInFile$productsInFileVid$productsInFileSound$productsInFileLights$productsInFileOther$productsInFileNull);
  10538.                 }
  10539.                 $items $productsInFile;       // En Items estaban todos pero sin ordenamiento, ahora estan organizados por location y tipo
  10540.             } else {
  10541.                 // Es factura ni proforma
  10542.                 $items $em->getRepository(AveDocProformaItems::class)->findBy(array('fileId' => $fileId'proformaId' => $invoiceId));
  10543.             }
  10544.         } else {
  10545.             // No es factura ni proforma, es una rectificativa
  10546.             $items $em->getRepository(AveDocInvoiceRecItems::class)->findBy(array('fileId' => $fileId'invoiceRecId' => $invoiceId));
  10547.             $arrayLocation = array();
  10548.             $arrayLocationWithNull false;
  10549.             foreach ($items as $item) {
  10550.                 if (!empty($item->getLocation())) {
  10551.                     $arrayLocation[$item->getLocation()] = $item->getLocation();
  10552.                 } else {
  10553.                     $arrayLocationWithNull true;
  10554.                 }
  10555.             }
  10556.             if ($arrayLocationWithNull) {
  10557.                 $arrayLocation['null'] = 'null';
  10558.             }
  10559.             $productsInFile = array();
  10560.             foreach ($arrayLocation as $item) {
  10561.                 // VIDEO
  10562.                 $parameters = array(
  10563.                     'fileId' => $fileId,
  10564.                     'type' => 'VĂ­deo',
  10565.                     'location' => $item,
  10566.                     'invoiceId' => $invoiceId,
  10567.                 );
  10568.                 $dql 'SELECT i
  10569.                         FROM AvexpressBundle:AveDocInvoiceRecItems i
  10570.                         WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceRecId = :invoiceId
  10571.                         ORDER BY i.rankquoteAv ASC';
  10572.                 $query $em->createQuery($dql)->setParameters($parameters);
  10573.                 $productsInFileVid $query->getResult();
  10574.                 // SONIDO
  10575.                 $parameters = array(
  10576.                     'fileId' => $fileId,
  10577.                     'type' => 'Sonido',
  10578.                     'location' => $item,
  10579.                     'invoiceId' => $invoiceId,
  10580.                 );
  10581.                 $dql 'SELECT i
  10582.                         FROM AvexpressBundle:AveDocInvoiceRecItems i
  10583.                         WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceRecId = :invoiceId
  10584.                         ORDER BY i.rankquoteAv ASC';
  10585.                 $query $em->createQuery($dql)->setParameters($parameters);
  10586.                 $productsInFileSound $query->getResult();
  10587.                 // ILUMINACION
  10588.                 $parameters = array(
  10589.                     'fileId' => $fileId,
  10590.                     'type' => 'IluminaciĂ³n',
  10591.                     'location' => $item,
  10592.                     'invoiceId' => $invoiceId,
  10593.                 );
  10594.                 $dql 'SELECT i
  10595.                         FROM AvexpressBundle:AveDocInvoiceRecItems i
  10596.                         WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceRecId = :invoiceId
  10597.                         ORDER BY i.rankquoteAv ASC';
  10598.                 $query $em->createQuery($dql)->setParameters($parameters);
  10599.                 $productsInFileLights $query->getResult();
  10600.                 // OTROS
  10601.                 $parameters = array(
  10602.                     'fileId' => $fileId,
  10603.                     'typeV' => 'VĂ­deo',
  10604.                     'typeS' => 'Sonido',
  10605.                     'typeI' => 'IluminaciĂ³n',
  10606.                     'location' => $item,
  10607.                     'invoiceId' => $invoiceId,
  10608.                 );
  10609.                 $dql 'SELECT i
  10610.                         FROM AvexpressBundle:AveDocInvoiceRecItems i
  10611.                         WHERE (i.fileId = :fileId AND i.prdType != :typeV AND i.prdType != :typeS AND i.prdType != :typeI AND i.location = :location AND i.invoiceRecId = :invoiceId)
  10612.                         ORDER BY i.rankquoteAv ASC';
  10613.                 $query $em->createQuery($dql)->setParameters($parameters);
  10614.                 $productsInFileOther $query->getResult();
  10615.                 // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  10616.                 $parameters = array(
  10617.                     'fileId' => $fileId,
  10618.                     'location' => $item,
  10619.                     'invoiceId' => $invoiceId,
  10620.                 );
  10621.                 $dql 'SELECT i
  10622.                         FROM AvexpressBundle:AveDocInvoiceRecItems i
  10623.                         WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location = :location AND i.invoiceRecId = :invoiceId)
  10624.                         ORDER BY i.rankquoteAv ASC';
  10625.                 $query $em->createQuery($dql)->setParameters($parameters);
  10626.                 $productsInFileNull $query->getResult();
  10627.                 // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  10628.                 if ($item == 'null') {
  10629.                     // VIDEO
  10630.                     $parameters = array(
  10631.                         'fileId' => $fileId,
  10632.                         'type' => 'VĂ­deo',
  10633.                         'invoiceId' => $invoiceId,
  10634.                     );
  10635.                     $dql 'SELECT i
  10636.                             FROM AvexpressBundle:AveDocInvoiceRecItems i
  10637.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceRecId = :invoiceId
  10638.                             ORDER BY i.rankquoteAv ASC';
  10639.                     $query $em->createQuery($dql)->setParameters($parameters);
  10640.                     $productsInFileVid $query->getResult();
  10641.                     // SONIDO
  10642.                     $parameters = array(
  10643.                         'fileId' => $fileId,
  10644.                         'type' => 'Sonido',
  10645.                         'invoiceId' => $invoiceId,
  10646.                     );
  10647.                     $dql 'SELECT i
  10648.                             FROM AvexpressBundle:AveDocInvoiceRecItems i
  10649.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceRecId = :invoiceId
  10650.                             ORDER BY i.rankquoteAv ASC';
  10651.                     $query $em->createQuery($dql)->setParameters($parameters);
  10652.                     $productsInFileSound $query->getResult();
  10653.                     // ILUMINACION
  10654.                     $parameters = array(
  10655.                         'fileId' => $fileId,
  10656.                         'type' => 'IluminaciĂ³n',
  10657.                         'invoiceId' => $invoiceId,
  10658.                     );
  10659.                     $dql 'SELECT i
  10660.                             FROM AvexpressBundle:AveDocInvoiceRecItems i
  10661.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceRecId = :invoiceId
  10662.                             ORDER BY i.rankquoteAv ASC';
  10663.                     $query $em->createQuery($dql)->setParameters($parameters);
  10664.                     $productsInFileLights $query->getResult();
  10665.                     // OTROS
  10666.                     $parameters = array(
  10667.                         'fileId' => $fileId,
  10668.                         'typeV' => 'VĂ­deo',
  10669.                         'typeS' => 'Sonido',
  10670.                         'typeI' => 'IluminaciĂ³n',
  10671.                         'invoiceId' => $invoiceId,
  10672.                     );
  10673.                     $dql 'SELECT i
  10674.                             FROM AvexpressBundle:AveDocInvoiceRecItems i
  10675.                             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)
  10676.                             ORDER BY i.rankquoteAv ASC';
  10677.                     $query $em->createQuery($dql)->setParameters($parameters);
  10678.                     $productsInFileOther $query->getResult();
  10679.                     // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  10680.                     $parameters = array(
  10681.                         'fileId' => $fileId,
  10682.                         'invoiceId' => $invoiceId,
  10683.                     );
  10684.                     $dql 'SELECT i
  10685.                             FROM AvexpressBundle:AveDocInvoiceRecItems i
  10686.                             WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location IS NULL AND i.invoiceRecId = :invoiceId)
  10687.                             ORDER BY i.rankquoteAv ASC';
  10688.                     $query $em->createQuery($dql)->setParameters($parameters);
  10689.                     $productsInFileNull $query->getResult();
  10690.                 }
  10691.                 $productsInFile array_merge($productsInFile$productsInFileVid$productsInFileSound$productsInFileLights$productsInFileOther$productsInFileNull);
  10692.             }
  10693.             $items $productsInFile;       // En Items estaban todos pero sin ordenamiento, ahora estan organizados por location y tipo
  10694.         }
  10695.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority(4);
  10696.         $client $em->getRepository(Client::class)->findById($file->getClient());
  10697.         if (empty($client)) {
  10698.             $client[0] = new Client();
  10699.             $client[0]->setName('');
  10700.             $client[0]->setTitle('');
  10701.             $client[0]->setIdDocument('');
  10702.             $client[0]->setPopulation('');
  10703.             $client[0]->setRegion('');
  10704.             $client[0]->setCountry('');
  10705.         } else {
  10706.             if (is_numeric($client[0]->getPopulation())) {
  10707.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  10708. //                $client[0]->setPopulation($city->getCity());
  10709.             }
  10710.             if (is_numeric($client[0]->getRegion())) {
  10711.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  10712. //                $client[0]->setRegion($region->getRegion());
  10713.             }
  10714.             if (is_numeric($client[0]->getCountry())) {
  10715.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  10716. //                $client[0]->setCountry($country->getCountry());
  10717.             }
  10718.         }
  10719.         if (empty($client)) {
  10720.             $client[0] = new Client();
  10721.             $client[0]->setName('');
  10722.             $client[0]->setTitle('');
  10723.             $client[0]->setIdDocument('');
  10724.             $client[0]->setPopulation('');
  10725.             $client[0]->setRegion('');
  10726.             $client[0]->setCountry('');
  10727.             $clientNew = array(
  10728.                 'name' => '',
  10729.                 'title' => '',
  10730.                 'idDocument' => '',
  10731.                 'population' => '',
  10732.                 'region' => '',
  10733.                 'country' => '',
  10734.                 'address' => '',
  10735.                 'addressNumber' => '',
  10736.                 'zipCode' => '',
  10737.                 'typeDocument' => '',
  10738.             );
  10739.         } else {
  10740.             $clientNew = array(
  10741.                 'name' => $client[0]->getName(),
  10742.                 'title' => $client[0]->getTitle(),
  10743.                 'idDocument' => $client[0]->getIdDocument(),
  10744.                 'population' => '',
  10745.                 'region' => '',
  10746.                 'country' => '',
  10747.                 'address' => $client[0]->getAddress(),
  10748.                 'addressNumber' => $client[0]->getAddressNumber(),
  10749.                 'zipCode' => $client[0]->getZipCode(),
  10750.                 'typeDocument' => $client[0]->getTypeDocument(),
  10751.             );
  10752.             if (is_numeric($client[0]->getPopulation())) {
  10753.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  10754.                 $clientNew['population'] = $city->getCity();
  10755.             }
  10756.             if (is_numeric($client[0]->getRegion())) {
  10757.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  10758.                 $clientNew['region'] = $region->getRegion();
  10759.             }
  10760.             if (is_numeric($client[0]->getCountry())) {
  10761.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  10762.                 $clientNew['country'] = $country->getCountry();
  10763.             }
  10764.         }
  10765.         // Acumuladores de los calculos
  10766.         $totales_neto_all 0;
  10767.         $data_iva = array(
  10768.             'iva' => 21,
  10769.             'ivaMontoVeintiUno' => 0,
  10770.             'ivaMontoDiez' => 0,
  10771.             'ivaMontoCero' => null,
  10772.         );
  10773.         //INICIO: Determinamos el numero de factura o proforma
  10774.         if ($typeBase == 'I') {
  10775.             // Es una Factura
  10776.             $number $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
  10777.             $dateDocument $number->getDateAt();
  10778.             $number $number->getNumber();
  10779.             $type 'Invoice';
  10780.         } else {
  10781.             if ($typeBase == 'R') {
  10782.                 // Es una factura rectificativa
  10783.                 $number $em->getRepository(AveDocInvoiceRec::class)->findOneById($invoiceId);
  10784.                 $dateDocument $number->getDateAt();
  10785.                 $type 'Invoice Rec';
  10786.             } else {
  10787.                 // Es una Proforma
  10788.                 $number $invoiceId;
  10789.                 $type 'Proforma';
  10790.             }
  10791.         }
  10792.         //FIN: Determinamos el numero de factura o proforma
  10793.         // Buscamos los productos, pagos y servicios
  10794.         $arrayItems = array();
  10795.         $fileProducts = array();
  10796.         $payments = array();
  10797.         $services = array();
  10798.         if (!empty($items)) {
  10799.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  10800.                 foreach ($items as $item) {
  10801.                     switch ($item->getItemType()) {
  10802.                         case 'PRODUCT'// Producto
  10803.                             $fileProducts[] = $item;
  10804.                             break;
  10805.                         case 'PAYMENT'// Pago
  10806.                             $payments[] = $item;
  10807.                             break;
  10808.                         case 'SERVICE'// Servicio
  10809.                             $services[] = $item;
  10810.                             break;
  10811.                         default:
  10812.                             break;
  10813.                     }
  10814.                 }
  10815.             } else {
  10816.                 // Es una proforma
  10817.                 foreach ($items as $item) {
  10818.                     switch ($item->getType()) {
  10819.                         case 'PRODUCT'// Producto
  10820.                             $productPro $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
  10821.                             if (!empty($productPro)) {
  10822.                                 $fileProducts[] = $productPro;
  10823.                             }
  10824.                             break;
  10825.                         case 'PAYMENT'// Pago
  10826.                             $paymentPro $em->getRepository(AvePaymentsClient::class)->findOneById($item->getControlId());
  10827.                             if (!empty($paymentPro)) {
  10828.                                 $payments[] = $paymentPro;
  10829.                             }
  10830.                             break;
  10831.                         case 'SERVICE'// Servicio
  10832.                             $servicePro $em->getRepository(AveServices::class)->findOneById($item->getControlId());
  10833.                             if (!empty($servicePro)) {
  10834.                                 $services[] = $servicePro;
  10835.                             }
  10836.                             break;
  10837.                         default:
  10838.                             break;
  10839.                     }
  10840.                 }
  10841.             }
  10842.         }
  10843.         $data_supplier = array();
  10844.         $i 0;
  10845.         $pax '1';
  10846.         $qty '1';
  10847.         $product = array(
  10848.             'neto' => 0,
  10849.             'sumSubT' => 0,
  10850.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  10851.         $service = array(
  10852.             'neto' => 0,
  10853.             'sumSubT' => 0,
  10854.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  10855.         foreach ($fileProducts as $item) {
  10856.             $days = ((($item->getPrdDateEnd())->diff($item->getPrdDateStart()))->days 1);
  10857.             if (!is_null($item->getPrdDays()) or !empty($item->getPrdDays())) {
  10858.                 $days $item->getPrdDays();
  10859.             }
  10860.             if (!is_null($item->getPrdQty()) or !empty($item->getPrdQty())) {
  10861.                 $qty $item->getPrdQty();
  10862.             }
  10863.             if (!empty($item->getPrdDays())) {
  10864.                 $days $item->getPrdDays();
  10865.             }
  10866.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  10867.                 if (is_null($item->getPrdServicePrice()) or empty($item->getPrdServicePrice())) {
  10868.                     $subtotal 0;
  10869.                     $neto 0;
  10870.                     $subtotalProduct 0;
  10871.                 } else {
  10872.                     //Buscamos el iva
  10873.                     $zProductFile $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  10874.                     if (empty($zProductFile)) {
  10875.                         $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId());
  10876.                     }
  10877.                     if (empty($zProductFile)) {
  10878.                         $zProductFile = new AveProductFile;
  10879.                         $zProductFile->setIva(21);
  10880.                     }             // No se consigue el iva, se obliga a 21%
  10881.                     $ivaFactor = empty($zProductFile) ? 0.21 : ($zProductFile->getIva() / 100);
  10882.                     
  10883.                     if (!empty($item->getPrdIva()) or ($item->getPrdIva() == 0)) {
  10884.                         $ivaFactor = ($item->getPrdIva()) / 100;
  10885.                     }        // El iva se incorporo en la entidad despues del año 2024 por eso las lineas anteriores del iva
  10886.                     $subtotalProduct $item->getPrdSubTotalPrice() * ($ivaFactor);
  10887.                     $subneto $item->getPrdSubTotalPrice();
  10888.                     $subtotal =  $subtotalProduct;
  10889.                     $neto =  $subneto;
  10890.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  10891.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  10892.                     $neto round($neto2PHP_ROUND_HALF_UP);
  10893.                     $arrayItems[] = array(
  10894.                         'type' => 'Product',
  10895.                         'name' => $item->getPrdName(),
  10896.                         'amount' => $neto,
  10897.                         'iva' => $zProductFile->getIva(),
  10898.                         'total' => $subtotal,
  10899.                     );
  10900.                     $ivaFactor = ($ivaFactor 100);
  10901.                     switch ($ivaFactor){
  10902.                         case 21:
  10903.                             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  10904.                             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  10905.                             break;
  10906.                         case 10:
  10907.                             $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1);
  10908.                             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  10909.                             break;
  10910.                         case 0:
  10911.                             $data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto 0);
  10912.                             $data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2PHP_ROUND_HALF_UP);
  10913.                             break;
  10914.                         default:
  10915.                             $data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
  10916.                             $data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2PHP_ROUND_HALF_UP);
  10917.                             break;
  10918.                     }
  10919.                 }
  10920.             } else {
  10921.                 // Es proforma
  10922.                 if (is_null($item->getServicePrice()) or empty($item->getServicePrice())) {
  10923.                     $subtotal 0;
  10924.                     $neto 0;
  10925.                     $subtotalProduct 0;
  10926.                 } else {
  10927.                     //Buscamos el iva
  10928.                     $zProductFile $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  10929.                     if (empty($zProductFile)){ $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
  10930.                     $ivaFactor = empty($zProductFile) ? 0.21 : ($zProductFile->getIva() / 100);
  10931.                     $subtotalProduct $item->getSubTotalPrice() * ($ivaFactor);
  10932.                     $subneto $item->getSubTotalPrice();
  10933.                     $subtotal =  $subtotalProduct;
  10934.                     $neto =  $subneto;
  10935.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  10936.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  10937.                     $neto round($neto2PHP_ROUND_HALF_UP);
  10938.                     $arrayItems[] = array(
  10939.                         'type' => 'Product',
  10940.                         'name' => $item->getProductName(),
  10941.                         'amount' => $neto,
  10942.                         'iva' => $zProductFile->getIva(),
  10943.                         'total' => $subtotal,
  10944.                     );
  10945.                     switch ($zProductFile->getIva()) {
  10946.                         case 21:
  10947.                             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  10948.                             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  10949.                             break;
  10950.                         case 10:
  10951.                             $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1);
  10952.                             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  10953.                             break;
  10954.                         case 0:
  10955.                             $data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto 0);
  10956.                             $data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2PHP_ROUND_HALF_UP);
  10957.                             break;
  10958.                         default:
  10959.                             $data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
  10960.                             $data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2PHP_ROUND_HALF_UP);
  10961.                             break;
  10962.                     }
  10963.                 }
  10964.             }
  10965.             // Acumula netos totales e IVA
  10966.             $totales_neto_all $totales_neto_all $neto;
  10967.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10968.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  10969.             // Acumula netos totales e IVA
  10970.             $product['neto'] = $product['neto'] + $neto;
  10971.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  10972.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10973.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  10974.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  10975.             // Calculo del precio unitario despues de aplicar Over y Comision
  10976.             $multiplo $qty * (float)$days;
  10977.             $item->setPrdServicePrice($subneto $multiplo);
  10978.             //Buscamos el iva
  10979.             $zProductFile $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  10980.             if (empty($zProductFile)){ $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
  10981.             $ivaFactor = empty($zProductFile) ? 21 $zProductFile->getIva();
  10982.             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
  10983.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  10984.                 $data_supplier['product'][$i] = array(
  10985.                     'id' => $item->getId(),
  10986.                     'productName' => $item->getPrdName(),
  10987.                     'productId' => $item->getPrdProductId(),
  10988.                     'dateStart' => $item->getPrdDateStart(),
  10989.                     'dateEnd' => $item->getPrdDateEnd(),
  10990.                     'location' => $item->getLocation(),
  10991.                     'servicePrice' => $item->getPrdServicePrice(),
  10992.                     'serviceSubTotalPrice' => $subneto,     //antes de IVA
  10993.                     'subtotalProduct' => $subtotalProduct,
  10994.                     'iva' => $ivaFactor,
  10995.                     'pax' => $pax,
  10996.                     'qty' => $qty,
  10997.                     'days' => $days,
  10998.                     'type' => $item->getPrdType(),
  10999.                     'subtotal' => $subtotal,
  11000.                 );
  11001.             } else {
  11002.                 // Es proforma
  11003.                 $data_supplier['product'][$i] = array(
  11004.                     'id' => $item->getId(),
  11005.                     'productName' => $item->getProductName(),
  11006.                     'productId' => $item->getProductId(),
  11007.                     'dateStart' => $item->getDateStart(),
  11008.                     'dateEnd' => $item->getDateEnd(),
  11009.                     'servicePrice' => $item->getServicePrice(),
  11010.                     'subtotalProduct' => $subtotalProduct,
  11011.                     'iva' => $ivaFactor,
  11012.                     'pax' => $pax,
  11013.                     'qty' => $qty,
  11014.                     'days' => $days,
  11015.                     'type' => $item->getType(),
  11016.                     'subtotal' => $subtotal,
  11017.                 );
  11018.             }
  11019.             $i++;
  11020.         }
  11021.         $data_supplier['productSubTotal'] = array(
  11022.             'neto' => $product['neto'],
  11023.             'sumSubT' => $product['sumSubT'],
  11024.         );
  11025.         $payment = array(
  11026.             'sumSubT' => 0,
  11027.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  11028.         $i 0;
  11029.         foreach ($payments as $item) {
  11030.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  11031.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getPayAmountTotal();
  11032.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  11033.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  11034.                 $data_supplier['payment'][$i] = array(
  11035.                     'id' => $item->getId(),
  11036.                     'amount' => $item->getPayAmount(),
  11037.                     'amountTotal' => $item->getPayAmountTotal(),
  11038.                     'vat' => $item->getPayVat(),
  11039.                     'datePayAt' => $item->getPayDatePayAt(),
  11040.                     'wayToPay' => $item->getPayWayToPay(),
  11041.                 );
  11042.                 $arrayItems[] = array(
  11043.                     'type' => 'Payment',
  11044.                     'name' => $item->getPayWayToPay(),
  11045.                     'amount' => $item->getPayAmount(),
  11046.                     'total' => $item->getPayAmountTotal(),
  11047.                     'iva' => $item->getPayVat(),
  11048.                 );
  11049.             } else {
  11050.                 // Es una proforma
  11051.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  11052.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  11053.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  11054.                 $data_supplier['payment'][$i] = array(
  11055.                     'id' => $item->getId(),
  11056.                     'amount' => $item->getAmount(),
  11057.                     'amountTotal' => $item->getAmountTotal(),
  11058.                     'vat' => $item->getVat(),
  11059.                     'datePayAt' => $item->getDatePayAt(),
  11060.                     'wayToPay' => $item->getWayToPay(),
  11061.                 );
  11062.                 $arrayItems[] = array(
  11063.                     'type' => 'Payment',
  11064.                     'name' => $item->getWayToPay(),
  11065.                     'amount' => $item->getAmount(),
  11066.                     'total' => $item->getAmountTotal(),
  11067.                     'iva' => $item->getVat(),
  11068.                 );
  11069.             }
  11070.             $i++;
  11071.         }
  11072.         if (!empty($payments)) {
  11073.             $data_supplier['paymentSubTotal'] = array(
  11074.                 'sumSubT' => $payment['sumSubT'],
  11075.             );
  11076.         }
  11077.         foreach ($services as $item) {
  11078.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  11079.                 if (is_null($item->getSrvPrice()) or empty($item->getSrvPrice())) {
  11080.                     $subtotal 0;
  11081.                     $neto 0;
  11082.                     $subtotalService 0;
  11083.                 } else {
  11084.                     $subtotalService $item->getSrvPrice();
  11085.                     $subneto $item->getSrvPrice();
  11086.                     // Commission
  11087.                     if ($item->getSrvOpCommission() == '1') {
  11088.                         $subtotalService $subtotalService * (+ ($item->getSrvCommission() / 100));
  11089.                         $subneto $subneto * (+ ($item->getSrvCommission() / 100));
  11090.                     } else {
  11091.                         $subtotalService $subtotalService * (- ($item->getSrvCommission() / 100));
  11092.                         $subneto $subneto * (- ($item->getSrvCommission() / 100));
  11093.                     }
  11094.                     // Over
  11095.                     if ($item->getSrvOpOver() == '1') {
  11096.                         $subtotalService $subtotalService $item->getSrvOver();
  11097.                         $subneto $subneto $item->getSrvOver();
  11098.                     } else {
  11099.                         $subtotalService $subtotalService $item->getSrvOver();
  11100.                         $subneto $subneto $item->getSrvOver();
  11101.                     }
  11102.                     // IVA
  11103.                     if ($item->getSrvOpIva() == '1') {
  11104.                         $subtotalService $subtotalService * (+ ($item->getSrvIva() / 100));
  11105.                     } else {
  11106.                         $subtotalService $item->getSrvPrice();
  11107.                         $subneto = ($subneto 100) / (100 $item->getSrvIva());
  11108.                     }
  11109.                     switch ($item->getSrvServiceCatId()) {
  11110.                         case 1// Alojamiento
  11111.                             // el numero de noches $numNoches; precio unitario $subneto
  11112.                             $numNoches = (($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days;
  11113.                             // La personas no afectan este calculo
  11114.                             $subtotal $subtotalService $numNoches $item->getSrvUnits();
  11115.                             $subnetoUnit $subneto;
  11116.                             $subneto $subneto $numNoches $item->getSrvUnits();
  11117.                             $data_supplier['service'][$i] = array(
  11118.                                 'id' => $item->getId(),
  11119.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11120.                                 'serviceName' => $item->getSrvName(),
  11121.                                 'serviceType' => 'Hotel',
  11122.                                 'date' => ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y'),
  11123.                                 'qty' => $item->getSrvUnits(),
  11124.                                 'iva' => $item->getSrvIva(),
  11125.                                 'pax' => '-',
  11126.                                 'precioUnit' => $subnetoUnit,
  11127.                                 'subneto' => $subneto,
  11128.                                 'subtotal' => $subtotal,
  11129.                             );
  11130.                             break;
  11131.                         case 2//Actividades
  11132.                             // El nĂºmero de personas es considerado en el calculo
  11133.                             $pax $item->getSrvPax();
  11134.                             if (empty($pax) or $pax == "0") {
  11135.                                 $pax 1;
  11136.                             }
  11137.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11138.                             if ($days 1) {
  11139.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11140.                             } else {
  11141.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11142.                             }
  11143.                             $subtotal $subtotalService $days $item->getSrvUnits();
  11144.                             $subnetoUnit $subneto;
  11145.                             $subneto $subneto $days $item->getSrvUnits();
  11146.                             $data_supplier['service'][$i] = array(
  11147.                                 'id' => $item->getId(),
  11148.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11149.                                 'serviceName' => $item->getSrvName(),
  11150.                                 'serviceType' => 'Actividad',
  11151.                                 'date' => $dateServ,
  11152.                                 'qty' => $item->getSrvUnits(),
  11153.                                 'iva' => $item->getSrvIva(),
  11154.                                 'pax' => $item->getSrvPax(),
  11155.                                 'precioUnit' => $subnetoUnit,
  11156.                                 'subneto' => $subneto,
  11157.                                 'subtotal' => $subtotal,
  11158.                             );
  11159.                             break;
  11160.                         case 3// AV
  11161.                             $pax $item->getSrvPax();
  11162.                             if (empty($pax) or $pax == "0") {
  11163.                                 $pax 1;
  11164.                             }
  11165.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11166.                             if ($days 1) {
  11167.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11168.                             } else {
  11169.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11170.                             }
  11171.                             $unitsServ $item->getSrvUnits();
  11172.                             if (empty($unitsServ) or $unitsServ == "0") {
  11173.                                 $unitsServ 1;
  11174.                             }
  11175.                             $subtotal $subtotalService $days $unitsServ $pax;
  11176.                             $subnetoUnit $subneto;
  11177.                             $subneto $subneto $days $unitsServ $pax;
  11178.                             $data_supplier['service'][$i] = array(
  11179.                                 'id' => $item->getId(),
  11180.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11181.                                 'serviceName' => $item->getSrvName(),
  11182.                                 'serviceType' => 'AV',
  11183.                                 'date' => $dateServ,
  11184.                                 'qty' => $unitsServ,
  11185.                                 'iva' => $item->getSrvIva(),
  11186.                                 'pax' => $item->getSrvPax(),
  11187.                                 'precioUnit' => $subnetoUnit,
  11188.                                 'subneto' => $subneto,
  11189.                                 'subtotal' => $subtotal,
  11190.                             );
  11191.                             break;
  11192.                         case 4//Creative
  11193.                             $pax $item->getSrvPax();
  11194.                             if (empty($pax) or $pax == "0") {
  11195.                                 $pax 1;
  11196.                             }
  11197.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11198.                             if ($days 1) {
  11199.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11200.                             } else {
  11201.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11202.                             }
  11203.                             $unitsServ $item->getSrvUnits();
  11204.                             if (empty($unitsServ) or $unitsServ == "0") {
  11205.                                 $unitsServ 1;
  11206.                             }
  11207.                             $subtotal $subtotalService $days $unitsServ $pax;
  11208.                             $subnetoUnit $subneto;
  11209.                             $subneto $subneto $days $unitsServ $pax;
  11210.                             $data_supplier['service'][$i] = array(
  11211.                                 'id' => $item->getId(),
  11212.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11213.                                 'serviceName' => $item->getSrvName(),
  11214.                                 'serviceType' => 'Creativo',
  11215.                                 'date' => $dateServ,
  11216.                                 'qty' => $unitsServ,
  11217.                                 'iva' => $item->getSrvIva(),
  11218.                                 'pax' => $item->getSrvPax(),
  11219.                                 'precioUnit' => $subnetoUnit,
  11220.                                 'subneto' => $subneto,
  11221.                                 'subtotal' => $subtotal,
  11222.                             );
  11223.                             break;
  11224.                         case 5//Cruise
  11225.                             $pax $item->getSrvPax();
  11226.                             if (empty($pax) or $pax == "0") {
  11227.                                 $pax 1;
  11228.                             }
  11229.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days);
  11230.                             if ($days 1) {
  11231.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11232.                             } else {
  11233.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11234.                             }
  11235.                             $unitsServ $item->getSrvUnits();
  11236.                             if (empty($unitsServ) or $unitsServ == "0") {
  11237.                                 $unitsServ 1;
  11238.                             }
  11239.                             $subtotal $subtotalService $days $unitsServ $pax;
  11240.                             $subnetoUnit $subneto;
  11241.                             $subneto $subneto $days $unitsServ $pax;
  11242.                             $data_supplier['service'][$i] = array(
  11243.                                 'id' => $item->getId(),
  11244.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11245.                                 'serviceName' => $item->getSrvName(),
  11246.                                 'serviceType' => 'Crucero',
  11247.                                 'date' => $dateServ,
  11248.                                 'qty' => $unitsServ,
  11249.                                 'iva' => $item->getSrvIva(),
  11250.                                 'pax' => $item->getSrvPax(),
  11251.                                 'precioUnit' => $subnetoUnit,
  11252.                                 'subneto' => $subneto,
  11253.                                 'subtotal' => $subtotal,
  11254.                             );
  11255.                             break;
  11256.                         case 6//Entertaiment
  11257.                             $pax $item->getSrvPax();
  11258.                             if (empty($pax) or $pax == "0") {
  11259.                                 $pax 1;
  11260.                             }
  11261.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11262.                             if ($days 1) {
  11263.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11264.                             } else {
  11265.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11266.                             }
  11267.                             $unitsServ $item->getSrvUnits();
  11268.                             if (empty($unitsServ) or $unitsServ == "0") {
  11269.                                 $unitsServ 1;
  11270.                             }
  11271.                             $subtotal $subtotalService $days $unitsServ $pax;
  11272.                             $subnetoUnit $subneto;
  11273.                             $subneto $subneto $days $unitsServ $pax;
  11274.                             $data_supplier['service'][$i] = array(
  11275.                                 'id' => $item->getId(),
  11276.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11277.                                 'serviceName' => $item->getSrvName(),
  11278.                                 'serviceType' => 'Entretenimiento',
  11279.                                 'date' => $dateServ,
  11280.                                 'qty' => $unitsServ,
  11281.                                 'iva' => $item->getSrvIva(),
  11282.                                 'pax' => $item->getSrvPax(),
  11283.                                 'precioUnit' => $subnetoUnit,
  11284.                                 'subneto' => $subneto,
  11285.                                 'subtotal' => $subtotal,
  11286.                             );
  11287.                             break;
  11288.                         case 7// Gifts
  11289.                             $pax $item->getSrvPax();
  11290.                             if (empty($pax) or $pax == "0") {
  11291.                                 $pax 1;
  11292.                             }
  11293.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  11294.                             $days 1;
  11295.                             if ($days 1) {
  11296.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11297.                             } else {
  11298.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11299.                             }
  11300.                             $unitsServ $item->getSrvUnits();
  11301.                             if (empty($unitsServ) or $unitsServ == "0") {
  11302.                                 $unitsServ 1;
  11303.                             }
  11304.                             $subtotal $subtotalService $days $unitsServ $pax;
  11305.                             $subnetoUnit $subneto;
  11306.                             $subneto $subneto $days $unitsServ $pax;
  11307.                             $data_supplier['service'][$i] = array(
  11308.                                 'id' => $item->getId(),
  11309.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11310.                                 'serviceName' => $item->getSrvName(),
  11311.                                 'serviceType' => 'Regalos',
  11312.                                 'date' => $dateServ,
  11313.                                 'qty' => $unitsServ,
  11314.                                 'iva' => $item->getSrvIva(),
  11315.                                 'pax' => $item->getSrvPax(),
  11316.                                 'precioUnit' => $subnetoUnit,
  11317.                                 'subneto' => $subneto,
  11318.                                 'subtotal' => $subtotal,
  11319.                             );
  11320.                             break;
  11321.                         case 8//Guide
  11322.                             $pax $item->getSrvPax();
  11323.                             if (empty($pax) or $pax == "0") {
  11324.                                 $pax 1;
  11325.                             }
  11326.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11327.                             if ($days 1) {
  11328.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11329.                             } else {
  11330.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11331.                             }
  11332.                             $unitsServ $item->getSrvUnits();
  11333.                             if (empty($unitsServ) or $unitsServ == "0") {
  11334.                                 $unitsServ 1;
  11335.                             }
  11336.                             $subtotal $subtotalService $days $unitsServ $pax;
  11337.                             $subnetoUnit $subneto;
  11338.                             $subneto $subneto $days $unitsServ $pax;
  11339.                             $data_supplier['service'][$i] = array(
  11340.                                 'id' => $item->getId(),
  11341.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11342.                                 'serviceName' => $item->getSrvName(),
  11343.                                 'serviceType' => 'Regalos',
  11344.                                 'date' => $dateServ,
  11345.                                 'qty' => $unitsServ,
  11346.                                 'iva' => $item->getSrvIva(),
  11347.                                 'pax' => $item->getSrvPax(),
  11348.                                 'precioUnit' => $subnetoUnit,
  11349.                                 'subneto' => $subneto,
  11350.                                 'subtotal' => $subtotal,
  11351.                             );
  11352.                             break;
  11353.                         case 9//Itineraries
  11354.                             $pax $item->getSrvPax();
  11355.                             if (empty($pax) or $pax == "0") {
  11356.                                 $pax 1;
  11357.                             }
  11358.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11359.                             if ($days 1) {
  11360.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11361.                             } else {
  11362.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11363.                             }
  11364.                             $unitsServ $item->getSrvUnits();
  11365.                             if (empty($unitsServ) or $unitsServ == "0") {
  11366.                                 $unitsServ 1;
  11367.                             }
  11368.                             $subtotal $subtotalService $days $unitsServ $pax;
  11369.                             $subnetoUnit $subneto;
  11370.                             $subneto $subneto $days $unitsServ $pax;
  11371.                             $data_supplier['service'][$i] = array(
  11372.                                 'id' => $item->getId(),
  11373.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11374.                                 'serviceName' => $item->getSrvName(),
  11375.                                 'serviceType' => 'Itinerarios',
  11376.                                 'date' => $dateServ,
  11377.                                 'qty' => $unitsServ,
  11378.                                 'iva' => $item->getSrvIva(),
  11379.                                 'pax' => $item->getSrvPax(),
  11380.                                 'precioUnit' => $subnetoUnit,
  11381.                                 'subneto' => $subneto,
  11382.                                 'subtotal' => $subtotal,
  11383.                             );
  11384.                             break;
  11385.                         case 10//Lounge  -- No Aplica
  11386.                             break;
  11387.                         case 11//Menu
  11388.                             $pax $item->getSrvPax();
  11389.                             if (empty($pax) or $pax == "0") {
  11390.                                 $pax 1;
  11391.                             }
  11392.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11393.                             if ($days 1) {
  11394.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11395.                             } else {
  11396.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11397.                             }
  11398.                             $unitsServ $item->getSrvUnits();
  11399.                             if (empty($unitsServ) or $unitsServ == "0") {
  11400.                                 $unitsServ 1;
  11401.                             }
  11402.                             $subtotal $subtotalService $days $unitsServ $pax;
  11403.                             $subnetoUnit $subneto;
  11404.                             $subneto $subneto $days $unitsServ $pax;
  11405.                             $data_supplier['service'][$i] = array(
  11406.                                 'id' => $item->getId(),
  11407.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11408.                                 'serviceName' => $item->getSrvName(),
  11409.                                 'serviceType' => 'MenĂº',
  11410.                                 'date' => $dateServ,
  11411.                                 'qty' => $unitsServ,
  11412.                                 'iva' => $item->getSrvIva(),
  11413.                                 'pax' => $item->getSrvPax(),
  11414.                                 'precioUnit' => $subnetoUnit,
  11415.                                 'subneto' => $subneto,
  11416.                                 'subtotal' => $subtotal,
  11417.                             );
  11418.                             break;
  11419.                         case 12//Others
  11420.                             $pax $item->getSrvPax();
  11421.                             if (empty($pax) or $pax == "0") {
  11422.                                 $pax 1;
  11423.                             }
  11424.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11425.                             if ($days 1) {
  11426.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11427.                             } else {
  11428.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11429.                             }
  11430.                             $unitsServ $item->getSrvUnits();
  11431.                             if (empty($unitsServ) or $unitsServ == "0") {
  11432.                                 $unitsServ 1;
  11433.                             }
  11434.                             $subtotal $subtotalService $days $unitsServ $pax;
  11435.                             $subnetoUnit $subneto;
  11436.                             $subneto $subneto $days $unitsServ $pax;
  11437.                             $data_supplier['service'][$i] = array(
  11438.                                 'id' => $item->getId(),
  11439.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11440.                                 'serviceName' => $item->getSrvName(),
  11441.                                 'serviceType' => 'Otros',
  11442.                                 'date' => $dateServ,
  11443.                                 'qty' => $unitsServ,
  11444.                                 'iva' => $item->getSrvIva(),
  11445.                                 'pax' => $item->getSrvPax(),
  11446.                                 'precioUnit' => $subnetoUnit,
  11447.                                 'subneto' => $subneto,
  11448.                                 'subtotal' => $subtotal,
  11449.                             );
  11450.                             break;
  11451.                         case 13//Transport
  11452.                             $pax $item->getSrvPax();
  11453.                             if (empty($pax) or $pax == "0") {
  11454.                                 $pax 1;
  11455.                             }
  11456.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11457.                             if ($days 1) {
  11458.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11459.                             } else {
  11460.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11461.                             }
  11462.                             $unitsServ $item->getSrvUnits();
  11463.                             if (empty($unitsServ) or $unitsServ == "0") {
  11464.                                 $unitsServ 1;
  11465.                             }
  11466.                             $subtotal $subtotalService $days $unitsServ $pax;
  11467.                             $subnetoUnit $subneto;
  11468.                             $subneto $subneto $days $unitsServ $pax;
  11469.                             $data_supplier['service'][$i] = array(
  11470.                                 'id' => $item->getId(),
  11471.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11472.                                 'serviceName' => $item->getSrvName(),
  11473.                                 'serviceType' => 'Transporte',
  11474.                                 'date' => $dateServ,
  11475.                                 'qty' => $unitsServ,
  11476.                                 'iva' => $item->getSrvIva(),
  11477.                                 'pax' => $item->getSrvPax(),
  11478.                                 'precioUnit' => $subnetoUnit,
  11479.                                 'subneto' => $subneto,
  11480.                                 'subtotal' => $subtotal,
  11481.                             );
  11482.                             break;
  11483.                         case 14//Technology
  11484.                             $pax $item->getSrvPax();
  11485.                             if (empty($pax) or $pax == "0") {
  11486.                                 $pax 1;
  11487.                             }
  11488.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  11489.                             $days 1;
  11490.                             //                        if ($days > 1){
  11491.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  11492.                             //                        } else {
  11493.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11494.                             //                        }
  11495.                             $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11496.                             $unitsServ $item->getSrvUnits();
  11497.                             if (empty($unitsServ) or $unitsServ == "0") {
  11498.                                 $unitsServ 1;
  11499.                             }
  11500.                             $subtotal $subtotalService $days $unitsServ $pax;
  11501.                             $subnetoUnit $subneto;
  11502.                             $subneto $subneto $days $unitsServ $pax;
  11503.                             $data_supplier['service'][$i] = array(
  11504.                                 'id' => $item->getId(),
  11505.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11506.                                 'serviceName' => $item->getSrvName(),
  11507.                                 'serviceType' => 'TecnologĂ­a',
  11508.                                 'date' => $dateServ,
  11509.                                 'qty' => $unitsServ,
  11510.                                 'iva' => $item->getSrvIva(),
  11511.                                 'pax' => $item->getSrvPax(),
  11512.                                 'precioUnit' => $subnetoUnit,
  11513.                                 'subneto' => $subneto,
  11514.                                 'subtotal' => $subtotal,
  11515.                             );
  11516.                             break;
  11517.                         case 15//Assisstant
  11518.                             $pax $item->getSrvPax();
  11519.                             if (empty($pax) or $pax == "0") {
  11520.                                 $pax 1;
  11521.                             }
  11522.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11523.                             if ($days 1) {
  11524.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11525.                             } else {
  11526.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11527.                             }
  11528.                             $unitsServ $item->getSrvUnits();
  11529.                             if (empty($unitsServ) or $unitsServ == "0") {
  11530.                                 $unitsServ 1;
  11531.                             }
  11532.                             $subtotal $subtotalService $days $unitsServ $pax;
  11533.                             $subnetoUnit $subneto;
  11534.                             $subneto $subneto $days $unitsServ $pax;
  11535.                             $data_supplier['service'][$i] = array(
  11536.                                 'id' => $item->getId(),
  11537.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11538.                                 'serviceName' => $item->getSrvName(),
  11539.                                 'serviceType' => 'Asistente',
  11540.                                 'date' => $dateServ,
  11541.                                 'qty' => $unitsServ,
  11542.                                 'iva' => $item->getSrvIva(),
  11543.                                 'pax' => $item->getSrvPax(),
  11544.                                 'precioUnit' => $subnetoUnit,
  11545.                                 'subneto' => $subneto,
  11546.                                 'subtotal' => $subtotal,
  11547.                             );
  11548.                             break;
  11549.                         case 16//DDR
  11550.                             $pax $item->getSrvPax();
  11551.                             if (empty($pax) or $pax == "0") {
  11552.                                 $pax 1;
  11553.                             }
  11554.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11555.                             if ($days 1) {
  11556.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11557.                             } else {
  11558.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11559.                             }
  11560.                             $unitsServ $item->getSrvUnits();
  11561.                             if (empty($unitsServ) or $unitsServ == "0") {
  11562.                                 $unitsServ 1;
  11563.                             }
  11564.                             $subtotal $subtotalService $days $unitsServ $pax;
  11565.                             $subnetoUnit $subneto;
  11566.                             $subneto $subneto $days $unitsServ $pax;
  11567.                             $data_supplier['service'][$i] = array(
  11568.                                 'id' => $item->getId(),
  11569.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11570.                                 'serviceName' => $item->getSrvName(),
  11571.                                 'serviceType' => 'DDR',
  11572.                                 'date' => $dateServ,
  11573.                                 'qty' => $unitsServ,
  11574.                                 'iva' => $item->getSrvIva(),
  11575.                                 'pax' => $item->getSrvPax(),
  11576.                                 'precioUnit' => $subnetoUnit,
  11577.                                 'subneto' => $subneto,
  11578.                                 'subtotal' => $subtotal,
  11579.                             );
  11580.                             break;
  11581.                         default:
  11582.                             break;
  11583.                     }
  11584.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  11585.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  11586.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  11587.                     $arrayItems[] = array(
  11588.                         'type' => 'Service',
  11589.                         'name' => $item->getSrvName(),
  11590.                         'amount' => $neto,
  11591.                         'iva' => $item->getSrvIva(),
  11592.                         'total' => $subtotal,
  11593.                     );
  11594.                 }
  11595.                 switch ($item->getSrvIva()) {
  11596.                         // Acumula IVA
  11597.                     case 21:
  11598.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getSrvIva() / 100));
  11599.                         break;
  11600.                     case 10:
  11601.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getSrvIva() / 100));
  11602.                         break;
  11603.                     case 0:
  11604.                         $data_iva['ivaMontoCero'] = 0;
  11605.                         break;
  11606.                     default:
  11607.                         break;
  11608.                 }
  11609.             } else {
  11610.                 // Es una proforma
  11611.                 if (is_null($item->getPrice()) or empty($item->getPrice())) {
  11612.                     $subtotal 0;
  11613.                     $neto 0;
  11614.                     $subtotalService 0;
  11615.                 } else {
  11616.                     $subtotalService $item->getPrice();
  11617.                     $subneto $item->getPrice();
  11618.                     // Commission
  11619.                     if ($item->getOpCommission() == '1') {
  11620.                         $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  11621.                         $subneto $subneto * (+ ($item->getCommission() / 100));
  11622.                     } else {
  11623.                         $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  11624.                         $subneto $subneto * (- ($item->getCommission() / 100));
  11625.                     }
  11626.                     // Over
  11627.                     if ($item->getOpOver() == '1') {
  11628.                         $subtotalService $subtotalService $item->getOver();
  11629.                         $subneto $subneto $item->getOver();
  11630.                     } else {
  11631.                         $subtotalService $subtotalService $item->getOver();
  11632.                         $subneto $subneto $item->getOver();
  11633.                     }
  11634.                     // IVA
  11635.                     if ($item->getOpIva() == '1') {
  11636.                         $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  11637.                     } else {
  11638.                         $subtotalService $item->getPrice();
  11639.                         $subneto = ($subneto 100) / (100 $item->getIva());
  11640.                     }
  11641.                     switch ($item->getServiceCatId()) {
  11642.                         case 1// Alojamiento
  11643.                             // el numero de noches $numNoches; precio unitario $subneto
  11644.                             $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  11645.                             // La personas no afectan este calculo
  11646.                             $subtotal $subtotalService $numNoches $item->getUnits();
  11647.                             $subnetoUnit $subneto;
  11648.                             $subneto $subneto $numNoches $item->getUnits();
  11649.                             $data_supplier['service'][$i] = array(
  11650.                                 'id' => $item->getId(),
  11651.                                 'serviceCatId' => $item->getServiceCatId(),
  11652.                                 'serviceName' => $item->getName(),
  11653.                                 'serviceType' => 'Hotel',
  11654.                                 'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  11655.                                 'qty' => $item->getUnits(),
  11656.                                 'iva' => $item->getIva(),
  11657.                                 'pax' => '-',
  11658.                                 'precioUnit' => $subnetoUnit,
  11659.                                 'subneto' => $subneto,
  11660.                                 'subtotal' => $subtotal,
  11661.                             );
  11662.                             break;
  11663.                         case 2//Actividades
  11664.                             // El nĂºmero de personas es considerado en el calculo
  11665.                             $pax $item->getPax();
  11666.                             if (empty($pax) or $pax == "0") {
  11667.                                 $pax 1;
  11668.                             }
  11669.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11670.                             if ($days 1) {
  11671.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11672.                             } else {
  11673.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11674.                             }
  11675.                             $subtotal $subtotalService $days $item->getUnits();
  11676.                             $subnetoUnit $subneto;
  11677.                             $subneto $subneto $days $item->getUnits();
  11678.                             $data_supplier['service'][$i] = array(
  11679.                                 'id' => $item->getId(),
  11680.                                 'serviceCatId' => $item->getServiceCatId(),
  11681.                                 'serviceName' => $item->getName(),
  11682.                                 'serviceType' => 'Actividad',
  11683.                                 'date' => $dateServ,
  11684.                                 'qty' => $item->getUnits(),
  11685.                                 'iva' => $item->getIva(),
  11686.                                 'pax' => $item->getPax(),
  11687.                                 'precioUnit' => $subnetoUnit,
  11688.                                 'subneto' => $subneto,
  11689.                                 'subtotal' => $subtotal,
  11690.                             );
  11691.                             break;
  11692.                         case 3// AV
  11693.                             $pax $item->getPax();
  11694.                             if (empty($pax) or $pax == "0") {
  11695.                                 $pax 1;
  11696.                             }
  11697.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11698.                             if ($days 1) {
  11699.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11700.                             } else {
  11701.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11702.                             }
  11703.                             $unitsServ $item->getUnits();
  11704.                             if (empty($unitsServ) or $unitsServ == "0") {
  11705.                                 $unitsServ 1;
  11706.                             }
  11707.                             $subtotal $subtotalService $days $unitsServ $pax;
  11708.                             $subnetoUnit $subneto;
  11709.                             $subneto $subneto $days $unitsServ $pax;
  11710.                             $data_supplier['service'][$i] = array(
  11711.                                 'id' => $item->getId(),
  11712.                                 'serviceCatId' => $item->getServiceCatId(),
  11713.                                 'serviceName' => $item->getName(),
  11714.                                 'serviceType' => 'AV',
  11715.                                 'date' => $dateServ,
  11716.                                 'qty' => $unitsServ,
  11717.                                 'iva' => $item->getIva(),
  11718.                                 'pax' => $item->getPax(),
  11719.                                 'precioUnit' => $subnetoUnit,
  11720.                                 'subneto' => $subneto,
  11721.                                 'subtotal' => $subtotal,
  11722.                             );
  11723.                             break;
  11724.                         case 4//Creative
  11725.                             $pax $item->getPax();
  11726.                             if (empty($pax) or $pax == "0") {
  11727.                                 $pax 1;
  11728.                             }
  11729.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11730.                             if ($days 1) {
  11731.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11732.                             } else {
  11733.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11734.                             }
  11735.                             $unitsServ $item->getUnits();
  11736.                             if (empty($unitsServ) or $unitsServ == "0") {
  11737.                                 $unitsServ 1;
  11738.                             }
  11739.                             $subtotal $subtotalService $days $unitsServ $pax;
  11740.                             $subnetoUnit $subneto;
  11741.                             $subneto $subneto $days $unitsServ $pax;
  11742.                             $data_supplier['service'][$i] = array(
  11743.                                 'id' => $item->getId(),
  11744.                                 'serviceCatId' => $item->getServiceCatId(),
  11745.                                 'serviceName' => $item->getName(),
  11746.                                 'serviceType' => 'Creativo',
  11747.                                 'date' => $dateServ,
  11748.                                 'qty' => $unitsServ,
  11749.                                 'iva' => $item->getIva(),
  11750.                                 'pax' => $item->getPax(),
  11751.                                 'precioUnit' => $subnetoUnit,
  11752.                                 'subneto' => $subneto,
  11753.                                 'subtotal' => $subtotal,
  11754.                             );
  11755.                             break;
  11756.                         case 5//Cruise
  11757.                             $pax $item->getPax();
  11758.                             if (empty($pax) or $pax == "0") {
  11759.                                 $pax 1;
  11760.                             }
  11761.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  11762.                             if ($days 1) {
  11763.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11764.                             } else {
  11765.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11766.                             }
  11767.                             $unitsServ $item->getUnits();
  11768.                             if (empty($unitsServ) or $unitsServ == "0") {
  11769.                                 $unitsServ 1;
  11770.                             }
  11771.                             $subtotal $subtotalService $days $unitsServ $pax;
  11772.                             $subnetoUnit $subneto;
  11773.                             $subneto $subneto $days $unitsServ $pax;
  11774.                             $data_supplier['service'][$i] = array(
  11775.                                 'id' => $item->getId(),
  11776.                                 'serviceCatId' => $item->getServiceCatId(),
  11777.                                 'serviceName' => $item->getName(),
  11778.                                 'serviceType' => 'Crucero',
  11779.                                 'date' => $dateServ,
  11780.                                 'qty' => $unitsServ,
  11781.                                 'iva' => $item->getIva(),
  11782.                                 'pax' => $item->getPax(),
  11783.                                 'precioUnit' => $subnetoUnit,
  11784.                                 'subneto' => $subneto,
  11785.                                 'subtotal' => $subtotal,
  11786.                             );
  11787.                             break;
  11788.                         case 6//Entertaiment
  11789.                             $pax $item->getPax();
  11790.                             if (empty($pax) or $pax == "0") {
  11791.                                 $pax 1;
  11792.                             }
  11793.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11794.                             if ($days 1) {
  11795.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11796.                             } else {
  11797.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11798.                             }
  11799.                             $unitsServ $item->getUnits();
  11800.                             if (empty($unitsServ) or $unitsServ == "0") {
  11801.                                 $unitsServ 1;
  11802.                             }
  11803.                             $subtotal $subtotalService $days $unitsServ $pax;
  11804.                             $subnetoUnit $subneto;
  11805.                             $subneto $subneto $days $unitsServ $pax;
  11806.                             $data_supplier['service'][$i] = array(
  11807.                                 'id' => $item->getId(),
  11808.                                 'serviceCatId' => $item->getServiceCatId(),
  11809.                                 'serviceName' => $item->getName(),
  11810.                                 'serviceType' => 'Entretenimiento',
  11811.                                 'date' => $dateServ,
  11812.                                 'qty' => $unitsServ,
  11813.                                 'iva' => $item->getIva(),
  11814.                                 'pax' => $item->getPax(),
  11815.                                 'precioUnit' => $subnetoUnit,
  11816.                                 'subneto' => $subneto,
  11817.                                 'subtotal' => $subtotal,
  11818.                             );
  11819.                             break;
  11820.                         case 7// Gifts
  11821.                             $pax $item->getPax();
  11822.                             if (empty($pax) or $pax == "0") {
  11823.                                 $pax 1;
  11824.                             }
  11825.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  11826.                             $days 1;
  11827.                             if ($days 1) {
  11828.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11829.                             } else {
  11830.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11831.                             }
  11832.                             $unitsServ $item->getUnits();
  11833.                             if (empty($unitsServ) or $unitsServ == "0") {
  11834.                                 $unitsServ 1;
  11835.                             }
  11836.                             $subtotal $subtotalService $days $unitsServ $pax;
  11837.                             $subnetoUnit $subneto;
  11838.                             $subneto $subneto $days $unitsServ $pax;
  11839.                             $data_supplier['service'][$i] = array(
  11840.                                 'id' => $item->getId(),
  11841.                                 'serviceCatId' => $item->getServiceCatId(),
  11842.                                 'serviceName' => $item->getName(),
  11843.                                 'serviceType' => 'Regalos',
  11844.                                 'date' => $dateServ,
  11845.                                 'qty' => $unitsServ,
  11846.                                 'iva' => $item->getIva(),
  11847.                                 'pax' => $item->getPax(),
  11848.                                 'precioUnit' => $subnetoUnit,
  11849.                                 'subneto' => $subneto,
  11850.                                 'subtotal' => $subtotal,
  11851.                             );
  11852.                             break;
  11853.                         case 8//Guide
  11854.                             $pax $item->getPax();
  11855.                             if (empty($pax) or $pax == "0") {
  11856.                                 $pax 1;
  11857.                             }
  11858.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11859.                             if ($days 1) {
  11860.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11861.                             } else {
  11862.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11863.                             }
  11864.                             $unitsServ $item->getUnits();
  11865.                             if (empty($unitsServ) or $unitsServ == "0") {
  11866.                                 $unitsServ 1;
  11867.                             }
  11868.                             $subtotal $subtotalService $days $unitsServ $pax;
  11869.                             $subnetoUnit $subneto;
  11870.                             $subneto $subneto $days $unitsServ $pax;
  11871.                             $data_supplier['service'][$i] = array(
  11872.                                 'id' => $item->getId(),
  11873.                                 'serviceCatId' => $item->getServiceCatId(),
  11874.                                 'serviceName' => $item->getName(),
  11875.                                 'serviceType' => 'Regalos',
  11876.                                 'date' => $dateServ,
  11877.                                 'qty' => $unitsServ,
  11878.                                 'iva' => $item->getIva(),
  11879.                                 'pax' => $item->getPax(),
  11880.                                 'precioUnit' => $subnetoUnit,
  11881.                                 'subneto' => $subneto,
  11882.                                 'subtotal' => $subtotal,
  11883.                             );
  11884.                             break;
  11885.                         case 9//Itineraries
  11886.                             $pax $item->getPax();
  11887.                             if (empty($pax) or $pax == "0") {
  11888.                                 $pax 1;
  11889.                             }
  11890.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11891.                             if ($days 1) {
  11892.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11893.                             } else {
  11894.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11895.                             }
  11896.                             $unitsServ $item->getUnits();
  11897.                             if (empty($unitsServ) or $unitsServ == "0") {
  11898.                                 $unitsServ 1;
  11899.                             }
  11900.                             $subtotal $subtotalService $days $unitsServ $pax;
  11901.                             $subnetoUnit $subneto;
  11902.                             $subneto $subneto $days $unitsServ $pax;
  11903.                             $data_supplier['service'][$i] = array(
  11904.                                 'id' => $item->getId(),
  11905.                                 'serviceCatId' => $item->getServiceCatId(),
  11906.                                 'serviceName' => $item->getName(),
  11907.                                 'serviceType' => 'Itinerarios',
  11908.                                 'date' => $dateServ,
  11909.                                 'qty' => $unitsServ,
  11910.                                 'iva' => $item->getIva(),
  11911.                                 'pax' => $item->getPax(),
  11912.                                 'precioUnit' => $subnetoUnit,
  11913.                                 'subneto' => $subneto,
  11914.                                 'subtotal' => $subtotal,
  11915.                             );
  11916.                             break;
  11917.                         case 10//Lounge  -- No Aplica
  11918.                             break;
  11919.                         case 11//Menu
  11920.                             $pax $item->getPax();
  11921.                             if (empty($pax) or $pax == "0") {
  11922.                                 $pax 1;
  11923.                             }
  11924.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11925.                             if ($days 1) {
  11926.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11927.                             } else {
  11928.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11929.                             }
  11930.                             $unitsServ $item->getUnits();
  11931.                             if (empty($unitsServ) or $unitsServ == "0") {
  11932.                                 $unitsServ 1;
  11933.                             }
  11934.                             $subtotal $subtotalService $days $unitsServ $pax;
  11935.                             $subnetoUnit $subneto;
  11936.                             $subneto $subneto $days $unitsServ $pax;
  11937.                             $data_supplier['service'][$i] = array(
  11938.                                 'id' => $item->getId(),
  11939.                                 'serviceCatId' => $item->getServiceCatId(),
  11940.                                 'serviceName' => $item->getName(),
  11941.                                 'serviceType' => 'MenĂº',
  11942.                                 'date' => $dateServ,
  11943.                                 'qty' => $unitsServ,
  11944.                                 'iva' => $item->getIva(),
  11945.                                 'pax' => $item->getPax(),
  11946.                                 'precioUnit' => $subnetoUnit,
  11947.                                 'subneto' => $subneto,
  11948.                                 'subtotal' => $subtotal,
  11949.                             );
  11950.                             break;
  11951.                         case 12//Others
  11952.                             $pax $item->getPax();
  11953.                             if (empty($pax) or $pax == "0") {
  11954.                                 $pax 1;
  11955.                             }
  11956.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11957.                             if ($days 1) {
  11958.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11959.                             } else {
  11960.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11961.                             }
  11962.                             $unitsServ $item->getUnits();
  11963.                             if (empty($unitsServ) or $unitsServ == "0") {
  11964.                                 $unitsServ 1;
  11965.                             }
  11966.                             $subtotal $subtotalService $days $unitsServ $pax;
  11967.                             $subnetoUnit $subneto;
  11968.                             $subneto $subneto $days $unitsServ $pax;
  11969.                             $data_supplier['service'][$i] = array(
  11970.                                 'id' => $item->getId(),
  11971.                                 'serviceCatId' => $item->getServiceCatId(),
  11972.                                 'serviceName' => $item->getName(),
  11973.                                 'serviceType' => 'Otros',
  11974.                                 'date' => $dateServ,
  11975.                                 'qty' => $unitsServ,
  11976.                                 'iva' => $item->getIva(),
  11977.                                 'pax' => $item->getPax(),
  11978.                                 'precioUnit' => $subnetoUnit,
  11979.                                 'subneto' => $subneto,
  11980.                                 'subtotal' => $subtotal,
  11981.                             );
  11982.                             break;
  11983.                         case 13//Transport
  11984.                             $pax $item->getPax();
  11985.                             if (empty($pax) or $pax == "0") {
  11986.                                 $pax 1;
  11987.                             }
  11988.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11989.                             if ($days 1) {
  11990.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11991.                             } else {
  11992.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11993.                             }
  11994.                             $unitsServ $item->getUnits();
  11995.                             if (empty($unitsServ) or $unitsServ == "0") {
  11996.                                 $unitsServ 1;
  11997.                             }
  11998.                             $subtotal $subtotalService $days $unitsServ $pax;
  11999.                             $subnetoUnit $subneto;
  12000.                             $subneto $subneto $days $unitsServ $pax;
  12001.                             $data_supplier['service'][$i] = array(
  12002.                                 'id' => $item->getId(),
  12003.                                 'serviceCatId' => $item->getServiceCatId(),
  12004.                                 'serviceName' => $item->getName(),
  12005.                                 'serviceType' => 'Transporte',
  12006.                                 'date' => $dateServ,
  12007.                                 'qty' => $unitsServ,
  12008.                                 'iva' => $item->getIva(),
  12009.                                 'pax' => $item->getPax(),
  12010.                                 'precioUnit' => $subnetoUnit,
  12011.                                 'subneto' => $subneto,
  12012.                                 'subtotal' => $subtotal,
  12013.                             );
  12014.                             break;
  12015.                         case 14//Technology
  12016.                             $pax $item->getPax();
  12017.                             if (empty($pax) or $pax == "0") {
  12018.                                 $pax 1;
  12019.                             }
  12020.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  12021.                             $days 1;
  12022.                             //                        if ($days > 1){
  12023.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  12024.                             //                        } else {
  12025.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  12026.                             //                        }
  12027.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  12028.                             $unitsServ $item->getUnits();
  12029.                             if (empty($unitsServ) or $unitsServ == "0") {
  12030.                                 $unitsServ 1;
  12031.                             }
  12032.                             $subtotal $subtotalService $days $unitsServ $pax;
  12033.                             $subnetoUnit $subneto;
  12034.                             $subneto $subneto $days $unitsServ $pax;
  12035.                             $data_supplier['service'][$i] = array(
  12036.                                 'id' => $item->getId(),
  12037.                                 'serviceCatId' => $item->getServiceCatId(),
  12038.                                 'serviceName' => $item->getName(),
  12039.                                 'serviceType' => 'TecnologĂ­a',
  12040.                                 'date' => $dateServ,
  12041.                                 'qty' => $unitsServ,
  12042.                                 'iva' => $item->getIva(),
  12043.                                 'pax' => $item->getPax(),
  12044.                                 'precioUnit' => $subnetoUnit,
  12045.                                 'subneto' => $subneto,
  12046.                                 'subtotal' => $subtotal,
  12047.                             );
  12048.                             break;
  12049.                         case 15//Assisstant
  12050.                             $pax $item->getPax();
  12051.                             if (empty($pax) or $pax == "0") {
  12052.                                 $pax 1;
  12053.                             }
  12054.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  12055.                             if ($days 1) {
  12056.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  12057.                             } else {
  12058.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  12059.                             }
  12060.                             $unitsServ $item->getUnits();
  12061.                             if (empty($unitsServ) or $unitsServ == "0") {
  12062.                                 $unitsServ 1;
  12063.                             }
  12064.                             $subtotal $subtotalService $days $unitsServ $pax;
  12065.                             $subnetoUnit $subneto;
  12066.                             $subneto $subneto $days $unitsServ $pax;
  12067.                             $data_supplier['service'][$i] = array(
  12068.                                 'id' => $item->getId(),
  12069.                                 'serviceCatId' => $item->getServiceCatId(),
  12070.                                 'serviceName' => $item->getName(),
  12071.                                 'serviceType' => 'Asistente',
  12072.                                 'date' => $dateServ,
  12073.                                 'qty' => $unitsServ,
  12074.                                 'iva' => $item->getIva(),
  12075.                                 'pax' => $item->getPax(),
  12076.                                 'precioUnit' => $subnetoUnit,
  12077.                                 'subneto' => $subneto,
  12078.                                 'subtotal' => $subtotal,
  12079.                             );
  12080.                             break;
  12081.                         case 16//DDR
  12082.                             $pax $item->getPax();
  12083.                             if (empty($pax) or $pax == "0") {
  12084.                                 $pax 1;
  12085.                             }
  12086.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  12087.                             if ($days 1) {
  12088.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  12089.                             } else {
  12090.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  12091.                             }
  12092.                             $unitsServ $item->getUnits();
  12093.                             if (empty($unitsServ) or $unitsServ == "0") {
  12094.                                 $unitsServ 1;
  12095.                             }
  12096.                             $subtotal $subtotalService $days $unitsServ $pax;
  12097.                             $subnetoUnit $subneto;
  12098.                             $subneto $subneto $days $unitsServ $pax;
  12099.                             $data_supplier['service'][$i] = array(
  12100.                                 'id' => $item->getId(),
  12101.                                 'serviceCatId' => $item->getServiceCatId(),
  12102.                                 'serviceName' => $item->getName(),
  12103.                                 'serviceType' => 'DDR',
  12104.                                 'date' => $dateServ,
  12105.                                 'qty' => $unitsServ,
  12106.                                 'iva' => $item->getIva(),
  12107.                                 'pax' => $item->getPax(),
  12108.                                 'precioUnit' => $subnetoUnit,
  12109.                                 'subneto' => $subneto,
  12110.                                 'subtotal' => $subtotal,
  12111.                             );
  12112.                             break;
  12113.                         default:
  12114.                             break;
  12115.                     }
  12116.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  12117.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  12118.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  12119.                     $arrayItems[] = array(
  12120.                         'type' => 'Service',
  12121.                         'name' => $item->getName(),
  12122.                         'amount' => $neto,
  12123.                         'iva' => $item->getIva(),
  12124.                         'total' => $subtotal,
  12125.                     );
  12126.                 }
  12127.                 switch ($item->getIva()) {
  12128.                         // Acumula IVA
  12129.                     case 21:
  12130.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  12131.                         break;
  12132.                     case 10:
  12133.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  12134.                         break;
  12135.                     case 0:
  12136.                         $data_iva['ivaMontoCero'] = 0;
  12137.                         break;
  12138.                     default:
  12139.                         break;
  12140.                 }
  12141.             }
  12142.             $totales_neto_all $totales_neto_all $neto;
  12143.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12144.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  12145.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  12146.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  12147.             $data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2PHP_ROUND_HALF_UP);
  12148.             // Acumula netos totales e IVA
  12149.             $service['neto'] = $service['neto'] + $neto;
  12150.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  12151.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12152.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  12153.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  12154.             $i++;
  12155.         }
  12156.         $data_supplier['serviceSubTotal'] = array(
  12157.             'neto' => $service['neto'],
  12158.             'sumSubT' => $service['sumSubT'],
  12159.         );
  12160.         $currency '€';
  12161.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  12162.         if (!empty($payments)) {
  12163.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  12164.         } else {
  12165.             $amount_pay 0;
  12166.         }
  12167.         $totales_all $totales_total $amount_pay;
  12168.         if (empty($dateDocument)) {
  12169.             $dateDocument = new DateTime('now');
  12170.         }
  12171.         $data = array(
  12172.             'id' => $fileId,
  12173.             'type' => $type,
  12174.             'number' => $number,
  12175.             'prefix' => 'AVE-' . (new DateTime('now'))->format('dmy') . '-' $invoiceId,
  12176.             'date' => $dateDocument,
  12177.             'file' => $file,
  12178.             'token' => $file->getAccessKey(),
  12179.             'company' => $company,
  12180.             'clients' => $clientNew,
  12181.             'arrayItems' => $arrayItems,
  12182.             'datasupplier' => $data_supplier,
  12183.             'currency' => $currency,
  12184.             'totales_neto' => $totales_neto_all,
  12185.             'bases_imponibles' => $data_iva,
  12186.             'totales' => $totales_total,
  12187.             'balance' => $totales_all,
  12188.             'paymentInvoice' => $amount_pay,
  12189.         );
  12190.         return $data;
  12191.     }
  12192.     private function baseInvoiceDoneFileTwo($fileId$invoiceId$typeBase)
  12193.     {
  12194.         $em $this->getDoctrine()->getManager();
  12195.         $file $em->getRepository(AveFiles::class)->findOneById($fileId);
  12196.         $dateDocument null;                                                                           //Fecha final del documento
  12197.         $subneto 0;
  12198.         if (($typeBase == 'I') or ($typeBase == 'P')) {
  12199.             if ($typeBase == 'I') {
  12200.                 $items $em->getRepository(AveDocInvoiceItems::class)->findBy(array('fileId' => $fileId'invoiceId' => $invoiceId));
  12201.             } else {
  12202.                 // Es factura ni proforma
  12203.                 $items $em->getRepository(AveDocProformaItems::class)->findBy(array('fileId' => $fileId'proformaId' => $invoiceId));
  12204.             }
  12205.         } else {
  12206.             // No es factura ni proforma, es una rectificativa
  12207.             $items $em->getRepository(AveDocInvoiceRecItems::class)->findBy(array('fileId' => $fileId'invoiceRecId' => $invoiceId));
  12208.         }
  12209.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  12210.         $client $em->getRepository(Client::class)->findById($file->getClient());
  12211.         if (empty($client)) {
  12212.             $client[0] = new Client();
  12213.             $client[0]->setName('');
  12214.             $client[0]->setTitle('');
  12215.             $client[0]->setIdDocument('');
  12216.             $client[0]->setPopulation('');
  12217.             $client[0]->setRegion('');
  12218.             $client[0]->setCountry('');
  12219.         } else {
  12220.             if (is_numeric($client[0]->getPopulation())) {
  12221.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  12222. //                $client[0]->setPopulation($city->getCity());
  12223.             }
  12224.             if (is_numeric($client[0]->getRegion())) {
  12225.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  12226. //                $client[0]->setRegion($region->getRegion());
  12227.             }
  12228.             if (is_numeric($client[0]->getCountry())) {
  12229.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  12230. //                $client[0]->setCountry($country->getCountry());
  12231.             }
  12232.         }
  12233.         if (empty($client)) {
  12234.             $client[0] = new Client();
  12235.             $client[0]->setName('');
  12236.             $client[0]->setTitle('');
  12237.             $client[0]->setIdDocument('');
  12238.             $client[0]->setPopulation('');
  12239.             $client[0]->setRegion('');
  12240.             $client[0]->setCountry('');
  12241.             $clientNew = array(
  12242.                 'name' => '',
  12243.                 'title' => '',
  12244.                 'idDocument' => '',
  12245.                 'population' => '',
  12246.                 'region' => '',
  12247.                 'country' => '',
  12248.                 'address' => '',
  12249.                 'addressNumber' => '',
  12250.                 'zipCode' => '',
  12251.                 'typeDocument' => '',
  12252.             );
  12253.         } else {
  12254.             $clientNew = array(
  12255.                 'name' => $client[0]->getName(),
  12256.                 'title' => $client[0]->getTitle(),
  12257.                 'idDocument' => $client[0]->getIdDocument(),
  12258.                 'population' => '',
  12259.                 'region' => '',
  12260.                 'country' => '',
  12261.                 'address' => $client[0]->getAddress(),
  12262.                 'addressNumber' => $client[0]->getAddressNumber(),
  12263.                 'zipCode' => $client[0]->getZipCode(),
  12264.                 'typeDocument' => $client[0]->getTypeDocument(),
  12265.             );
  12266.             if (is_numeric($client[0]->getPopulation())) {
  12267.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  12268.                 $clientNew['population'] = $city->getCity();
  12269.             }
  12270.             if (is_numeric($client[0]->getRegion())) {
  12271.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  12272.                 $clientNew['region'] = $region->getRegion();
  12273.             }
  12274.             if (is_numeric($client[0]->getCountry())) {
  12275.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  12276.                 $clientNew['country'] = $country->getCountry();
  12277.             }
  12278.         }
  12279.         // Acumuladores de los calculos
  12280.         $totales_neto_all 0;
  12281.         $data_iva = array(
  12282.             'iva' => 21,
  12283.             'ivaMontoVeintiUno' => 0,
  12284.             'ivaMontoDiez' => 0,
  12285.             'ivaMontoCero' => 0,
  12286.         );
  12287.         //INICIO: Determinamos el numero de factura o proforma
  12288.         if ($typeBase == 'I') {
  12289.             // Es una Factura
  12290.             $number $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
  12291.             $dateDocument $number->getDateAt();
  12292.             $number $number->getNumber();
  12293.             $type 'Invoice';
  12294.         } else {
  12295.             if ($typeBase == 'R') {
  12296.                 // Es una factura rectificativa
  12297.                 $number $em->getRepository(AveDocInvoiceRec::class)->findOneById($invoiceId);
  12298.                 $dateDocument $number->getDateAt();
  12299.                 $type 'Invoice Rec';
  12300.             } else {
  12301.                 // Es una Proforma
  12302.                 $number $invoiceId;
  12303.                 $type 'Proforma';
  12304.             }
  12305.         }
  12306.         //FIN: Determinamos el numero de factura o proforma
  12307.         // Buscamos los productos, pagos y servicios
  12308.         $arrayItems = array();
  12309.         $fileProducts = array();
  12310.         $payments = array();
  12311.         $services = array();
  12312.         if (!empty($items)) {
  12313.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  12314.                 foreach ($items as $item) {
  12315.                     switch ($item->getItemType()) {
  12316.                         case 'PRODUCT'// Producto
  12317.                             $fileProducts[] = $item;
  12318.                             break;
  12319.                         case 'PAYMENT'// Pago
  12320.                             $payments[] = $item;
  12321.                             break;
  12322.                         case 'SERVICE'// Servicio
  12323.                             $services[] = $item;
  12324.                             break;
  12325.                         default:
  12326.                             break;
  12327.                     }
  12328.                 }
  12329.             } else {
  12330.                 // Es una proforma
  12331.                 foreach ($items as $item) {
  12332.                     switch ($item->getType()) {
  12333.                         case 'PRODUCT'// Producto
  12334.                             $productPro $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
  12335.                             if (!empty($productPro)) {
  12336.                                 $fileProducts[] = $productPro;
  12337.                             }
  12338.                             break;
  12339.                         case 'PAYMENT'// Pago
  12340.                             $paymentPro $em->getRepository(AvePaymentsClient::class)->findOneById($item->getControlId());
  12341.                             if (!empty($paymentPro)) {
  12342.                                 $payments[] = $paymentPro;
  12343.                             }
  12344.                             break;
  12345.                         case 'SERVICE'// Servicio
  12346.                             $servicePro $em->getRepository(AveServices::class)->findOneById($item->getControlId());
  12347.                             if (!empty($servicePro)) {
  12348.                                 $services[] = $servicePro;
  12349.                             }
  12350.                             break;
  12351.                         default:
  12352.                             break;
  12353.                     }
  12354.                 }
  12355.             }
  12356.         }
  12357.         $data_supplier = array();
  12358.         $i 0;
  12359.         $iva '21';            // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
  12360.         $pax '1';
  12361.         $qty '1';
  12362.         $product = array(
  12363.             'neto' => 0,
  12364.             'sumSubT' => 0,
  12365.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  12366.         $service = array(
  12367.             'neto' => 0,
  12368.             'sumSubT' => 0,
  12369.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  12370.         foreach ($fileProducts as $item) {
  12371.             if (!is_null($item->getUnits()) or !empty($item->getUnits())) {
  12372.                 $qty $item->getUnits();
  12373.             }
  12374.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  12375.                 if (is_null($item->getPrdServicePrice()) or empty($item->getPrdServicePrice())) {
  12376.                     $subtotal 0;
  12377.                     $neto 0;
  12378.                     $subtotalProduct 0;
  12379.                     $ivaFactor 0;
  12380.                 } else {
  12381.                         
  12382.                     //Buscamos el iva
  12383.                     $zProductFile $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  12384.                     if (empty($zProductFile)){ $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
  12385. //                    $subtotalProduct = $item->getPrdServicePrice() * 1.21;
  12386.                     $ivaFactor = empty($zProductFile) ? 21 $zProductFile->getIva();
  12387.                     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
  12388.                     $ivaFactor = (+ ($ivaFactor/100));
  12389.                     
  12390.                     $subtotalProduct $item->getPrdSubTotalPrice() * $ivaFactor;
  12391.                     $ivaFactor = (($ivaFactor 1) * 100);
  12392.                     $subneto $item->getPrdSubTotalPrice();
  12393.                     $subtotal =  $subtotalProduct;
  12394.                     $neto =  $subneto;
  12395.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  12396.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  12397.                     $neto round($neto2PHP_ROUND_HALF_UP);
  12398.                     $arrayItems[] = array(
  12399.                         'type' => 'Product',
  12400.                         'name' => $item->getPrdName(),
  12401.                         'amount' => $neto,
  12402.                         'iva' => $ivaFactor,
  12403.                         'total' => $subtotal,
  12404.                     );
  12405.                 }
  12406.             } else {
  12407.                 // Es proforma
  12408.                 if (is_null($item->getServicePrice()) or empty($item->getServicePrice())) {
  12409.                     $subtotal 0;
  12410.                     $neto 0;
  12411.                     $subtotalProduct 0;
  12412.                     $ivaFactor 0;
  12413.                 } else {
  12414.                     //Buscamos el iva
  12415. //                    d($item);
  12416. //                    $zProductFile = $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  12417.                     $zProductFile $item;
  12418.                     if (empty($zProductFile)){ $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
  12419. //                    $subtotalProduct = $item->getServicePrice() * 1.21;
  12420.                     $ivaFactor = empty($zProductFile) ? 21 $zProductFile->getIva();
  12421. //                    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
  12422.                     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
  12423.                     $ivaFactor = (+ ($ivaFactor/100));
  12424.                     $subtotalProduct $item->getSubTotalPrice() * $ivaFactor;
  12425.                     $ivaFactor = (($ivaFactor 1) * 100);
  12426.                     $subneto $item->getSubTotalPrice();
  12427.                     $subtotal =  $subtotalProduct;
  12428.                     $neto =  $subneto;
  12429.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  12430.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  12431.                     $neto round($neto2PHP_ROUND_HALF_UP);
  12432.                     $arrayItems[] = array(
  12433.                         'type' => 'Product',
  12434.                         'name' => $item->getProductName(),
  12435.                         'amount' => $neto,
  12436.                         'iva' => '21',
  12437.                         'total' => $subtotal,
  12438.                     );
  12439.                 }
  12440.             }
  12441.             // Acumula netos totales e IVA
  12442.             $totales_neto_all $totales_neto_all $neto;
  12443.             switch ($ivaFactor) {
  12444.                 case 21$data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21); break;
  12445.                 case 10$data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1); break;
  12446.                 case 0$data_iva['ivaMontoCero'] = 0; break;
  12447.                 default: break;
  12448.             }
  12449.             
  12450.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12451.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  12452.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  12453.             // Acumula netos totales e IVA
  12454.             $product['neto'] = $product['neto'] + $neto;
  12455.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  12456.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12457.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  12458.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  12459.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  12460.                 $data_supplier['product'][$i] = array(
  12461.                     'id' => $item->getId(),
  12462.                     'productName' => $item->getPrdName(),
  12463.                     'productId' => $item->getPrdProductId(),
  12464.                     'dateStart' => $item->getPrdDateStart(),
  12465.                     'dateEnd' => $item->getPrdDateEnd(),
  12466.                     'servicePrice' => $item->getPrdServicePrice(),
  12467.                     'serviceSubTotalPrice' => $subneto,     //antes de IVA
  12468.                     'subtotalProduct' => $subtotalProduct,
  12469.                     'iva' => $iva,
  12470.                     'pax' => $pax,
  12471.                     'qty' => $qty,
  12472.                     'type' => $item->getPrdType(),
  12473.                     'subtotal' => $subtotal,
  12474.                 );
  12475.             } else {
  12476.                 // Es proforma
  12477.                 $data_supplier['product'][$i] = array(
  12478.                     'id' => $item->getId(),
  12479.                     'productName' => $item->getProductName(),
  12480.                     'productId' => $item->getProductId(),
  12481.                     'dateStart' => $item->getDateStart(),
  12482.                     'dateEnd' => $item->getDateEnd(),
  12483.                     'servicePrice' => $item->getServicePrice(),
  12484.                     'subtotalProduct' => $subtotalProduct,
  12485.                     'iva' => $iva,
  12486.                     'pax' => $pax,
  12487.                     'qty' => $qty,
  12488.                     'type' => $item->getType(),
  12489.                     'subtotal' => $subtotal,
  12490.                 );
  12491.             }
  12492.             $i++;
  12493.         }
  12494.         $data_supplier['productSubTotal'] = array(
  12495.             'neto' => $product['neto'],
  12496.             'sumSubT' => $product['sumSubT'],
  12497.         );
  12498.         $payment = array(
  12499.             'sumSubT' => 0,
  12500.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  12501.         $i 0;
  12502.         foreach ($payments as $item) {
  12503.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  12504.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getPayAmountTotal();
  12505.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12506.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  12507.                 $data_supplier['payment'][$i] = array(
  12508.                     'id' => $item->getId(),
  12509.                     'amount' => $item->getPayAmount(),
  12510.                     'amountTotal' => $item->getPayAmountTotal(),
  12511.                     'vat' => $item->getPayVat(),
  12512.                     'datePayAt' => $item->getPayDatePayAt(),
  12513.                     'wayToPay' => $item->getPayWayToPay(),
  12514.                 );
  12515.                 $arrayItems[] = array(
  12516.                     'type' => 'Payment',
  12517.                     'name' => $item->getPayWayToPay(),
  12518.                     'amount' => $item->getPayAmount(),
  12519.                     'total' => $item->getPayAmountTotal(),
  12520.                     'iva' => $item->getPayVat(),
  12521.                 );
  12522.             } else {
  12523.                 // Es una proforma
  12524.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  12525.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12526.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  12527.                 $data_supplier['payment'][$i] = array(
  12528.                     'id' => $item->getId(),
  12529.                     'amount' => $item->getAmount(),
  12530.                     'amountTotal' => $item->getAmountTotal(),
  12531.                     'vat' => $item->getVat(),
  12532.                     'datePayAt' => $item->getDatePayAt(),
  12533.                     'wayToPay' => $item->getWayToPay(),
  12534.                 );
  12535.                 $arrayItems[] = array(
  12536.                     'type' => 'Payment',
  12537.                     'name' => $item->getWayToPay(),
  12538.                     'amount' => $item->getAmount(),
  12539.                     'total' => $item->getAmountTotal(),
  12540.                     'iva' => $item->getVat(),
  12541.                 );
  12542.             }
  12543.             $i++;
  12544.         }
  12545.         if (!empty($payments)) {
  12546.             $data_supplier['paymentSubTotal'] = array(
  12547.                 'sumSubT' => $payment['sumSubT'],
  12548.             );
  12549.         }
  12550.         foreach ($services as $item) {
  12551.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  12552.                 if (is_null($item->getSrvPrice()) or empty($item->getSrvPrice())) {
  12553.                     $subtotal 0;
  12554.                     $neto 0;
  12555.                     $subtotalService 0;
  12556.                 } else {
  12557.                     $subtotalService $item->getSrvPrice();
  12558.                     $subneto $item->getSrvPrice();
  12559.                     // Commission
  12560.                     if ($item->getSrvOpCommission() == '1') {
  12561.                         $subtotalService $subtotalService * (+ ($item->getSrvCommission() / 100));
  12562.                         $subneto $subneto * (+ ($item->getSrvCommission() / 100));
  12563.                     } else {
  12564.                         $subtotalService $subtotalService * (- ($item->getSrvCommission() / 100));
  12565.                         $subneto $subneto * (- ($item->getSrvCommission() / 100));
  12566.                     }
  12567.                     // Over
  12568.                     if ($item->getSrvOpOver() == '1') {
  12569.                         $subtotalService $subtotalService $item->getSrvOver();
  12570.                         $subneto $subneto $item->getSrvOver();
  12571.                     } else {
  12572.                         $subtotalService $subtotalService $item->getSrvOver();
  12573.                         $subneto $subneto $item->getSrvOver();
  12574.                     }
  12575.                     // IVA
  12576.                     if ($item->getSrvOpIva() == '1') {
  12577.                         $subtotalService $subtotalService * (+ ($item->getSrvIva() / 100));
  12578.                     } else {
  12579.                         $subtotalService $item->getSrvPrice();
  12580.                         $subneto = ($subneto 100) / (100 $item->getSrvIva());
  12581.                     }
  12582.                     switch ($item->getSrvServiceCatId()) {
  12583.                         case 1// Alojamiento
  12584.                             // el numero de noches $numNoches; precio unitario $subneto
  12585.                             $numNoches = (($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days;
  12586.                             // La personas no afectan este calculo
  12587.                             $subtotal $subtotalService $numNoches $item->getSrvUnits();
  12588.                             $subnetoUnit $subneto;
  12589.                             $subneto $subneto $numNoches $item->getSrvUnits();
  12590.                             $data_supplier['service'][$i] = array(
  12591.                                 'id' => $item->getId(),
  12592.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12593.                                 'serviceName' => $item->getSrvName(),
  12594.                                 'serviceType' => 'Hotel',
  12595.                                 'date' => ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y'),
  12596.                                 'qty' => $item->getSrvUnits(),
  12597.                                 'iva' => $item->getSrvIva(),
  12598.                                 'pax' => '-',
  12599.                                 'precioUnit' => $subnetoUnit,
  12600.                                 'subneto' => $subneto,
  12601.                                 'subtotal' => $subtotal,
  12602.                             );
  12603.                             break;
  12604.                         case 2//Actividades
  12605.                             // El nĂºmero de personas es considerado en el calculo
  12606.                             $pax $item->getSrvPax();
  12607.                             if (empty($pax) or $pax == "0") {
  12608.                                 $pax 1;
  12609.                             }
  12610.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12611.                             if ($days 1) {
  12612.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12613.                             } else {
  12614.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12615.                             }
  12616.                             $subtotal $subtotalService $days $item->getSrvUnits();
  12617.                             $subnetoUnit $subneto;
  12618.                             $subneto $subneto $days $item->getSrvUnits();
  12619.                             $data_supplier['service'][$i] = array(
  12620.                                 'id' => $item->getId(),
  12621.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12622.                                 'serviceName' => $item->getSrvName(),
  12623.                                 'serviceType' => 'Actividad',
  12624.                                 'date' => $dateServ,
  12625.                                 'qty' => $item->getSrvUnits(),
  12626.                                 'iva' => $item->getSrvIva(),
  12627.                                 'pax' => $item->getSrvPax(),
  12628.                                 'precioUnit' => $subnetoUnit,
  12629.                                 'subneto' => $subneto,
  12630.                                 'subtotal' => $subtotal,
  12631.                             );
  12632.                             break;
  12633.                         case 3// AV
  12634.                             $pax $item->getSrvPax();
  12635.                             if (empty($pax) or $pax == "0") {
  12636.                                 $pax 1;
  12637.                             }
  12638.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12639.                             if ($days 1) {
  12640.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12641.                             } else {
  12642.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12643.                             }
  12644.                             $unitsServ $item->getSrvUnits();
  12645.                             if (empty($unitsServ) or $unitsServ == "0") {
  12646.                                 $unitsServ 1;
  12647.                             }
  12648.                             $subtotal $subtotalService $days $unitsServ $pax;
  12649.                             $subnetoUnit $subneto;
  12650.                             $subneto $subneto $days $unitsServ $pax;
  12651.                             $data_supplier['service'][$i] = array(
  12652.                                 'id' => $item->getId(),
  12653.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12654.                                 'serviceName' => $item->getSrvName(),
  12655.                                 'serviceType' => 'AV',
  12656.                                 'date' => $dateServ,
  12657.                                 'qty' => $unitsServ,
  12658.                                 'iva' => $item->getSrvIva(),
  12659.                                 'pax' => $item->getSrvPax(),
  12660.                                 'precioUnit' => $subnetoUnit,
  12661.                                 'subneto' => $subneto,
  12662.                                 'subtotal' => $subtotal,
  12663.                             );
  12664.                             break;
  12665.                         case 4//Creative
  12666.                             $pax $item->getSrvPax();
  12667.                             if (empty($pax) or $pax == "0") {
  12668.                                 $pax 1;
  12669.                             }
  12670.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12671.                             if ($days 1) {
  12672.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12673.                             } else {
  12674.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12675.                             }
  12676.                             $unitsServ $item->getSrvUnits();
  12677.                             if (empty($unitsServ) or $unitsServ == "0") {
  12678.                                 $unitsServ 1;
  12679.                             }
  12680.                             $subtotal $subtotalService $days $unitsServ $pax;
  12681.                             $subnetoUnit $subneto;
  12682.                             $subneto $subneto $days $unitsServ $pax;
  12683.                             $data_supplier['service'][$i] = array(
  12684.                                 'id' => $item->getId(),
  12685.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12686.                                 'serviceName' => $item->getSrvName(),
  12687.                                 'serviceType' => 'Creativo',
  12688.                                 'date' => $dateServ,
  12689.                                 'qty' => $unitsServ,
  12690.                                 'iva' => $item->getSrvIva(),
  12691.                                 'pax' => $item->getSrvPax(),
  12692.                                 'precioUnit' => $subnetoUnit,
  12693.                                 'subneto' => $subneto,
  12694.                                 'subtotal' => $subtotal,
  12695.                             );
  12696.                             break;
  12697.                         case 5//Cruise
  12698.                             $pax $item->getSrvPax();
  12699.                             if (empty($pax) or $pax == "0") {
  12700.                                 $pax 1;
  12701.                             }
  12702.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days);
  12703.                             if ($days 1) {
  12704.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12705.                             } else {
  12706.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12707.                             }
  12708.                             $unitsServ $item->getSrvUnits();
  12709.                             if (empty($unitsServ) or $unitsServ == "0") {
  12710.                                 $unitsServ 1;
  12711.                             }
  12712.                             $subtotal $subtotalService $days $unitsServ $pax;
  12713.                             $subnetoUnit $subneto;
  12714.                             $subneto $subneto $days $unitsServ $pax;
  12715.                             $data_supplier['service'][$i] = array(
  12716.                                 'id' => $item->getId(),
  12717.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12718.                                 'serviceName' => $item->getSrvName(),
  12719.                                 'serviceType' => 'Crucero',
  12720.                                 'date' => $dateServ,
  12721.                                 'qty' => $unitsServ,
  12722.                                 'iva' => $item->getSrvIva(),
  12723.                                 'pax' => $item->getSrvPax(),
  12724.                                 'precioUnit' => $subnetoUnit,
  12725.                                 'subneto' => $subneto,
  12726.                                 'subtotal' => $subtotal,
  12727.                             );
  12728.                             break;
  12729.                         case 6//Entertaiment
  12730.                             $pax $item->getSrvPax();
  12731.                             if (empty($pax) or $pax == "0") {
  12732.                                 $pax 1;
  12733.                             }
  12734.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12735.                             if ($days 1) {
  12736.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12737.                             } else {
  12738.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12739.                             }
  12740.                             $unitsServ $item->getSrvUnits();
  12741.                             if (empty($unitsServ) or $unitsServ == "0") {
  12742.                                 $unitsServ 1;
  12743.                             }
  12744.                             $subtotal $subtotalService $days $unitsServ $pax;
  12745.                             $subnetoUnit $subneto;
  12746.                             $subneto $subneto $days $unitsServ $pax;
  12747.                             $data_supplier['service'][$i] = array(
  12748.                                 'id' => $item->getId(),
  12749.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12750.                                 'serviceName' => $item->getSrvName(),
  12751.                                 'serviceType' => 'Entretenimiento',
  12752.                                 'date' => $dateServ,
  12753.                                 'qty' => $unitsServ,
  12754.                                 'iva' => $item->getSrvIva(),
  12755.                                 'pax' => $item->getSrvPax(),
  12756.                                 'precioUnit' => $subnetoUnit,
  12757.                                 'subneto' => $subneto,
  12758.                                 'subtotal' => $subtotal,
  12759.                             );
  12760.                             break;
  12761.                         case 7// Gifts
  12762.                             $pax $item->getSrvPax();
  12763.                             if (empty($pax) or $pax == "0") {
  12764.                                 $pax 1;
  12765.                             }
  12766.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  12767.                             $days 1;
  12768.                             if ($days 1) {
  12769.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12770.                             } else {
  12771.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12772.                             }
  12773.                             $unitsServ $item->getSrvUnits();
  12774.                             if (empty($unitsServ) or $unitsServ == "0") {
  12775.                                 $unitsServ 1;
  12776.                             }
  12777.                             $subtotal $subtotalService $days $unitsServ $pax;
  12778.                             $subnetoUnit $subneto;
  12779.                             $subneto $subneto $days $unitsServ $pax;
  12780.                             $data_supplier['service'][$i] = array(
  12781.                                 'id' => $item->getId(),
  12782.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12783.                                 'serviceName' => $item->getSrvName(),
  12784.                                 'serviceType' => 'Regalos',
  12785.                                 'date' => $dateServ,
  12786.                                 'qty' => $unitsServ,
  12787.                                 'iva' => $item->getSrvIva(),
  12788.                                 'pax' => $item->getSrvPax(),
  12789.                                 'precioUnit' => $subnetoUnit,
  12790.                                 'subneto' => $subneto,
  12791.                                 'subtotal' => $subtotal,
  12792.                             );
  12793.                             break;
  12794.                         case 8//Guide
  12795.                             $pax $item->getSrvPax();
  12796.                             if (empty($pax) or $pax == "0") {
  12797.                                 $pax 1;
  12798.                             }
  12799.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12800.                             if ($days 1) {
  12801.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12802.                             } else {
  12803.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12804.                             }
  12805.                             $unitsServ $item->getSrvUnits();
  12806.                             if (empty($unitsServ) or $unitsServ == "0") {
  12807.                                 $unitsServ 1;
  12808.                             }
  12809.                             $subtotal $subtotalService $days $unitsServ $pax;
  12810.                             $subnetoUnit $subneto;
  12811.                             $subneto $subneto $days $unitsServ $pax;
  12812.                             $data_supplier['service'][$i] = array(
  12813.                                 'id' => $item->getId(),
  12814.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12815.                                 'serviceName' => $item->getSrvName(),
  12816.                                 'serviceType' => 'Regalos',
  12817.                                 'date' => $dateServ,
  12818.                                 'qty' => $unitsServ,
  12819.                                 'iva' => $item->getSrvIva(),
  12820.                                 'pax' => $item->getSrvPax(),
  12821.                                 'precioUnit' => $subnetoUnit,
  12822.                                 'subneto' => $subneto,
  12823.                                 'subtotal' => $subtotal,
  12824.                             );
  12825.                             break;
  12826.                         case 9//Itineraries
  12827.                             $pax $item->getSrvPax();
  12828.                             if (empty($pax) or $pax == "0") {
  12829.                                 $pax 1;
  12830.                             }
  12831.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12832.                             if ($days 1) {
  12833.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12834.                             } else {
  12835.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12836.                             }
  12837.                             $unitsServ $item->getSrvUnits();
  12838.                             if (empty($unitsServ) or $unitsServ == "0") {
  12839.                                 $unitsServ 1;
  12840.                             }
  12841.                             $subtotal $subtotalService $days $unitsServ $pax;
  12842.                             $subnetoUnit $subneto;
  12843.                             $subneto $subneto $days $unitsServ $pax;
  12844.                             $data_supplier['service'][$i] = array(
  12845.                                 'id' => $item->getId(),
  12846.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12847.                                 'serviceName' => $item->getSrvName(),
  12848.                                 'serviceType' => 'Itinerarios',
  12849.                                 'date' => $dateServ,
  12850.                                 'qty' => $unitsServ,
  12851.                                 'iva' => $item->getSrvIva(),
  12852.                                 'pax' => $item->getSrvPax(),
  12853.                                 'precioUnit' => $subnetoUnit,
  12854.                                 'subneto' => $subneto,
  12855.                                 'subtotal' => $subtotal,
  12856.                             );
  12857.                             break;
  12858.                         case 10//Lounge  -- No Aplica
  12859.                             //                        $pax = $item->getPax();
  12860.                             //                        if (empty($pax) or $pax == "0") {
  12861.                             //                            $pax = 1;
  12862.                             //                        }
  12863.                             //
  12864.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  12865.                             //                        if ($days > 1){
  12866.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  12867.                             //                        } else {
  12868.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  12869.                             //                        }
  12870.                             //
  12871.                             //                        $unitsServ = $item->getUnits();
  12872.                             //                        if (empty($unitsServ) or $unitsServ == "0") {
  12873.                             //                            $unitsServ = 1;
  12874.                             //                        }
  12875.                             //
  12876.                             //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  12877.                             //                        $subnetoUnit = $subneto;
  12878.                             //                        $subneto = $subneto * $days * $unitsServ * $pax;
  12879.                             //
  12880.                             //                        $data_supplier['service'][$i] = array (
  12881.                             //                            'id' => $item->getId(),
  12882.                             //                            'serviceCatId' => $item->getServiceCatId(),
  12883.                             //                            'serviceName' => $item->getName(),
  12884.                             //                            'serviceType' => 'Itinerarios',
  12885.                             //                            'date' => $dateServ,
  12886.                             //                            'qty' => $unitsServ,
  12887.                             //                            'iva' => $item->getIva(),
  12888.                             //                            'pax' => $item->getPax(),
  12889.                             //                            'precioUnit' => $subnetoUnit,
  12890.                             //                            'subneto' => $subneto,
  12891.                             //                            'subtotal' => $subtotal,
  12892.                             //                        );
  12893.                             break;
  12894.                         case 11//Menu
  12895.                             $pax $item->getSrvPax();
  12896.                             if (empty($pax) or $pax == "0") {
  12897.                                 $pax 1;
  12898.                             }
  12899.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12900.                             if ($days 1) {
  12901.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12902.                             } else {
  12903.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12904.                             }
  12905.                             $unitsServ $item->getSrvUnits();
  12906.                             if (empty($unitsServ) or $unitsServ == "0") {
  12907.                                 $unitsServ 1;
  12908.                             }
  12909.                             $subtotal $subtotalService $days $unitsServ $pax;
  12910.                             $subnetoUnit $subneto;
  12911.                             $subneto $subneto $days $unitsServ $pax;
  12912.                             $data_supplier['service'][$i] = array(
  12913.                                 'id' => $item->getId(),
  12914.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12915.                                 'serviceName' => $item->getSrvName(),
  12916.                                 'serviceType' => 'MenĂº',
  12917.                                 'date' => $dateServ,
  12918.                                 'qty' => $unitsServ,
  12919.                                 'iva' => $item->getSrvIva(),
  12920.                                 'pax' => $item->getSrvPax(),
  12921.                                 'precioUnit' => $subnetoUnit,
  12922.                                 'subneto' => $subneto,
  12923.                                 'subtotal' => $subtotal,
  12924.                             );
  12925.                             break;
  12926.                         case 12//Others
  12927.                             $pax $item->getSrvPax();
  12928.                             if (empty($pax) or $pax == "0") {
  12929.                                 $pax 1;
  12930.                             }
  12931.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12932.                             if ($days 1) {
  12933.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12934.                             } else {
  12935.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12936.                             }
  12937.                             $unitsServ $item->getSrvUnits();
  12938.                             if (empty($unitsServ) or $unitsServ == "0") {
  12939.                                 $unitsServ 1;
  12940.                             }
  12941.                             $subtotal $subtotalService $days $unitsServ $pax;
  12942.                             $subnetoUnit $subneto;
  12943.                             $subneto $subneto $days $unitsServ $pax;
  12944.                             $data_supplier['service'][$i] = array(
  12945.                                 'id' => $item->getId(),
  12946.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12947.                                 'serviceName' => $item->getSrvName(),
  12948.                                 'serviceType' => 'Otros',
  12949.                                 'date' => $dateServ,
  12950.                                 'qty' => $unitsServ,
  12951.                                 'iva' => $item->getSrvIva(),
  12952.                                 'pax' => $item->getSrvPax(),
  12953.                                 'precioUnit' => $subnetoUnit,
  12954.                                 'subneto' => $subneto,
  12955.                                 'subtotal' => $subtotal,
  12956.                             );
  12957.                             break;
  12958.                         case 13//Transport
  12959.                             $pax $item->getSrvPax();
  12960.                             if (empty($pax) or $pax == "0") {
  12961.                                 $pax 1;
  12962.                             }
  12963.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12964.                             if ($days 1) {
  12965.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12966.                             } else {
  12967.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12968.                             }
  12969.                             $unitsServ $item->getSrvUnits();
  12970.                             if (empty($unitsServ) or $unitsServ == "0") {
  12971.                                 $unitsServ 1;
  12972.                             }
  12973.                             $subtotal $subtotalService $days $unitsServ $pax;
  12974.                             $subnetoUnit $subneto;
  12975.                             $subneto $subneto $days $unitsServ $pax;
  12976.                             $data_supplier['service'][$i] = array(
  12977.                                 'id' => $item->getId(),
  12978.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12979.                                 'serviceName' => $item->getSrvName(),
  12980.                                 'serviceType' => 'Transporte',
  12981.                                 'date' => $dateServ,
  12982.                                 'qty' => $unitsServ,
  12983.                                 'iva' => $item->getSrvIva(),
  12984.                                 'pax' => $item->getSrvPax(),
  12985.                                 'precioUnit' => $subnetoUnit,
  12986.                                 'subneto' => $subneto,
  12987.                                 'subtotal' => $subtotal,
  12988.                             );
  12989.                             break;
  12990.                         case 14//Technology
  12991.                             $pax $item->getSrvPax();
  12992.                             if (empty($pax) or $pax == "0") {
  12993.                                 $pax 1;
  12994.                             }
  12995.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  12996.                             $days 1;
  12997.                             //                        if ($days > 1){
  12998.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  12999.                             //                        } else {
  13000.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13001.                             //                        }
  13002.                             $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  13003.                             $unitsServ $item->getSrvUnits();
  13004.                             if (empty($unitsServ) or $unitsServ == "0") {
  13005.                                 $unitsServ 1;
  13006.                             }
  13007.                             $subtotal $subtotalService $days $unitsServ $pax;
  13008.                             $subnetoUnit $subneto;
  13009.                             $subneto $subneto $days $unitsServ $pax;
  13010.                             $data_supplier['service'][$i] = array(
  13011.                                 'id' => $item->getId(),
  13012.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  13013.                                 'serviceName' => $item->getSrvName(),
  13014.                                 'serviceType' => 'TecnologĂ­a',
  13015.                                 'date' => $dateServ,
  13016.                                 'qty' => $unitsServ,
  13017.                                 'iva' => $item->getSrvIva(),
  13018.                                 'pax' => $item->getSrvPax(),
  13019.                                 'precioUnit' => $subnetoUnit,
  13020.                                 'subneto' => $subneto,
  13021.                                 'subtotal' => $subtotal,
  13022.                             );
  13023.                             break;
  13024.                         case 15//Assisstant
  13025.                             $pax $item->getSrvPax();
  13026.                             if (empty($pax) or $pax == "0") {
  13027.                                 $pax 1;
  13028.                             }
  13029.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  13030.                             if ($days 1) {
  13031.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  13032.                             } else {
  13033.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  13034.                             }
  13035.                             $unitsServ $item->getSrvUnits();
  13036.                             if (empty($unitsServ) or $unitsServ == "0") {
  13037.                                 $unitsServ 1;
  13038.                             }
  13039.                             $subtotal $subtotalService $days $unitsServ $pax;
  13040.                             $subnetoUnit $subneto;
  13041.                             $subneto $subneto $days $unitsServ $pax;
  13042.                             $data_supplier['service'][$i] = array(
  13043.                                 'id' => $item->getId(),
  13044.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  13045.                                 'serviceName' => $item->getSrvName(),
  13046.                                 'serviceType' => 'Asistente',
  13047.                                 'date' => $dateServ,
  13048.                                 'qty' => $unitsServ,
  13049.                                 'iva' => $item->getSrvIva(),
  13050.                                 'pax' => $item->getSrvPax(),
  13051.                                 'precioUnit' => $subnetoUnit,
  13052.                                 'subneto' => $subneto,
  13053.                                 'subtotal' => $subtotal,
  13054.                             );
  13055.                             break;
  13056.                         case 16//DDR
  13057.                             $pax $item->getSrvPax();
  13058.                             if (empty($pax) or $pax == "0") {
  13059.                                 $pax 1;
  13060.                             }
  13061.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  13062.                             if ($days 1) {
  13063.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  13064.                             } else {
  13065.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  13066.                             }
  13067.                             $unitsServ $item->getSrvUnits();
  13068.                             if (empty($unitsServ) or $unitsServ == "0") {
  13069.                                 $unitsServ 1;
  13070.                             }
  13071.                             $subtotal $subtotalService $days $unitsServ $pax;
  13072.                             $subnetoUnit $subneto;
  13073.                             $subneto $subneto $days $unitsServ $pax;
  13074.                             $data_supplier['service'][$i] = array(
  13075.                                 'id' => $item->getId(),
  13076.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  13077.                                 'serviceName' => $item->getSrvName(),
  13078.                                 'serviceType' => 'DDR',
  13079.                                 'date' => $dateServ,
  13080.                                 'qty' => $unitsServ,
  13081.                                 'iva' => $item->getSrvIva(),
  13082.                                 'pax' => $item->getSrvPax(),
  13083.                                 'precioUnit' => $subnetoUnit,
  13084.                                 'subneto' => $subneto,
  13085.                                 'subtotal' => $subtotal,
  13086.                             );
  13087.                             break;
  13088.                         default:
  13089.                             break;
  13090.                     }
  13091.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  13092.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  13093.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  13094.                     $arrayItems[] = array(
  13095.                         'type' => 'Service',
  13096.                         'name' => $item->getSrvName(),
  13097.                         'amount' => $neto,
  13098.                         'iva' => $item->getSrvIva(),
  13099.                         'total' => $subtotal,
  13100.                     );
  13101.                 }
  13102.                 switch ($item->getSrvIva()) {
  13103.                         // Acumula IVA
  13104.                     case 21:
  13105.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getSrvIva() / 100));
  13106.                         break;
  13107.                     case 10:
  13108.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getSrvIva() / 100));
  13109.                         break;
  13110.                     case 0:
  13111.                         break;
  13112.                     default:
  13113.                         break;
  13114.                 }
  13115.             } else {
  13116.                 // Es una proforma
  13117.                 if (is_null($item->getPrice()) or empty($item->getPrice())) {
  13118.                     $subtotal 0;
  13119.                     $neto 0;
  13120.                     $subtotalService 0;
  13121.                 } else {
  13122.                     $subtotalService $item->getPrice();
  13123.                     $subneto $item->getPrice();
  13124.                     // Commission
  13125.                     if ($item->getOpCommission() == '1') {
  13126.                         $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  13127.                         $subneto $subneto * (+ ($item->getCommission() / 100));
  13128.                     } else {
  13129.                         $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  13130.                         $subneto $subneto * (- ($item->getCommission() / 100));
  13131.                     }
  13132.                     // Over
  13133.                     if ($item->getOpOver() == '1') {
  13134.                         $subtotalService $subtotalService $item->getOver();
  13135.                         $subneto $subneto $item->getOver();
  13136.                     } else {
  13137.                         $subtotalService $subtotalService $item->getOver();
  13138.                         $subneto $subneto $item->getOver();
  13139.                     }
  13140.                     // IVA
  13141.                     if ($item->getOpIva() == '1') {
  13142.                         $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  13143.                     } else {
  13144.                         $subtotalService $item->getPrice();
  13145.                         $subneto = ($subneto 100) / (100 $item->getIva());
  13146.                     }
  13147.                     switch ($item->getServiceCatId()) {
  13148.                         case 1// Alojamiento
  13149.                             // el numero de noches $numNoches; precio unitario $subneto
  13150.                             $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  13151.                             // La personas no afectan este calculo
  13152.                             $subtotal $subtotalService $numNoches $item->getUnits();
  13153.                             $subnetoUnit $subneto;
  13154.                             $subneto $subneto $numNoches $item->getUnits();
  13155.                             $data_supplier['service'][$i] = array(
  13156.                                 'id' => $item->getId(),
  13157.                                 'serviceCatId' => $item->getServiceCatId(),
  13158.                                 'serviceName' => $item->getName(),
  13159.                                 'serviceType' => 'Hotel',
  13160.                                 'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  13161.                                 'qty' => $item->getUnits(),
  13162.                                 'iva' => $item->getIva(),
  13163.                                 'pax' => '-',
  13164.                                 'precioUnit' => $subnetoUnit,
  13165.                                 'subneto' => $subneto,
  13166.                                 'subtotal' => $subtotal,
  13167.                             );
  13168.                             break;
  13169.                         case 2//Actividades
  13170.                             // El nĂºmero de personas es considerado en el calculo
  13171.                             $pax $item->getPax();
  13172.                             if (empty($pax) or $pax == "0") {
  13173.                                 $pax 1;
  13174.                             }
  13175.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13176.                             if ($days 1) {
  13177.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13178.                             } else {
  13179.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13180.                             }
  13181.                             $subtotal $subtotalService $days $item->getUnits();
  13182.                             $subnetoUnit $subneto;
  13183.                             $subneto $subneto $days $item->getUnits();
  13184.                             $data_supplier['service'][$i] = array(
  13185.                                 'id' => $item->getId(),
  13186.                                 'serviceCatId' => $item->getServiceCatId(),
  13187.                                 'serviceName' => $item->getName(),
  13188.                                 'serviceType' => 'Actividad',
  13189.                                 'date' => $dateServ,
  13190.                                 'qty' => $item->getUnits(),
  13191.                                 'iva' => $item->getIva(),
  13192.                                 'pax' => $item->getPax(),
  13193.                                 'precioUnit' => $subnetoUnit,
  13194.                                 'subneto' => $subneto,
  13195.                                 'subtotal' => $subtotal,
  13196.                             );
  13197.                             break;
  13198.                         case 3// AV
  13199.                             $pax $item->getPax();
  13200.                             if (empty($pax) or $pax == "0") {
  13201.                                 $pax 1;
  13202.                             }
  13203.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13204.                             if ($days 1) {
  13205.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13206.                             } else {
  13207.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13208.                             }
  13209.                             $unitsServ $item->getUnits();
  13210.                             if (empty($unitsServ) or $unitsServ == "0") {
  13211.                                 $unitsServ 1;
  13212.                             }
  13213.                             $subtotal $subtotalService $days $unitsServ $pax;
  13214.                             $subnetoUnit $subneto;
  13215.                             $subneto $subneto $days $unitsServ $pax;
  13216.                             $data_supplier['service'][$i] = array(
  13217.                                 'id' => $item->getId(),
  13218.                                 'serviceCatId' => $item->getServiceCatId(),
  13219.                                 'serviceName' => $item->getName(),
  13220.                                 'serviceType' => 'AV',
  13221.                                 'date' => $dateServ,
  13222.                                 'qty' => $unitsServ,
  13223.                                 'iva' => $item->getIva(),
  13224.                                 'pax' => $item->getPax(),
  13225.                                 'precioUnit' => $subnetoUnit,
  13226.                                 'subneto' => $subneto,
  13227.                                 'subtotal' => $subtotal,
  13228.                             );
  13229.                             break;
  13230.                         case 4//Creative
  13231.                             $pax $item->getPax();
  13232.                             if (empty($pax) or $pax == "0") {
  13233.                                 $pax 1;
  13234.                             }
  13235.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13236.                             if ($days 1) {
  13237.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13238.                             } else {
  13239.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13240.                             }
  13241.                             $unitsServ $item->getUnits();
  13242.                             if (empty($unitsServ) or $unitsServ == "0") {
  13243.                                 $unitsServ 1;
  13244.                             }
  13245.                             $subtotal $subtotalService $days $unitsServ $pax;
  13246.                             $subnetoUnit $subneto;
  13247.                             $subneto $subneto $days $unitsServ $pax;
  13248.                             $data_supplier['service'][$i] = array(
  13249.                                 'id' => $item->getId(),
  13250.                                 'serviceCatId' => $item->getServiceCatId(),
  13251.                                 'serviceName' => $item->getName(),
  13252.                                 'serviceType' => 'Creativo',
  13253.                                 'date' => $dateServ,
  13254.                                 'qty' => $unitsServ,
  13255.                                 'iva' => $item->getIva(),
  13256.                                 'pax' => $item->getPax(),
  13257.                                 'precioUnit' => $subnetoUnit,
  13258.                                 'subneto' => $subneto,
  13259.                                 'subtotal' => $subtotal,
  13260.                             );
  13261.                             break;
  13262.                         case 5//Cruise
  13263.                             $pax $item->getPax();
  13264.                             if (empty($pax) or $pax == "0") {
  13265.                                 $pax 1;
  13266.                             }
  13267.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  13268.                             if ($days 1) {
  13269.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13270.                             } else {
  13271.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13272.                             }
  13273.                             $unitsServ $item->getUnits();
  13274.                             if (empty($unitsServ) or $unitsServ == "0") {
  13275.                                 $unitsServ 1;
  13276.                             }
  13277.                             $subtotal $subtotalService $days $unitsServ $pax;
  13278.                             $subnetoUnit $subneto;
  13279.                             $subneto $subneto $days $unitsServ $pax;
  13280.                             $data_supplier['service'][$i] = array(
  13281.                                 'id' => $item->getId(),
  13282.                                 'serviceCatId' => $item->getServiceCatId(),
  13283.                                 'serviceName' => $item->getName(),
  13284.                                 'serviceType' => 'Crucero',
  13285.                                 'date' => $dateServ,
  13286.                                 'qty' => $unitsServ,
  13287.                                 'iva' => $item->getIva(),
  13288.                                 'pax' => $item->getPax(),
  13289.                                 'precioUnit' => $subnetoUnit,
  13290.                                 'subneto' => $subneto,
  13291.                                 'subtotal' => $subtotal,
  13292.                             );
  13293.                             break;
  13294.                         case 6//Entertaiment
  13295.                             $pax $item->getPax();
  13296.                             if (empty($pax) or $pax == "0") {
  13297.                                 $pax 1;
  13298.                             }
  13299.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13300.                             if ($days 1) {
  13301.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13302.                             } else {
  13303.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13304.                             }
  13305.                             $unitsServ $item->getUnits();
  13306.                             if (empty($unitsServ) or $unitsServ == "0") {
  13307.                                 $unitsServ 1;
  13308.                             }
  13309.                             $subtotal $subtotalService $days $unitsServ $pax;
  13310.                             $subnetoUnit $subneto;
  13311.                             $subneto $subneto $days $unitsServ $pax;
  13312.                             $data_supplier['service'][$i] = array(
  13313.                                 'id' => $item->getId(),
  13314.                                 'serviceCatId' => $item->getServiceCatId(),
  13315.                                 'serviceName' => $item->getName(),
  13316.                                 'serviceType' => 'Entretenimiento',
  13317.                                 'date' => $dateServ,
  13318.                                 'qty' => $unitsServ,
  13319.                                 'iva' => $item->getIva(),
  13320.                                 'pax' => $item->getPax(),
  13321.                                 'precioUnit' => $subnetoUnit,
  13322.                                 'subneto' => $subneto,
  13323.                                 'subtotal' => $subtotal,
  13324.                             );
  13325.                             break;
  13326.                         case 7// Gifts
  13327.                             $pax $item->getPax();
  13328.                             if (empty($pax) or $pax == "0") {
  13329.                                 $pax 1;
  13330.                             }
  13331.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  13332.                             $days 1;
  13333.                             if ($days 1) {
  13334.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13335.                             } else {
  13336.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13337.                             }
  13338.                             $unitsServ $item->getUnits();
  13339.                             if (empty($unitsServ) or $unitsServ == "0") {
  13340.                                 $unitsServ 1;
  13341.                             }
  13342.                             $subtotal $subtotalService $days $unitsServ $pax;
  13343.                             $subnetoUnit $subneto;
  13344.                             $subneto $subneto $days $unitsServ $pax;
  13345.                             $data_supplier['service'][$i] = array(
  13346.                                 'id' => $item->getId(),
  13347.                                 'serviceCatId' => $item->getServiceCatId(),
  13348.                                 'serviceName' => $item->getName(),
  13349.                                 'serviceType' => 'Regalos',
  13350.                                 'date' => $dateServ,
  13351.                                 'qty' => $unitsServ,
  13352.                                 'iva' => $item->getIva(),
  13353.                                 'pax' => $item->getPax(),
  13354.                                 'precioUnit' => $subnetoUnit,
  13355.                                 'subneto' => $subneto,
  13356.                                 'subtotal' => $subtotal,
  13357.                             );
  13358.                             break;
  13359.                         case 8//Guide
  13360.                             $pax $item->getPax();
  13361.                             if (empty($pax) or $pax == "0") {
  13362.                                 $pax 1;
  13363.                             }
  13364.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13365.                             if ($days 1) {
  13366.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13367.                             } else {
  13368.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13369.                             }
  13370.                             $unitsServ $item->getUnits();
  13371.                             if (empty($unitsServ) or $unitsServ == "0") {
  13372.                                 $unitsServ 1;
  13373.                             }
  13374.                             $subtotal $subtotalService $days $unitsServ $pax;
  13375.                             $subnetoUnit $subneto;
  13376.                             $subneto $subneto $days $unitsServ $pax;
  13377.                             $data_supplier['service'][$i] = array(
  13378.                                 'id' => $item->getId(),
  13379.                                 'serviceCatId' => $item->getServiceCatId(),
  13380.                                 'serviceName' => $item->getName(),
  13381.                                 'serviceType' => 'Regalos',
  13382.                                 'date' => $dateServ,
  13383.                                 'qty' => $unitsServ,
  13384.                                 'iva' => $item->getIva(),
  13385.                                 'pax' => $item->getPax(),
  13386.                                 'precioUnit' => $subnetoUnit,
  13387.                                 'subneto' => $subneto,
  13388.                                 'subtotal' => $subtotal,
  13389.                             );
  13390.                             break;
  13391.                         case 9//Itineraries
  13392.                             $pax $item->getPax();
  13393.                             if (empty($pax) or $pax == "0") {
  13394.                                 $pax 1;
  13395.                             }
  13396.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13397.                             if ($days 1) {
  13398.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13399.                             } else {
  13400.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13401.                             }
  13402.                             $unitsServ $item->getUnits();
  13403.                             if (empty($unitsServ) or $unitsServ == "0") {
  13404.                                 $unitsServ 1;
  13405.                             }
  13406.                             $subtotal $subtotalService $days $unitsServ $pax;
  13407.                             $subnetoUnit $subneto;
  13408.                             $subneto $subneto $days $unitsServ $pax;
  13409.                             $data_supplier['service'][$i] = array(
  13410.                                 'id' => $item->getId(),
  13411.                                 'serviceCatId' => $item->getServiceCatId(),
  13412.                                 'serviceName' => $item->getName(),
  13413.                                 'serviceType' => 'Itinerarios',
  13414.                                 'date' => $dateServ,
  13415.                                 'qty' => $unitsServ,
  13416.                                 'iva' => $item->getIva(),
  13417.                                 'pax' => $item->getPax(),
  13418.                                 'precioUnit' => $subnetoUnit,
  13419.                                 'subneto' => $subneto,
  13420.                                 'subtotal' => $subtotal,
  13421.                             );
  13422.                             break;
  13423.                         case 10//Lounge  -- No Aplica
  13424.                             //                        $pax = $item->getPax();
  13425.                             //                        if (empty($pax) or $pax == "0") {
  13426.                             //                            $pax = 1;
  13427.                             //                        }
  13428.                             //
  13429.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  13430.                             //                        if ($days > 1){
  13431.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  13432.                             //                        } else {
  13433.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13434.                             //                        }
  13435.                             //
  13436.                             //                        $unitsServ = $item->getUnits();
  13437.                             //                        if (empty($unitsServ) or $unitsServ == "0") {
  13438.                             //                            $unitsServ = 1;
  13439.                             //                        }
  13440.                             //
  13441.                             //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  13442.                             //                        $subnetoUnit = $subneto;
  13443.                             //                        $subneto = $subneto * $days * $unitsServ * $pax;
  13444.                             //
  13445.                             //                        $data_supplier['service'][$i] = array (
  13446.                             //                            'id' => $item->getId(),
  13447.                             //                            'serviceCatId' => $item->getServiceCatId(),
  13448.                             //                            'serviceName' => $item->getName(),
  13449.                             //                            'serviceType' => 'Itinerarios',
  13450.                             //                            'date' => $dateServ,
  13451.                             //                            'qty' => $unitsServ,
  13452.                             //                            'iva' => $item->getIva(),
  13453.                             //                            'pax' => $item->getPax(),
  13454.                             //                            'precioUnit' => $subnetoUnit,
  13455.                             //                            'subneto' => $subneto,
  13456.                             //                            'subtotal' => $subtotal,
  13457.                             //                        );
  13458.                             break;
  13459.                         case 11//Menu
  13460.                             $pax $item->getPax();
  13461.                             if (empty($pax) or $pax == "0") {
  13462.                                 $pax 1;
  13463.                             }
  13464.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13465.                             if ($days 1) {
  13466.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13467.                             } else {
  13468.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13469.                             }
  13470.                             $unitsServ $item->getUnits();
  13471.                             if (empty($unitsServ) or $unitsServ == "0") {
  13472.                                 $unitsServ 1;
  13473.                             }
  13474.                             $subtotal $subtotalService $days $unitsServ $pax;
  13475.                             $subnetoUnit $subneto;
  13476.                             $subneto $subneto $days $unitsServ $pax;
  13477.                             $data_supplier['service'][$i] = array(
  13478.                                 'id' => $item->getId(),
  13479.                                 'serviceCatId' => $item->getServiceCatId(),
  13480.                                 'serviceName' => $item->getName(),
  13481.                                 'serviceType' => 'MenĂº',
  13482.                                 'date' => $dateServ,
  13483.                                 'qty' => $unitsServ,
  13484.                                 'iva' => $item->getIva(),
  13485.                                 'pax' => $item->getPax(),
  13486.                                 'precioUnit' => $subnetoUnit,
  13487.                                 'subneto' => $subneto,
  13488.                                 'subtotal' => $subtotal,
  13489.                             );
  13490.                             break;
  13491.                         case 12//Others
  13492.                             $pax $item->getPax();
  13493.                             if (empty($pax) or $pax == "0") {
  13494.                                 $pax 1;
  13495.                             }
  13496.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13497.                             if ($days 1) {
  13498.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13499.                             } else {
  13500.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13501.                             }
  13502.                             $unitsServ $item->getUnits();
  13503.                             if (empty($unitsServ) or $unitsServ == "0") {
  13504.                                 $unitsServ 1;
  13505.                             }
  13506.                             $subtotal $subtotalService $days $unitsServ $pax;
  13507.                             $subnetoUnit $subneto;
  13508.                             $subneto $subneto $days $unitsServ $pax;
  13509.                             $data_supplier['service'][$i] = array(
  13510.                                 'id' => $item->getId(),
  13511.                                 'serviceCatId' => $item->getServiceCatId(),
  13512.                                 'serviceName' => $item->getName(),
  13513.                                 'serviceType' => 'Otros',
  13514.                                 'date' => $dateServ,
  13515.                                 'qty' => $unitsServ,
  13516.                                 'iva' => $item->getIva(),
  13517.                                 'pax' => $item->getPax(),
  13518.                                 'precioUnit' => $subnetoUnit,
  13519.                                 'subneto' => $subneto,
  13520.                                 'subtotal' => $subtotal,
  13521.                             );
  13522.                             break;
  13523.                         case 13//Transport
  13524.                             $pax $item->getPax();
  13525.                             if (empty($pax) or $pax == "0") {
  13526.                                 $pax 1;
  13527.                             }
  13528.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13529.                             if ($days 1) {
  13530.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13531.                             } else {
  13532.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13533.                             }
  13534.                             $unitsServ $item->getUnits();
  13535.                             if (empty($unitsServ) or $unitsServ == "0") {
  13536.                                 $unitsServ 1;
  13537.                             }
  13538.                             $subtotal $subtotalService $days $unitsServ $pax;
  13539.                             $subnetoUnit $subneto;
  13540.                             $subneto $subneto $days $unitsServ $pax;
  13541.                             $data_supplier['service'][$i] = array(
  13542.                                 'id' => $item->getId(),
  13543.                                 'serviceCatId' => $item->getServiceCatId(),
  13544.                                 'serviceName' => $item->getName(),
  13545.                                 'serviceType' => 'Transporte',
  13546.                                 'date' => $dateServ,
  13547.                                 'qty' => $unitsServ,
  13548.                                 'iva' => $item->getIva(),
  13549.                                 'pax' => $item->getPax(),
  13550.                                 'precioUnit' => $subnetoUnit,
  13551.                                 'subneto' => $subneto,
  13552.                                 'subtotal' => $subtotal,
  13553.                             );
  13554.                             break;
  13555.                         case 14//Technology
  13556.                             $pax $item->getPax();
  13557.                             if (empty($pax) or $pax == "0") {
  13558.                                 $pax 1;
  13559.                             }
  13560.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  13561.                             $days 1;
  13562.                             //                        if ($days > 1){
  13563.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  13564.                             //                        } else {
  13565.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13566.                             //                        }
  13567.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13568.                             $unitsServ $item->getUnits();
  13569.                             if (empty($unitsServ) or $unitsServ == "0") {
  13570.                                 $unitsServ 1;
  13571.                             }
  13572.                             $subtotal $subtotalService $days $unitsServ $pax;
  13573.                             $subnetoUnit $subneto;
  13574.                             $subneto $subneto $days $unitsServ $pax;
  13575.                             $data_supplier['service'][$i] = array(
  13576.                                 'id' => $item->getId(),
  13577.                                 'serviceCatId' => $item->getServiceCatId(),
  13578.                                 'serviceName' => $item->getName(),
  13579.                                 'serviceType' => 'TecnologĂ­a',
  13580.                                 'date' => $dateServ,
  13581.                                 'qty' => $unitsServ,
  13582.                                 'iva' => $item->getIva(),
  13583.                                 'pax' => $item->getPax(),
  13584.                                 'precioUnit' => $subnetoUnit,
  13585.                                 'subneto' => $subneto,
  13586.                                 'subtotal' => $subtotal,
  13587.                             );
  13588.                             break;
  13589.                         case 15//Assisstant
  13590.                             $pax $item->getPax();
  13591.                             if (empty($pax) or $pax == "0") {
  13592.                                 $pax 1;
  13593.                             }
  13594.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13595.                             if ($days 1) {
  13596.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13597.                             } else {
  13598.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13599.                             }
  13600.                             $unitsServ $item->getUnits();
  13601.                             if (empty($unitsServ) or $unitsServ == "0") {
  13602.                                 $unitsServ 1;
  13603.                             }
  13604.                             $subtotal $subtotalService $days $unitsServ $pax;
  13605.                             $subnetoUnit $subneto;
  13606.                             $subneto $subneto $days $unitsServ $pax;
  13607.                             $data_supplier['service'][$i] = array(
  13608.                                 'id' => $item->getId(),
  13609.                                 'serviceCatId' => $item->getServiceCatId(),
  13610.                                 'serviceName' => $item->getName(),
  13611.                                 'serviceType' => 'Asistente',
  13612.                                 'date' => $dateServ,
  13613.                                 'qty' => $unitsServ,
  13614.                                 'iva' => $item->getIva(),
  13615.                                 'pax' => $item->getPax(),
  13616.                                 'precioUnit' => $subnetoUnit,
  13617.                                 'subneto' => $subneto,
  13618.                                 'subtotal' => $subtotal,
  13619.                             );
  13620.                             break;
  13621.                         case 16//DDR
  13622.                             $pax $item->getPax();
  13623.                             if (empty($pax) or $pax == "0") {
  13624.                                 $pax 1;
  13625.                             }
  13626.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13627.                             if ($days 1) {
  13628.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13629.                             } else {
  13630.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13631.                             }
  13632.                             $unitsServ $item->getUnits();
  13633.                             if (empty($unitsServ) or $unitsServ == "0") {
  13634.                                 $unitsServ 1;
  13635.                             }
  13636.                             $subtotal $subtotalService $days $unitsServ $pax;
  13637.                             $subnetoUnit $subneto;
  13638.                             $subneto $subneto $days $unitsServ $pax;
  13639.                             $data_supplier['service'][$i] = array(
  13640.                                 'id' => $item->getId(),
  13641.                                 'serviceCatId' => $item->getServiceCatId(),
  13642.                                 'serviceName' => $item->getName(),
  13643.                                 'serviceType' => 'DDR',
  13644.                                 'date' => $dateServ,
  13645.                                 'qty' => $unitsServ,
  13646.                                 'iva' => $item->getIva(),
  13647.                                 'pax' => $item->getPax(),
  13648.                                 'precioUnit' => $subnetoUnit,
  13649.                                 'subneto' => $subneto,
  13650.                                 'subtotal' => $subtotal,
  13651.                             );
  13652.                             break;
  13653.                         default:
  13654.                             break;
  13655.                     }
  13656.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  13657.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  13658.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  13659.                     $arrayItems[] = array(
  13660.                         'type' => 'Service',
  13661.                         'name' => $item->getName(),
  13662.                         'amount' => $neto,
  13663.                         'iva' => $item->getIva(),
  13664.                         'total' => $subtotal,
  13665.                     );
  13666.                 }
  13667.                 switch ($item->getIva()) {
  13668.                         // Acumula IVA
  13669.                     case 21:
  13670.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  13671.                         break;
  13672.                     case 10:
  13673.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  13674.                         break;
  13675.                     case 0:
  13676.                         break;
  13677.                     default:
  13678.                         break;
  13679.                 }
  13680.             }
  13681.             $totales_neto_all $totales_neto_all $neto;
  13682.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13683.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  13684.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  13685.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  13686.             // Acumula netos totales e IVA
  13687.             $service['neto'] = $service['neto'] + $neto;
  13688.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  13689.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13690.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  13691.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  13692.             $i++;
  13693.         }
  13694.         $data_supplier['serviceSubTotal'] = array(
  13695.             'neto' => $service['neto'],
  13696.             'sumSubT' => $service['sumSubT'],
  13697.         );
  13698.         $currency '€';
  13699.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  13700.         if (!empty($payments)) {
  13701.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  13702.         } else {
  13703.             $amount_pay 0;
  13704.         }
  13705.         $totales_all $totales_total $amount_pay;
  13706.         if (empty($dateDocument)) {
  13707.             $dateDocument = new DateTime('now');
  13708.         }
  13709.         $data = array(
  13710.             'id' => $fileId,
  13711.             'type' => $type,
  13712.             'number' => $number,
  13713.             'prefix' => 'AVE-' . (new DateTime('now'))->format('dmy') . '-' $invoiceId,
  13714.             'date' => $dateDocument,
  13715.             'file' => $file,
  13716.             'token' => $file->getAccessKey(),
  13717.             'company' => $company,
  13718.             'clients' => $clientNew,
  13719.             'arrayItems' => $arrayItems,
  13720.             'datasupplier' => $data_supplier,
  13721.             'currency' => $currency,
  13722.             'totales_neto' => $totales_neto_all,
  13723.             'bases_imponibles' => $data_iva,
  13724.             'totales' => $totales_total,
  13725.             'balance' => $totales_all,
  13726.             'paymentInvoice' => $amount_pay,
  13727.         );
  13728.         return $data;
  13729.     }
  13730.     private function sendTelegram($id$text)
  13731.     {
  13732.         $em $this->getDoctrine()->getManager();
  13733.         $telegUser $em->getRepository(MdvTelegramUser::class)->findOneByUserId($id);
  13734.         if (empty($telegUser)) {
  13735.             return true;
  13736.         }
  13737.         $parameters = array(
  13738.             'chat_id' => $telegUser->getChatId(),
  13739.             'text' => $text,
  13740.         );
  13741.         $bot_token $telegUser->getBotToken();
  13742.         $url "https://api.telegram.org/bot$bot_token/sendMessage";
  13743.         if (!$curl curl_init()) {
  13744.             exit();
  13745.         }
  13746.         curl_setopt($curlCURLOPT_POSTtrue);
  13747.         curl_setopt($curlCURLOPT_POSTFIELDS$parameters);
  13748.         curl_setopt($curlCURLOPT_URL$url);
  13749.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  13750.         $output curl_exec($curl);
  13751.         curl_close($curl);
  13752.         return true;
  13753.     }
  13754.     private function baseProformaSelect($id$type$number$prefix$date$proformaId)
  13755.     {
  13756.         $em $this->getDoctrine()->getManager();
  13757.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  13758.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  13759.         $client $em->getRepository(Client::class)->findById($file->getClient());
  13760.         if (empty($client)) {
  13761.             $client[0] = new Client();
  13762.             $client[0]->setName('');
  13763.             $client[0]->setTitle('');
  13764.             $client[0]->setIdDocument('');
  13765.             $client[0]->setPopulation('');
  13766.             $client[0]->setRegion('');
  13767.             $client[0]->setCountry('');
  13768.         } else {
  13769.             if (is_numeric($client[0]->getPopulation())) {
  13770.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  13771. //                $client[0]->setPopulation($city->getCity());
  13772.             }
  13773.             if (is_numeric($client[0]->getRegion())) {
  13774.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  13775. //                $client[0]->setRegion($region->getRegion());
  13776.             }
  13777.             if (is_numeric($client[0]->getCountry())) {
  13778.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  13779. //                $client[0]->setCountry($country->getCountry());
  13780.             }
  13781.         }
  13782.         if (empty($client)) {
  13783.             $client[0] = new Client();
  13784.             $client[0]->setName('');
  13785.             $client[0]->setTitle('');
  13786.             $client[0]->setIdDocument('');
  13787.             $client[0]->setPopulation('');
  13788.             $client[0]->setRegion('');
  13789.             $client[0]->setCountry('');
  13790.             $clientNew = array(
  13791.                 'name' => '',
  13792.                 'title' => '',
  13793.                 'idDocument' => '',
  13794.                 'population' => '',
  13795.                 'region' => '',
  13796.                 'country' => '',
  13797.                 'address' => '',
  13798.                 'addressNumber' => '',
  13799.                 'zipCode' => '',
  13800.                 'typeDocument' => '',
  13801.             );
  13802.         } else {
  13803.             $clientNew = array(
  13804.                 'name' => $client[0]->getName(),
  13805.                 'title' => $client[0]->getTitle(),
  13806.                 'idDocument' => $client[0]->getIdDocument(),
  13807.                 'population' => '',
  13808.                 'region' => '',
  13809.                 'country' => '',
  13810.                 'address' => $client[0]->getAddress(),
  13811.                 'addressNumber' => $client[0]->getAddressNumber(),
  13812.                 'zipCode' => $client[0]->getZipCode(),
  13813.                 'typeDocument' => $client[0]->getTypeDocument(),
  13814.             );
  13815.             if (is_numeric($client[0]->getPopulation())) {
  13816.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  13817.                 $clientNew['population'] = $city->getCity();
  13818.             }
  13819.             if (is_numeric($client[0]->getRegion())) {
  13820.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  13821.                 $clientNew['region'] = $region->getRegion();
  13822.             }
  13823.             if (is_numeric($client[0]->getCountry())) {
  13824.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  13825.                 $clientNew['country'] = $country->getCountry();
  13826.             }
  13827.         }
  13828.         // Acumuladores de los calculos
  13829.         $totales_neto_all 0;
  13830.         $data_iva = array(
  13831.             'iva' => 21,
  13832.             'ivaMontoVeintiUno' => 0,
  13833.             'ivaMontoDiez' => 0,
  13834.             'ivaMontoCero' => null,
  13835.         );
  13836.         // Buscamos las salas reservadas, pagos y servicios para el evento
  13837.         // Buscamos los productos de la proforma
  13838.         $productsInProforma $em->getRepository(AveDocProformaItems::class)->findByProformaId($proformaId);
  13839.         $productsInFile = array();
  13840.         foreach ($productsInProforma as $item) {
  13841.             $producto $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
  13842.             if (!empty($producto)) {
  13843.                 $productsInFile[] = $producto;
  13844.             }
  13845.         }
  13846.         //        $productsInFile = $em->getRepository(AveProductFile::class)->findByFileId($id);
  13847.         $payments $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  13848.         $services $em->getRepository(AveServices::class)->findByFileId($id);
  13849.         $data_supplier = array();
  13850.         $i 0;
  13851.         $iva '21';            // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
  13852.         $pax '1';
  13853.         $qty '1';
  13854.         $product = array(
  13855.             'neto' => 0,
  13856.             'sumSubT' => 0,
  13857.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  13858.         $service = array(
  13859.             'neto' => 0,
  13860.             'sumSubT' => 0,
  13861.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  13862.         foreach ($productsInFile as $item) {
  13863.             //            $days = '1';
  13864.             //            $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  13865.             $days = ((($item->getDateEnd())->diff($item->getDateStart()))->days 1);
  13866.             // Verificamos que el producto no se encuentre ya en una factura
  13867.             $existe $em->getRepository(AveDocInvoiceItems::class)->findByPrdControlId($item->getId());
  13868.             $pax $item->getPax();
  13869.             $qty $item->getUnits();
  13870.             if (!empty($item->getDays())) {
  13871.                 $days $item->getDays();
  13872.             }
  13873.             if (is_null($item->getServicePrice()) or empty($item->getServicePrice()) or !empty($existe)) {
  13874.                 $subtotal 0;
  13875.                 $neto 0;
  13876.                 $subtotalProduct 0;
  13877.             } else {
  13878.                 //                $subtotalProduct = $item->getServicePrice() * 1.21;
  13879.                 $subtotalProduct $item->getSubTotalPrice() * 1.21;
  13880.                 //                $subneto = $item->getServicePrice();
  13881.                 $subneto $item->getSubTotalPrice();
  13882.                 $subtotal =  $subtotalProduct;
  13883.                 $neto =  $subneto;
  13884.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  13885.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  13886.                 $neto round($neto2PHP_ROUND_HALF_UP);
  13887.             }
  13888.             // Acumula netos totales e IVA
  13889.             $totales_neto_all $totales_neto_all $neto;
  13890.             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  13891.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13892.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  13893.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  13894.             // Acumula netos totales e IVA
  13895.             $product['neto'] = $product['neto'] + $neto;
  13896.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  13897.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13898.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  13899.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  13900.             $data_supplier['product'][$i] = array(
  13901.                 'id' => $item->getId(),
  13902.                 'productName' => $item->getProductName(),
  13903.                 'productId' => $item->getProductId(),
  13904.                 'dateStart' => $item->getDateStart(),
  13905.                 'dateEnd' => $item->getDateEnd(),
  13906.                 'servicePrice' => $item->getServicePrice(),
  13907.                 'subTotalPrice' => $item->getSubTotalPrice(),
  13908.                 'subtotalProduct' => $subtotalProduct,
  13909.                 'iva' => $iva,
  13910.                 'pax' => $pax,
  13911.                 'qty' => $qty,
  13912.                 'days' => $days,
  13913.                 'type' => $item->getType(),
  13914.                 'subtotal' => $subtotal,
  13915.             );
  13916.             $i++;
  13917.         }
  13918.         $data_supplier['productSubTotal'] = array(
  13919.             'neto' => $product['neto'],
  13920.             'sumSubT' => $product['sumSubT'],
  13921.         );
  13922.         $payment = array(
  13923.             'sumSubT' => 0,
  13924.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  13925.         $i 0;
  13926.         foreach ($payments as $item) {
  13927.             // Verificamos que el pago no se encuentre ya en una factura
  13928.             $existe $em->getRepository(AveDocInvoiceItems::class)->findByPayControlId($item->getId());
  13929.             if (!empty($existe)) {
  13930.                 $payment['sumSubT'] = $payment['sumSubT'] + 0;
  13931.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13932.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  13933.             } else {
  13934.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  13935.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13936.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  13937.             }
  13938.             $data_supplier['payment'][$i] = array(
  13939.                 'id' => $item->getId(),
  13940.                 'amount' => $item->getAmount(),
  13941.                 'datePayAt' => $item->getDatePayAt(),
  13942.                 'wayToPay' => $item->getWayToPay(),
  13943.                 'amountTotal' => $item->getAmountTotal(),
  13944.                 'vat' => $item->getVat(),
  13945.             );
  13946.             $i++;
  13947.         }
  13948.         if (!empty($payments)) {
  13949.             $data_supplier['paymentSubTotal'] = array(
  13950.                 'sumSubT' => $payment['sumSubT'],
  13951.             );
  13952.         }
  13953.         foreach ($services as $item) {
  13954.             // Verificamos que el servicio no se encuentre ya en una factura
  13955.             $existe $em->getRepository(AveDocInvoiceItems::class)->findBySrvControlId($item->getId());
  13956.             if (is_null($item->getPrice()) or empty($item->getPrice()) or !empty($existe)) {
  13957.                 $subtotal 0;
  13958.                 $neto 0;
  13959.                 $subtotalService 0;
  13960.                 $subneto 0;
  13961.                 switch ($item->getServiceCatId()) {
  13962.                     case 1// Alojamiento
  13963.                         // el numero de noches $numNoches; precio unitario $subneto
  13964.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  13965.                         // La personas no afectan este calculo
  13966.                         $subtotal $subtotalService $numNoches $item->getUnits();
  13967.                         $subnetoUnit $subneto;
  13968.                         $subneto $subneto $numNoches $item->getUnits();
  13969.                         $data_supplier['service'][$i] = array(
  13970.                             'id' => $item->getId(),
  13971.                             'serviceCatId' => $item->getServiceCatId(),
  13972.                             'serviceName' => $item->getName(),
  13973.                             'serviceType' => 'Hotel',
  13974.                             'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  13975.                             'qty' => $item->getUnits(),
  13976.                             'iva' => $item->getIva(),
  13977.                             'pax' => '-',
  13978.                             'precioUnit' => $subnetoUnit,
  13979.                             'subneto' => $subneto,
  13980.                             'subtotal' => $subtotal,
  13981.                         );
  13982.                         break;
  13983.                     case 2//Actividades
  13984.                         // El nĂºmero de personas es considerado en el calculo
  13985.                         $pax $item->getPax();
  13986.                         if (empty($pax) or $pax == "0") {
  13987.                             $pax 1;
  13988.                         }
  13989.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13990.                         if ($days 1) {
  13991.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13992.                         } else {
  13993.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13994.                         }
  13995.                         $subtotal $subtotalService $days $item->getUnits();
  13996.                         $subnetoUnit $subneto;
  13997.                         $subneto $subneto $days $item->getUnits();
  13998.                         $data_supplier['service'][$i] = array(
  13999.                             'id' => $item->getId(),
  14000.                             'serviceCatId' => $item->getServiceCatId(),
  14001.                             'serviceName' => $item->getName(),
  14002.                             'serviceType' => 'Actividad',
  14003.                             'date' => $dateServ,
  14004.                             'qty' => $item->getUnits(),
  14005.                             'iva' => $item->getIva(),
  14006.                             'pax' => $item->getPax(),
  14007.                             'precioUnit' => $subnetoUnit,
  14008.                             'subneto' => $subneto,
  14009.                             'subtotal' => $subtotal,
  14010.                         );
  14011.                         break;
  14012.                     case 3// AV
  14013.                         $pax $item->getPax();
  14014.                         if (empty($pax) or $pax == "0") {
  14015.                             $pax 1;
  14016.                         }
  14017.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14018.                         if ($days 1) {
  14019.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14020.                         } else {
  14021.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14022.                         }
  14023.                         $unitsServ $item->getUnits();
  14024.                         if (empty($unitsServ) or $unitsServ == "0") {
  14025.                             $unitsServ 1;
  14026.                         }
  14027.                         $subtotal $subtotalService $days $unitsServ $pax;
  14028.                         $subnetoUnit $subneto;
  14029.                         $subneto $subneto $days $unitsServ $pax;
  14030.                         $data_supplier['service'][$i] = array(
  14031.                             'id' => $item->getId(),
  14032.                             'serviceCatId' => $item->getServiceCatId(),
  14033.                             'serviceName' => $item->getName(),
  14034.                             'serviceType' => 'AV',
  14035.                             'date' => $dateServ,
  14036.                             'qty' => $unitsServ,
  14037.                             'iva' => $item->getIva(),
  14038.                             'pax' => $item->getPax(),
  14039.                             'precioUnit' => $subnetoUnit,
  14040.                             'subneto' => $subneto,
  14041.                             'subtotal' => $subtotal,
  14042.                         );
  14043.                         break;
  14044.                     case 4//Creative
  14045.                         $pax $item->getPax();
  14046.                         if (empty($pax) or $pax == "0") {
  14047.                             $pax 1;
  14048.                         }
  14049.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14050.                         if ($days 1) {
  14051.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14052.                         } else {
  14053.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14054.                         }
  14055.                         $unitsServ $item->getUnits();
  14056.                         if (empty($unitsServ) or $unitsServ == "0") {
  14057.                             $unitsServ 1;
  14058.                         }
  14059.                         $subtotal $subtotalService $days $unitsServ $pax;
  14060.                         $subnetoUnit $subneto;
  14061.                         $subneto $subneto $days $unitsServ $pax;
  14062.                         $data_supplier['service'][$i] = array(
  14063.                             'id' => $item->getId(),
  14064.                             'serviceCatId' => $item->getServiceCatId(),
  14065.                             'serviceName' => $item->getName(),
  14066.                             'serviceType' => 'Creativo',
  14067.                             'date' => $dateServ,
  14068.                             'qty' => $unitsServ,
  14069.                             'iva' => $item->getIva(),
  14070.                             'pax' => $item->getPax(),
  14071.                             'precioUnit' => $subnetoUnit,
  14072.                             'subneto' => $subneto,
  14073.                             'subtotal' => $subtotal,
  14074.                         );
  14075.                         break;
  14076.                     case 5//Cruise
  14077.                         $pax $item->getPax();
  14078.                         if (empty($pax) or $pax == "0") {
  14079.                             $pax 1;
  14080.                         }
  14081.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  14082.                         if ($days 1) {
  14083.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14084.                         } else {
  14085.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14086.                         }
  14087.                         $unitsServ $item->getUnits();
  14088.                         if (empty($unitsServ) or $unitsServ == "0") {
  14089.                             $unitsServ 1;
  14090.                         }
  14091.                         $subtotal $subtotalService $days $unitsServ $pax;
  14092.                         $subnetoUnit $subneto;
  14093.                         $subneto $subneto $days $unitsServ $pax;
  14094.                         $data_supplier['service'][$i] = array(
  14095.                             'id' => $item->getId(),
  14096.                             'serviceCatId' => $item->getServiceCatId(),
  14097.                             'serviceName' => $item->getName(),
  14098.                             'serviceType' => 'Crucero',
  14099.                             'date' => $dateServ,
  14100.                             'qty' => $unitsServ,
  14101.                             'iva' => $item->getIva(),
  14102.                             'pax' => $item->getPax(),
  14103.                             'precioUnit' => $subnetoUnit,
  14104.                             'subneto' => $subneto,
  14105.                             'subtotal' => $subtotal,
  14106.                         );
  14107.                         break;
  14108.                     case 6//Entertaiment
  14109.                         $pax $item->getPax();
  14110.                         if (empty($pax) or $pax == "0") {
  14111.                             $pax 1;
  14112.                         }
  14113.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14114.                         if ($days 1) {
  14115.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14116.                         } else {
  14117.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14118.                         }
  14119.                         $unitsServ $item->getUnits();
  14120.                         if (empty($unitsServ) or $unitsServ == "0") {
  14121.                             $unitsServ 1;
  14122.                         }
  14123.                         $subtotal $subtotalService $days $unitsServ $pax;
  14124.                         $subnetoUnit $subneto;
  14125.                         $subneto $subneto $days $unitsServ $pax;
  14126.                         $data_supplier['service'][$i] = array(
  14127.                             'id' => $item->getId(),
  14128.                             'serviceCatId' => $item->getServiceCatId(),
  14129.                             'serviceName' => $item->getName(),
  14130.                             'serviceType' => 'Entretenimiento',
  14131.                             'date' => $dateServ,
  14132.                             'qty' => $unitsServ,
  14133.                             'iva' => $item->getIva(),
  14134.                             'pax' => $item->getPax(),
  14135.                             'precioUnit' => $subnetoUnit,
  14136.                             'subneto' => $subneto,
  14137.                             'subtotal' => $subtotal,
  14138.                         );
  14139.                         break;
  14140.                     case 7// Gifts
  14141.                         $pax $item->getPax();
  14142.                         if (empty($pax) or $pax == "0") {
  14143.                             $pax 1;
  14144.                         }
  14145.                         $days 1;
  14146.                         if ($days 1) {
  14147.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14148.                         } else {
  14149.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14150.                         }
  14151.                         $unitsServ $item->getUnits();
  14152.                         if (empty($unitsServ) or $unitsServ == "0") {
  14153.                             $unitsServ 1;
  14154.                         }
  14155.                         $subtotal $subtotalService $days $unitsServ $pax;
  14156.                         $subnetoUnit $subneto;
  14157.                         $subneto $subneto $days $unitsServ $pax;
  14158.                         $data_supplier['service'][$i] = array(
  14159.                             'id' => $item->getId(),
  14160.                             'serviceCatId' => $item->getServiceCatId(),
  14161.                             'serviceName' => $item->getName(),
  14162.                             'serviceType' => 'Regalos',
  14163.                             'date' => $dateServ,
  14164.                             'qty' => $unitsServ,
  14165.                             'iva' => $item->getIva(),
  14166.                             'pax' => $item->getPax(),
  14167.                             'precioUnit' => $subnetoUnit,
  14168.                             'subneto' => $subneto,
  14169.                             'subtotal' => $subtotal,
  14170.                         );
  14171.                         break;
  14172.                     case 8//Guide
  14173.                         $pax $item->getPax();
  14174.                         if (empty($pax) or $pax == "0") {
  14175.                             $pax 1;
  14176.                         }
  14177.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14178.                         if ($days 1) {
  14179.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14180.                         } else {
  14181.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14182.                         }
  14183.                         $unitsServ $item->getUnits();
  14184.                         if (empty($unitsServ) or $unitsServ == "0") {
  14185.                             $unitsServ 1;
  14186.                         }
  14187.                         $subtotal $subtotalService $days $unitsServ $pax;
  14188.                         $subnetoUnit $subneto;
  14189.                         $subneto $subneto $days $unitsServ $pax;
  14190.                         $data_supplier['service'][$i] = array(
  14191.                             'id' => $item->getId(),
  14192.                             'serviceCatId' => $item->getServiceCatId(),
  14193.                             'serviceName' => $item->getName(),
  14194.                             'serviceType' => 'Regalos',
  14195.                             'date' => $dateServ,
  14196.                             'qty' => $unitsServ,
  14197.                             'iva' => $item->getIva(),
  14198.                             'pax' => $item->getPax(),
  14199.                             'precioUnit' => $subnetoUnit,
  14200.                             'subneto' => $subneto,
  14201.                             'subtotal' => $subtotal,
  14202.                         );
  14203.                         break;
  14204.                     case 9//Itineraries
  14205.                         $pax $item->getPax();
  14206.                         if (empty($pax) or $pax == "0") {
  14207.                             $pax 1;
  14208.                         }
  14209.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14210.                         if ($days 1) {
  14211.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14212.                         } else {
  14213.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14214.                         }
  14215.                         $unitsServ $item->getUnits();
  14216.                         if (empty($unitsServ) or $unitsServ == "0") {
  14217.                             $unitsServ 1;
  14218.                         }
  14219.                         $subtotal $subtotalService $days $unitsServ $pax;
  14220.                         $subnetoUnit $subneto;
  14221.                         $subneto $subneto $days $unitsServ $pax;
  14222.                         $data_supplier['service'][$i] = array(
  14223.                             'id' => $item->getId(),
  14224.                             'serviceCatId' => $item->getServiceCatId(),
  14225.                             'serviceName' => $item->getName(),
  14226.                             'serviceType' => 'Itinerarios',
  14227.                             'date' => $dateServ,
  14228.                             'qty' => $unitsServ,
  14229.                             'iva' => $item->getIva(),
  14230.                             'pax' => $item->getPax(),
  14231.                             'precioUnit' => $subnetoUnit,
  14232.                             'subneto' => $subneto,
  14233.                             'subtotal' => $subtotal,
  14234.                         );
  14235.                         break;
  14236.                     case 10//Lounge  -- No Aplica
  14237.                         //                        $pax = $item->getPax();
  14238.                         //                        if (empty($pax) or $pax == "0") {
  14239.                         //                            $pax = 1;
  14240.                         //                        }
  14241.                         //
  14242.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  14243.                         //                        if ($days > 1){
  14244.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  14245.                         //                        } else {
  14246.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14247.                         //                        }
  14248.                         //
  14249.                         //                        $unitsServ = $item->getUnits();
  14250.                         //                        if (empty($unitsServ) or $unitsServ == "0") {
  14251.                         //                            $unitsServ = 1;
  14252.                         //                        }
  14253.                         //
  14254.                         //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  14255.                         //                        $subnetoUnit = $subneto;
  14256.                         //                        $subneto = $subneto * $days * $unitsServ * $pax;
  14257.                         //
  14258.                         //                        $data_supplier['service'][$i] = array (
  14259.                         //                            'id' => $item->getId(),
  14260.                         //                            'serviceCatId' => $item->getServiceCatId(),
  14261.                         //                            'serviceName' => $item->getName(),
  14262.                         //                            'serviceType' => 'Itinerarios',
  14263.                         //                            'date' => $dateServ,
  14264.                         //                            'qty' => $unitsServ,
  14265.                         //                            'iva' => $item->getIva(),
  14266.                         //                            'pax' => $item->getPax(),
  14267.                         //                            'precioUnit' => $subnetoUnit,
  14268.                         //                            'subneto' => $subneto,
  14269.                         //                            'subtotal' => $subtotal,
  14270.                         //                        );
  14271.                         break;
  14272.                     case 11//Menu
  14273.                         $pax $item->getPax();
  14274.                         if (empty($pax) or $pax == "0") {
  14275.                             $pax 1;
  14276.                         }
  14277.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14278.                         if ($days 1) {
  14279.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14280.                         } else {
  14281.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14282.                         }
  14283.                         $unitsServ $item->getUnits();
  14284.                         if (empty($unitsServ) or $unitsServ == "0") {
  14285.                             $unitsServ 1;
  14286.                         }
  14287.                         $subtotal $subtotalService $days $unitsServ $pax;
  14288.                         $subnetoUnit $subneto;
  14289.                         $subneto $subneto $days $unitsServ $pax;
  14290.                         $data_supplier['service'][$i] = array(
  14291.                             'id' => $item->getId(),
  14292.                             'serviceCatId' => $item->getServiceCatId(),
  14293.                             'serviceName' => $item->getName(),
  14294.                             'serviceType' => 'MenĂº',
  14295.                             'date' => $dateServ,
  14296.                             'qty' => $unitsServ,
  14297.                             'iva' => $item->getIva(),
  14298.                             'pax' => $item->getPax(),
  14299.                             'precioUnit' => $subnetoUnit,
  14300.                             'subneto' => $subneto,
  14301.                             'subtotal' => $subtotal,
  14302.                         );
  14303.                         break;
  14304.                     case 12//Others
  14305.                         $pax $item->getPax();
  14306.                         if (empty($pax) or $pax == "0") {
  14307.                             $pax 1;
  14308.                         }
  14309.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14310.                         if ($days 1) {
  14311.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14312.                         } else {
  14313.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14314.                         }
  14315.                         $unitsServ $item->getUnits();
  14316.                         if (empty($unitsServ) or $unitsServ == "0") {
  14317.                             $unitsServ 1;
  14318.                         }
  14319.                         $subtotal $subtotalService $days $unitsServ $pax;
  14320.                         $subnetoUnit $subneto;
  14321.                         $subneto $subneto $days $unitsServ $pax;
  14322.                         $data_supplier['service'][$i] = array(
  14323.                             'id' => $item->getId(),
  14324.                             'serviceCatId' => $item->getServiceCatId(),
  14325.                             'serviceName' => $item->getName(),
  14326.                             'serviceType' => 'Otros',
  14327.                             'date' => $dateServ,
  14328.                             'qty' => $unitsServ,
  14329.                             'iva' => $item->getIva(),
  14330.                             'pax' => $item->getPax(),
  14331.                             'precioUnit' => $subnetoUnit,
  14332.                             'subneto' => $subneto,
  14333.                             'subtotal' => $subtotal,
  14334.                         );
  14335.                         break;
  14336.                     case 13//Transport
  14337.                         $pax $item->getPax();
  14338.                         if (empty($pax) or $pax == "0") {
  14339.                             $pax 1;
  14340.                         }
  14341.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14342.                         if ($days 1) {
  14343.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14344.                         } else {
  14345.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14346.                         }
  14347.                         $unitsServ $item->getUnits();
  14348.                         if (empty($unitsServ) or $unitsServ == "0") {
  14349.                             $unitsServ 1;
  14350.                         }
  14351.                         $subtotal $subtotalService $days $unitsServ $pax;
  14352.                         $subnetoUnit $subneto;
  14353.                         $subneto $subneto $days $unitsServ $pax;
  14354.                         $data_supplier['service'][$i] = array(
  14355.                             'id' => $item->getId(),
  14356.                             'serviceCatId' => $item->getServiceCatId(),
  14357.                             'serviceName' => $item->getName(),
  14358.                             'serviceType' => 'Transporte',
  14359.                             'date' => $dateServ,
  14360.                             'qty' => $unitsServ,
  14361.                             'iva' => $item->getIva(),
  14362.                             'pax' => $item->getPax(),
  14363.                             'precioUnit' => $subnetoUnit,
  14364.                             'subneto' => $subneto,
  14365.                             'subtotal' => $subtotal,
  14366.                         );
  14367.                         break;
  14368.                     case 14//Technology
  14369.                         $pax $item->getPax();
  14370.                         if (empty($pax) or $pax == "0") {
  14371.                             $pax 1;
  14372.                         }
  14373.                         $days 1;
  14374.                         $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14375.                         $unitsServ $item->getUnits();
  14376.                         if (empty($unitsServ) or $unitsServ == "0") {
  14377.                             $unitsServ 1;
  14378.                         }
  14379.                         $subtotal $subtotalService $days $unitsServ $pax;
  14380.                         $subnetoUnit $subneto;
  14381.                         $subneto $subneto $days $unitsServ $pax;
  14382.                         $data_supplier['service'][$i] = array(
  14383.                             'id' => $item->getId(),
  14384.                             'serviceCatId' => $item->getServiceCatId(),
  14385.                             'serviceName' => $item->getName(),
  14386.                             'serviceType' => 'TecnologĂ­a',
  14387.                             'date' => $dateServ,
  14388.                             'qty' => $unitsServ,
  14389.                             'iva' => $item->getIva(),
  14390.                             'pax' => $item->getPax(),
  14391.                             'precioUnit' => $subnetoUnit,
  14392.                             'subneto' => $subneto,
  14393.                             'subtotal' => $subtotal,
  14394.                         );
  14395.                         break;
  14396.                     case 15//Assisstant
  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.                         $unitsServ $item->getUnits();
  14408.                         if (empty($unitsServ) or $unitsServ == "0") {
  14409.                             $unitsServ 1;
  14410.                         }
  14411.                         $subtotal $subtotalService $days $unitsServ $pax;
  14412.                         $subnetoUnit $subneto;
  14413.                         $subneto $subneto $days $unitsServ $pax;
  14414.                         $data_supplier['service'][$i] = array(
  14415.                             'id' => $item->getId(),
  14416.                             'serviceCatId' => $item->getServiceCatId(),
  14417.                             'serviceName' => $item->getName(),
  14418.                             'serviceType' => 'Asistente',
  14419.                             'date' => $dateServ,
  14420.                             'qty' => $unitsServ,
  14421.                             'iva' => $item->getIva(),
  14422.                             'pax' => $item->getPax(),
  14423.                             'precioUnit' => $subnetoUnit,
  14424.                             'subneto' => $subneto,
  14425.                             'subtotal' => $subtotal,
  14426.                         );
  14427.                         break;
  14428.                     case 16//DDR
  14429.                         $pax $item->getPax();
  14430.                         if (empty($pax) or $pax == "0") {
  14431.                             $pax 1;
  14432.                         }
  14433.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14434.                         if ($days 1) {
  14435.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14436.                         } else {
  14437.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14438.                         }
  14439.                         $unitsServ $item->getUnits();
  14440.                         if (empty($unitsServ) or $unitsServ == "0") {
  14441.                             $unitsServ 1;
  14442.                         }
  14443.                         $subtotal $subtotalService $days $unitsServ $pax;
  14444.                         $subnetoUnit $subneto;
  14445.                         $subneto $subneto $days $unitsServ $pax;
  14446.                         $data_supplier['service'][$i] = array(
  14447.                             'id' => $item->getId(),
  14448.                             'serviceCatId' => $item->getServiceCatId(),
  14449.                             'serviceName' => $item->getName(),
  14450.                             'serviceType' => 'DDR',
  14451.                             'date' => $dateServ,
  14452.                             'qty' => $unitsServ,
  14453.                             'iva' => $item->getIva(),
  14454.                             'pax' => $item->getPax(),
  14455.                             'precioUnit' => $subnetoUnit,
  14456.                             'subneto' => $subneto,
  14457.                             'subtotal' => $subtotal,
  14458.                         );
  14459.                         break;
  14460.                     default:
  14461.                         break;
  14462.                 }
  14463.             } else {
  14464.                 $subtotalService $item->getPrice();
  14465.                 $subneto $item->getPrice();
  14466.                 // Commission
  14467.                 if ($item->getOpCommission() == '1') {
  14468.                     $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  14469.                     $subneto $subneto  * (+ ($item->getCommission() / 100));
  14470.                 } else {
  14471.                     $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  14472.                     $subneto $subneto * (- ($item->getCommission() / 100));
  14473.                 }
  14474.                 // Over
  14475.                 if ($item->getOpOver() == '1') {
  14476.                     $subtotalService $subtotalService $item->getOver();
  14477.                     $subneto $subneto $item->getOver();
  14478.                 } else {
  14479.                     $subtotalService $subtotalService $item->getOver();
  14480.                     $subneto $subneto $item->getOver();
  14481.                 }
  14482.                 // IVA
  14483.                 if ($item->getOpIva() == '1') {
  14484.                     $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  14485.                 } else {
  14486.                     $subtotalService $item->getPrice();
  14487.                     $subneto = ($subneto 100) / (100 $item->getIva());
  14488.                 }
  14489.                 switch ($item->getServiceCatId()) {
  14490.                     case 1// Alojamiento
  14491.                         // el numero de noches $numNoches; precio unitario $subneto
  14492.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  14493.                         // La personas no afectan este calculo
  14494.                         $subtotal $subtotalService $numNoches $item->getUnits();
  14495.                         $subnetoUnit $subneto;
  14496.                         $subneto $subneto $numNoches $item->getUnits();
  14497.                         $data_supplier['service'][$i] = array(
  14498.                             'id' => $item->getId(),
  14499.                             'serviceCatId' => $item->getServiceCatId(),
  14500.                             'serviceName' => $item->getName(),
  14501.                             'serviceType' => 'Hotel',
  14502.                             'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  14503.                             'qty' => $item->getUnits(),
  14504.                             'iva' => $item->getIva(),
  14505.                             'pax' => '-',
  14506.                             'precioUnit' => $subnetoUnit,
  14507.                             'subneto' => $subneto,
  14508.                             'subtotal' => $subtotal,
  14509.                         );
  14510.                         break;
  14511.                     case 2//Actividades
  14512.                         // El nĂºmero de personas es considerado en el calculo
  14513.                         $pax $item->getPax();
  14514.                         if (empty($pax) or $pax == "0") {
  14515.                             $pax 1;
  14516.                         }
  14517.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14518.                         if ($days 1) {
  14519.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14520.                         } else {
  14521.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14522.                         }
  14523.                         $subtotal $subtotalService $days $item->getUnits();
  14524.                         $subnetoUnit $subneto;
  14525.                         $subneto $subneto $days $item->getUnits();
  14526.                         $data_supplier['service'][$i] = array(
  14527.                             'id' => $item->getId(),
  14528.                             'serviceCatId' => $item->getServiceCatId(),
  14529.                             'serviceName' => $item->getName(),
  14530.                             'serviceType' => 'Actividad',
  14531.                             'date' => $dateServ,
  14532.                             'qty' => $item->getUnits(),
  14533.                             'iva' => $item->getIva(),
  14534.                             'pax' => $item->getPax(),
  14535.                             'precioUnit' => $subnetoUnit,
  14536.                             'subneto' => $subneto,
  14537.                             'subtotal' => $subtotal,
  14538.                         );
  14539.                         break;
  14540.                     case 3// AV
  14541.                         $pax $item->getPax();
  14542.                         if (empty($pax) or $pax == "0") {
  14543.                             $pax 1;
  14544.                         }
  14545.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14546.                         if ($days 1) {
  14547.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14548.                         } else {
  14549.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14550.                         }
  14551.                         $unitsServ $item->getUnits();
  14552.                         if (empty($unitsServ) or $unitsServ == "0") {
  14553.                             $unitsServ 1;
  14554.                         }
  14555.                         $subtotal $subtotalService $days $unitsServ $pax;
  14556.                         $subnetoUnit $subneto;
  14557.                         $subneto $subneto $days $unitsServ $pax;
  14558.                         $data_supplier['service'][$i] = array(
  14559.                             'id' => $item->getId(),
  14560.                             'serviceCatId' => $item->getServiceCatId(),
  14561.                             'serviceName' => $item->getName(),
  14562.                             'serviceType' => 'AV',
  14563.                             'date' => $dateServ,
  14564.                             'qty' => $unitsServ,
  14565.                             'iva' => $item->getIva(),
  14566.                             'pax' => $item->getPax(),
  14567.                             'precioUnit' => $subnetoUnit,
  14568.                             'subneto' => $subneto,
  14569.                             'subtotal' => $subtotal,
  14570.                         );
  14571.                         break;
  14572.                     case 4//Creative
  14573.                         $pax $item->getPax();
  14574.                         if (empty($pax) or $pax == "0") {
  14575.                             $pax 1;
  14576.                         }
  14577.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14578.                         if ($days 1) {
  14579.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14580.                         } else {
  14581.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14582.                         }
  14583.                         $unitsServ $item->getUnits();
  14584.                         if (empty($unitsServ) or $unitsServ == "0") {
  14585.                             $unitsServ 1;
  14586.                         }
  14587.                         $subtotal $subtotalService $days $unitsServ $pax;
  14588.                         $subnetoUnit $subneto;
  14589.                         $subneto $subneto $days $unitsServ $pax;
  14590.                         $data_supplier['service'][$i] = array(
  14591.                             'id' => $item->getId(),
  14592.                             'serviceCatId' => $item->getServiceCatId(),
  14593.                             'serviceName' => $item->getName(),
  14594.                             'serviceType' => 'Creativo',
  14595.                             'date' => $dateServ,
  14596.                             'qty' => $unitsServ,
  14597.                             'iva' => $item->getIva(),
  14598.                             'pax' => $item->getPax(),
  14599.                             'precioUnit' => $subnetoUnit,
  14600.                             'subneto' => $subneto,
  14601.                             'subtotal' => $subtotal,
  14602.                         );
  14603.                         break;
  14604.                     case 5//Cruise
  14605.                         $pax $item->getPax();
  14606.                         if (empty($pax) or $pax == "0") {
  14607.                             $pax 1;
  14608.                         }
  14609.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  14610.                         if ($days 1) {
  14611.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14612.                         } else {
  14613.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14614.                         }
  14615.                         $unitsServ $item->getUnits();
  14616.                         if (empty($unitsServ) or $unitsServ == "0") {
  14617.                             $unitsServ 1;
  14618.                         }
  14619.                         $subtotal $subtotalService $days $unitsServ $pax;
  14620.                         $subnetoUnit $subneto;
  14621.                         $subneto $subneto $days $unitsServ $pax;
  14622.                         $data_supplier['service'][$i] = array(
  14623.                             'id' => $item->getId(),
  14624.                             'serviceCatId' => $item->getServiceCatId(),
  14625.                             'serviceName' => $item->getName(),
  14626.                             'serviceType' => 'Crucero',
  14627.                             'date' => $dateServ,
  14628.                             'qty' => $unitsServ,
  14629.                             'iva' => $item->getIva(),
  14630.                             'pax' => $item->getPax(),
  14631.                             'precioUnit' => $subnetoUnit,
  14632.                             'subneto' => $subneto,
  14633.                             'subtotal' => $subtotal,
  14634.                         );
  14635.                         break;
  14636.                     case 6//Entertaiment
  14637.                         $pax $item->getPax();
  14638.                         if (empty($pax) or $pax == "0") {
  14639.                             $pax 1;
  14640.                         }
  14641.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14642.                         if ($days 1) {
  14643.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14644.                         } else {
  14645.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14646.                         }
  14647.                         $unitsServ $item->getUnits();
  14648.                         if (empty($unitsServ) or $unitsServ == "0") {
  14649.                             $unitsServ 1;
  14650.                         }
  14651.                         $subtotal $subtotalService $days $unitsServ $pax;
  14652.                         $subnetoUnit $subneto;
  14653.                         $subneto $subneto $days $unitsServ $pax;
  14654.                         $data_supplier['service'][$i] = array(
  14655.                             'id' => $item->getId(),
  14656.                             'serviceCatId' => $item->getServiceCatId(),
  14657.                             'serviceName' => $item->getName(),
  14658.                             'serviceType' => 'Entretenimiento',
  14659.                             'date' => $dateServ,
  14660.                             'qty' => $unitsServ,
  14661.                             'iva' => $item->getIva(),
  14662.                             'pax' => $item->getPax(),
  14663.                             'precioUnit' => $subnetoUnit,
  14664.                             'subneto' => $subneto,
  14665.                             'subtotal' => $subtotal,
  14666.                         );
  14667.                         break;
  14668.                     case 7// Gifts
  14669.                         $pax $item->getPax();
  14670.                         if (empty($pax) or $pax == "0") {
  14671.                             $pax 1;
  14672.                         }
  14673.                         $days 1;
  14674.                         if ($days 1) {
  14675.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14676.                         } else {
  14677.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14678.                         }
  14679.                         $unitsServ $item->getUnits();
  14680.                         if (empty($unitsServ) or $unitsServ == "0") {
  14681.                             $unitsServ 1;
  14682.                         }
  14683.                         $subtotal $subtotalService $days $unitsServ $pax;
  14684.                         $subnetoUnit $subneto;
  14685.                         $subneto $subneto $days $unitsServ $pax;
  14686.                         $data_supplier['service'][$i] = array(
  14687.                             'id' => $item->getId(),
  14688.                             'serviceCatId' => $item->getServiceCatId(),
  14689.                             'serviceName' => $item->getName(),
  14690.                             'serviceType' => 'Regalos',
  14691.                             'date' => $dateServ,
  14692.                             'qty' => $unitsServ,
  14693.                             'iva' => $item->getIva(),
  14694.                             'pax' => $item->getPax(),
  14695.                             'precioUnit' => $subnetoUnit,
  14696.                             'subneto' => $subneto,
  14697.                             'subtotal' => $subtotal,
  14698.                         );
  14699.                         break;
  14700.                     case 8//Guide
  14701.                         $pax $item->getPax();
  14702.                         if (empty($pax) or $pax == "0") {
  14703.                             $pax 1;
  14704.                         }
  14705.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14706.                         if ($days 1) {
  14707.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14708.                         } else {
  14709.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14710.                         }
  14711.                         $unitsServ $item->getUnits();
  14712.                         if (empty($unitsServ) or $unitsServ == "0") {
  14713.                             $unitsServ 1;
  14714.                         }
  14715.                         $subtotal $subtotalService $days $unitsServ $pax;
  14716.                         $subnetoUnit $subneto;
  14717.                         $subneto $subneto $days $unitsServ $pax;
  14718.                         $data_supplier['service'][$i] = array(
  14719.                             'id' => $item->getId(),
  14720.                             'serviceCatId' => $item->getServiceCatId(),
  14721.                             'serviceName' => $item->getName(),
  14722.                             'serviceType' => 'Regalos',
  14723.                             'date' => $dateServ,
  14724.                             'qty' => $unitsServ,
  14725.                             'iva' => $item->getIva(),
  14726.                             'pax' => $item->getPax(),
  14727.                             'precioUnit' => $subnetoUnit,
  14728.                             'subneto' => $subneto,
  14729.                             'subtotal' => $subtotal,
  14730.                         );
  14731.                         break;
  14732.                     case 9//Itineraries
  14733.                         $pax $item->getPax();
  14734.                         if (empty($pax) or $pax == "0") {
  14735.                             $pax 1;
  14736.                         }
  14737.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14738.                         if ($days 1) {
  14739.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14740.                         } else {
  14741.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14742.                         }
  14743.                         $unitsServ $item->getUnits();
  14744.                         if (empty($unitsServ) or $unitsServ == "0") {
  14745.                             $unitsServ 1;
  14746.                         }
  14747.                         $subtotal $subtotalService $days $unitsServ $pax;
  14748.                         $subnetoUnit $subneto;
  14749.                         $subneto $subneto $days $unitsServ $pax;
  14750.                         $data_supplier['service'][$i] = array(
  14751.                             'id' => $item->getId(),
  14752.                             'serviceCatId' => $item->getServiceCatId(),
  14753.                             'serviceName' => $item->getName(),
  14754.                             'serviceType' => 'Itinerarios',
  14755.                             'date' => $dateServ,
  14756.                             'qty' => $unitsServ,
  14757.                             'iva' => $item->getIva(),
  14758.                             'pax' => $item->getPax(),
  14759.                             'precioUnit' => $subnetoUnit,
  14760.                             'subneto' => $subneto,
  14761.                             'subtotal' => $subtotal,
  14762.                         );
  14763.                         break;
  14764.                     case 10//Lounge  -- No Aplica
  14765.                         //                        $pax = $item->getPax();
  14766.                         //                        if (empty($pax) or $pax == "0") {
  14767.                         //                            $pax = 1;
  14768.                         //                        }
  14769.                         //
  14770.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  14771.                         //                        if ($days > 1){
  14772.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  14773.                         //                        } else {
  14774.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14775.                         //                        }
  14776.                         //
  14777.                         //                        $unitsServ = $item->getUnits();
  14778.                         //                        if (empty($unitsServ) or $unitsServ == "0") {
  14779.                         //                            $unitsServ = 1;
  14780.                         //                        }
  14781.                         //
  14782.                         //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  14783.                         //                        $subnetoUnit = $subneto;
  14784.                         //                        $subneto = $subneto * $days * $unitsServ * $pax;
  14785.                         //
  14786.                         //                        $data_supplier['service'][$i] = array (
  14787.                         //                            'id' => $item->getId(),
  14788.                         //                            'serviceCatId' => $item->getServiceCatId(),
  14789.                         //                            'serviceName' => $item->getName(),
  14790.                         //                            'serviceType' => 'Itinerarios',
  14791.                         //                            'date' => $dateServ,
  14792.                         //                            'qty' => $unitsServ,
  14793.                         //                            'iva' => $item->getIva(),
  14794.                         //                            'pax' => $item->getPax(),
  14795.                         //                            'precioUnit' => $subnetoUnit,
  14796.                         //                            'subneto' => $subneto,
  14797.                         //                            'subtotal' => $subtotal,
  14798.                         //                        );
  14799.                         break;
  14800.                     case 11//Menu
  14801.                         $pax $item->getPax();
  14802.                         if (empty($pax) or $pax == "0") {
  14803.                             $pax 1;
  14804.                         }
  14805.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14806.                         if ($days 1) {
  14807.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14808.                         } else {
  14809.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14810.                         }
  14811.                         $unitsServ $item->getUnits();
  14812.                         if (empty($unitsServ) or $unitsServ == "0") {
  14813.                             $unitsServ 1;
  14814.                         }
  14815.                         $subtotal $subtotalService $days $unitsServ $pax;
  14816.                         $subnetoUnit $subneto;
  14817.                         $subneto $subneto $days $unitsServ $pax;
  14818.                         $data_supplier['service'][$i] = array(
  14819.                             'id' => $item->getId(),
  14820.                             'serviceCatId' => $item->getServiceCatId(),
  14821.                             'serviceName' => $item->getName(),
  14822.                             'serviceType' => 'MenĂº',
  14823.                             'date' => $dateServ,
  14824.                             'qty' => $unitsServ,
  14825.                             'iva' => $item->getIva(),
  14826.                             'pax' => $item->getPax(),
  14827.                             'precioUnit' => $subnetoUnit,
  14828.                             'subneto' => $subneto,
  14829.                             'subtotal' => $subtotal,
  14830.                         );
  14831.                         break;
  14832.                     case 12//Others
  14833.                         $pax $item->getPax();
  14834.                         if (empty($pax) or $pax == "0") {
  14835.                             $pax 1;
  14836.                         }
  14837.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14838.                         if ($days 1) {
  14839.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14840.                         } else {
  14841.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14842.                         }
  14843.                         $unitsServ $item->getUnits();
  14844.                         if (empty($unitsServ) or $unitsServ == "0") {
  14845.                             $unitsServ 1;
  14846.                         }
  14847.                         $subtotal $subtotalService $days $unitsServ $pax;
  14848.                         $subnetoUnit $subneto;
  14849.                         $subneto $subneto $days $unitsServ $pax;
  14850.                         $data_supplier['service'][$i] = array(
  14851.                             'id' => $item->getId(),
  14852.                             'serviceCatId' => $item->getServiceCatId(),
  14853.                             'serviceName' => $item->getName(),
  14854.                             'serviceType' => 'Otros',
  14855.                             'date' => $dateServ,
  14856.                             'qty' => $unitsServ,
  14857.                             'iva' => $item->getIva(),
  14858.                             'pax' => $item->getPax(),
  14859.                             'precioUnit' => $subnetoUnit,
  14860.                             'subneto' => $subneto,
  14861.                             'subtotal' => $subtotal,
  14862.                         );
  14863.                         break;
  14864.                     case 13//Transport
  14865.                         $pax $item->getPax();
  14866.                         if (empty($pax) or $pax == "0") {
  14867.                             $pax 1;
  14868.                         }
  14869.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14870.                         if ($days 1) {
  14871.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14872.                         } else {
  14873.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14874.                         }
  14875.                         $unitsServ $item->getUnits();
  14876.                         if (empty($unitsServ) or $unitsServ == "0") {
  14877.                             $unitsServ 1;
  14878.                         }
  14879.                         $subtotal $subtotalService $days $unitsServ $pax;
  14880.                         $subnetoUnit $subneto;
  14881.                         $subneto $subneto $days $unitsServ $pax;
  14882.                         $data_supplier['service'][$i] = array(
  14883.                             'id' => $item->getId(),
  14884.                             'serviceCatId' => $item->getServiceCatId(),
  14885.                             'serviceName' => $item->getName(),
  14886.                             'serviceType' => 'Transporte',
  14887.                             'date' => $dateServ,
  14888.                             'qty' => $unitsServ,
  14889.                             'iva' => $item->getIva(),
  14890.                             'pax' => $item->getPax(),
  14891.                             'precioUnit' => $subnetoUnit,
  14892.                             'subneto' => $subneto,
  14893.                             'subtotal' => $subtotal,
  14894.                         );
  14895.                         break;
  14896.                     case 14//Technology
  14897.                         $pax $item->getPax();
  14898.                         if (empty($pax) or $pax == "0") {
  14899.                             $pax 1;
  14900.                         }
  14901.                         $days 1;
  14902.                         $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14903.                         $unitsServ $item->getUnits();
  14904.                         if (empty($unitsServ) or $unitsServ == "0") {
  14905.                             $unitsServ 1;
  14906.                         }
  14907.                         $subtotal $subtotalService $days $unitsServ $pax;
  14908.                         $subnetoUnit $subneto;
  14909.                         $subneto $subneto $days $unitsServ $pax;
  14910.                         $data_supplier['service'][$i] = array(
  14911.                             'id' => $item->getId(),
  14912.                             'serviceCatId' => $item->getServiceCatId(),
  14913.                             'serviceName' => $item->getName(),
  14914.                             'serviceType' => 'TecnologĂ­a',
  14915.                             'date' => $dateServ,
  14916.                             'qty' => $unitsServ,
  14917.                             'iva' => $item->getIva(),
  14918.                             'pax' => $item->getPax(),
  14919.                             'precioUnit' => $subnetoUnit,
  14920.                             'subneto' => $subneto,
  14921.                             'subtotal' => $subtotal,
  14922.                         );
  14923.                         break;
  14924.                     case 15//Assisstant
  14925.                         $pax $item->getPax();
  14926.                         if (empty($pax) or $pax == "0") {
  14927.                             $pax 1;
  14928.                         }
  14929.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14930.                         if ($days 1) {
  14931.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14932.                         } else {
  14933.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14934.                         }
  14935.                         $unitsServ $item->getUnits();
  14936.                         if (empty($unitsServ) or $unitsServ == "0") {
  14937.                             $unitsServ 1;
  14938.                         }
  14939.                         $subtotal $subtotalService $days $unitsServ $pax;
  14940.                         $subnetoUnit $subneto;
  14941.                         $subneto $subneto $days $unitsServ $pax;
  14942.                         $data_supplier['service'][$i] = array(
  14943.                             'id' => $item->getId(),
  14944.                             'serviceCatId' => $item->getServiceCatId(),
  14945.                             'serviceName' => $item->getName(),
  14946.                             'serviceType' => 'Asistente',
  14947.                             'date' => $dateServ,
  14948.                             'qty' => $unitsServ,
  14949.                             'iva' => $item->getIva(),
  14950.                             'pax' => $item->getPax(),
  14951.                             'precioUnit' => $subnetoUnit,
  14952.                             'subneto' => $subneto,
  14953.                             'subtotal' => $subtotal,
  14954.                         );
  14955.                         break;
  14956.                     case 16//DDR
  14957.                         $pax $item->getPax();
  14958.                         if (empty($pax) or $pax == "0") {
  14959.                             $pax 1;
  14960.                         }
  14961.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14962.                         if ($days 1) {
  14963.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14964.                         } else {
  14965.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14966.                         }
  14967.                         $unitsServ $item->getUnits();
  14968.                         if (empty($unitsServ) or $unitsServ == "0") {
  14969.                             $unitsServ 1;
  14970.                         }
  14971.                         $subtotal $subtotalService $days $unitsServ $pax;
  14972.                         $subnetoUnit $subneto;
  14973.                         $subneto $subneto $days $unitsServ $pax;
  14974.                         $data_supplier['service'][$i] = array(
  14975.                             'id' => $item->getId(),
  14976.                             'serviceCatId' => $item->getServiceCatId(),
  14977.                             'serviceName' => $item->getName(),
  14978.                             'serviceType' => 'DDR',
  14979.                             'date' => $dateServ,
  14980.                             'qty' => $unitsServ,
  14981.                             'iva' => $item->getIva(),
  14982.                             'pax' => $item->getPax(),
  14983.                             'precioUnit' => $subnetoUnit,
  14984.                             'subneto' => $subneto,
  14985.                             'subtotal' => $subtotal,
  14986.                         );
  14987.                         break;
  14988.                     default:
  14989.                         break;
  14990.                 }
  14991.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  14992.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  14993.                 $neto round($subneto2PHP_ROUND_HALF_UP);
  14994.             }
  14995.             switch ($item->getIva()) {
  14996.                     // Acumula IVA
  14997.                 case 21:
  14998.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  14999.                     break;
  15000.                 case 10:
  15001.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  15002.                     break;
  15003.                 case 0:
  15004.                     break;
  15005.                 default:
  15006.                     break;
  15007.             }
  15008.             $totales_neto_all $totales_neto_all $neto;
  15009.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  15010.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  15011.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  15012.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  15013.             // Acumula netos totales e IVA
  15014.             $service['neto'] = $service['neto'] + $neto;
  15015.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  15016.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  15017.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  15018.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  15019.             $i++;
  15020.         }
  15021.         $data_supplier['serviceSubTotal'] = array(
  15022.             'neto' => $service['neto'],
  15023.             'sumSubT' => $service['sumSubT'],
  15024.         );
  15025.         $currency '€';
  15026.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  15027.         if (!empty($payments)) {
  15028.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  15029.         } else {
  15030.             $amount_pay 0;
  15031.         }
  15032.         $totales_all $totales_total $amount_pay;
  15033.         $data = array(
  15034.             'id' => $id,
  15035.             'type' => $type,
  15036.             'number' => $number,
  15037.             'prefix' => $prefix,
  15038.             'date' => $date,
  15039.             'file' => $file,
  15040.             'token' => ''// $file->getAccessKey(),
  15041.             'company' => $company,
  15042.             'clients' => $clientNew,
  15043.             'datasupplier' => $data_supplier,
  15044.             'currency' => $currency,
  15045.             'totales_neto' => $totales_neto_all,
  15046.             'bases_imponibles' => $data_iva,
  15047.             'totales' => $totales_total,
  15048.             'balance' => $totales_all,
  15049.             'paymentInvoice' => $amount_pay,
  15050.         );
  15051.         return $data;
  15052.     }
  15053.     private function sendMailLot($mailAddressFrom$mailArrayTo$mailSubject$mailBody)
  15054.     {
  15055.         $em $this->getDoctrine()->getManager();
  15056.         $agent $em->getRepository(User::class)->findOneByEmail($mailAddressFrom);
  15057.         //        $client = $em->getRepository(User::class)->findOneByEmail($mailAddressTo);
  15058.         $replyTo = array();
  15059.         foreach ($mailArrayTo as $item) {
  15060.             // Verificamos que los correos sean validos
  15061.             if (filter_var($itemFILTER_VALIDATE_EMAIL)) {
  15062.                 $replyTo[$item] = $item;
  15063.             }
  15064.         }
  15065.         $agentMail $mailAddressFrom;
  15066.         $mailAgent $agentMail;
  15067.         //Se prepara el correo con los agentes a notificar
  15068.         $firmGmail $agent->getFirmGmail();
  15069.         $data = array(
  15070.             'body' => $mailBody,
  15071.             'firm' => $firmGmail,
  15072.         );
  15073.         // EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
  15074.         $transporter = new Swift_SmtpTransport();
  15075.         $transporter->setHost('smtp.gmail.com')
  15076.             ->setEncryption('ssl'//ssl / tls
  15077.             ->setPort(465// 465 / 587
  15078.             ->setUsername('desarrollo@develup.solutions')
  15079.             ->setPassword('utvh hzoi wfdo ztjs');
  15080.         $mailer = new Swift_Mailer($transporter);
  15081.         $message = new Swift_Message();
  15082.         $message->setSubject($mailSubject)
  15083.             ->setSender($agentMail)
  15084.             ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  15085.             ->setReplyTo($agentMail)
  15086.             ->setTo($replyTo)
  15087.             ->setBody(
  15088.                 $this->renderView(
  15089.                     'mail/structure-mail.html.twig',
  15090.                     array('data' => $data)
  15091.                 ),
  15092.                 'text/html'
  15093.             );
  15094.         $mailer->send($message);
  15095.         return true;
  15096.     }
  15097.     private function calculoBeneficiosDocumento($id$typeDoc)
  15098.     {
  15099.         // Funcion para registrar los beneficios al crear facturas o facturas rectificativas
  15100.         $em $this->getDoctrine()->getManager();
  15101.         if ($typeDoc == 'Invoice') {
  15102.             // Es factura
  15103.             $invoice $em->getRepository(AveDocInvoice::class)->findOneById($id);
  15104.             $invoiceItems $em->getRepository(AveDocInvoiceItems::class)->findByInvoiceId($id);
  15105.             // ComisiĂ³n de AV a GreenPatio
  15106.             $aveFile $em->getRepository(AveFiles::class)->findOneById($invoice->getFileId());
  15107.             $reserva $em->getRepository(Reservation::class)->findOneById($aveFile->getReservation());
  15108.             if (!empty($reserva)){
  15109. //                if (!is_null($reserva->getComAvGp())) {
  15110. //                    $supplierNet = $invoice->getTotalNet() * ($reserva->getComAvGp()/100);
  15111. //                } else {
  15112.                     // Valor por defecto de la Comision de Av 10%
  15113.                     $supplierNet $invoice->getTotalNet() * (10/100);
  15114. //                }
  15115.                 $description $id.' - ComisiĂ³n MANTE de Green Patio (Generado automaticamente)';
  15116.                 $supplier $em->getRepository(Supplier::class)->findOneById(2028);     // Green Patio como proveedor
  15117.                 $benSup = new AveBenefitsSupplier();
  15118.                 $benSup->setFileId($aveFile->getId());
  15119.                 $benSup->setDocId(0);
  15120.                 $benSup->setDocType('.');
  15121.                 $benSup->setSupplierId(2028);
  15122.                 $benSup->setSupplierName($supplier->getCompany() . ' | ' $supplier->getName());
  15123.                 $benSup->setDescription($description);
  15124.                 $benSup->setBenefitSupplier($supplierNet);
  15125.                 $em->persist($benSup);
  15126.                 $em->flush();
  15127.             }
  15128.         } else {
  15129.             // Es factura rectificativa
  15130.             // Se busca la entrada de los beneficios de la factura y se genera su contraparte. Tambien se necesita el ID de la factura rectificativa
  15131.             $invoiceRec $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
  15132.             if (empty($invoiceRec)) { return true; }
  15133.             $ben $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneByDocId($invoiceRec->getInvoiceToRec());
  15134.             $benefits = new AveBenefitsInvoiceInvoiceRec();
  15135.             $benefits->setDocId($invoiceRec->getId());
  15136.             $benefits->setFileId($ben->getFileId());
  15137.             $benefits->setDocType('Invoice Rec');
  15138.             $benefits->setDateAt($invoiceRec->getDateAt());
  15139.             $benefits->setFileName($ben->getFileName());
  15140.             $benefits->setClientId($ben->getClientId());
  15141.             $benefits->setClientName($ben->getClientName());
  15142.             $benefits->setBenefitEuro($ben->getBenefitEuro() * (-1));
  15143.             $benefits->setBenefitPerc($ben->getBenefitPerc());
  15144.             $benefits->setNetSale($ben->getNetSale() * (-1));
  15145.             $benefits->setTotalSale($ben->getTotalSale() * (-1));
  15146.             $em->persist($benefits);
  15147.             $em->flush();
  15148.             return true;
  15149.         }
  15150.         $productsItems = array();
  15151.         // Buscamos los productos de la factura para determinar el proveedor
  15152.         foreach ($invoiceItems as $item) {
  15153.             $prdItem $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  15154.             $sup = (empty($prdItem) or empty($prdItem->getSupplierExt())) ? 'AV EXPRESS S.L.' $prdItem->getSupplierExt();
  15155.             $iva = (empty($prdItem) or empty($prdItem->getIva())) ? '21' $prdItem->getSupplierExt();
  15156.             switch ($iva) {
  15157.                 case '21':
  15158.                     if (empty($prdItem)) {
  15159.                         $ivaxPlus 1.21;
  15160.                     } else {
  15161.                         $ivaxPlus = ($prdItem->getOpIva() == 0) ? 0.83 1.21;  // 100/121 = 0.826
  15162.                     }
  15163.                     break;
  15164.                 case '10':
  15165.                     if (empty($prdItem)) {
  15166.                         $ivaxPlus 1.10;
  15167.                     } else {
  15168.                         $ivaxPlus = ($prdItem->getOpIva() == 0) ? 0.91 1.10;  // 100/110 = 0.909
  15169.                     }
  15170.                     break;
  15171.                 case '0':
  15172.                     $ivaxPlus 1;
  15173.                     break;
  15174.                 default:
  15175.                     $ivaxPlus 1.21;
  15176.                     break;
  15177.             }
  15178.             $productsItems[] = array(
  15179.                 'invoiceItemOrInvoiceRecItem' => $item,
  15180.                 'productFile' => $prdItem,
  15181.                 'supplier' => $sup,
  15182.                 'iva' => $ivaxPlus,
  15183.                 'typeDoc' => $typeDoc
  15184.             );
  15185.         }
  15186.         $data = array();
  15187.         foreach ($productsItems as $elem) {
  15188.             if (empty($data[$invoice->getFileId()])) {
  15189.                 $data[$invoice->getFileId()] = array(
  15190.                     'id' => $invoice->getFileId(),
  15191.                     'benefitEuro' => 0,
  15192.                     'benefitPerc' => 0,
  15193.                     'netSale' => 0,
  15194.                     'totalSale' => 0,
  15195.                 );
  15196.             }
  15197.             $benefitEuro $data[$invoice->getFileId()]['benefitEuro'];
  15198.             $benefitPerc $data[$invoice->getFileId()]['benefitPerc'];
  15199.             $netSale $data[$invoice->getFileId()]['netSale'];
  15200.             $totalSale $data[$invoice->getFileId()]['totalSale'];
  15201.             // Con los factores se sumarĂ¡ o restarĂ¡ el beneficio
  15202.             // Se verifica si es una factura o factura rectificativa
  15203.             if ($typeDoc == 'Invoice') {
  15204.                 $indiceOpOver = (empty($elem['productFile']) or empty($elem['productFile']->getOpOver())) ? $elem['productFile']->getOpOver();
  15205.                 $indiceOpComission = (empty($elem['productFile']) or empty($elem['productFile']->getOpCommission())) ? $elem['productFile']->getOpCommission();
  15206.                 $indicePax $elem['invoiceItemOrInvoiceRecItem']->getPrdPax();
  15207.                 $indiceQty $elem['invoiceItemOrInvoiceRecItem']->getPrdQty();
  15208.                 $indiceDays $elem['invoiceItemOrInvoiceRecItem']->getPrdDays();
  15209.                 $indicePriceProduct $elem['invoiceItemOrInvoiceRecItem']->getPrdServicePrice();
  15210.                 $indiceOver = (empty($elem['productFile']) or empty($elem['productFile']->getOver())) ? $elem['productFile']->getOver();
  15211.                 $indiceCommission = (empty($elem['productFile']) or empty($elem['productFile']->getCommission())) ? $elem['productFile']->getCommission();
  15212.             } else {
  15213.                 $indiceOpOver = (empty($elem['productFile']) or empty($elem['productFile']->getOpOver())) ? $elem['productFile']->getOpOver();
  15214.                 $indiceOpComission = (empty($elem['productFile']) or empty($elem['productFile']->getOpCommission())) ? $elem['productFile']->getOpCommission();
  15215.                 $indicePax $elem['invoiceItemOrInvoiceRecItem']->getPrdPax();
  15216.                 $indiceQty $elem['invoiceItemOrInvoiceRecItem']->getPrdQty();
  15217.                 $indiceDays $elem['invoiceItemOrInvoiceRecItem']->getPrdDays();
  15218.                 $indicePriceProduct $elem['invoiceItemOrInvoiceRecItem']->getPrdServicePrice();
  15219.                 $indiceOver = (empty($elem['productFile']) or empty($elem['productFile']->getOver())) ? $elem['productFile']->getOver();
  15220.                 $indiceCommission = (empty($elem['productFile']) or empty($elem['productFile']->getCommission())) ? $elem['productFile']->getCommission();
  15221.             }
  15222.             // Se verifica el proveedor
  15223.             if ($elem['supplier'] == 'AV EXPRESS S.L.') { $factorSupp 0; } else { $factorSupp 1; }
  15224.             // Se verifica si es ganancia o perdida segun OVER (- o +)
  15225.             if ($indiceOpOver == 0) { $factorOver = -1; } else { $factorOver 1; }
  15226.             // Se verifica si es ganancia o perdida segun COMISION (- o +)
  15227.             if ($indiceOpComission == 0) { $factorCommission = -1; } else { $factorCommission 1; }
  15228.             // Pax
  15229.             if ($indicePax == or empty($indicePax)) { $pax 1; } else { $pax $indicePax; }
  15230.             // Qty
  15231.             if ($indiceQty == or empty($indiceQty)) { $qty 1; } else { $qty $indiceQty; }
  15232.             // Days
  15233.             if ($indiceDays == or empty($indiceDays)) { $days 1; } else { $days $indiceDays; }
  15234.             // Precio base
  15235.             $priceBase $indicePriceProduct $pax $qty $days;
  15236.             // Agregamos el over (se consideran over + o -)
  15237.             $price $priceBase + ($factorOver $indiceOver);
  15238.             // Agregamos la comision (se consideran comision + o -)
  15239.             $price $price + ((($factorCommission $indiceCommission) * $price) / 100);
  15240.             // Agregamos el factor proveedor
  15241.             $benefitEuroItem $price - ($priceBase $factorSupp);
  15242.             // Agregamos al porcentaje el factor del tipo de documento (factura o fact rectificativa), NO HACE FALTA LOS PRECIOS VIENEN NEGATIVOS
  15243.             //                $benefitEuroItem = $benefitEuroItem * $factorTypeDoc;
  15244.             // Agregamos al precio el factor del tipo de documento (factura o fact rectificativa), NO HACE FALTA LOS PRECIOS VIENEN NEGATIVOS
  15245.             //                $price = $price * $factorTypeDoc;
  15246.             // Agregamos el precio a la venta neta
  15247.             $netSale $netSale $price;
  15248.             // Agregamos al precio el IVA para la venta total
  15249.             $totalSale $totalSale + ($price $elem['iva']);
  15250.             $benefitPercItem = (empty($invoice) or ($invoice->getTotalNet() == 0)) ? round((($benefitEuroItem 100) / $invoice->getTotalNet()), 2PHP_ROUND_HALF_UP);
  15251.             $data[$invoice->getFileId()] = array(
  15252.                 'id' => $invoice->getFileId(),
  15253.                 'benefitEuro' => $benefitEuro $benefitEuroItem,
  15254.                 'benefitPerc' => $benefitPerc $benefitPercItem,
  15255.                 'netSale' => $netSale,
  15256.                 'totalSale' => $totalSale,
  15257.             );
  15258.         }
  15259.         foreach ($data as $key => $elem) {
  15260.             // Verificamos beneficios simplificados de proveedores
  15261.             $simplyBen $em->getRepository(AveBenefitsSupplier::class)->findByFileId($elem['id']);
  15262.             $benefitEuro $elem['benefitEuro'];
  15263.             foreach ($simplyBen as $item) { $benefitEuro $benefitEuro $item->getBenefitSupplier(); }
  15264.             $data[$key]['benefitEuro'] = $benefitEuro;
  15265.             $newBenefitPerc = (($benefitEuro 100) / $elem['netSale']);
  15266.             $newBenefitPerc round($newBenefitPerc2PHP_ROUND_HALF_UP);
  15267.             $data[$key]['benefitPerc'] = $newBenefitPerc;
  15268.         }
  15269.         // Los $benefitPercItem de 99.97 o 100.01 lo llevamos a 100
  15270. //        if ($data[$invoice->getFileId()]['benefitEuro'] == $data[$invoice->getFileId()]['netSale']) { $data[$invoice->getFileId()]['benefitPerc'] = 100; }
  15271.         $fileId $invoice->getFileId();
  15272.         if (isset($data[$fileId]) && $data[$fileId]['benefitEuro'] == $data[$fileId]['netSale']) {
  15273.             $data[$fileId]['benefitPerc'] = 100;
  15274.         }
  15275.         // Buscamos los datos del cliente
  15276.         if (!empty($invoice)) {
  15277.             $file $em->getRepository(AveFiles::class)->findOneById($invoice->getFileId());
  15278.             $clientId = empty($file) ? null $file->getClient();
  15279.             $clientName = empty($clientId) ? null $em->getRepository(Client::class)->findOneById($clientId);
  15280.             $clientName = empty($clientName) ? null $clientName->getName();
  15281.         } else {
  15282.             $clientId null;
  15283.             $clientName null;
  15284.         }
  15285.         if (!empty($data)) {
  15286.             $benefits = new AveBenefitsInvoiceInvoiceRec();
  15287.             $benefits->setDocId($invoice->getId());
  15288.             $benefits->setFileId($invoice->getFileId());
  15289.             $benefits->setDocType($typeDoc);
  15290.             $benefits->setDateAt($invoice->getDateAt());
  15291.             $benefits->setFileName($file->getTitle());
  15292.             $benefits->setClientId($clientId);
  15293.             $benefits->setClientName($clientName);
  15294.             $benefits->setBenefitEuro($data[$invoice->getFileId()]['benefitEuro']);
  15295.             $benefits->setBenefitPerc($data[$invoice->getFileId()]['benefitPerc']);
  15296.             $benefits->setNetSale($data[$invoice->getFileId()]['netSale']);
  15297.             $benefits->setTotalSale($data[$invoice->getFileId()]['totalSale']);
  15298.             $em->persist($benefits);
  15299.             $em->flush();
  15300.         }
  15301.         //Llamamos al servicio del gestor de comisiones internas entre empresas
  15302.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  15303.         $user_id $user_logueado->getId();
  15304. //        $dataService = $this->commisionEnterpriseService->commissionAvExpressVenues($invoice->getId(), $user_id);
  15305.         return true;
  15306.     }
  15307. };