src/MDS/GreenPatioBundle/Controller/ReservationsInvoiceController.php line 61

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Carlos.Rojas
  5.  * Date: 18/12/2019
  6.  * Time: 12:49
  7.  */
  8. namespace App\MDS\GreenPatioBundle\Controller;
  9. use App\Entity\Cities;
  10. use App\Entity\Client;
  11. use App\Entity\Configuration;
  12. use App\Entity\Country;
  13. use App\Entity\Regions;
  14. use App\Entity\SettingsCompany;
  15. use App\Entity\Supplier;
  16. use App\MDS\GreenPatioBundle\Entity\CvrReservationInvoiceItems;
  17. use App\MDS\GreenPatioBundle\Entity\Reservation;
  18. use App\MDS\GreenPatioBundle\Entity\ReservationBudgetItems;
  19. use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceItems;
  20. use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceProformaItems;
  21. use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceRec;
  22. use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceRecItems;
  23. use App\MDS\GreenPatioBundle\Entity\ReservationPaymentsClient;
  24. use App\MDS\GreenPatioBundle\Entity\ReservationProforma;
  25. use App\MDS\GreenPatioBundle\Entity\ReservationInvoice;
  26. use App\MDS\GreenPatioBundle\Entity\ReservationProformaDeposit;
  27. use App\MDS\GreenPatioBundle\Entity\ReservationTracing;
  28. use App\MDS\GreenPatioBundle\Form\ReservationPaymentsClientType;
  29. use App\MDS\GreenPatioBundle\Form\ReservationInvoiceType;
  30. use Symfony\Component\Routing\Annotation\Route;
  31. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  32. use Symfony\Component\HttpFoundation\Request;
  33. use Symfony\Component\HttpFoundation\JsonResponse;
  34. use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceDepositItems;
  35. use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceDepositControl;
  36. use App\MDS\GreenPatioBundle\Entity\ReservationLounge;
  37. use App\MDS\GreenPatioBundle\Entity\ReservationLoungeProfile;
  38. use App\MDS\GreenPatioBundle\Entity\ReservationLoungeSimple;
  39. use App\MDS\GreenPatioBundle\Entity\ReservationService;
  40. use App\MDS\GreenPatioBundle\Form\ReservationInvoiceDepositItemsType;
  41. use DateTime;
  42. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  43. use PhpOffice\PhpSpreadsheet\Style\Fill;
  44. use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
  45. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  46. use Symfony\Contracts\Translation\TranslatorInterface;
  47. class ReservationsInvoiceController extends AbstractController
  48. {
  49.     private $translator;
  50.     public function __construct(TranslatorInterface $translator) {
  51.         $this->translator $translator;
  52.     }
  53.     
  54.     /**
  55.      * @Route("/payment/{id}",  name="reservations_payment")
  56.      */
  57.     public function detailsReservationProformaAction($idRequest $request)
  58.     {
  59.         $em $this->getDoctrine()->getManager();
  60.         $paymentsClient = new ReservationPaymentsClient();
  61.         $paymentsClient->setReservationId($id);
  62.         $form $this->createReservationPaymentsClientForm($paymentsClient);
  63.         $reserva $em->getRepository(Reservation::class)->findOneById($id);
  64.         $payments $em->getRepository(ReservationPaymentsClient::class)->findByReservationId($id);
  65.         $services $em->getRepository(ReservationService::class)->findByReservationId($id);
  66.         $proforma $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
  67.         $reservaInv = new ReservationInvoice();
  68.         $reservaInv->setReservationId($id);
  69.         $form1 $this->createReservationInvoiceProformaForm($reservaInv);
  70.         if (!empty($proforma)){
  71.             $type 'Proforma';
  72.             $number $proforma->getId();
  73.             $date $proforma->getDateAt();
  74.             $prefix $proforma->getPrefix();
  75.             $data $this->baseInvoiceReservation($id$type$number$prefix$date);
  76.             $token $data['token'];
  77.         }else{
  78.             return $this->redirectToRoute('reservations_generate_proforma',
  79.                 array(
  80.                     'id' => $id
  81.                 )
  82.             );
  83.         }
  84.         $idLounges = array();
  85.         $loungesBoolToInvoice = array();
  86.         if (array_key_exists('lounge',$data['datasupplier'])) {
  87.             foreach ($data['datasupplier']['lounge'] as $item) {
  88.                 $idLounges[] = $item['id'];
  89.                 $loungesBoolToInvoice[] = 1;
  90.             }
  91.             $idLounges implode(','$idLounges);
  92.             $loungesBoolToInvoice implode(','$loungesBoolToInvoice);
  93.         } else {
  94.             $idLounges '0';
  95.             $loungesBoolToInvoice '0';
  96.         }
  97.         $idPayments = array();
  98.         $paymentsBoolToInvoice = array();
  99.         if (array_key_exists('payment',$data['datasupplier'])) {
  100.             foreach ($data['datasupplier']['payment'] as $item) {
  101.                 $idPayments[] = $item['id'];
  102.                 $paymentsBoolToInvoice[] = 1;
  103.             }
  104.             $idPayments implode(','$idPayments);
  105.             $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  106.             // Se han generado dos arreglos, cada uno dividido en 2 strings
  107.             // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  108.             // Para manipularlos entre la vista y el JS
  109.         } else {
  110.             $idPayments '0';
  111.             $paymentsBoolToInvoice '0';
  112.         }
  113.         /* Obtengo usuario logueado */
  114.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  115.         $user_id $user_logueado->getId();
  116.         //INICIO: Facturas de deposito
  117.         $allInvoiceDeposit = array();
  118. //        $allInvoiceDepositControl = $em->getRepository(ReservationInvoiceDepositControl::class)->findByReservationId($id);
  119. //        foreach($allInvoiceDepositControl as $control){
  120. //
  121. //            $items = $em->getRepository(ReservationInvoiceDepositItems::class)->findByControlId($control->getId());
  122. //
  123. //            foreach ($items as $item){
  124. //                $allInvoiceDeposit[$control->getId()] = array(
  125. //                    'controlId' => $control->getId(),
  126. //                    'dateAt' => $control->getDateAt(),
  127. //                    'itemId' => $item->getId(),
  128. //                    'name' => $item->getName(),
  129. //                    'amount' => $item->getAmount(),
  130. //                    'iva' => $item->getIva(),
  131. //                    'reservationId' => $item->getReservationId()
  132. //                );
  133. //            }
  134. //        }
  135.         $items $em->getRepository(ReservationProformaDeposit::class)->findByReservationId($id);
  136.         foreach ($items as $item){
  137.             $allInvoiceDeposit[$item->getId()] = array(
  138. //                'controlId' => $control->getId(),
  139. //                'dateAt' => $control->getDateAt(),
  140.                 'itemId' => $item->getId(),
  141.                 'name' => $item->getName(),
  142.                 'amount' => $item->getAmount(),
  143.                 'iva' => $item->getIva(),
  144.                 'reservationId' => $item->getReservationId(),
  145.                 'total' => $item->getTotal()
  146.             );
  147.         }
  148.         //FIN: Facturas de deposito
  149.         return $this->render('MDS/GreenPatioBundle/reservations/services-proforma-reservation.html.twig',
  150.             array(
  151.                 'id' => $id,
  152.                 'idLounges' => $idLounges,
  153.                 'reserva' => $reserva,
  154.                 'idPayments' => $idPayments,
  155.                 'loungesBoolToInvoice' => $loungesBoolToInvoice,
  156.                 'paymentsBoolToInvoice' => $paymentsBoolToInvoice,
  157.                 'type' => $data['type'],
  158.                 'number' => $data['number'],
  159.                 'prefix' => $data['prefix'],
  160.                 'date' => $data['date'],
  161.                 'token' => $token,
  162.                 'company' => $data['company'],
  163.                 'clients' => $data['clients'],
  164.                 'datasupplier' => $data['datasupplier'],
  165.                 'currency' => $data['currency'],
  166.                 'totales_neto' => $data['totales_neto'],
  167.                 'bases_imponibles' => $data['bases_imponibles'],
  168.                 'totales' => $data['totales'],
  169.                 'balance' => $data['balance'],
  170.                 'paymentInvoice' => $data['paymentInvoice'],
  171.                 'payments' => $payments,
  172.                 'allInvoiceDeposit' => $allInvoiceDeposit,
  173.                 'user_id' => $user_id,
  174.                 'form' => $form->createView(),
  175.                 'form1' => $form1->createView(),
  176.             )
  177.         );
  178.     }
  179.     private function createReservationInvoiceProformaForm(ReservationInvoice $entity)
  180.     {
  181.         $form $this->createForm(ReservationInvoiceType::class, $entity, array(
  182.             'action' => $this->generateUrl('reservation_proforma_invoice_pdf_print_action'),
  183.             'method' => 'POST'
  184.         ));
  185.         return $form;
  186.     }
  187.     private function createReservationPaymentsClientForm(ReservationPaymentsClient $entity)
  188.     {
  189.         $form $this->createForm(ReservationPaymentsClientType::class, $entity, array(
  190.             'action' => $this->generateUrl('reservation_payments_client_add'),
  191.             'method' => 'POST'
  192. //            'method' => 'PUT'
  193.         ));
  194.         return $form;
  195.     }
  196.     /**
  197.      * @Route("/payment/delete/{id}",  name="reservations_payment_delete")
  198.      */
  199.     public function deleteReservationPaymentAction($idRequest $request)
  200.     {
  201.         $em $this->getDoctrine()->getManager();
  202.         $payment $em->getRepository(ReservationPaymentsClient::class)->findOneById($id);
  203.         $reservationId $payment->getReservationId();
  204.         $em->remove($payment);
  205.         $em->flush();
  206.         return $this->redirectToRoute('reservations_payment',
  207.             array(
  208.                 'id' =>$reservationId
  209.             )
  210.         );
  211.     }
  212.     /**
  213.      * @Route("/reservations/payments", name="reservation_payments_client_add")
  214.      */
  215.     public function createAction(Request $request)
  216.     {
  217.         $paymentsClient = new ReservationPaymentsClient();
  218.         $form $this->createReservationPaymentsClientForm($paymentsClient);
  219.         $form->handleRequest($request);
  220.         // INICIO: Si la reserva esta facturada no puede ser modificada, no se pueden agregar pagos
  221.         $em $this->getDoctrine()->getManager();
  222.         $tempoReserva $em->getRepository(Reservation::class)->findOneById($paymentsClient->getReservationId());
  223.         if ($tempoReserva->getStatus() == 'Invoiced'){
  224.             return $this->redirectToRoute('reservations_payment',
  225.                 array('id' => $paymentsClient->getReservationId()));
  226.         }
  227.         // FIN: Si la reserva esta facturada no puede ser modificada, no se pueden agregar pagos
  228.         if($form->isValid())
  229.         {
  230.             $em $this->getDoctrine()->getManager();
  231.             /* Obtengo usuario logueado */
  232.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  233.             $user_id $user_logueado->getId();
  234.             $paymentsClient->setCreatedAt(new \DateTime('now'));
  235.             $paymentsClient->setCreatedId($user_id);
  236.             $paymentsClient->setUpdatedId($user_id);
  237.             $paymentsClient->setUpdatedAt(new \DateTime('now'));
  238.             /* Gestión de eventos en Log */
  239.             $user_lastname $user_logueado->getLastname();
  240.             $user_name $user_logueado->getName();
  241.             $user_email $user_logueado->getEmail();
  242.             $user_rol $user_logueado->getRoles();
  243.             $event_url $request->getPathInfo();
  244.             $event_complete $user_name.' '.$user_lastname.' - '.$user_email.' - '.$user_rol[0].' | '.$event_url;
  245.             $em->persist($paymentsClient);
  246.             $em->flush();
  247.             $event 'the payment was registered';
  248.             $successMessage $this->translator->trans($event);
  249.             $this->addFlash('mensajepaymentsclient'$successMessage);
  250.             $tempoReserva->setStatus('Confirmed');
  251.             $em->persist($tempoReserva);
  252.             $em->flush();
  253.             return $this->redirectToRoute('reservations_payment',
  254.                 array(
  255.                     'id' => $paymentsClient->getReservationId()
  256.                 )
  257.             );
  258.         }else{
  259.             $errorMessage $this->translator->trans('Error, some fields are empty');
  260.             $this->addFlash('mensajepaymentsclienterror'$errorMessage);
  261.         }
  262.         return $this->redirectToRoute('reservations_payment',
  263.             array(
  264.                 'id' => $paymentsClient->getReservationId()
  265.             )
  266.         );
  267.     }
  268.     /**
  269.      * @Route("/reservations/proforma/invoice/pdf/print/action", name="reservation_proforma_invoice_pdf_print_action")
  270.      */
  271.     public function createProformaInvoicePdfPrintAction(Request $request)
  272.     {
  273. //        d('llegue', $request);
  274.         $array $request->request->get('mds_greenpatiobundle_reservationsinvoice');
  275. //        d(
  276. //            array_keys($array)[0]
  277. //
  278. //        );
  279. //        d($request->request->get('mds_greenpatiobundle_reservationsinvoice'));
  280. //
  281. //        exit();
  282.         $paymentsClient = new ReservationPaymentsClient();
  283.         $form $this->createReservationPaymentsClientForm($paymentsClient);
  284.         $form->handleRequest($request);
  285.         if($form->isValid())
  286.         {
  287.             $em $this->getDoctrine()->getManager();
  288.             /* Obtengo usuario logueado */
  289.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  290.             $user_id $user_logueado->getId();
  291.             $paymentsClient->setCreatedAt(new \DateTime('now'));
  292.             $paymentsClient->setCreatedId($user_id);
  293.             $paymentsClient->setUpdatedId($user_id);
  294.             $paymentsClient->setUpdatedAt(new \DateTime('now'));
  295.             /* Gestión de eventos en Log */
  296.             $user_lastname $user_logueado->getLastname();
  297.             $user_name $user_logueado->getName();
  298.             $user_email $user_logueado->getEmail();
  299.             $user_rol $user_logueado->getRoles();
  300.             $event_url $request->getPathInfo();
  301.             $event_complete $user_name.' '.$user_lastname.' - '.$user_email.' - '.$user_rol[0].' | '.$event_url;
  302.             $em->persist($paymentsClient);
  303.             $em->flush();
  304.             $event 'the payment was registered';
  305.             $successMessage $this->translator->trans($event);
  306.             $this->addFlash('mensajepaymentsclient'$successMessage);
  307.             return $this->redirectToRoute('reservations_payment',
  308.                 array(
  309.                     'id' => $paymentsClient->getReservationId()
  310.                 )
  311.             );
  312.         }else{
  313.             $errorMessage $this->translator->trans('Error, some fields are empty');
  314.             $this->addFlash('mensajepaymentsclienterror'$errorMessage);
  315.         }
  316.         return $this->redirectToRoute('reservations_payment',
  317.             array(
  318.                 'id' => $paymentsClient->getReservationId()
  319.             )
  320.         );
  321.     }
  322.     /**
  323.      * @Route("/reservations/generate/proforma/{id}",  name="reservations_generate_proforma")
  324.      */
  325.     public function generateProformaAction($idRequest $request)
  326.     {
  327.         $em $this->getDoctrine()->getManager();
  328.         $proforma $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
  329.         $prefix "GP-".date('dmy')."-";
  330.         if (is_null($proforma)){
  331.             $proforma_new = new ReservationProforma();
  332.             $proforma_new->setReservationId($id);
  333.             $proforma_new->setPrefix($prefix);
  334.             $proforma_new->setDateAt(new \DateTime("now"));
  335.             // En items, se ponen todas las salas y pagos de esa reserva
  336.             $lounges $em->getRepository(ReservationLoungeSimple::class)->findByIdReservation($id);
  337.             $payments $em->getRepository(ReservationPaymentsClient::class)->findByReservationId($id);
  338.             $services $em->getRepository(ReservationService::class)->findByReservationId($id);
  339.             $items '';
  340.             if (!empty($lounges)) {
  341.                 foreach ($lounges as $item) {
  342.                     if ($items == ''){
  343.                         $items 'L' $item->getId();  // L## para lounges
  344.                     } else {
  345.                         $items $items ',' 'L' $item->getId();  // L## para lounges
  346.                     }
  347.                 }
  348.             }
  349.             if (!empty($payments)) {
  350.                 foreach ($payments as $item) {
  351.                     if ($items == ''){
  352.                         $items 'P' $item->getId();  // P## para payments
  353.                     } else {
  354.                         $items $items ',' 'P' $item->getId();  // P## para payments
  355.                     }
  356.                 }
  357.             }
  358.             if (!empty($services)) {
  359.                 foreach ($services as $item) {
  360.                     if ($items == ''){
  361.                         $items 'S' $item->getId();  // S## para services
  362.                     } else {
  363.                         $items $items ',' 'S' $item->getId();  // S## para services
  364.                     }
  365.                 }
  366.             }
  367.             $proforma_new->setItems($items);
  368.             /* Obtengo usuario logueado */
  369.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  370.             $user_id $user_logueado->getId();
  371.             $proforma_new->setCreatedId($user_id);
  372.             $proforma_new->setUpdatedId($user_id);
  373.             $proforma_new->setCreatedAt(new \DateTime("now"));
  374.             $proforma_new->setUpdatedAt(new \DateTime("now"));
  375.             //Access Key para entrar en la proforma
  376.             $accessKey md5('CR-JDEF'rand() * time());
  377.             $proforma_new->setAccessKey($accessKey);
  378.             $em->persist($proforma_new);
  379.             $em->flush();
  380.         }
  381.         return $this->redirectToRoute('reservations_payment',
  382.             array(
  383.                 'id' => $id
  384.             )
  385.         );
  386.     }
  387.     private function baseInvoiceReservation($id$type$number$prefix$date)
  388.     {
  389.         $em $this->getDoctrine()->getManager();
  390.         $reservation $em->getRepository(Reservation::class)->findOneById($id);
  391.         $items $em->getRepository(ReservationInvoiceProformaItems::class)->findByReservationId($reservation->getId());
  392.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  393.         $client $em->getRepository(Client::class)->findById($reservation->getClient());
  394.         if (!empty($client)){
  395.             $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  396.             $client[0]->setPopulation($city);
  397.             $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  398.             $client[0]->setRegion($region);
  399.             $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  400.             $client[0]->setCountry($country);
  401.             $client['city'] = $city;
  402.             $client['region'] = $region;
  403.             $client['country'] = $country;
  404.         } else {
  405.             $client[0] = new Client();
  406.             $client[0]->setName('');
  407.             $client[0]->setTitle('');
  408.             $client[0]->setIdDocument('');
  409.             $client[0]->setPopulation('');
  410.             $client[0]->setRegion('');
  411.             $client[0]->setCountry('');
  412.         }
  413.         // Acumuladores de los calculos
  414.         $totales_neto_all 0;
  415.         $data_iva = array(
  416.             'iva' => 21,
  417.             'ivaMontoVeintiUno' => 0,
  418.             'ivaMontoDiez' => 0,
  419.             'ivaMontoCero' => 0,
  420.         );
  421.         // Buscamos las salas reservadas, pagos y servicios para el evento
  422.         $reservationLounges $em->getRepository(ReservationLoungeSimple::class)->findByIdReservation($id);
  423.         $payments $em->getRepository(ReservationPaymentsClient::class)->findByReservationId($id);
  424.         $services $em->getRepository(ReservationService::class)->findBy(['reservationId' => $id'toinvoice' => 1]);
  425.         $data_supplier = array();
  426.         $i 0;
  427.         $iva '21';            // Esteban Rincon: "Por Ley de localización del impuesto, siempre será un 21%"
  428.         $pax '-';
  429.         $qty '1';
  430.         $lounge = array(
  431.             'neto' => 0,
  432.             'sumSubT' => 0,
  433.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  434.         $service = array(
  435.             'neto' => 0,
  436.             'sumSubT' => 0,
  437.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  438.         foreach ($reservationLounges as $item){
  439.             // Verificamos que el salon no se encuentre ya en una factura
  440.             $existe $em->getRepository(ReservationInvoiceItems::class)->findByLngControlId($item->getId());
  441.             $existeCvr $em->getRepository(CvrReservationInvoiceItems::class)->findByLngControlId($item->getId());
  442.             $existe = (!empty($existe) or !empty($existeCvr));
  443.             if (is_null($item->getServicePrice()) or empty($item->getServicePrice()) or !empty($existe)){
  444.                 $subtotal 0;
  445.                 $neto 0;
  446.                 $subneto 0;
  447.                 $subnetoMounting 0;
  448.                 $subtotalLounge 0;
  449.                 $subnetoRemoval 0;
  450.             } else {
  451. //                if (!empty($item->getMountingPrice()) and ($item->getMountingPrice() != 0 )){
  452. //                    $subtotalMounting = $item->getMountingPrice() * 1.21;
  453. //                    $subnetoMounting = $item->getMountingPrice();
  454. //                } else {
  455. //                    $subtotalMounting = 0;
  456. //                    $subnetoMounting = 0;
  457. //                }
  458.                 $subtotalLounge $item->getServicePrice() * 1.21;
  459.                 $subneto $item->getServicePrice();
  460. //                if (!empty($item->getRemovalPrice()) and ($item->getRemovalPrice() != 0 )){
  461. //                    $subtotalRemoval = $item->getRemovalPrice() * 1.21;
  462. //                    $subnetoRemoval = $item->getRemovalPrice();
  463. //                } else {
  464. //                    $subtotalRemoval = 0;
  465. //                    $subnetoRemoval = 0;
  466. //                }
  467.                 $subtotal =  $subtotalLounge;
  468.                 $neto =  $subneto;
  469.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  470.                 $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  471.                 $neto round($neto,2,PHP_ROUND_HALF_UP);
  472.             }
  473.             // Acumula netos totales e IVA
  474.             $totales_neto_all $totales_neto_all $neto;
  475.             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  476.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  477.             $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  478.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  479.             // Acumula netos totales e IVA
  480.             $lounge['neto'] = $lounge['neto'] + $neto;
  481.             $lounge['sumSubT'] = $lounge['sumSubT'] + $subtotal;
  482.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  483.             $lounge['neto'] = round($lounge['neto'],2,PHP_ROUND_HALF_UP);
  484.             $lounge['sumSubT'] = round($lounge['sumSubT'],2,PHP_ROUND_HALF_UP);
  485.             $data_supplier['lounge'][$i] = array (
  486.                 'id' => $item->getId(),
  487.                 'loungeName' => $item->getLoungeName(),
  488.                 'idLounge' => $item->getIdLounge(),
  489.                 'dateStart' => $item->getDateStart(),
  490.                 'dateEnd' => $item->getDateEnd(),
  491.                 'servicePrice' => $item->getServicePrice(),
  492.                 'subtotalLounge' => $subtotalLounge,
  493.                 'iva' => $iva,
  494.                 'pax' => $pax,
  495.                 'qty' => $qty,
  496.                 'type' => $item->getType(),
  497.                 'subtotal' => $subtotal,
  498.             );
  499.             $i++;
  500.         }
  501.         $data_supplier['loungeSubTotal'] = array(
  502.             'neto' => $lounge['neto'],
  503.             'sumSubT' => $lounge['sumSubT'],
  504.         );
  505.         $payment = array(
  506.             'neto' => 0,
  507.             'sumSubT' => 0,
  508.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  509.         $i 0;
  510.         foreach ($payments as $item){
  511.             // Verificamos que el pago no se encuentre ya en una factura
  512.             $existe $em->getRepository(ReservationInvoiceItems::class)->findByPayControlId($item->getId());
  513.             $existeCvr $em->getRepository(CvrReservationInvoiceItems::class)->findByPayControlId($item->getId());
  514.             $existe = (!empty($existe) or !empty($existeCvr));
  515.             // Por indicaciones de Esteban Rincon, no deseamos estos conceptos en las facturas
  516.             if (!($item->getWayToPay() == 'TRANSFERENCIA') and !($item->getWayToPay() == 'VISA') and !($item->getWayToPay() == 'AMEX') and !($item->getWayToPay() == 'CHEQUE') and !($item->getWayToPay() == 'EFECTIVO')) {
  517.                 if (!empty($existe)) {
  518.                     $payment['sumSubT'] = $payment['sumSubT'] + 0;
  519.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  520.                     $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  521.                 } else {
  522.                     $subtotalLounge $item->getAmountTotal() * (-1);
  523.                     $subneto $item->getAmount() * (-1);
  524.                     $subtotal $subtotalLounge;
  525.                     $neto $subneto;
  526.                     $payment['sumSubT'] = $payment['sumSubT'] - $item->getAmountTotal();
  527.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  528.                     $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  529.                     // Acumula netos totales e IVA
  530.                     $totales_neto_all $totales_neto_all $neto;
  531.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  532.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  533.                     $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  534.                     $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  535.                     // Acumula netos totales e IVA
  536. //                $lounge['neto'] = $lounge['neto'] + $neto;
  537. //                $lounge['sumSubT'] = $lounge['sumSubT'] + $subtotal;
  538. //                // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  539. //                $lounge['neto'] = round($lounge['neto'],2,PHP_ROUND_HALF_UP);
  540. //                $lounge['sumSubT'] = round($lounge['sumSubT'],2,PHP_ROUND_HALF_UP);
  541.                 }
  542.                 $data_supplier['payment'][$i] = array(
  543.                     'id' => $item->getId(),
  544.                     'amount' => $item->getAmount() * (-1),
  545.                     'datePayAt' => $item->getDatePayAt(),
  546.                     'wayToPay' => $item->getWayToPay(),
  547.                     'amountTotal' => $item->getAmountTotal() * (-1),
  548.                     'vat' => $item->getVat(),
  549.                 );
  550.                 $i++;
  551.             }
  552.         }
  553.         if (!empty($payments)) {
  554.             $data_supplier['paymentSubTotal'] = array(
  555.                 'neto' => $payment['neto'],
  556.                 'sumSubT' => $payment['sumSubT'],
  557.             );
  558.         }
  559.         foreach ($services as $item){
  560.             // Verificamos que el servicio no se encuentre ya en una factura
  561.             $existe $em->getRepository(ReservationInvoiceItems::class)->findBySrvControlId($item->getId());
  562.             $existeCvr $em->getRepository(CvrReservationInvoiceItems::class)->findBySrvControlId($item->getId());
  563.             $existe = (!empty($existe) or !empty($existeCvr));
  564.             if (is_null($item->getPrice()) or empty($item->getPrice()) or !empty($existe)){
  565.                 $subtotal 0;
  566.                 $neto 0;
  567.                 $subtotalService 0;
  568.                 $subneto 0;
  569.                 switch ($item->getServiceCatId()){
  570.                     case 1// Alojamiento
  571.                         // el numero de noches $numNoches; precio unitario $subneto
  572.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  573.                         // La personas no afectan este calculo
  574.                         $subtotal $subtotalService $numNoches $item->getUnits();
  575.                         $subnetoUnit $subneto;
  576.                         $subneto $subneto $numNoches $item->getUnits();
  577.                         $data_supplier['service'][$i] = array (
  578.                             'id' => $item->getId(),
  579.                             'serviceCatId' => $item->getServiceCatId(),
  580.                             'serviceName' => $item->getName(),
  581.                             'serviceType' => 'Hotel',
  582.                             'date' => ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y'),
  583.                             'qty' => $item->getUnits(),
  584.                             'iva' => $item->getIva(),
  585.                             'pax' => '-',
  586.                             'precioUnit' => $subnetoUnit,
  587.                             'subneto' => $subneto,
  588.                             'subtotal' => $subtotal,
  589.                         );
  590.                         break;
  591.                     case 2//Actividades
  592.                         // El número de personas es considerado en el calculo
  593.                         $pax $item->getPax();
  594.                         if (empty($pax) or $pax == "0") {
  595.                             $pax 1;
  596.                         }
  597.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  598.                         if ($days 1){
  599.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  600.                         } else {
  601.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  602.                         }
  603.                         $subtotal $subtotalService $days $item->getUnits();
  604.                         $subnetoUnit $subneto;
  605.                         $subneto $subneto $days $item->getUnits();
  606.                         $data_supplier['service'][$i] = array (
  607.                             'id' => $item->getId(),
  608.                             'serviceCatId' => $item->getServiceCatId(),
  609.                             'serviceName' => $item->getName(),
  610.                             'serviceType' => 'Actividad',
  611.                             'date' => $dateServ,
  612.                             'qty' => $item->getUnits(),
  613.                             'iva' => $item->getIva(),
  614.                             'pax' => $item->getPax(),
  615.                             'precioUnit' => $subnetoUnit,
  616.                             'subneto' => $subneto,
  617.                             'subtotal' => $subtotal,
  618.                         );
  619.                         break;
  620.                     case 3// AV
  621.                         $pax $item->getPax();
  622.                         if (empty($pax) or $pax == "0") {
  623.                             $pax 1;
  624.                         }
  625.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  626.                         if ($days 1){
  627.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  628.                         } else {
  629.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  630.                         }
  631.                         $unitsServ $item->getUnits();
  632.                         if (empty($unitsServ) or $unitsServ == "0") {
  633.                             $unitsServ 1;
  634.                         }
  635.                         $subtotal $subtotalService $days $unitsServ $pax;
  636.                         $subnetoUnit $subneto;
  637.                         $subneto $subneto $days $unitsServ $pax;
  638.                         $data_supplier['service'][$i] = array (
  639.                             'id' => $item->getId(),
  640.                             'serviceCatId' => $item->getServiceCatId(),
  641.                             'serviceName' => $item->getName(),
  642.                             'serviceType' => 'AV',
  643.                             'date' => $dateServ,
  644.                             'qty' => $unitsServ,
  645.                             'iva' => $item->getIva(),
  646.                             'pax' => $item->getPax(),
  647.                             'precioUnit' => $subnetoUnit,
  648.                             'subneto' => $subneto,
  649.                             'subtotal' => $subtotal,
  650.                         );
  651.                         break;
  652.                     case 4//Creative
  653.                         $pax $item->getPax();
  654.                         if (empty($pax) or $pax == "0") {
  655.                             $pax 1;
  656.                         }
  657.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  658.                         if ($days 1){
  659.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  660.                         } else {
  661.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  662.                         }
  663.                         $unitsServ $item->getUnits();
  664.                         if (empty($unitsServ) or $unitsServ == "0") {
  665.                             $unitsServ 1;
  666.                         }
  667.                         $subtotal $subtotalService $days $unitsServ $pax;
  668.                         $subnetoUnit $subneto;
  669.                         $subneto $subneto $days $unitsServ $pax;
  670.                         $data_supplier['service'][$i] = array (
  671.                             'id' => $item->getId(),
  672.                             'serviceCatId' => $item->getServiceCatId(),
  673.                             'serviceName' => $item->getName(),
  674.                             'serviceType' => 'Creativo',
  675.                             'date' => $dateServ,
  676.                             'qty' => $unitsServ,
  677.                             'iva' => $item->getIva(),
  678.                             'pax' => $item->getPax(),
  679.                             'precioUnit' => $subnetoUnit,
  680.                             'subneto' => $subneto,
  681.                             'subtotal' => $subtotal,
  682.                         );
  683.                         break;
  684.                     case 5//Cruise
  685.                         $pax $item->getPax();
  686.                         if (empty($pax) or $pax == "0") {
  687.                             $pax 1;
  688.                         }
  689.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  690.                         if ($days 1){
  691.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  692.                         } else {
  693.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  694.                         }
  695.                         $unitsServ $item->getUnits();
  696.                         if (empty($unitsServ) or $unitsServ == "0") {
  697.                             $unitsServ 1;
  698.                         }
  699.                         $subtotal $subtotalService $days $unitsServ $pax;
  700.                         $subnetoUnit $subneto;
  701.                         $subneto $subneto $days $unitsServ $pax;
  702.                         $data_supplier['service'][$i] = array (
  703.                             'id' => $item->getId(),
  704.                             'serviceCatId' => $item->getServiceCatId(),
  705.                             'serviceName' => $item->getName(),
  706.                             'serviceType' => 'Crucero',
  707.                             'date' => $dateServ,
  708.                             'qty' => $unitsServ,
  709.                             'iva' => $item->getIva(),
  710.                             'pax' => $item->getPax(),
  711.                             'precioUnit' => $subnetoUnit,
  712.                             'subneto' => $subneto,
  713.                             'subtotal' => $subtotal,
  714.                         );
  715.                         break;
  716.                     case 6//Entertaiment
  717.                         $pax $item->getPax();
  718.                         if (empty($pax) or $pax == "0") {
  719.                             $pax 1;
  720.                         }
  721.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  722.                         if ($days 1){
  723.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  724.                         } else {
  725.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  726.                         }
  727.                         $unitsServ $item->getUnits();
  728.                         if (empty($unitsServ) or $unitsServ == "0") {
  729.                             $unitsServ 1;
  730.                         }
  731.                         $subtotal $subtotalService $days $unitsServ $pax;
  732.                         $subnetoUnit $subneto;
  733.                         $subneto $subneto $days $unitsServ $pax;
  734.                         $data_supplier['service'][$i] = array (
  735.                             'id' => $item->getId(),
  736.                             'serviceCatId' => $item->getServiceCatId(),
  737.                             'serviceName' => $item->getName(),
  738.                             'serviceType' => 'Entretenimiento',
  739.                             'date' => $dateServ,
  740.                             'qty' => $unitsServ,
  741.                             'iva' => $item->getIva(),
  742.                             'pax' => $item->getPax(),
  743.                             'precioUnit' => $subnetoUnit,
  744.                             'subneto' => $subneto,
  745.                             'subtotal' => $subtotal,
  746.                         );
  747.                         break;
  748.                     case 7// Gifts
  749.                         $pax $item->getPax();
  750.                         if (empty($pax) or $pax == "0") {
  751.                             $pax 1;
  752.                         }
  753. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  754.                         $days 1;
  755.                         if ($days 1){
  756.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  757.                         } else {
  758.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  759.                         }
  760.                         $unitsServ $item->getUnits();
  761.                         if (empty($unitsServ) or $unitsServ == "0") {
  762.                             $unitsServ 1;
  763.                         }
  764.                         $subtotal $subtotalService $days $unitsServ $pax;
  765.                         $subnetoUnit $subneto;
  766.                         $subneto $subneto $days $unitsServ $pax;
  767.                         $data_supplier['service'][$i] = array (
  768.                             'id' => $item->getId(),
  769.                             'serviceCatId' => $item->getServiceCatId(),
  770.                             'serviceName' => $item->getName(),
  771.                             'serviceType' => 'Regalos',
  772.                             'date' => $dateServ,
  773.                             'qty' => $unitsServ,
  774.                             'iva' => $item->getIva(),
  775.                             'pax' => $item->getPax(),
  776.                             'precioUnit' => $subnetoUnit,
  777.                             'subneto' => $subneto,
  778.                             'subtotal' => $subtotal,
  779.                         );
  780.                         break;
  781.                     case 8//Guide
  782.                         $pax $item->getPax();
  783.                         if (empty($pax) or $pax == "0") {
  784.                             $pax 1;
  785.                         }
  786.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  787.                         if ($days 1){
  788.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  789.                         } else {
  790.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  791.                         }
  792.                         $unitsServ $item->getUnits();
  793.                         if (empty($unitsServ) or $unitsServ == "0") {
  794.                             $unitsServ 1;
  795.                         }
  796.                         $subtotal $subtotalService $days $unitsServ $pax;
  797.                         $subnetoUnit $subneto;
  798.                         $subneto $subneto $days $unitsServ $pax;
  799.                         $data_supplier['service'][$i] = array (
  800.                             'id' => $item->getId(),
  801.                             'serviceCatId' => $item->getServiceCatId(),
  802.                             'serviceName' => $item->getName(),
  803.                             'serviceType' => 'Regalos',
  804.                             'date' => $dateServ,
  805.                             'qty' => $unitsServ,
  806.                             'iva' => $item->getIva(),
  807.                             'pax' => $item->getPax(),
  808.                             'precioUnit' => $subnetoUnit,
  809.                             'subneto' => $subneto,
  810.                             'subtotal' => $subtotal,
  811.                         );
  812.                         break;
  813.                     case 9//Itineraries
  814.                         $pax $item->getPax();
  815.                         if (empty($pax) or $pax == "0") {
  816.                             $pax 1;
  817.                         }
  818.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  819.                         if ($days 1){
  820.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  821.                         } else {
  822.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  823.                         }
  824.                         $unitsServ $item->getUnits();
  825.                         if (empty($unitsServ) or $unitsServ == "0") {
  826.                             $unitsServ 1;
  827.                         }
  828.                         $subtotal $subtotalService $days $unitsServ $pax;
  829.                         $subnetoUnit $subneto;
  830.                         $subneto $subneto $days $unitsServ $pax;
  831.                         $data_supplier['service'][$i] = array (
  832.                             'id' => $item->getId(),
  833.                             'serviceCatId' => $item->getServiceCatId(),
  834.                             'serviceName' => $item->getName(),
  835.                             'serviceType' => 'Itinerarios',
  836.                             'date' => $dateServ,
  837.                             'qty' => $unitsServ,
  838.                             'iva' => $item->getIva(),
  839.                             'pax' => $item->getPax(),
  840.                             'precioUnit' => $subnetoUnit,
  841.                             'subneto' => $subneto,
  842.                             'subtotal' => $subtotal,
  843.                         );
  844.                         break;
  845.                     case 10//Lounge  -- No Aplica
  846. //                        $pax = $item->getPax();
  847. //                        if (empty($pax) or $pax == "0") {
  848. //                            $pax = 1;
  849. //                        }
  850. //
  851. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  852. //                        if ($days > 1){
  853. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  854. //                        } else {
  855. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  856. //                        }
  857. //
  858. //                        $unitsServ = $item->getUnits();
  859. //                        if (empty($unitsServ) or $unitsServ == "0") {
  860. //                            $unitsServ = 1;
  861. //                        }
  862. //
  863. //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  864. //                        $subnetoUnit = $subneto;
  865. //                        $subneto = $subneto * $days * $unitsServ * $pax;
  866. //
  867. //                        $data_supplier['service'][$i] = array (
  868. //                            'id' => $item->getId(),
  869. //                            'serviceCatId' => $item->getServiceCatId(),
  870. //                            'serviceName' => $item->getName(),
  871. //                            'serviceType' => 'Itinerarios',
  872. //                            'date' => $dateServ,
  873. //                            'qty' => $unitsServ,
  874. //                            'iva' => $item->getIva(),
  875. //                            'pax' => $item->getPax(),
  876. //                            'precioUnit' => $subnetoUnit,
  877. //                            'subneto' => $subneto,
  878. //                            'subtotal' => $subtotal,
  879. //                        );
  880.                         break;
  881.                     case 11//Catering
  882.                         $pax $item->getPax();
  883.                         if (empty($pax) or $pax == "0") {
  884.                             $pax 1;
  885.                         }
  886.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  887.                         if ($days 1){
  888.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  889.                         } else {
  890.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  891.                         }
  892.                         $unitsServ $item->getUnits();
  893.                         if (empty($unitsServ) or $unitsServ == "0") {
  894.                             $unitsServ 1;
  895.                         }
  896.                         $subtotal $subtotalService $days $unitsServ $pax;
  897.                         $subnetoUnit $subneto;
  898.                         $subneto $subneto $days $unitsServ $pax;
  899.                         $data_supplier['service'][$i] = array (
  900.                             'id' => $item->getId(),
  901.                             'serviceCatId' => $item->getServiceCatId(),
  902.                             'serviceName' => $item->getName(),
  903.                             'serviceType' => 'Catering',
  904.                             'date' => $dateServ,
  905.                             'qty' => $unitsServ,
  906.                             'iva' => $item->getIva(),
  907.                             'pax' => $item->getPax(),
  908.                             'precioUnit' => $subnetoUnit,
  909.                             'subneto' => $subneto,
  910.                             'subtotal' => $subtotal,
  911.                         );
  912.                         break;
  913.                     case 12//Others
  914.                         $pax $item->getPax();
  915.                         if (empty($pax) or $pax == "0") {
  916.                             $pax 1;
  917.                         }
  918.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  919.                         if ($days 1){
  920.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  921.                         } else {
  922.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  923.                         }
  924.                         $unitsServ $item->getUnits();
  925.                         if (empty($unitsServ) or $unitsServ == "0") {
  926.                             $unitsServ 1;
  927.                         }
  928.                         $subtotal $subtotalService $days $unitsServ $pax;
  929.                         $subnetoUnit $subneto;
  930.                         $subneto $subneto $days $unitsServ $pax;
  931.                         $data_supplier['service'][$i] = array (
  932.                             'id' => $item->getId(),
  933.                             'serviceCatId' => $item->getServiceCatId(),
  934.                             'serviceName' => $item->getName(),
  935.                             'serviceType' => 'Otros',
  936.                             'date' => $dateServ,
  937.                             'qty' => $unitsServ,
  938.                             'iva' => $item->getIva(),
  939.                             'pax' => $item->getPax(),
  940.                             'precioUnit' => $subnetoUnit,
  941.                             'subneto' => $subneto,
  942.                             'subtotal' => $subtotal,
  943.                         );
  944.                         break;
  945.                     case 13//Transport
  946.                         $pax $item->getPax();
  947.                         if (empty($pax) or $pax == "0") {
  948.                             $pax 1;
  949.                         }
  950.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  951.                         if ($days 1){
  952.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  953.                         } else {
  954.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  955.                         }
  956.                         $unitsServ $item->getUnits();
  957.                         if (empty($unitsServ) or $unitsServ == "0") {
  958.                             $unitsServ 1;
  959.                         }
  960.                         $subtotal $subtotalService $days $unitsServ $pax;
  961.                         $subnetoUnit $subneto;
  962.                         $subneto $subneto $days $unitsServ $pax;
  963.                         $data_supplier['service'][$i] = array (
  964.                             'id' => $item->getId(),
  965.                             'serviceCatId' => $item->getServiceCatId(),
  966.                             'serviceName' => $item->getName(),
  967.                             'serviceType' => 'Transporte',
  968.                             'date' => $dateServ,
  969.                             'qty' => $unitsServ,
  970.                             'iva' => $item->getIva(),
  971.                             'pax' => $item->getPax(),
  972.                             'precioUnit' => $subnetoUnit,
  973.                             'subneto' => $subneto,
  974.                             'subtotal' => $subtotal,
  975.                         );
  976.                         break;
  977.                     case 14//Technology
  978.                         $pax $item->getPax();
  979.                         if (empty($pax) or $pax == "0") {
  980.                             $pax 1;
  981.                         }
  982. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  983.                         $days 1;
  984. //                        if ($days > 1){
  985. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  986. //                        } else {
  987. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  988. //                        }
  989.                         $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  990.                         $unitsServ $item->getUnits();
  991.                         if (empty($unitsServ) or $unitsServ == "0") {
  992.                             $unitsServ 1;
  993.                         }
  994.                         $subtotal $subtotalService $days $unitsServ $pax;
  995.                         $subnetoUnit $subneto;
  996.                         $subneto $subneto $days $unitsServ $pax;
  997.                         $data_supplier['service'][$i] = array (
  998.                             'id' => $item->getId(),
  999.                             'serviceCatId' => $item->getServiceCatId(),
  1000.                             'serviceName' => $item->getName(),
  1001.                             'serviceType' => 'Tecnología',
  1002.                             'date' => $dateServ,
  1003.                             'qty' => $unitsServ,
  1004.                             'iva' => $item->getIva(),
  1005.                             'pax' => $item->getPax(),
  1006.                             'precioUnit' => $subnetoUnit,
  1007.                             'subneto' => $subneto,
  1008.                             'subtotal' => $subtotal,
  1009.                         );
  1010.                         break;
  1011.                     case 15//Assisstant
  1012.                         $pax $item->getPax();
  1013.                         if (empty($pax) or $pax == "0") {
  1014.                             $pax 1;
  1015.                         }
  1016.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1017.                         if ($days 1){
  1018.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1019.                         } else {
  1020.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1021.                         }
  1022.                         $unitsServ $item->getUnits();
  1023.                         if (empty($unitsServ) or $unitsServ == "0") {
  1024.                             $unitsServ 1;
  1025.                         }
  1026.                         $subtotal $subtotalService $days $unitsServ $pax;
  1027.                         $subnetoUnit $subneto;
  1028.                         $subneto $subneto $days $unitsServ $pax;
  1029.                         $data_supplier['service'][$i] = array (
  1030.                             'id' => $item->getId(),
  1031.                             'serviceCatId' => $item->getServiceCatId(),
  1032.                             'serviceName' => $item->getName(),
  1033.                             'serviceType' => 'Asistente',
  1034.                             'date' => $dateServ,
  1035.                             'qty' => $unitsServ,
  1036.                             'iva' => $item->getIva(),
  1037.                             'pax' => $item->getPax(),
  1038.                             'precioUnit' => $subnetoUnit,
  1039.                             'subneto' => $subneto,
  1040.                             'subtotal' => $subtotal,
  1041.                         );
  1042.                         break;
  1043.                     case 16//DDR
  1044.                         $pax $item->getPax();
  1045.                         if (empty($pax) or $pax == "0") {
  1046.                             $pax 1;
  1047.                         }
  1048.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1049.                         if ($days 1){
  1050.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1051.                         } else {
  1052.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1053.                         }
  1054.                         $unitsServ $item->getUnits();
  1055.                         if (empty($unitsServ) or $unitsServ == "0") {
  1056.                             $unitsServ 1;
  1057.                         }
  1058.                         $subtotal $subtotalService $days $unitsServ $pax;
  1059.                         $subnetoUnit $subneto;
  1060.                         $subneto $subneto $days $unitsServ $pax;
  1061.                         $data_supplier['service'][$i] = array (
  1062.                             'id' => $item->getId(),
  1063.                             'serviceCatId' => $item->getServiceCatId(),
  1064.                             'serviceName' => $item->getName(),
  1065.                             'serviceType' => 'DDR',
  1066.                             'date' => $dateServ,
  1067.                             'qty' => $unitsServ,
  1068.                             'iva' => $item->getIva(),
  1069.                             'pax' => $item->getPax(),
  1070.                             'precioUnit' => $subnetoUnit,
  1071.                             'subneto' => $subneto,
  1072.                             'subtotal' => $subtotal,
  1073.                         );
  1074.                         break;
  1075.                     case 17// Seguridad
  1076.                         $pax $item->getPax();
  1077.                         if (empty($pax) or $pax == "0") { $pax 1; }
  1078.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1079.                         if ($days 1){
  1080.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1081.                         } else {
  1082.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1083.                         }
  1084.                         $unitsServ $item->getUnits();
  1085.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  1086.                         $subtotal $subtotalService $days $unitsServ $pax;
  1087.                         $subnetoUnit $subneto;
  1088.                         $subneto $subneto $days $unitsServ $pax;
  1089.                         $data_supplier['service'][$i] = array (
  1090.                             'id' => $item->getId(),
  1091.                             'serviceCatId' => $item->getServiceCatId(),
  1092.                             'serviceName' => $item->getName(),
  1093.                             'serviceType' => 'Seguridad',
  1094.                             'date' => $dateServ,
  1095.                             'qty' => $unitsServ,
  1096.                             'iva' => $item->getIva(),
  1097.                             'pax' => $item->getPax(),
  1098.                             'precioUnit' => $subnetoUnit,
  1099.                             'subneto' => $subneto,
  1100.                             'subtotal' => $subtotal,
  1101.                         );
  1102.                         break;
  1103.                     default:
  1104.                         //Others
  1105.                         $pax $item->getPax();
  1106.                         if (empty($pax) or $pax == "0") {
  1107.                             $pax 1;
  1108.                         }
  1109.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1110.                         if ($days 1){
  1111.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1112.                         } else {
  1113.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1114.                         }
  1115.                         $unitsServ $item->getUnits();
  1116.                         if (empty($unitsServ) or $unitsServ == "0") {
  1117.                             $unitsServ 1;
  1118.                         }
  1119.                         $subtotal $subtotalService $days $unitsServ $pax;
  1120.                         $subnetoUnit $subneto;
  1121.                         $subneto $subneto $days $unitsServ $pax;
  1122.                         $data_supplier['service'][$i] = array (
  1123.                             'id' => $item->getId(),
  1124.                             'serviceCatId' => $item->getServiceCatId(),
  1125.                             'serviceName' => $item->getName(),
  1126.                             'serviceType' => 'Otros',
  1127.                             'date' => $dateServ,
  1128.                             'qty' => $unitsServ,
  1129.                             'iva' => $item->getIva(),
  1130.                             'pax' => $item->getPax(),
  1131.                             'precioUnit' => $subnetoUnit,
  1132.                             'subneto' => $subneto,
  1133.                             'subtotal' => $subtotal,
  1134.                         );
  1135.                         break;
  1136.                 }
  1137.             } else {
  1138.                 $subtotalService $item->getPrice();
  1139.                 $subneto $item->getPrice();
  1140.                 // Commission
  1141.                 if ($item->getOpCommission()=='1'){
  1142.                     $subtotalService $subtotalService * (+ ($item->getCommission()/100));
  1143.                     $subneto $subneto  * (+ ($item->getCommission()/100));
  1144.                 } else {
  1145.                     $subtotalService $subtotalService * (- ($item->getCommission()/100));
  1146.                     $subneto $subneto * (- ($item->getCommission()/100));
  1147.                 }
  1148.                 // Over
  1149.                 if ($item->getOpOver()=='1'){
  1150.                     $subtotalService $subtotalService $item->getOver();
  1151.                     $subneto $subneto $item->getOver();
  1152.                 } else {
  1153.                     $subtotalService $subtotalService $item->getOver();
  1154.                     $subneto $subneto $item->getOver();
  1155.                 }
  1156.                 // IVA
  1157.                 if ($item->getOpIva()=='1'){
  1158.                     $subtotalService $subtotalService * (+ ($item->getIva()/100));
  1159.                 } else {
  1160.                     $subtotalService $item->getPrice();
  1161.                     $subneto = ($subneto 100) / (100 $item->getIva());
  1162.                 }
  1163.                 switch ($item->getServiceCatId()){
  1164.                     case 1// Alojamiento
  1165.                         // el numero de noches $numNoches; precio unitario $subneto
  1166.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  1167.                         // La personas no afectan este calculo
  1168.                         $subtotal $subtotalService $numNoches $item->getUnits();
  1169.                         $subnetoUnit $subneto;
  1170.                         $subneto $subneto $numNoches $item->getUnits();
  1171.                         $data_supplier['service'][$i] = array (
  1172.                             'id' => $item->getId(),
  1173.                             'serviceCatId' => $item->getServiceCatId(),
  1174.                             'serviceName' => $item->getName(),
  1175.                             'serviceType' => 'Hotel',
  1176.                             'date' => ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y'),
  1177.                             'qty' => $item->getUnits(),
  1178.                             'iva' => $item->getIva(),
  1179.                             'pax' => '-',
  1180.                             'precioUnit' => $subnetoUnit,
  1181.                             'subneto' => $subneto,
  1182.                             'subtotal' => $subtotal,
  1183.                         );
  1184.                         break;
  1185.                     case 2//Actividades
  1186.                         // El número de personas es considerado en el calculo
  1187.                         $pax $item->getPax();
  1188.                         if (empty($pax) or $pax == "0") {
  1189.                             $pax 1;
  1190.                         }
  1191.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1192.                         if ($days 1){
  1193.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1194.                         } else {
  1195.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1196.                         }
  1197.                         $subtotal $subtotalService $days $item->getUnits();
  1198.                         $subnetoUnit $subneto;
  1199.                         $subneto $subneto $days $item->getUnits();
  1200.                         $data_supplier['service'][$i] = array (
  1201.                             'id' => $item->getId(),
  1202.                             'serviceCatId' => $item->getServiceCatId(),
  1203.                             'serviceName' => $item->getName(),
  1204.                             'serviceType' => 'Actividad',
  1205.                             'date' => $dateServ,
  1206.                             'qty' => $item->getUnits(),
  1207.                             'iva' => $item->getIva(),
  1208.                             'pax' => $item->getPax(),
  1209.                             'precioUnit' => $subnetoUnit,
  1210.                             'subneto' => $subneto,
  1211.                             'subtotal' => $subtotal,
  1212.                         );
  1213.                         break;
  1214.                     case 3// AV
  1215.                         $pax $item->getPax();
  1216.                         if (empty($pax) or $pax == "0") {
  1217.                             $pax 1;
  1218.                         }
  1219.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1220.                         if ($days 1){
  1221.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1222.                         } else {
  1223.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1224.                         }
  1225.                         $unitsServ $item->getUnits();
  1226.                         if (empty($unitsServ) or $unitsServ == "0") {
  1227.                             $unitsServ 1;
  1228.                         }
  1229.                         $subtotal $subtotalService $days $unitsServ $pax;
  1230.                         $subnetoUnit $subneto;
  1231.                         $subneto $subneto $days $unitsServ $pax;
  1232.                         $data_supplier['service'][$i] = array (
  1233.                             'id' => $item->getId(),
  1234.                             'serviceCatId' => $item->getServiceCatId(),
  1235.                             'serviceName' => $item->getName(),
  1236.                             'serviceType' => 'AV',
  1237.                             'date' => $dateServ,
  1238.                             'qty' => $unitsServ,
  1239.                             'iva' => $item->getIva(),
  1240.                             'pax' => $item->getPax(),
  1241.                             'precioUnit' => $subnetoUnit,
  1242.                             'subneto' => $subneto,
  1243.                             'subtotal' => $subtotal,
  1244.                         );
  1245.                         break;
  1246.                     case 4//Creative
  1247.                         $pax $item->getPax();
  1248.                         if (empty($pax) or $pax == "0") {
  1249.                             $pax 1;
  1250.                         }
  1251.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1252.                         if ($days 1){
  1253.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1254.                         } else {
  1255.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1256.                         }
  1257.                         $unitsServ $item->getUnits();
  1258.                         if (empty($unitsServ) or $unitsServ == "0") {
  1259.                             $unitsServ 1;
  1260.                         }
  1261.                         $subtotal $subtotalService $days $unitsServ $pax;
  1262.                         $subnetoUnit $subneto;
  1263.                         $subneto $subneto $days $unitsServ $pax;
  1264.                         $data_supplier['service'][$i] = array (
  1265.                             'id' => $item->getId(),
  1266.                             'serviceCatId' => $item->getServiceCatId(),
  1267.                             'serviceName' => $item->getName(),
  1268.                             'serviceType' => 'Creativo',
  1269.                             'date' => $dateServ,
  1270.                             'qty' => $unitsServ,
  1271.                             'iva' => $item->getIva(),
  1272.                             'pax' => $item->getPax(),
  1273.                             'precioUnit' => $subnetoUnit,
  1274.                             'subneto' => $subneto,
  1275.                             'subtotal' => $subtotal,
  1276.                         );
  1277.                         break;
  1278.                     case 5//Cruise
  1279.                         $pax $item->getPax();
  1280.                         if (empty($pax) or $pax == "0") {
  1281.                             $pax 1;
  1282.                         }
  1283.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  1284.                         if ($days 1){
  1285.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1286.                         } else {
  1287.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1288.                         }
  1289.                         $unitsServ $item->getUnits();
  1290.                         if (empty($unitsServ) or $unitsServ == "0") {
  1291.                             $unitsServ 1;
  1292.                         }
  1293.                         $subtotal $subtotalService $days $unitsServ $pax;
  1294.                         $subnetoUnit $subneto;
  1295.                         $subneto $subneto $days $unitsServ $pax;
  1296.                         $data_supplier['service'][$i] = array (
  1297.                             'id' => $item->getId(),
  1298.                             'serviceCatId' => $item->getServiceCatId(),
  1299.                             'serviceName' => $item->getName(),
  1300.                             'serviceType' => 'Crucero',
  1301.                             'date' => $dateServ,
  1302.                             'qty' => $unitsServ,
  1303.                             'iva' => $item->getIva(),
  1304.                             'pax' => $item->getPax(),
  1305.                             'precioUnit' => $subnetoUnit,
  1306.                             'subneto' => $subneto,
  1307.                             'subtotal' => $subtotal,
  1308.                         );
  1309.                         break;
  1310.                     case 6//Entertaiment
  1311.                         $pax $item->getPax();
  1312.                         if (empty($pax) or $pax == "0") {
  1313.                             $pax 1;
  1314.                         }
  1315.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1316.                         if ($days 1){
  1317.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1318.                         } else {
  1319.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1320.                         }
  1321.                         $unitsServ $item->getUnits();
  1322.                         if (empty($unitsServ) or $unitsServ == "0") {
  1323.                             $unitsServ 1;
  1324.                         }
  1325.                         $subtotal $subtotalService $days $unitsServ $pax;
  1326.                         $subnetoUnit $subneto;
  1327.                         $subneto $subneto $days $unitsServ $pax;
  1328.                         $data_supplier['service'][$i] = array (
  1329.                             'id' => $item->getId(),
  1330.                             'serviceCatId' => $item->getServiceCatId(),
  1331.                             'serviceName' => $item->getName(),
  1332.                             'serviceType' => 'Entretenimiento',
  1333.                             'date' => $dateServ,
  1334.                             'qty' => $unitsServ,
  1335.                             'iva' => $item->getIva(),
  1336.                             'pax' => $item->getPax(),
  1337.                             'precioUnit' => $subnetoUnit,
  1338.                             'subneto' => $subneto,
  1339.                             'subtotal' => $subtotal,
  1340.                         );
  1341.                         break;
  1342.                     case 7// Gifts
  1343.                         $pax $item->getPax();
  1344.                         if (empty($pax) or $pax == "0") {
  1345.                             $pax 1;
  1346.                         }
  1347. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  1348.                         $days 1;
  1349.                         if ($days 1){
  1350.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1351.                         } else {
  1352.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1353.                         }
  1354.                         $unitsServ $item->getUnits();
  1355.                         if (empty($unitsServ) or $unitsServ == "0") {
  1356.                             $unitsServ 1;
  1357.                         }
  1358.                         $subtotal $subtotalService $days $unitsServ $pax;
  1359.                         $subnetoUnit $subneto;
  1360.                         $subneto $subneto $days $unitsServ $pax;
  1361.                         $data_supplier['service'][$i] = array (
  1362.                             'id' => $item->getId(),
  1363.                             'serviceCatId' => $item->getServiceCatId(),
  1364.                             'serviceName' => $item->getName(),
  1365.                             'serviceType' => 'Regalos',
  1366.                             'date' => $dateServ,
  1367.                             'qty' => $unitsServ,
  1368.                             'iva' => $item->getIva(),
  1369.                             'pax' => $item->getPax(),
  1370.                             'precioUnit' => $subnetoUnit,
  1371.                             'subneto' => $subneto,
  1372.                             'subtotal' => $subtotal,
  1373.                         );
  1374.                         break;
  1375.                     case 8//Guide
  1376.                         $pax $item->getPax();
  1377.                         if (empty($pax) or $pax == "0") {
  1378.                             $pax 1;
  1379.                         }
  1380.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1381.                         if ($days 1){
  1382.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1383.                         } else {
  1384.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1385.                         }
  1386.                         $unitsServ $item->getUnits();
  1387.                         if (empty($unitsServ) or $unitsServ == "0") {
  1388.                             $unitsServ 1;
  1389.                         }
  1390.                         $subtotal $subtotalService $days $unitsServ $pax;
  1391.                         $subnetoUnit $subneto;
  1392.                         $subneto $subneto $days $unitsServ $pax;
  1393.                         $data_supplier['service'][$i] = array (
  1394.                             'id' => $item->getId(),
  1395.                             'serviceCatId' => $item->getServiceCatId(),
  1396.                             'serviceName' => $item->getName(),
  1397.                             'serviceType' => 'Guía',
  1398.                             'date' => $dateServ,
  1399.                             'qty' => $unitsServ,
  1400.                             'iva' => $item->getIva(),
  1401.                             'pax' => $item->getPax(),
  1402.                             'precioUnit' => $subnetoUnit,
  1403.                             'subneto' => $subneto,
  1404.                             'subtotal' => $subtotal,
  1405.                         );
  1406.                         break;
  1407.                     case 9//Itineraries
  1408.                         $pax $item->getPax();
  1409.                         if (empty($pax) or $pax == "0") {
  1410.                             $pax 1;
  1411.                         }
  1412.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1413.                         if ($days 1){
  1414.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1415.                         } else {
  1416.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1417.                         }
  1418.                         $unitsServ $item->getUnits();
  1419.                         if (empty($unitsServ) or $unitsServ == "0") {
  1420.                             $unitsServ 1;
  1421.                         }
  1422.                         $subtotal $subtotalService $days $unitsServ $pax;
  1423.                         $subnetoUnit $subneto;
  1424.                         $subneto $subneto $days $unitsServ $pax;
  1425.                         $data_supplier['service'][$i] = array (
  1426.                             'id' => $item->getId(),
  1427.                             'serviceCatId' => $item->getServiceCatId(),
  1428.                             'serviceName' => $item->getName(),
  1429.                             'serviceType' => 'Itinerarios',
  1430.                             'date' => $dateServ,
  1431.                             'qty' => $unitsServ,
  1432.                             'iva' => $item->getIva(),
  1433.                             'pax' => $item->getPax(),
  1434.                             'precioUnit' => $subnetoUnit,
  1435.                             'subneto' => $subneto,
  1436.                             'subtotal' => $subtotal,
  1437.                         );
  1438.                         break;
  1439.                     case 10//Lounge  -- No Aplica
  1440. //                        $pax = $item->getPax();
  1441. //                        if (empty($pax) or $pax == "0") {
  1442. //                            $pax = 1;
  1443. //                        }
  1444. //
  1445. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  1446. //                        if ($days > 1){
  1447. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1448. //                        } else {
  1449. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1450. //                        }
  1451. //
  1452. //                        $unitsServ = $item->getUnits();
  1453. //                        if (empty($unitsServ) or $unitsServ == "0") {
  1454. //                            $unitsServ = 1;
  1455. //                        }
  1456. //
  1457. //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  1458. //                        $subnetoUnit = $subneto;
  1459. //                        $subneto = $subneto * $days * $unitsServ * $pax;
  1460. //
  1461. //                        $data_supplier['service'][$i] = array (
  1462. //                            'id' => $item->getId(),
  1463. //                            'serviceCatId' => $item->getServiceCatId(),
  1464. //                            'serviceName' => $item->getName(),
  1465. //                            'serviceType' => 'Itinerarios',
  1466. //                            'date' => $dateServ,
  1467. //                            'qty' => $unitsServ,
  1468. //                            'iva' => $item->getIva(),
  1469. //                            'pax' => $item->getPax(),
  1470. //                            'precioUnit' => $subnetoUnit,
  1471. //                            'subneto' => $subneto,
  1472. //                            'subtotal' => $subtotal,
  1473. //                        );
  1474.                         break;
  1475.                     case 11//Catering
  1476.                         $pax $item->getPax();
  1477.                         if (empty($pax) or $pax == "0") {
  1478.                             $pax 1;
  1479.                         }
  1480.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1481.                         if ($days 1){
  1482.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1483.                         } else {
  1484.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1485.                         }
  1486.                         $unitsServ $item->getUnits();
  1487.                         if (empty($unitsServ) or $unitsServ == "0") {
  1488.                             $unitsServ 1;
  1489.                         }
  1490.                         $subtotal $subtotalService $days $unitsServ $pax;
  1491.                         $subnetoUnit $subneto;
  1492.                         $subneto $subneto $days $unitsServ $pax;
  1493.                         $data_supplier['service'][$i] = array (
  1494.                             'id' => $item->getId(),
  1495.                             'serviceCatId' => $item->getServiceCatId(),
  1496.                             'serviceName' => $item->getName(),
  1497.                             'serviceType' => 'Catering',
  1498.                             'date' => $dateServ,
  1499.                             'qty' => $unitsServ,
  1500.                             'iva' => $item->getIva(),
  1501.                             'pax' => $item->getPax(),
  1502.                             'precioUnit' => $subnetoUnit,
  1503.                             'subneto' => $subneto,
  1504.                             'subtotal' => $subtotal,
  1505.                         );
  1506.                         break;
  1507.                     case 12//Others
  1508.                         $pax $item->getPax();
  1509.                         if (empty($pax) or $pax == "0") {
  1510.                             $pax 1;
  1511.                         }
  1512.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1513.                         if ($days 1){
  1514.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1515.                         } else {
  1516.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1517.                         }
  1518.                         $unitsServ $item->getUnits();
  1519.                         if (empty($unitsServ) or $unitsServ == "0") {
  1520.                             $unitsServ 1;
  1521.                         }
  1522.                         $subtotal $subtotalService $days $unitsServ $pax;
  1523.                         $subnetoUnit $subneto;
  1524.                         $subneto $subneto $days $unitsServ $pax;
  1525.                         $data_supplier['service'][$i] = array (
  1526.                             'id' => $item->getId(),
  1527.                             'serviceCatId' => $item->getServiceCatId(),
  1528.                             'serviceName' => $item->getName(),
  1529.                             'serviceType' => 'Otros',
  1530.                             'date' => $dateServ,
  1531.                             'qty' => $unitsServ,
  1532.                             'iva' => $item->getIva(),
  1533.                             'pax' => $item->getPax(),
  1534.                             'precioUnit' => $subnetoUnit,
  1535.                             'subneto' => $subneto,
  1536.                             'subtotal' => $subtotal,
  1537.                         );
  1538.                         break;
  1539.                     case 13//Transport
  1540.                         $pax $item->getPax();
  1541.                         if (empty($pax) or $pax == "0") {
  1542.                             $pax 1;
  1543.                         }
  1544.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1545.                         if ($days 1){
  1546.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1547.                         } else {
  1548.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1549.                         }
  1550.                         $unitsServ $item->getUnits();
  1551.                         if (empty($unitsServ) or $unitsServ == "0") {
  1552.                             $unitsServ 1;
  1553.                         }
  1554.                         $subtotal $subtotalService $days $unitsServ $pax;
  1555.                         $subnetoUnit $subneto;
  1556.                         $subneto $subneto $days $unitsServ $pax;
  1557.                         $data_supplier['service'][$i] = array (
  1558.                             'id' => $item->getId(),
  1559.                             'serviceCatId' => $item->getServiceCatId(),
  1560.                             'serviceName' => $item->getName(),
  1561.                             'serviceType' => 'Transporte',
  1562.                             'date' => $dateServ,
  1563.                             'qty' => $unitsServ,
  1564.                             'iva' => $item->getIva(),
  1565.                             'pax' => $item->getPax(),
  1566.                             'precioUnit' => $subnetoUnit,
  1567.                             'subneto' => $subneto,
  1568.                             'subtotal' => $subtotal,
  1569.                         );
  1570.                         break;
  1571.                     case 14//Technology
  1572.                         $pax $item->getPax();
  1573.                         if (empty($pax) or $pax == "0") {
  1574.                             $pax 1;
  1575.                         }
  1576. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  1577.                         $days 1;
  1578. //                        if ($days > 1){
  1579. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1580. //                        } else {
  1581. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1582. //                        }
  1583.                         $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1584.                         $unitsServ $item->getUnits();
  1585.                         if (empty($unitsServ) or $unitsServ == "0") {
  1586.                             $unitsServ 1;
  1587.                         }
  1588.                         $subtotal $subtotalService $days $unitsServ $pax;
  1589.                         $subnetoUnit $subneto;
  1590.                         $subneto $subneto $days $unitsServ $pax;
  1591.                         $data_supplier['service'][$i] = array (
  1592.                             'id' => $item->getId(),
  1593.                             'serviceCatId' => $item->getServiceCatId(),
  1594.                             'serviceName' => $item->getName(),
  1595.                             'serviceType' => 'Tecnología',
  1596.                             'date' => $dateServ,
  1597.                             'qty' => $unitsServ,
  1598.                             'iva' => $item->getIva(),
  1599.                             'pax' => $item->getPax(),
  1600.                             'precioUnit' => $subnetoUnit,
  1601.                             'subneto' => $subneto,
  1602.                             'subtotal' => $subtotal,
  1603.                         );
  1604.                         break;
  1605.                     case 15//Assisstant
  1606.                         $pax $item->getPax();
  1607.                         if (empty($pax) or $pax == "0") {
  1608.                             $pax 1;
  1609.                         }
  1610.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1611.                         if ($days 1){
  1612.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1613.                         } else {
  1614.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1615.                         }
  1616.                         $unitsServ $item->getUnits();
  1617.                         if (empty($unitsServ) or $unitsServ == "0") {
  1618.                             $unitsServ 1;
  1619.                         }
  1620.                         $subtotal $subtotalService $days $unitsServ $pax;
  1621.                         $subnetoUnit $subneto;
  1622.                         $subneto $subneto $days $unitsServ $pax;
  1623.                         $data_supplier['service'][$i] = array (
  1624.                             'id' => $item->getId(),
  1625.                             'serviceCatId' => $item->getServiceCatId(),
  1626.                             'serviceName' => $item->getName(),
  1627.                             'serviceType' => 'Asistente',
  1628.                             'date' => $dateServ,
  1629.                             'qty' => $unitsServ,
  1630.                             'iva' => $item->getIva(),
  1631.                             'pax' => $item->getPax(),
  1632.                             'precioUnit' => $subnetoUnit,
  1633.                             'subneto' => $subneto,
  1634.                             'subtotal' => $subtotal,
  1635.                         );
  1636.                         break;
  1637.                     case 16//DDR
  1638.                         $pax $item->getPax();
  1639.                         if (empty($pax) or $pax == "0") {
  1640.                             $pax 1;
  1641.                         }
  1642.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1643.                         if ($days 1){
  1644.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1645.                         } else {
  1646.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1647.                         }
  1648.                         $unitsServ $item->getUnits();
  1649.                         if (empty($unitsServ) or $unitsServ == "0") {
  1650.                             $unitsServ 1;
  1651.                         }
  1652.                         $subtotal $subtotalService $days $unitsServ $pax;
  1653.                         $subnetoUnit $subneto;
  1654.                         $subneto $subneto $days $unitsServ $pax;
  1655.                         $data_supplier['service'][$i] = array (
  1656.                             'id' => $item->getId(),
  1657.                             'serviceCatId' => $item->getServiceCatId(),
  1658.                             'serviceName' => $item->getName(),
  1659.                             'serviceType' => 'DDR',
  1660.                             'date' => $dateServ,
  1661.                             'qty' => $unitsServ,
  1662.                             'iva' => $item->getIva(),
  1663.                             'pax' => $item->getPax(),
  1664.                             'precioUnit' => $subnetoUnit,
  1665.                             'subneto' => $subneto,
  1666.                             'subtotal' => $subtotal,
  1667.                         );
  1668.                         break;
  1669.                     case 17//Seguridad
  1670.                         $pax $item->getPax();
  1671.                         if (empty($pax) or $pax == "0") { $pax 1; }
  1672.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1673.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  1674.                         $unitsServ $item->getUnits();
  1675.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  1676.                         $subtotal $subtotalService $days $unitsServ $pax;
  1677.                         $subnetoUnit $subneto;
  1678.                         $subneto $subneto $days $unitsServ $pax;
  1679.                         $data_supplier['service'][$i] = array (
  1680.                             'id' => $item->getId(),
  1681.                             'serviceCatId' => $item->getServiceCatId(),
  1682.                             'serviceName' => $item->getName(),
  1683.                             'serviceType' => 'Seguridad',
  1684.                             'date' => $dateServ,
  1685.                             'qty' => $unitsServ,
  1686.                             'iva' => $item->getIva(),
  1687.                             'pax' => $item->getPax(),
  1688.                             'precioUnit' => $subnetoUnit,
  1689.                             'subneto' => $subneto,
  1690.                             'subtotal' => $subtotal,
  1691.                         );
  1692.                         break;
  1693.                     case 18//WiFi
  1694.                         $pax $item->getPax();
  1695.                         if (empty($pax) or $pax == "0") { $pax 1; }
  1696.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1697.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  1698.                         $unitsServ $item->getUnits();
  1699.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  1700.                         $subtotal $subtotalService $days $unitsServ $pax;
  1701.                         $subnetoUnit $subneto;
  1702.                         $subneto $subneto $days $unitsServ $pax;
  1703.                         $data_supplier['service'][$i] = array (
  1704.                             'id' => $item->getId(),
  1705.                             'serviceCatId' => $item->getServiceCatId(),
  1706.                             'serviceName' => $item->getName(),
  1707.                             'serviceType' => 'WiFi',
  1708.                             'date' => $dateServ,
  1709.                             'qty' => $unitsServ,
  1710.                             'iva' => $item->getIva(),
  1711.                             'pax' => $item->getPax(),
  1712.                             'precioUnit' => $subnetoUnit,
  1713.                             'subneto' => $subneto,
  1714.                             'subtotal' => $subtotal,
  1715.                         );
  1716.                         break;
  1717.                     case 19//Mobiliario
  1718.                         $pax $item->getPax();
  1719.                         if (empty($pax) or $pax == "0") { $pax 1; }
  1720.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1721.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  1722.                         $unitsServ $item->getUnits();
  1723.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  1724.                         $subtotal $subtotalService $days $unitsServ $pax;
  1725.                         $subnetoUnit $subneto;
  1726.                         $subneto $subneto $days $unitsServ $pax;
  1727.                         $data_supplier['service'][$i] = array (
  1728.                             'id' => $item->getId(),
  1729.                             'serviceCatId' => $item->getServiceCatId(),
  1730.                             'serviceName' => $item->getName(),
  1731.                             'serviceType' => 'Mobiliario',
  1732.                             'date' => $dateServ,
  1733.                             'qty' => $unitsServ,
  1734.                             'iva' => $item->getIva(),
  1735.                             'pax' => $item->getPax(),
  1736.                             'precioUnit' => $subnetoUnit,
  1737.                             'subneto' => $subneto,
  1738.                             'subtotal' => $subtotal,
  1739.                         );
  1740.                         break;
  1741.                     case 20//Parking
  1742.                         $pax $item->getPax();
  1743.                         if (empty($pax) or $pax == "0") { $pax 1; }
  1744.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1745.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  1746.                         $unitsServ $item->getUnits();
  1747.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  1748.                         $subtotal $subtotalService $days $unitsServ $pax;
  1749.                         $subnetoUnit $subneto;
  1750.                         $subneto $subneto $days $unitsServ $pax;
  1751.                         $data_supplier['service'][$i] = array (
  1752.                             'id' => $item->getId(),
  1753.                             'serviceCatId' => $item->getServiceCatId(),
  1754.                             'serviceName' => $item->getName(),
  1755.                             'serviceType' => 'Parking',
  1756.                             'date' => $dateServ,
  1757.                             'qty' => $unitsServ,
  1758.                             'iva' => $item->getIva(),
  1759.                             'pax' => $item->getPax(),
  1760.                             'precioUnit' => $subnetoUnit,
  1761.                             'subneto' => $subneto,
  1762.                             'subtotal' => $subtotal,
  1763.                         );
  1764.                         break;
  1765.                     case 21//Limpieza
  1766.                         $pax $item->getPax();
  1767.                         if (empty($pax) or $pax == "0") { $pax 1; }
  1768.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1769.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  1770.                         $unitsServ $item->getUnits();
  1771.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  1772.                         $subtotal $subtotalService $days $unitsServ $pax;
  1773.                         $subnetoUnit $subneto;
  1774.                         $subneto $subneto $days $unitsServ $pax;
  1775.                         $data_supplier['service'][$i] = array (
  1776.                             'id' => $item->getId(),
  1777.                             'serviceCatId' => $item->getServiceCatId(),
  1778.                             'serviceName' => $item->getName(),
  1779.                             'serviceType' => 'Limpieza',
  1780.                             'date' => $dateServ,
  1781.                             'qty' => $unitsServ,
  1782.                             'iva' => $item->getIva(),
  1783.                             'pax' => $item->getPax(),
  1784.                             'precioUnit' => $subnetoUnit,
  1785.                             'subneto' => $subneto,
  1786.                             'subtotal' => $subtotal,
  1787.                         );
  1788.                         break;
  1789.                     default:
  1790.                         //Others
  1791.                         $pax $item->getPax();
  1792.                         if (empty($pax) or $pax == "0") {
  1793.                             $pax 1;
  1794.                         }
  1795.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1796.                         if ($days 1){
  1797.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1798.                         } else {
  1799.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1800.                         }
  1801.                         $unitsServ $item->getUnits();
  1802.                         if (empty($unitsServ) or $unitsServ == "0") {
  1803.                             $unitsServ 1;
  1804.                         }
  1805.                         $subtotal $subtotalService $days $unitsServ $pax;
  1806.                         $subnetoUnit $subneto;
  1807.                         $subneto $subneto $days $unitsServ $pax;
  1808.                         $data_supplier['service'][$i] = array (
  1809.                             'id' => $item->getId(),
  1810.                             'serviceCatId' => $item->getServiceCatId(),
  1811.                             'serviceName' => $item->getName(),
  1812.                             'serviceType' => 'Otros',
  1813.                             'date' => $dateServ,
  1814.                             'qty' => $unitsServ,
  1815.                             'iva' => $item->getIva(),
  1816.                             'pax' => $item->getPax(),
  1817.                             'precioUnit' => $subnetoUnit,
  1818.                             'subneto' => $subneto,
  1819.                             'subtotal' => $subtotal,
  1820.                         );
  1821.                         break;
  1822.                 }
  1823.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  1824.                 $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  1825.                 $neto round($subneto,2,PHP_ROUND_HALF_UP);
  1826.             }
  1827.             switch ($item->getIva()){
  1828.                 // Acumula IVA
  1829.                 case 21:
  1830.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva()/100));
  1831.                     break;
  1832.                 case 10:
  1833.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva()/100));
  1834.                     break;
  1835.                 case 0:
  1836.                     break;
  1837.                 default:
  1838.                     break;
  1839.             }
  1840.             $totales_neto_all $totales_neto_all $neto;
  1841.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  1842.             $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  1843.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  1844.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'],2,PHP_ROUND_HALF_UP);
  1845.             // Acumula netos totales e IVA
  1846.             $service['neto'] = $service['neto'] + $neto;
  1847.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  1848.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  1849.             $service['neto'] = round($service['neto'],2,PHP_ROUND_HALF_UP);
  1850.             $service['sumSubT'] = round($service['sumSubT'],2,PHP_ROUND_HALF_UP);
  1851.             $i++;
  1852.         }
  1853.         $data_supplier['serviceSubTotal'] = array(
  1854.             'neto' => $service['neto'],
  1855.             'sumSubT' => $service['sumSubT'],
  1856.         );
  1857.         $currency '€';
  1858.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  1859.         if (!empty($payments)) {
  1860.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  1861.         } else {
  1862.             $amount_pay 0;
  1863.         }
  1864.         $totales_all $totales_total $amount_pay;
  1865.         $data = array(
  1866.             'id' => $id,
  1867.             'type' => $type,
  1868.             'number' => $number,
  1869.             'prefix' => $prefix,
  1870.             'date' => $date,
  1871.             'reservation' => $reservation,
  1872.             'token' => $reservation->getAccessKey(),
  1873.             'company' => $company,
  1874.             'clients' => $client,
  1875.             'datasupplier' => $data_supplier,
  1876.             'currency' => $currency,
  1877.             'totales_neto' => $totales_neto_all,
  1878.             'bases_imponibles' => $data_iva,
  1879.             'totales' => $totales_total,
  1880.             'balance' => $totales_all,
  1881.             'paymentInvoice' => $amount_pay,
  1882.         );
  1883.         return $data;
  1884.     }
  1885.     /**
  1886.      * @Route("/reservations/invoice/proforma/print/{id}",  name="reservations_invoice_proforma_print")
  1887.      */
  1888.     public function detailsProformaPrintAction($idRequest $request)
  1889.     {
  1890.         $data = array();
  1891.         $em $this->getDoctrine()->getManager();
  1892.         $proforma $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
  1893.         if (!empty($proforma)){
  1894.             $type 'Proforma';
  1895.             $number $proforma->getId();
  1896.             $date $proforma->getDateAt();
  1897.             $prefix $proforma->getPrefix();
  1898.             $data $this->baseInvoiceReservation($id$type$number$prefix$date);
  1899.             $token $data['token'];
  1900.         }else{
  1901.             return $this->redirectToRoute('reservations_generate_proforma',
  1902.                 array(
  1903.                     'id' => $id
  1904.                 )
  1905.             );
  1906.         }
  1907.         return $this->render('MDS/GreenPatioBundle/reservations/services-proforma-print-reservation.html.twig',
  1908.             array(
  1909.                 'id' => $id,
  1910.                 'type' => $data['type'],
  1911.                 'number' => $data['number'],
  1912.                 'prefix' => $data['prefix'],
  1913.                 'date' => $data['date'],
  1914.                 'token' => $token,
  1915.                 'company' => $data['company'],
  1916.                 'clients' => $data['clients'],
  1917.                 'datasupplier' => $data['datasupplier'],
  1918.                 'totales_neto' => $data['totales_neto'],
  1919.                 'bases_imponibles' => $data['bases_imponibles'],
  1920.                 'totales' => $data['totales'],
  1921.                 'balance' => $data['balance'],
  1922.                 'currency' => $data['currency'],
  1923.                 'paymentInvoice' => $data['paymentInvoice']
  1924.             )
  1925.         );
  1926.     }
  1927.     /**
  1928.      * @Route("/invoice/{id}",  name="reservations_invoice")
  1929.      */
  1930.     public function detailsReservationInvoiceAction($idRequest $request)
  1931.     {
  1932.         $em $this->getDoctrine()->getManager();
  1933.         $payments $em->getRepository(ReservationPaymentsClient::class)->findByReservationId($id);
  1934. ////        $services = $em->getRepository(ReservationService::class)->findByReservationId($id);     // ********************************************** PENDIENTE POR PROGRAMAR EL CALCULO DE CADA TIPO DE SERVICIO PARA LA FACTURA **********************************************
  1935. //        $invoice = $em->getRepository(ReservationInvoice::class)->findOneByReservationId($id);
  1936.         $invoice $em->getRepository(ReservationInvoice::class)->findOneBy(
  1937.             array(
  1938.                 'reservationId' => $id,
  1939.                 'master' => 'master',
  1940.             )
  1941.         );
  1942.         $reservaInv = new ReservationInvoice();
  1943.         $reservaInv->setReservationId($id);
  1944.         $form1 $this->createReservationInvoiceProformaForm($reservaInv);
  1945.         if (!empty($invoice)){
  1946.             $type 'Invoice';
  1947.             $number $invoice->getId();
  1948.             $date $invoice->getDateAt();
  1949.             $prefix $invoice->getPrefix();
  1950.             $data $this->baseInvoiceReservation($id$type$number$prefix$date);
  1951.             $token $data['token'];
  1952.         }else{
  1953.             // No hay factura creada se debe enviar a proforma, si es un ADMIN podra generar la factura. Tal vez sea necesario poner un mensaje indicando que no hay factura generada aun
  1954.             return $this->redirectToRoute('reservations_generate_proforma',
  1955.                 array(
  1956.                     'id' => $id
  1957.                 )
  1958.             );
  1959.         }
  1960.         $idLounges = array();
  1961.         $loungesBoolToInvoice = array();
  1962.         if (array_key_exists('lounge',$data['datasupplier'])) {
  1963.             foreach ($data['datasupplier']['lounge'] as $item) {
  1964.                 $idLounges[] = $item['id'];
  1965.                 $loungesBoolToInvoice[] = 1;
  1966.             }
  1967.             $idLounges implode(','$idLounges);
  1968.             $loungesBoolToInvoice implode(','$loungesBoolToInvoice);
  1969.         } else {
  1970.             $idLounges '0';
  1971.             $loungesBoolToInvoice '0';
  1972.         }
  1973.         $idPayments = array();
  1974.         $paymentsBoolToInvoice = array();
  1975.         if (array_key_exists('payment',$data['datasupplier'])) {
  1976.             foreach ($data['datasupplier']['payment'] as $item) {
  1977.                 $idPayments[] = $item['id'];
  1978.                 $paymentsBoolToInvoice[] = 1;
  1979.             }
  1980.             $idPayments implode(','$idPayments);
  1981.             $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  1982.             // Se han generado dos arreglos, cada uno dividido en 2 strings
  1983.             // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  1984.             // Para manipularlos entre la vista y el JS
  1985.         } else {
  1986.             $idPayments '';
  1987.             $paymentsBoolToInvoice '';
  1988.         }
  1989.         return $this->render('MDS/GreenPatioBundle/reservations/services-invoice-reservation.html.twig',
  1990.             array(
  1991.                 'id' => $id,
  1992.                 'idLounges' => $idLounges,
  1993.                 'idPayments' => $idPayments,
  1994.                 'loungesBoolToInvoice' => $loungesBoolToInvoice,
  1995.                 'paymentsBoolToInvoice' => $paymentsBoolToInvoice,
  1996.                 'type' => $data['type'],
  1997.                 'number' => $data['number'],
  1998.                 'prefix' => $data['prefix'],
  1999.                 'date' => $data['date'],
  2000.                 'token' => $token,
  2001.                 'company' => $data['company'],
  2002.                 'clients' => $data['clients'],
  2003.                 'datasupplier' => $data['datasupplier'],
  2004.                 'currency' => $data['currency'],
  2005.                 'totales_neto' => $data['totales_neto'],
  2006.                 'bases_imponibles' => $data['bases_imponibles'],
  2007.                 'totales' => $data['totales'],
  2008.                 'balance' => $data['balance'],
  2009.                 'paymentInvoice' => $data['paymentInvoice'],
  2010.                 'payments' => $payments,
  2011.                 'form1' => $form1->createView(),
  2012.                 'clientName' => $invoice->getClientName(),
  2013.                 'clientAddress' => $invoice->getClientAddress(),
  2014.                 'clientDocument' => $invoice->getClientDocument(),
  2015.             )
  2016.         );
  2017.     }
  2018.     /**
  2019.      * @Route("/reservations/invoice/print/{id}",  name="reservations_invoice_print")
  2020.      */
  2021.     public function detailsInvoicePrintAction($idRequest $request)
  2022.     {
  2023.         $data = array();
  2024.         $em $this->getDoctrine()->getManager();
  2025.         $invoice $em->getRepository(ReservationInvoice::class)->findOneByReservationId($id);
  2026.         if (!empty($invoice)){
  2027.             $type 'Invoice';
  2028.             $number $invoice->getId();
  2029.             $date $invoice->getDateAt();
  2030.             $prefix $invoice->getPrefix();
  2031.             $data $this->baseInvoiceReservation($id$type$number$prefix$date);
  2032.             $token $data['token'];
  2033.         }else{
  2034.             return $this->redirectToRoute('reservations_generate_invoice',
  2035.                 array(
  2036.                     'id' => $id
  2037.                 )
  2038.             );
  2039.         }
  2040.         return $this->render('MDS/GreenPatioBundle/reservations/services-invoice-print-reservation.html.twig',
  2041.             array(
  2042.                 'id' => $id,
  2043.                 'type' => $data['type'],
  2044.                 'number' => $data['number'],
  2045.                 'prefix' => $data['prefix'],
  2046.                 'date' => $data['date'],
  2047.                 'token' => $token,
  2048.                 'company' => $data['company'],
  2049.                 'clients' => $data['clients'],
  2050.                 'datasupplier' => $data['datasupplier'],
  2051.                 'totales_neto' => $data['totales_neto'],
  2052.                 'bases_imponibles' => $data['bases_imponibles'],
  2053.                 'totales' => $data['totales'],
  2054.                 'balance' => $data['balance'],
  2055.                 'currency' => $data['currency'],
  2056.                 'paymentInvoice' => $data['paymentInvoice']
  2057.             )
  2058.         );
  2059.     }
  2060.     /**
  2061.      * @Route("/invoice/generate/{id}",  name="reservations_generate_invoice")
  2062.      */
  2063.     public function generateInvoiceAction($idRequest $request)
  2064.     {
  2065.         $em $this->getDoctrine()->getManager();
  2066.         $invoiceGenerate $request->request->get('invoiceGenerate');
  2067.         $invoice $em->getRepository(ReservationInvoice::class)->findOneBy(
  2068.             array(
  2069.                 'reservationId' => $id,
  2070.                 'master' => 'master',
  2071.             )
  2072.         );
  2073.         if (is_null($invoice)){
  2074.             $reserva $em->getRepository(Reservation::class)->findOneById($id);
  2075.             $pagos $em->getRepository(ReservationPaymentsClient::class)->findOneByReservationId($id);
  2076.             $servicios $em->getRepository(ReservationService::class)->findOneByReservationId($id);
  2077.             $salas $em->getRepository(ReservationLounge::class)->findOneByIdReservation($id);
  2078. //
  2079. //  Aqui se deberia verificar que pagos, salas o servicios, al menos uno sea distinto de null. En caso contrario no hay nada que facturar
  2080. //            if (empty($pagos) and empty($servicios) and empty($salas)){
  2081. //                d('factura vacia');
  2082. //            }
  2083. //
  2084. //
  2085. //
  2086. //
  2087.             $reserva->setStatus('Invoiced');
  2088.             $em->persist($reserva);
  2089.             $em->flush();
  2090.             $invoice_new = new ReservationInvoice();
  2091.             $invoice_new->setNumber('GPF-'.date('d').date('m').substr(date('Y'),-2).'-'.$id);           //GreenPatioFactura - dia mes año idReserva
  2092.             $invoice_new->setDateAt(new \DateTime());
  2093.             $invoice_new->setType($invoiceGenerate['type']);
  2094.             $invoice_new->setReservationId($invoiceGenerate['id']);
  2095.             $invoice_new->setReservationId($id);
  2096.             $invoice_new->setPrefix('');
  2097.             $invoice_new->setType('Invoice');
  2098.             $proforma $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
  2099.             $type 'Invoice';
  2100.             $number $proforma->getId();
  2101.             $date $proforma->getDateAt();
  2102.             $prefix $proforma->getPrefix();
  2103.             $data $this->baseInvoiceReservation($id$type$number$prefix$date);
  2104.             $em->clear();
  2105.             $invoice_new->setTotal($data['totales']);
  2106.             $invoice_new->setTotalNet($data['totales_neto']);
  2107.             $invoice_new->setVat($data['totales'] - $data['totales_neto']);
  2108.             /* Obtengo usuario logueado */
  2109.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2110.             $user_id $user_logueado->getId();
  2111.             $invoice_new->setCreatedId($user_id);
  2112.             $invoice_new->setUpdatedId($user_id);
  2113.             $invoice_new->setCreatedAt(new \DateTime());
  2114.             $invoice_new->setUpdatedAt(new \DateTime());
  2115.             // Guardamos los datos del cliente dentro de la factura
  2116.             $typeClient $request->request->get('typeClient');
  2117.             $typeClient = empty($typeClient) ? 'Client' $typeClient;
  2118.             $idClient $request->request->get('idClient');
  2119.             $idClient = empty($idClient) ? $reserva->getClient() : $idClient;
  2120.             $invoice_new $this->clientDataToInvoice($invoice_new$typeClient$idClient$invoice_new->getReservationId());
  2121.             $em->persist($invoice_new);
  2122.             $em->flush();
  2123.         }
  2124.         return $this->redirectToRoute('reservations_invoice', array( 'id' => $id ));
  2125.     }
  2126.     /**
  2127.      * @Route("/reservations/invoice/generatenew",  name="reservations_generatenew_invoice")
  2128.      * Generar una nueva factura
  2129.      */
  2130.     public function generatenewInvoiceAction(Request $request)
  2131.     {
  2132.         $em $this->getDoctrine()->getManager();
  2133.         // Se genera y muestra en nueva pantalla la nueva proforma
  2134.         $arrayBools = array(
  2135.             'lounge' => null,
  2136.             'service' => null,
  2137.             'payment' => null,
  2138.         );
  2139.         $arrayBools['lounge'] = $request->request->get('inv_lounge_hidden_bool');
  2140.         $arrayBools['service'] = $request->request->get('inv_service_hidden_bool');
  2141.         $arrayBools['payment'] = $request->request->get('inv_payment_hidden_bool');
  2142.         $clientName $request->request->get('clientName');
  2143.         $clientAddress $request->request->get('clientAddress');
  2144.         $clientDocument $request->request->get('clientDocument');
  2145.         $clientType $request->request->get('clientType');
  2146.         $id $request->request->get('inv_reservation_id');
  2147.         // INICIO: Verificamos la linea de facturacion
  2148.         $parameters = array( 'id' => $id, );
  2149.         $dql 'SELECT p
  2150.                 FROM GreenPatioBundle:ReservationLoungeSimple p
  2151.                 WHERE p.idReservation = :id AND p.idLounge > 21';
  2152.         $query $em->createQuery($dql)->setParameters($parameters);
  2153.         $loungesSimples $query->getResult();
  2154.         if (!empty($loungesSimples)){
  2155.             // Redirigir a Covarrubias
  2156.             return $this->redirectToRoute('reservations_generatenew_invoice_cvr',
  2157.                 array(
  2158.                     'id' => $id,
  2159.                     'lounge' => $arrayBools['lounge'],
  2160.                     'service' => $arrayBools['service'],
  2161.                     'payment' => $arrayBools['payment'],
  2162.                     'clientName' => $clientName,
  2163.                     'clientAddress' => $clientAddress,
  2164.                     'clientDocument' => $clientDocument,
  2165.                     'clientType' => $clientType
  2166.                 )
  2167.             );
  2168.         }
  2169.         // FIN: Verificamos la linea de facturacion
  2170.         //INICIO: buscamos el ID de la factura
  2171.         $allFacturas $em->getRepository(ReservationInvoice::class)->findAll();
  2172.         if (!empty($allFacturas)){
  2173.             $invoiceId end($allFacturas)->getId() + 1;
  2174.         } else {
  2175.             $invoiceId 1;
  2176.         }
  2177.         $boolMakeInvoice false;  // Control para verificar si se debe hacer factura o todos los indicadores (sala, servicios y pagos) estaban en falso
  2178.         //FIN: buscamos el ID de la factura
  2179.         /* Obtengo usuario logueado */
  2180.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2181.         $user_id $user_logueado->getId();
  2182.         //Acumuladores de datos globales de la factura
  2183.         $valorTotalNet 0;
  2184.         $valorVat 0;
  2185.         //INICIO: Creamos los items de la factura
  2186.         if (!empty($arrayBools['lounge'])) {
  2187.             foreach ($arrayBools['lounge'] as $key => $item) {
  2188.                 if ($item == 'true') {
  2189.                     $boolMakeInvoice true;
  2190.                     $sala $em->getRepository(ReservationLoungeSimple::class)->findOneById($key);
  2191.                     $itemInvoice = new ReservationInvoiceItems();
  2192.                     $itemInvoice->setReservationId($id);
  2193.                     $itemInvoice->setInvoiceId($invoiceId);
  2194.                     $itemInvoice->setItemType('LOUNGE');
  2195.                     $itemInvoice->setLngControlId($key);
  2196.                     $itemInvoice->setLngLoungeName($sala->getLoungeName());
  2197.                     $itemInvoice->setLngIdLounge($sala->getIdLounge());
  2198.                     $itemInvoice->setLngIdLounge($sala->getIdLounge());
  2199.                     $itemInvoice->setLngDateStart($sala->getDateStart());
  2200.                     $itemInvoice->setLngDateEnd($sala->getDateEnd());
  2201.                     $itemInvoice->setLngServicePrice($sala->getServicePrice());
  2202.                     $itemInvoice->setLngPax($sala->getPax());
  2203.                     $itemInvoice->setLngType($sala->getType());
  2204.                     $itemInvoice->setCreatedId($user_id);
  2205.                     $itemInvoice->setCreatedAt(new DateTime('now'));
  2206.                     $itemInvoice->setUpdatedId($user_id);
  2207.                     $itemInvoice->setUpdatedAt(new DateTime('now'));
  2208.                     $itemInvoice->setLngHourStart($sala->getHourStart());
  2209.                     $itemInvoice->setLngMinStart($sala->getMinStart());
  2210.                     $itemInvoice->setLngHourEnd($sala->getHourEnd());
  2211.                     $itemInvoice->setLngMinEnd($sala->getMinEnd());
  2212.                     $em->persist($itemInvoice);
  2213.                     $em->flush();
  2214.                     //Acumulamos neto e iva para la factura
  2215.                     $valorTotalNet $valorTotalNet $itemInvoice->getLngServicePrice();
  2216.                     $valorVat $valorVat round(($itemInvoice->getLngServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
  2217.                 }
  2218.             }
  2219.         }
  2220.         if (!empty($arrayBools['service'])) {
  2221.             foreach ($arrayBools['service'] as $key => $item) {
  2222.                 if ($item == 'true') {
  2223.                     $boolMakeInvoice true;
  2224.                     $servicio $em->getRepository(ReservationService::class)->findOneById($key);
  2225.                     $itemInvoice = new ReservationInvoiceItems();
  2226.                     $itemInvoice->setReservationId($id);
  2227.                     $itemInvoice->setInvoiceId($invoiceId);
  2228.                     $itemInvoice->setItemType('SERVICE');
  2229.                     $itemInvoice->setSrvControlId($key);
  2230.                     $itemInvoice->setSrvName($servicio->getName());
  2231.                     $itemInvoice->setSrvSupplierId($servicio->getSupplierId());
  2232.                     $itemInvoice->setSrvServiceId($servicio->getServiceId());
  2233.                     $itemInvoice->setSrvServiceCatId($servicio->getServiceCatId());
  2234.                     $itemInvoice->setSrvServiceCatName($servicio->getServiceCatName());
  2235.                     $itemInvoice->setSrvPrice($servicio->getPrice());
  2236.                     $itemInvoice->setSrvCurrency($servicio->getCurrency());
  2237.                     $itemInvoice->setSrvUnits($servicio->getUnits());
  2238.                     $itemInvoice->setSrvOpCommission($servicio->getOpCommission());
  2239.                     $itemInvoice->setSrvCommission($servicio->getCommission());
  2240.                     $itemInvoice->setSrvOpOver($servicio->getOpOver());
  2241.                     $itemInvoice->setSrvOver($servicio->getOver());
  2242.                     $itemInvoice->setSrvOpIva($servicio->getOpIva());
  2243.                     $itemInvoice->setSrvIva($servicio->getIva());
  2244.                     $itemInvoice->setSrvPax($servicio->getPax());
  2245.                     $itemInvoice->setSrvHour($servicio->getHour());
  2246.                     $itemInvoice->setSrvDateInAt($servicio->getDateInAt());
  2247.                     $itemInvoice->setSrvDateOutAt($servicio->getDateOutAt());
  2248.                     $itemInvoice->setSrvContcolor($servicio->getContcolor());
  2249.                     $itemInvoice->setSrvRank($servicio->getRank());
  2250.                     $itemInvoice->setSrvAssistantId($servicio->getAssistantId());
  2251.                     $itemInvoice->setSrvActivityId($servicio->getActivityId());
  2252.                     $itemInvoice->setSrvPay($servicio->getPay());
  2253.                     $itemInvoice->setCreatedAt(new DateTime('now'));
  2254.                     $itemInvoice->setUpdatedAt(new DateTime('now'));
  2255.                     $itemInvoice->setCreatedId($user_id);
  2256.                     $itemInvoice->setUpdatedId($user_id);
  2257.                     $em->persist($itemInvoice);
  2258.                     $em->flush();
  2259.                     //Acumulamos neto e iva para la factura
  2260.                     if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())){
  2261.                         $subtotal 0;
  2262.                         $neto 0;
  2263.                         $subtotalService 0;
  2264.                     } else {
  2265.                         $subtotalService $itemInvoice->getSrvPrice();
  2266.                         $subneto $itemInvoice->getSrvPrice();
  2267.                         // Commission
  2268.                         if ($itemInvoice->getSrvOpCommission()=='1'){
  2269.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvCommission()/100));
  2270.                             $subneto $subneto  * (+ ($itemInvoice->getSrvCommission()/100));
  2271.                         } else {
  2272.                             $subtotalService $subtotalService * (- ($itemInvoice->getSrvCommission()/100));
  2273.                             $subneto $subneto * (- ($itemInvoice->getSrvCommission()/100));
  2274.                         }
  2275.                         // Over
  2276.                         if ($itemInvoice->getSrvOpOver()=='1'){
  2277.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  2278.                             $subneto $subneto $itemInvoice->getSrvOver();
  2279.                         } else {
  2280.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  2281.                             $subneto $subneto $itemInvoice->getSrvOver();
  2282.                         }
  2283.                         // IVA
  2284.                         if ($itemInvoice->getSrvOpIva()=='1'){
  2285.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvIva()/100));
  2286.                         } else {
  2287.                             $subtotalService $itemInvoice->getSrvPrice();
  2288.                             $subneto = ($subneto 100) / (100 $itemInvoice->getSrvIva());
  2289.                         }
  2290.                         switch ($itemInvoice->getSrvServiceCatId()){
  2291.                             case 1// Alojamiento
  2292.                                 // el numero de noches $numNoches; precio unitario $subneto
  2293.                                 $numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
  2294.                                 // La personas no afectan este calculo
  2295.                                 $subtotal $subtotalService $numNoches $itemInvoice->getSrvUnits();
  2296.                                 $subnetoUnit $subneto;
  2297.                                 $subneto $subneto $numNoches $itemInvoice->getSrvUnits();
  2298.                                 break;
  2299.                             case 2//Actividades
  2300.                                 // El número de personas es considerado en el calculo
  2301.                                 $pax $itemInvoice->getSrvPax();
  2302.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2303.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2304.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2305.                                 $subtotal $subtotalService $days $itemInvoice->getSrvUnits();
  2306.                                 $subnetoUnit $subneto;
  2307.                                 $subneto $subneto $days $itemInvoice->getSrvUnits();
  2308.                                 break;
  2309.                             case 3// AV
  2310.                                 $pax $itemInvoice->getSrvPax();
  2311.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2312.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2313.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2314.                                 $unitsServ $itemInvoice->getSrvUnits();
  2315.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2316.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2317.                                 $subnetoUnit $subneto;
  2318.                                 $subneto $subneto $days $unitsServ $pax;
  2319.                                 break;
  2320.                             case 4//Creative
  2321.                                 $pax $itemInvoice->getSrvPax();
  2322.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2323.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2324.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2325.                                 $unitsServ $itemInvoice->getSrvUnits();
  2326.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2327.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2328.                                 $subnetoUnit $subneto;
  2329.                                 $subneto $subneto $days $unitsServ $pax;
  2330.                                 break;
  2331.                             case 5//Cruise
  2332.                                 $pax $itemInvoice->getSrvPax();
  2333.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2334.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
  2335.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2336.                                 $unitsServ $itemInvoice->getSrvUnits();
  2337.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2338.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2339.                                 $subnetoUnit $subneto;
  2340.                                 $subneto $subneto $days $unitsServ $pax;
  2341.                                 break;
  2342.                             case 6//Entertaiment
  2343.                                 $pax $itemInvoice->getSrvPax();
  2344.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2345.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2346.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2347.                                 $unitsServ $itemInvoice->getSrvUnits();
  2348.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2349.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2350.                                 $subnetoUnit $subneto;
  2351.                                 $subneto $subneto $days $unitsServ $pax;
  2352.                                 break;
  2353.                             case 7// Gifts
  2354.                                 $pax $itemInvoice->getSrvPax();
  2355.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2356.                                 $days 1;
  2357.                                 $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2358.                                 $unitsServ $itemInvoice->getSrvUnits();
  2359.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2360.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2361.                                 $subnetoUnit $subneto;
  2362.                                 $subneto $subneto $days $unitsServ $pax;
  2363.                                 break;
  2364.                             case 8//Guide
  2365.                                 $pax $itemInvoice->getSrvPax();
  2366.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2367.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2368.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2369.                                 $unitsServ $itemInvoice->getSrvUnits();
  2370.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2371.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2372.                                 $subnetoUnit $subneto;
  2373.                                 $subneto $subneto $days $unitsServ $pax;
  2374.                                 break;
  2375.                             case 9//Itineraries
  2376.                                 $pax $itemInvoice->getSrvPax();
  2377.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2378.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2379.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2380.                                 $unitsServ $itemInvoice->getSrvUnits();
  2381.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2382.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2383.                                 $subnetoUnit $subneto;
  2384.                                 $subneto $subneto $days $unitsServ $pax;
  2385.                                 break;
  2386.                             case 10//Lounge  -- No Aplica
  2387.                                 break;
  2388.                             case 11//Menu (Catering)
  2389.                                 $pax $itemInvoice->getSrvPax();
  2390.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2391.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2392.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2393.                                 $unitsServ $itemInvoice->getSrvUnits();
  2394.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2395.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2396.                                 $subnetoUnit $subneto;
  2397.                                 $subneto $subneto $days $unitsServ $pax;
  2398.                                 break;
  2399.                             case 12//Others
  2400.                                 $pax $itemInvoice->getSrvPax();
  2401.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2402.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2403.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2404.                                  $unitsServ $itemInvoice->getSrvUnits();
  2405.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2406.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2407.                                 $subnetoUnit $subneto;
  2408.                                 $subneto $subneto $days $unitsServ $pax;
  2409.                                 break;
  2410.                             case 13//Transport
  2411.                                 $pax $itemInvoice->getSrvPax();
  2412.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2413.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2414.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2415.                                 $unitsServ $itemInvoice->getSrvUnits();
  2416.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2417.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2418.                                 $subnetoUnit $subneto;
  2419.                                 $subneto $subneto $days $unitsServ $pax;
  2420.                                 break;
  2421.                             case 14//Technology
  2422.                                 $pax $itemInvoice->getSrvPax();
  2423.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2424.                                 $days 1;
  2425.                                 $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  2426.                                 $unitsServ $itemInvoice->getSrvUnits();
  2427.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2428.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2429.                                 $subnetoUnit $subneto;
  2430.                                 $subneto $subneto $days $unitsServ $pax;
  2431.                                 break;
  2432.                             case 15//Assisstant
  2433.                                 $pax $itemInvoice->getSrvPax();
  2434.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2435.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2436.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2437.                                 $unitsServ $itemInvoice->getSrvUnits();
  2438.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2439.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2440.                                 $subnetoUnit $subneto;
  2441.                                 $subneto $subneto $days $unitsServ $pax;
  2442.                                 break;
  2443.                             case 16//DDR
  2444.                                 $pax $itemInvoice->getSrvPax();
  2445.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2446.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2447.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2448.                                 $unitsServ $itemInvoice->getSrvUnits();
  2449.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2450.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2451.                                 $subnetoUnit $subneto;
  2452.                                 $subneto $subneto $days $unitsServ $pax;
  2453.                                 break;
  2454.                             case 17//Seguridad
  2455.                                 $pax $itemInvoice->getSrvPax();
  2456.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2457.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2458.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2459.                                 $unitsServ $itemInvoice->getSrvUnits();
  2460.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2461.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2462.                                 $subnetoUnit $subneto;
  2463.                                 $subneto $subneto $days $unitsServ $pax;
  2464.                                 break;
  2465.                             case 18//WiFi
  2466.                                 $pax $itemInvoice->getSrvPax();
  2467.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2468.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2469.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2470.                                 $unitsServ $itemInvoice->getSrvUnits();
  2471.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2472.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2473.                                 $subnetoUnit $subneto;
  2474.                                 $subneto $subneto $days $unitsServ $pax;
  2475.                                 break;
  2476.                             case 19//Mobiliario
  2477.                                 $pax $itemInvoice->getSrvPax();
  2478.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2479.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2480.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2481.                                 $unitsServ $itemInvoice->getSrvUnits();
  2482.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2483.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2484.                                 $subnetoUnit $subneto;
  2485.                                 $subneto $subneto $days $unitsServ $pax;
  2486.                                 break;
  2487.                             case 20//Parking
  2488.                                 $pax $itemInvoice->getSrvPax();
  2489.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2490.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2491.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2492.                                 $unitsServ $itemInvoice->getSrvUnits();
  2493.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2494.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2495.                                 $subnetoUnit $subneto;
  2496.                                 $subneto $subneto $days $unitsServ $pax;
  2497.                                 break;
  2498.                             case 21//Limpieza
  2499.                                 $pax $itemInvoice->getSrvPax();
  2500.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2501.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2502.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2503.                                 $unitsServ $itemInvoice->getSrvUnits();
  2504.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2505.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2506.                                 $subnetoUnit $subneto;
  2507.                                 $subneto $subneto $days $unitsServ $pax;
  2508.                                 break;
  2509.                             default: //Others (por default)
  2510.                                 $pax $itemInvoice->getSrvPax();
  2511.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2512.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2513.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2514.                                 $unitsServ $itemInvoice->getSrvUnits();
  2515.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2516.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2517.                                 $subnetoUnit $subneto;
  2518.                                 $subneto $subneto $days $unitsServ $pax;
  2519.                                 break;
  2520.                         }
  2521.                         // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  2522.                         $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  2523.                         $neto round($subneto,2,PHP_ROUND_HALF_UP);
  2524.                         $valorTotalNet $valorTotalNet $neto;
  2525.                         $valorVat $valorVat + ($subtotal $neto);
  2526.                     }
  2527.                 }
  2528.             }
  2529.         }
  2530.         if (!empty($arrayBools['payment'])) {
  2531.             foreach ($arrayBools['payment'] as $key => $item) {
  2532.                 if ($item == 'true') {
  2533.                     $boolMakeInvoice true;
  2534.                     $pago $em->getRepository(ReservationPaymentsClient::class)->findOneById($key);
  2535.                     $itemInvoice = new ReservationInvoiceItems();
  2536.                     $itemInvoice->setReservationId($id);
  2537.                     $itemInvoice->setInvoiceId($invoiceId);
  2538.                     $itemInvoice->setItemType('PAYMENT');
  2539.                     $itemInvoice->setPayControlId($key);
  2540.                     $itemInvoice->setPayAmount($pago->getAmount());
  2541.                     $itemInvoice->setPayVat($pago->getVat());
  2542.                     $itemInvoice->setPayAmountTotal($pago->getAmountTotal());
  2543.                     $itemInvoice->setPayDatePayAt($pago->getDatePayAt());
  2544.                     $itemInvoice->setPayWayToPay($pago->getWayToPay());
  2545.                     $itemInvoice->setCreatedAt(new DateTime('now'));
  2546.                     $itemInvoice->setUpdatedAt(new DateTime('now'));
  2547.                     $itemInvoice->setCreatedId($user_id);
  2548.                     $itemInvoice->setUpdatedId($user_id);
  2549.                     $em->persist($itemInvoice);
  2550.                     $em->flush();
  2551.                     //Acumulamos neto e iva para la factura
  2552.                     //$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();    // El pago no puede afectar el neto de la factura
  2553.                     $valorTotalNet $valorTotalNet $itemInvoice->getPayAmount();
  2554.                     $valorVat $valorVat round(($itemInvoice->getPayAmount() * 0.21),2,PHP_ROUND_HALF_UP);
  2555.                 }
  2556.             }
  2557.         }
  2558.         //FIN: Creamos los items de la factura
  2559.         $valorTotal $valorTotalNet $valorVat;
  2560.         //INICIO: Creamos la factura
  2561.         $newInvoice = new ReservationInvoice();
  2562.         $newInvoice->setNumber("GPF-".date('dmy')."-".$id);
  2563.         $newInvoice->setDateAt(new DateTime('now'));
  2564.         $newInvoice->setType('Invoice');
  2565.         $newInvoice->setReservationId($id);
  2566.         $newInvoice->setTotalNet($valorTotalNet);
  2567.         $newInvoice->setVat($valorVat);
  2568.         $newInvoice->setTotal($valorTotal);
  2569.         $newInvoice->setCreatedAt(new DateTime('now'));
  2570.         $newInvoice->setCreatedId($user_id);
  2571.         $newInvoice->setUpdatedAt(new DateTime('now'));
  2572.         $newInvoice->setUpdatedId($user_id);
  2573.         $newInvoice->setMaster('master');
  2574.         $newInvoice->setClientName($clientName);
  2575.         $newInvoice->setClientAddress($clientAddress);
  2576.         $newInvoice->setClientDocument($clientDocument);
  2577.         $newInvoice->setClientType($clientType);
  2578.         if ($boolMakeInvoice){
  2579.             // Solo se debe crear factura si hay un elemento
  2580.             $em->persist($newInvoice);
  2581.             $em->flush();
  2582.             $newInvoice->setNumber($newInvoice->getNumber().'-'.$newInvoice->getId());
  2583.             $em->persist($newInvoice);
  2584.             $em->flush();
  2585.         } else {
  2586.             // Se llama a la vista de facturas del expediente
  2587.             return $this->redirectToRoute('reservations_viewreservation_invoices',array('id' => $id));
  2588.         }
  2589.         //FIN: Creamos la factura
  2590.         $data = array();
  2591.         $data $this->baseInvoiceSelectedReservation($id$arrayBools,'I'.$newInvoice->getId());
  2592.         $paymentsClient = new ReservationPaymentsClient();
  2593.         $paymentsClient->setReservationId($id);
  2594.         $reserva $em->getRepository(Reservation::class)->findOneById($id);
  2595.         if ($boolMakeInvoice){
  2596.             // Si se creo la factura se cambia el estado de la reserva a Facturado
  2597.             $reserva->setStatus('Invoiced');
  2598.             $em->persist($reserva);
  2599.             $em->flush();
  2600.         }
  2601.         $reservaInv = new ReservationInvoice();
  2602.         $reservaInv->setReservationId($id);
  2603.         $form1 $this->createReservationInvoiceProformaForm($reservaInv);
  2604.         $idLounges = array();
  2605.         $loungesBoolToInvoice = array();
  2606.         if (array_key_exists('lounge',$data['datasupplier'])) {
  2607.             foreach ($data['datasupplier']['lounge'] as $item) {
  2608.                 $idLounges[] = $item['id'];
  2609.                 $loungesBoolToInvoice[] = 1;
  2610.             }
  2611.             $idLounges implode(','$idLounges);
  2612.             $loungesBoolToInvoice implode(','$loungesBoolToInvoice);
  2613.         } else {
  2614.             $idLounges '0';
  2615.             $loungesBoolToInvoice '0';
  2616.         }
  2617.         $idPayments = array();
  2618.         $paymentsBoolToInvoice = array();
  2619.         if (array_key_exists('payment',$data['datasupplier'])) {
  2620.             foreach ($data['datasupplier']['payment'] as $item) {
  2621.                 $idPayments[] = $item['id'];
  2622.                 $paymentsBoolToInvoice[] = 1;
  2623.             }
  2624.             $idPayments implode(','$idPayments);
  2625.             $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  2626.             // Se han generado dos arreglos, cada uno dividido en 2 strings
  2627.             // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  2628.             // Para manipularlos entre la vista y el JS
  2629.         } else {
  2630.             $idPayments '0';
  2631.             $paymentsBoolToInvoice '0';
  2632.         }
  2633.         // Una factura solo se puede rectificar una vez
  2634.         $rectf $em->getRepository(ReservationInvoiceRec::class)->findBy( array('number' => 'REC-'.$newInvoice->getNumber()));
  2635.         $boolToRec = empty($rectf);
  2636.         $allInvoices $em->getRepository(ReservationInvoice::class)->findByReservationId($id);
  2637.         $allInvoicesRec $em->getRepository(ReservationInvoiceRec::class)->findByReservationId($id);
  2638.         foreach ($allInvoicesRec as $item){ array_push($allInvoices$item); }
  2639.         $allProformas $em->getRepository(ReservationProforma::class)->findByReservationId($id);
  2640.         if(empty($data['type'])){$data['type'] = 'Invoice';}
  2641.         return $this->redirectToRoute('reservations_viewnew_invoice',array('id' => $newInvoice->getId()));
  2642.     }
  2643.     /**
  2644.      * @Route("/reservations/invoice/generatenewproforma",  name="reservations_generatenew_proforma")
  2645.      */
  2646.     public function generatenewProformaAction(Request $request)
  2647.     {
  2648.         $em $this->getDoctrine()->getManager();
  2649.         // Se genera y muestra en nueva pantalla la nueva proforma
  2650.         $arrayBools = array(
  2651.             'lounge' => null,
  2652.             'service' => null,
  2653.             'payment' => null,
  2654.         );
  2655.         $arrayBools['lounge'] = $request->request->get('lounge_hidden_bool');
  2656.         $arrayBools['service'] = $request->request->get('service_hidden_bool');
  2657.         $arrayBools['payment'] = $request->request->get('payment_hidden_bool');
  2658.         $id $request->request->get('reservation_id');
  2659.         $proforma_number $request->request->get('proforma_number');
  2660.         $proforma_prefix $request->request->get('proforma_prefix').'-'.$proforma_number.'-'.$id;
  2661.         //INICIO: buscamos el ID de la factura
  2662. //        $allFacturas = $em->getRepository(ReservationInvoice::class)->findAll();
  2663. //        if (!empty($allFacturas)){
  2664. //            $invoiceId = end($allFacturas)->getId() + 1;
  2665. //        } else {
  2666. //            $invoiceId = 1;
  2667. //        }
  2668.         $boolMakeInvoice false;  // Control para verificar si se debe hacer (PROFORMA) o todos los indicadores (sala, servicios y pagos) estaban en falso
  2669.         //FIN: buscamos el ID de la factura
  2670.         /* Obtengo usuario logueado */
  2671.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2672.         $user_id $user_logueado->getId();
  2673.         //Acumuladores de datos globales de la factura
  2674.         $valorTotalNet 0;
  2675.         $valorVat 0;
  2676. //        $valorTotal = 0;
  2677.         //INICIO: Creamos los items de la proforma
  2678.         if (!empty($arrayBools['lounge'])) {
  2679.             foreach ($arrayBools['lounge'] as $key => $item) {
  2680.                 if ($item == 'true') {
  2681.                     $boolMakeInvoice true;
  2682.                     $sala $em->getRepository(ReservationLoungeSimple::class)->findOneById($key);
  2683.                     $itemProforma = new ReservationInvoiceProformaItems();
  2684.                     $itemProforma->setType('LOUNGE');
  2685.                     $itemProforma->setReservationId($id);
  2686.                     $itemProforma->setProformaId($proforma_number);
  2687.                     $itemProforma->setControlId($key);
  2688.                     $em->persist($itemProforma);
  2689.                     $em->flush();
  2690.                     //Acumulamos neto e iva para la factura (PROFORMA)
  2691.                     $valorTotalNet $valorTotalNet $sala->getServicePrice();
  2692.                     $valorVat $valorVat round(($sala->getServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
  2693.                 }
  2694.             }
  2695.         }
  2696.         if (!empty($arrayBools['service'])) {
  2697.             foreach ($arrayBools['service'] as $key => $item) {
  2698.                 if ($item == 'true') {
  2699.                     $boolMakeInvoice true;
  2700.                     $servicio $em->getRepository(ReservationService::class)->findOneById($key);
  2701.                     $itemProforma = new ReservationInvoiceProformaItems();
  2702.                     $itemProforma->setType('SERVICE');
  2703.                     $itemProforma->setReservationId($id);
  2704.                     $itemProforma->setProformaId($proforma_number);
  2705.                     $itemProforma->setControlId($key);
  2706.                     $em->persist($itemProforma);
  2707.                     $em->flush();
  2708.                     //Acumulamos neto e iva para la factura
  2709.                     if (is_null($servicio->getPrice()) or empty($servicio->getPrice())){
  2710.                         $subtotal 0;
  2711.                         $neto 0;
  2712.                         $subtotalService 0;
  2713.                     } else {
  2714.                         $subtotalService $servicio->getPrice();
  2715.                         $subneto $servicio->getPrice();
  2716.                         // Commission
  2717.                         if ($servicio->getOpCommission()=='1'){
  2718.                             $subtotalService $subtotalService * (+ ($servicio->getCommission()/100));
  2719.                             $subneto $subneto  * (+ ($servicio->getCommission()/100));
  2720.                         } else {
  2721.                             $subtotalService $subtotalService * (- ($servicio->getCommission()/100));
  2722.                             $subneto $subneto * (- ($servicio->getCommission()/100));
  2723.                         }
  2724.                         // Over
  2725.                         if ($servicio->getOpOver()=='1'){
  2726.                             $subtotalService $subtotalService $servicio->getOver();
  2727.                             $subneto $subneto $servicio->getOver();
  2728.                         } else {
  2729.                             $subtotalService $subtotalService $servicio->getOver();
  2730.                             $subneto $subneto $servicio->getOver();
  2731.                         }
  2732.                         // IVA
  2733.                         if ($servicio->getOpIva()=='1'){
  2734.                             $subtotalService $subtotalService * (+ ($servicio->getIva()/100));
  2735.                         } else {
  2736.                             $subtotalService $servicio->getPrice();
  2737.                             $subneto = ($subneto 100) / (100 $servicio->getIva());
  2738.                         }
  2739.                         switch ($servicio->getServiceCatId()){
  2740.                             case 1// Alojamiento
  2741.                                 // el numero de noches $numNoches; precio unitario $subneto
  2742.                                 $numNoches = (($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days;
  2743.                                 // La personas no afectan este calculo
  2744.                                 $subtotal $subtotalService $numNoches $servicio->getUnits();
  2745.                                 $subnetoUnit $subneto;
  2746.                                 $subneto $subneto $numNoches $servicio->getUnits();
  2747.                                 break;
  2748.                             case 2//Actividades
  2749.                                 // El número de personas es considerado en el calculo
  2750.                                 $pax $servicio->getPax();
  2751.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2752.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2753.                                 if ($days 1){
  2754.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y');
  2755.                                 } else {
  2756.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2757.                                 }
  2758.                                 $subtotal $subtotalService $days $servicio->getUnits();
  2759.                                 $subnetoUnit $subneto;
  2760.                                 $subneto $subneto $days $servicio->getUnits();
  2761.                                 break;
  2762.                             case 3// AV
  2763.                                 $pax $servicio->getPax();
  2764.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2765.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2766.                                 if ($days 1){
  2767.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y');
  2768.                                 } else {
  2769.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2770.                                 }
  2771.                                 $unitsServ $servicio->getUnits();
  2772.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2773.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2774.                                 $subnetoUnit $subneto;
  2775.                                 $subneto $subneto $days $unitsServ $pax;
  2776.                                 break;
  2777.                             case 4//Creative
  2778.                                 $pax $servicio->getPax();
  2779.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2780.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2781.                                 if ($days 1){
  2782.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y');
  2783.                                 } else {
  2784.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2785.                                 }
  2786.                                 $unitsServ $servicio->getUnits();
  2787.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2788.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2789.                                 $subnetoUnit $subneto;
  2790.                                 $subneto $subneto $days $unitsServ $pax;
  2791.                                 break;
  2792.                             case 5//Cruise
  2793.                                 $pax $servicio->getPax();
  2794.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2795.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days);
  2796.                                 if ($days 1){
  2797.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y');
  2798.                                 } else {
  2799.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2800.                                 }
  2801.                                 $unitsServ $servicio->getUnits();
  2802.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2803.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2804.                                 $subnetoUnit $subneto;
  2805.                                 $subneto $subneto $days $unitsServ $pax;
  2806.                                 break;
  2807.                             case 6//Entertaiment
  2808.                                 $pax $servicio->getPax();
  2809.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2810.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2811.                                 if ($days 1){
  2812.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y');
  2813.                                 } else {
  2814.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2815.                                 }
  2816.                                 $unitsServ $servicio->getUnits();
  2817.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2818.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2819.                                 $subnetoUnit $subneto;
  2820.                                 $subneto $subneto $days $unitsServ $pax;
  2821.                                 break;
  2822.                             case 7// Gifts
  2823.                                 $pax $servicio->getPax();
  2824.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2825.                                 $days 1;
  2826.                                 if ($days 1){
  2827.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y');
  2828.                                 } else {
  2829.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2830.                                 }
  2831.                                 $unitsServ $servicio->getUnits();
  2832.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2833.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2834.                                 $subnetoUnit $subneto;
  2835.                                 $subneto $subneto $days $unitsServ $pax;
  2836.                                 break;
  2837.                             case 8//Guide
  2838.                                 $pax $servicio->getPax();
  2839.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2840.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2841.                                 $dateServ = ($days 1) ? ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y') : $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2842.                                 $unitsServ $servicio->getUnits();
  2843.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2844.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2845.                                 $subnetoUnit $subneto;
  2846.                                 $subneto $subneto $days $unitsServ $pax;
  2847.                                 break;
  2848.                             case 9//Itineraries
  2849.                                 $pax $servicio->getPax();
  2850.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2851.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2852.                                 $dateServ = ($days 1) ? ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y') : ($servicio->getDateInAt())->format('d/m/Y');
  2853.                                 $unitsServ $servicio->getUnits();
  2854.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2855.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2856.                                 $subnetoUnit $subneto;
  2857.                                 $subneto $subneto $days $unitsServ $pax;
  2858.                                 break;
  2859.                             case 10//Lounge  -- No Aplica
  2860.                                 break;
  2861.                             case 11//Menu
  2862.                                 $pax $servicio->getPax();
  2863.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2864.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2865.                                 if ($days 1){
  2866.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y');
  2867.                                 } else {
  2868.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2869.                                 }
  2870.                                 $unitsServ $servicio->getUnits();
  2871.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2872.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2873.                                 $subnetoUnit $subneto;
  2874.                                 $subneto $subneto $days $unitsServ $pax;
  2875.                                 break;
  2876.                             case 12//Others
  2877.                                 $pax $servicio->getPax();
  2878.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2879.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2880.                                 if ($days 1){
  2881.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y');
  2882.                                 } else {
  2883.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2884.                                 }
  2885.                                 $unitsServ $servicio->getUnits();
  2886.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2887.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2888.                                 $subnetoUnit $subneto;
  2889.                                 $subneto $subneto $days $unitsServ $pax;
  2890.                                 break;
  2891.                             case 13//Transport
  2892.                                 $pax $servicio->getPax();
  2893.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2894.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2895.                                 if ($days 1){
  2896.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y');
  2897.                                 } else {
  2898.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2899.                                 }
  2900.                                 $unitsServ $servicio->getUnits();
  2901.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2902.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2903.                                 $subnetoUnit $subneto;
  2904.                                 $subneto $subneto $days $unitsServ $pax;
  2905.                                 break;
  2906.                             case 14//Technology
  2907.                                 $pax $servicio->getPax();
  2908.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2909.                                 $days 1;
  2910.                                 $dateServ = ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y');
  2911.                                 $unitsServ $servicio->getUnits();
  2912.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2913.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2914.                                 $subnetoUnit $subneto;
  2915.                                 $subneto $subneto $days $unitsServ $pax;
  2916.                                 break;
  2917.                             case 15//Assisstant
  2918.                                 $pax $servicio->getPax();
  2919.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2920.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2921.                                 if ($days 1){
  2922.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y');
  2923.                                 } else {
  2924.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2925.                                 }
  2926.                                 $unitsServ $servicio->getUnits();
  2927.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2928.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2929.                                 $subnetoUnit $subneto;
  2930.                                 $subneto $subneto $days $unitsServ $pax;
  2931.                                 break;
  2932.                             case 16//DDR
  2933.                                 $pax $servicio->getPax();
  2934.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2935.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2936.                                 if ($days 1){
  2937.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y');
  2938.                                 } else {
  2939.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2940.                                 }
  2941.                                 $unitsServ $servicio->getUnits();
  2942.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2943.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2944.                                 $subnetoUnit $subneto;
  2945.                                 $subneto $subneto $days $unitsServ $pax;
  2946.                                 break;
  2947.                             case 17//Seguridad
  2948.                                 $pax $servicio->getPax();
  2949.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2950.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2951.                                 $dateServ = ($days 1) ? ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y') : ($servicio->getDateInAt())->format('d/m/Y');
  2952.                                 $unitsServ $servicio->getUnits();
  2953.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2954.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2955.                                 $subnetoUnit $subneto;
  2956.                                 $subneto $subneto $days $unitsServ $pax;
  2957.                                 break;
  2958.                             case 18//WiFi
  2959.                                 $pax $servicio->getPax();
  2960.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2961.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2962.                                 $dateServ = ($days 1) ? ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y') : ($servicio->getDateInAt())->format('d/m/Y');
  2963.                                 $unitsServ $servicio->getUnits();
  2964.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2965.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2966.                                 $subnetoUnit $subneto;
  2967.                                 $subneto $subneto $days $unitsServ $pax;
  2968.                                 break;
  2969.                             case 19//Mobiliario
  2970.                                 $pax $servicio->getPax();
  2971.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2972.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2973.                                 $dateServ = ($days 1) ? ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y') : ($servicio->getDateInAt())->format('d/m/Y');
  2974.                                 $unitsServ $servicio->getUnits();
  2975.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2976.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2977.                                 $subnetoUnit $subneto;
  2978.                                 $subneto $subneto $days $unitsServ $pax;
  2979.                                 break;
  2980.                             case 20//Parking
  2981.                                 $pax $servicio->getPax();
  2982.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2983.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2984.                                 $dateServ = ($days 1) ? ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y') : ($servicio->getDateInAt())->format('d/m/Y');
  2985.                                 $unitsServ $servicio->getUnits();
  2986.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2987.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2988.                                 $subnetoUnit $subneto;
  2989.                                 $subneto $subneto $days $unitsServ $pax;
  2990.                                 break;
  2991.                             case 21//Limpieza
  2992.                                 $pax $servicio->getPax();
  2993.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  2994.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2995.                                 $dateServ = ($days 1) ? ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y') : ($servicio->getDateInAt())->format('d/m/Y');
  2996.                                 $unitsServ $servicio->getUnits();
  2997.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  2998.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2999.                                 $subnetoUnit $subneto;
  3000.                                 $subneto $subneto $days $unitsServ $pax;
  3001.                                 break;
  3002.                             default: //Others (por default)
  3003.                                 $pax $servicio->getPax();
  3004.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  3005.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  3006.                                 if ($days 1){
  3007.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y'). ' - '.($servicio->getDateOutAt())->format('d/m/Y');
  3008.                                 } else {
  3009.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  3010.                                 }
  3011.                                 $unitsServ $servicio->getUnits();
  3012.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  3013.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3014.                                 $subnetoUnit $subneto;
  3015.                                 $subneto $subneto $days $unitsServ $pax;
  3016.                                 break;
  3017.                         }
  3018.                         // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  3019.                         $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  3020.                         $neto round($subneto,2,PHP_ROUND_HALF_UP);
  3021.                         $valorTotalNet $valorTotalNet $neto;
  3022.                         $valorVat $valorVat + ($subtotal $neto);
  3023.                     }
  3024.                 }
  3025.             }
  3026.         }
  3027.         if (!empty($arrayBools['payment'])) {
  3028.             foreach ($arrayBools['payment'] as $key => $item) {
  3029.                 if ($item == 'true') {
  3030.                     $boolMakeInvoice true;
  3031.                     $pago $em->getRepository(ReservationPaymentsClient::class)->findOneById($key);
  3032.                     $itemProforma = new ReservationInvoiceProformaItems();
  3033.                     $itemProforma->setType('PAYMENT');
  3034.                     $itemProforma->setReservationId($id);
  3035.                     $itemProforma->setProformaId($proforma_number);
  3036.                     $itemProforma->setControlId($key);
  3037.                     $em->persist($itemProforma);
  3038.                     $em->flush();
  3039.                 }
  3040.             }
  3041.         }
  3042.         //FIN: Creamos los items de la proforma
  3043.         $valorTotal $valorTotalNet $valorVat;
  3044.         //INICIO: Creamos la proforma
  3045.         $newProforma = new ReservationProforma();
  3046.         $newProforma->setPrefix("GPP-".date('dmy')."-".$id);
  3047.         $newProforma->setDateAt(new DateTime('now'));
  3048.         $newProforma->setReservationId($id);
  3049.         $newProforma->setCreatedAt(new DateTime('now'));
  3050.         $newProforma->setCreatedId($user_id);
  3051.         $newProforma->setUpdatedAt(new DateTime('now'));
  3052.         $newProforma->setUpdatedId($user_id);
  3053.         $newProforma->setItems(null);
  3054.         $newProforma->setAccessKey(null);
  3055.         if ($boolMakeInvoice){
  3056.             // Solo se debe crear factura si hay un elemento
  3057.             $em->persist($newProforma);
  3058.             $em->flush();
  3059.         } else {
  3060.             // Se llama a la vista de facturas del expediente
  3061.             return $this->redirectToRoute('reservations_viewreservation_proformas',array('id' => $id));
  3062.         }
  3063.         //FIN: Creamos la proforma
  3064.         $data = array();
  3065.         $data $this->baseInvoiceSelectedReservation($id$arrayBools,'P'.$newProforma->getId());
  3066.         $paymentsClient = new ReservationPaymentsClient();
  3067.         $paymentsClient->setReservationId($id);
  3068.         $form $this->createReservationPaymentsClientForm($paymentsClient);
  3069.         $reserva $em->getRepository(Reservation::class)->findOneById($id);
  3070.         $payments $em->getRepository(ReservationPaymentsClient::class)->findByReservationId($id);
  3071.         $services $em->getRepository(ReservationService::class)->findByReservationId($id);
  3072.         $proforma $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
  3073.         $reservaInv = new ReservationInvoice();
  3074.         $reservaInv->setReservationId($id);
  3075.         $form1 $this->createReservationInvoiceProformaForm($reservaInv);
  3076.         $idLounges = array();
  3077.         $loungesBoolToInvoice = array();
  3078.         if (array_key_exists('lounge',$data['datasupplier'])) {
  3079.             foreach ($data['datasupplier']['lounge'] as $item) {
  3080.                 $idLounges[] = $item['id'];
  3081.                 $loungesBoolToInvoice[] = 1;
  3082.             }
  3083.             $idLounges implode(','$idLounges);
  3084.             $loungesBoolToInvoice implode(','$loungesBoolToInvoice);
  3085.         } else {
  3086.             $idLounges '0';
  3087.             $loungesBoolToInvoice '0';
  3088.         }
  3089.         $idPayments = array();
  3090.         $paymentsBoolToInvoice = array();
  3091.         if (array_key_exists('payment',$data['datasupplier'])) {
  3092.             foreach ($data['datasupplier']['payment'] as $item) {
  3093.                 $idPayments[] = $item['id'];
  3094.                 $paymentsBoolToInvoice[] = 1;
  3095.             }
  3096.             $idPayments implode(','$idPayments);
  3097.             $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  3098.             // Se han generado dos arreglos, cada uno dividido en 2 strings
  3099.             // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  3100.             // Para manipularlos entre la vista y el JS
  3101.         } else {
  3102.             $idPayments '0';
  3103.             $paymentsBoolToInvoice '0';
  3104.         }
  3105.         // Una factura solo se puede rectificar una vez
  3106. //        $rectf = $em->getRepository(ReservationInvoiceRec::class)->findBy( array('number' => 'REC-'.$newInvoice->getNumber()));
  3107. //        $boolToRec = empty($rectf);
  3108.         $boolToRec false;
  3109.         $allInvoices $em->getRepository(ReservationInvoice::class)->findByReservationId($id);
  3110.         $allInvoicesRec $em->getRepository(ReservationInvoiceRec::class)->findByReservationId($id);
  3111.         foreach ($allInvoicesRec as $item){
  3112.             array_push($allInvoices$item);
  3113.         }
  3114.         $allProformas $em->getRepository(ReservationProforma::class)->findByReservationId($id);
  3115.         if(empty($data['type'])){$data['type'] = 'Proforma';}
  3116.         return $this->redirectToRoute('reservations_viewnew_proforma',array('id' => $newProforma->getId()));
  3117.     }
  3118.     /**
  3119.      * @Route("/reservations/invoice/viewnew/{id}",  name="reservations_viewnew_invoice")
  3120.      */
  3121.     public function viewNewInvoiceAction($idRequest $request)
  3122.     {
  3123.         $em $this->getDoctrine()->getManager();
  3124.         // Se genera y muestra en nueva pantalla la nueva proforma
  3125.         $arrayBools = array(
  3126.             'lounge' => null,
  3127.             'service' => null,
  3128.             'payment' => null,
  3129.         );
  3130.         $arrayBools['lounge'] = $request->request->get('inv_lounge_hidden_bool');
  3131.         $arrayBools['service'] = $request->request->get('inv_service_hidden_bool');
  3132.         $arrayBools['payment'] = $request->request->get('inv_payment_hidden_bool');
  3133.         /* Obtengo usuario logueado */
  3134.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  3135.         $user_id $user_logueado->getId();
  3136.         //Acumuladores de datos globales de la factura
  3137.         $valorTotalNet 0;
  3138.         $valorVat 0;
  3139. //        $valorTotal = 0;
  3140.         //INICIO: Creamos los items de la factura
  3141.         $arrayInvoicedItems $em->getRepository(ReservationInvoiceItems::class)->findByInvoiceId($id);
  3142.         if (!empty($arrayInvoicedItems)) {
  3143.             foreach ($arrayInvoicedItems as $itemInvoice) {
  3144.                 if ($itemInvoice->getItemType() == 'LOUNGE') {
  3145.                     //Acumulamos neto e iva para la factura
  3146.                     $valorTotalNet $valorTotalNet $itemInvoice->getLngServicePrice();
  3147.                     $valorVat $valorVat round(($itemInvoice->getLngServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
  3148.                 }
  3149.             }
  3150.         }
  3151.         if (!empty($arrayInvoicedItems)) {
  3152.             foreach ($arrayInvoicedItems as $itemInvoice) {
  3153.                 if ($itemInvoice->getItemType() == 'SERVICE') {
  3154.                     //Acumulamos neto e iva para la factura
  3155.                     if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())){
  3156.                         $subtotal 0;
  3157.                         $neto 0;
  3158.                         $subtotalService 0;
  3159.                     } else {
  3160.                         $subtotalService $itemInvoice->getSrvPrice();
  3161.                         $subtotalService str_replace(',','.',$subtotalService);
  3162.                         $subtotalService floatval($subtotalService);
  3163.                         $subneto $itemInvoice->getSrvPrice();
  3164.                         // Commission
  3165.                         if ($itemInvoice->getSrvOpCommission()=='1'){
  3166.                             if (!($itemInvoice->getSrvCommission()=='0')) {
  3167.                                 $subtotalService $subtotalService * (+ ($itemInvoice->getSrvCommission() / 100));
  3168.                                 $subneto $subneto * (+ ($itemInvoice->getSrvCommission() / 100));
  3169.                             }
  3170.                         } else {
  3171.                             $subtotalService $subtotalService * (- ($itemInvoice->getSrvCommission()/100));
  3172.                             $subneto $subneto * (- ($itemInvoice->getSrvCommission()/100));
  3173.                         }
  3174.                         // Over
  3175.                         if ($itemInvoice->getSrvOpOver()=='1'){
  3176.                             if (!($itemInvoice->getSrvOver()=='0')) {
  3177.                                 $subtotalService $subtotalService $itemInvoice->getSrvOver();
  3178.                                 $subneto $subneto $itemInvoice->getSrvOver();
  3179.                             }
  3180.                         } else {
  3181.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  3182.                             $subneto $subneto $itemInvoice->getSrvOver();
  3183.                         }
  3184.                         // IVA
  3185.                         if ($itemInvoice->getSrvOpIva()=='1'){
  3186.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvIva()/100));
  3187.                         } else {
  3188.                             $subtotalService $itemInvoice->getSrvPrice();
  3189.                             $subneto = ($subneto 100) / (100 $itemInvoice->getSrvIva());
  3190.                         }
  3191.                         $subneto str_replace(',','.',$subneto);
  3192.                         $subneto floatval($subneto);
  3193.                         switch ($itemInvoice->getSrvServiceCatId()){
  3194.                             case 1// Alojamiento
  3195.                                 // el numero de noches $numNoches; precio unitario $subneto
  3196.                                 $numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
  3197.                                 // La personas no afectan este calculo
  3198.                                 $subtotal $subtotalService $numNoches $itemInvoice->getSrvUnits();
  3199.                                 $subnetoUnit $subneto;
  3200.                                 $subneto $subneto $numNoches $itemInvoice->getSrvUnits();
  3201.                                 break;
  3202.                             case 2//Actividades
  3203.                                 // El número de personas es considerado en el calculo
  3204.                                 $pax $itemInvoice->getSrvPax();
  3205.                                 if (empty($pax) or $pax == "0") {
  3206.                                     $pax 1;
  3207.                                 }
  3208.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3209.                                 if ($days 1){
  3210.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3211.                                 } else {
  3212.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3213.                                 }
  3214.                                 $subtotal $subtotalService $days $itemInvoice->getSrvUnits();
  3215.                                 $subnetoUnit $subneto;
  3216.                                 $subneto $subneto $days $itemInvoice->getSrvUnits();
  3217.                                 break;
  3218.                             case 3// AV
  3219.                                 $pax $itemInvoice->getSrvPax();
  3220.                                 if (empty($pax) or $pax == "0") {
  3221.                                     $pax 1;
  3222.                                 }
  3223.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3224.                                 if ($days 1){
  3225.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3226.                                 } else {
  3227.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3228.                                 }
  3229.                                 $unitsServ $itemInvoice->getSrvUnits();
  3230.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3231.                                     $unitsServ 1;
  3232.                                 }
  3233.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3234.                                 $subnetoUnit $subneto;
  3235.                                 $subneto $subneto $days $unitsServ $pax;
  3236.                                 break;
  3237.                             case 4//Creative
  3238.                                 $pax $itemInvoice->getSrvPax();
  3239.                                 if (empty($pax) or $pax == "0") {
  3240.                                     $pax 1;
  3241.                                 }
  3242.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3243.                                 if ($days 1){
  3244.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3245.                                 } else {
  3246.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3247.                                 }
  3248.                                 $unitsServ $itemInvoice->getSrvUnits();
  3249.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3250.                                     $unitsServ 1;
  3251.                                 }
  3252.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3253.                                 $subnetoUnit $subneto;
  3254.                                 $subneto $subneto $days $unitsServ $pax;
  3255.                                 break;
  3256.                             case 5//Cruise
  3257.                                 $pax $itemInvoice->getSrvPax();
  3258.                                 if (empty($pax) or $pax == "0") {
  3259.                                     $pax 1;
  3260.                                 }
  3261.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
  3262.                                 if ($days 1){
  3263.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3264.                                 } else {
  3265.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3266.                                 }
  3267.                                 $unitsServ $itemInvoice->getSrvUnits();
  3268.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3269.                                     $unitsServ 1;
  3270.                                 }
  3271.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3272.                                 $subnetoUnit $subneto;
  3273.                                 $subneto $subneto $days $unitsServ $pax;
  3274.                                 break;
  3275.                             case 6//Entertaiment
  3276.                                 $pax $itemInvoice->getSrvPax();
  3277.                                 if (empty($pax) or $pax == "0") {
  3278.                                     $pax 1;
  3279.                                 }
  3280.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3281.                                 if ($days 1){
  3282.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3283.                                 } else {
  3284.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3285.                                 }
  3286.                                 $unitsServ $itemInvoice->getSrvUnits();
  3287.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3288.                                     $unitsServ 1;
  3289.                                 }
  3290.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3291.                                 $subnetoUnit $subneto;
  3292.                                 $subneto $subneto $days $unitsServ $pax;
  3293.                                 break;
  3294.                             case 7// Gifts
  3295.                                 $pax $itemInvoice->getSrvPax();
  3296.                                 if (empty($pax) or $pax == "0") {
  3297.                                     $pax 1;
  3298.                                 }
  3299.                                 $days 1;
  3300.                                 if ($days 1){
  3301.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3302.                                 } else {
  3303.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3304.                                 }
  3305.                                 $unitsServ $itemInvoice->getSrvUnits();
  3306.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3307.                                     $unitsServ 1;
  3308.                                 }
  3309.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3310.                                 $subnetoUnit $subneto;
  3311.                                 $subneto $subneto $days $unitsServ $pax;
  3312.                                 break;
  3313.                             case 8//Guide
  3314.                                 $pax $itemInvoice->getSrvPax();
  3315.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  3316.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3317.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3318.                                 $unitsServ $itemInvoice->getSrvUnits();
  3319.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  3320.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3321.                                 $subnetoUnit $subneto;
  3322.                                 $subneto $subneto $days $unitsServ $pax;
  3323.                                 break;
  3324.                             case 9//Itineraries
  3325.                                 $pax $itemInvoice->getSrvPax();
  3326.                                 if (empty($pax) or $pax == "0") {
  3327.                                     $pax 1;
  3328.                                 }
  3329.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3330.                                 if ($days 1){
  3331.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3332.                                 } else {
  3333.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3334.                                 }
  3335.                                 $unitsServ $itemInvoice->getSrvUnits();
  3336.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3337.                                     $unitsServ 1;
  3338.                                 }
  3339.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3340.                                 $subnetoUnit $subneto;
  3341.                                 $subneto $subneto $days $unitsServ $pax;
  3342.                                 break;
  3343.                             case 10//Lounge  -- No Aplica
  3344.                                 break;
  3345.                             case 11//Menu
  3346.                                 $pax $itemInvoice->getSrvPax();
  3347.                                 if (empty($pax) or $pax == "0") {
  3348.                                     $pax 1;
  3349.                                 }
  3350.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3351.                                 if ($days 1){
  3352.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3353.                                 } else {
  3354.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3355.                                 }
  3356.                                 $unitsServ $itemInvoice->getSrvUnits();
  3357.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3358.                                     $unitsServ 1;
  3359.                                 }
  3360.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3361.                                 $subnetoUnit $subneto;
  3362.                                 $subneto $subneto $days $unitsServ $pax;
  3363.                                 break;
  3364.                             case 12//Others
  3365.                                 $pax $itemInvoice->getSrvPax();
  3366.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  3367.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3368.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3369.                                 $unitsServ $itemInvoice->getSrvUnits();
  3370.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; } else { $unitsServ intval($unitsServ); }
  3371.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3372.                                 $subnetoUnit $subneto;
  3373.                                 $subneto $subneto $days $unitsServ $pax;
  3374.                                 break;
  3375.                             case 13//Transport
  3376.                                 $pax $itemInvoice->getSrvPax();
  3377.                                 if (empty($pax) or $pax == "0") {
  3378.                                     $pax 1;
  3379.                                 }
  3380.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3381.                                 if ($days 1){
  3382.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3383.                                 } else {
  3384.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3385.                                 }
  3386.                                 $unitsServ $itemInvoice->getSrvUnits();
  3387.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3388.                                     $unitsServ 1;
  3389.                                 }
  3390.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3391.                                 $subnetoUnit $subneto;
  3392.                                 $subneto $subneto $days $unitsServ $pax;
  3393.                                 break;
  3394.                             case 14//Technology
  3395.                                 $pax $itemInvoice->getSrvPax();
  3396.                                 if (empty($pax) or $pax == "0") {
  3397.                                     $pax 1;
  3398.                                 }
  3399.                                 $days 1;
  3400.                                 $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3401.                                 $unitsServ $itemInvoice->getSrvUnits();
  3402.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3403.                                     $unitsServ 1;
  3404.                                 }
  3405.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3406.                                 $subnetoUnit $subneto;
  3407.                                 $subneto $subneto $days $unitsServ $pax;
  3408.                                 break;
  3409.                             case 15//Assisstant
  3410.                                 $pax $itemInvoice->getSrvPax();
  3411.                                 if (empty($pax) or $pax == "0") {
  3412.                                     $pax 1;
  3413.                                 }
  3414.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3415.                                 if ($days 1){
  3416.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3417.                                 } else {
  3418.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3419.                                 }
  3420.                                 $unitsServ $itemInvoice->getSrvUnits();
  3421.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3422.                                     $unitsServ 1;
  3423.                                 }
  3424.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3425.                                 $subnetoUnit $subneto;
  3426.                                 $subneto $subneto $days $unitsServ $pax;
  3427.                                 break;
  3428.                             case 16//DDR
  3429.                                 $pax $itemInvoice->getSrvPax();
  3430.                                 if (empty($pax) or $pax == "0") {
  3431.                                     $pax 1;
  3432.                                 }
  3433.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3434.                                 if ($days 1){
  3435.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3436.                                 } else {
  3437.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3438.                                 }
  3439.                                 $unitsServ $itemInvoice->getSrvUnits();
  3440.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3441.                                     $unitsServ 1;
  3442.                                 }
  3443.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3444.                                 $subnetoUnit $subneto;
  3445.                                 $subneto $subneto $days $unitsServ $pax;
  3446.                                 break;
  3447.                             case 17//Seguridad
  3448.                                 $pax $itemInvoice->getSrvPax();
  3449.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  3450.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3451.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3452.                                 $unitsServ $itemInvoice->getSrvUnits();
  3453.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  3454.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3455.                                 $subnetoUnit $subneto;
  3456.                                 $subneto $subneto $days $unitsServ $pax;
  3457.                                 break;
  3458.                             case 18//WiFi
  3459.                                 $pax $itemInvoice->getSrvPax();
  3460.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  3461.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3462.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3463.                                 $unitsServ $itemInvoice->getSrvUnits();
  3464.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  3465.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3466.                                 $subnetoUnit $subneto;
  3467.                                 $subneto $subneto $days $unitsServ $pax;
  3468.                                 break;
  3469.                             case 19//Mobiliario
  3470.                                 $pax $itemInvoice->getSrvPax();
  3471.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  3472.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3473.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3474.                                 $unitsServ $itemInvoice->getSrvUnits();
  3475.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  3476.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3477.                                 $subnetoUnit $subneto;
  3478.                                 $subneto $subneto $days $unitsServ $pax;
  3479.                                 break;
  3480.                             case 20//Parking
  3481.                                 $pax $itemInvoice->getSrvPax();
  3482.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  3483.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3484.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3485.                                 $unitsServ $itemInvoice->getSrvUnits();
  3486.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  3487.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3488.                                 $subnetoUnit $subneto;
  3489.                                 $subneto $subneto $days $unitsServ $pax;
  3490.                                 break;
  3491.                             case 21//Limpieza
  3492.                                 $pax $itemInvoice->getSrvPax();
  3493.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  3494.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3495.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3496.                                 $unitsServ $itemInvoice->getSrvUnits();
  3497.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  3498.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3499.                                 $subnetoUnit $subneto;
  3500.                                 $subneto $subneto $days $unitsServ $pax;
  3501.                                 break;
  3502.                             default: //Others (por default)
  3503.                                 $pax $itemInvoice->getSrvPax();
  3504.                                 if (empty($pax) or $pax == "0") { $pax 1; }
  3505.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3506.                                 $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3507.                                 $unitsServ $itemInvoice->getSrvUnits();
  3508.                                 if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; } else { $unitsServ intval($unitsServ); }
  3509.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3510.                                 $subnetoUnit $subneto;
  3511.                                 $subneto $subneto $days $unitsServ $pax;
  3512.                                 break;
  3513.                         }
  3514.                         // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  3515.                         $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  3516.                         $neto round($subneto,2,PHP_ROUND_HALF_UP);
  3517.                         $valorTotalNet $valorTotalNet $neto;
  3518.                         $valorVat $valorVat + ($subtotal $neto);
  3519.                     }
  3520.                 }
  3521.             }
  3522.         }
  3523.         if (!empty($arrayInvoicedItems)) {
  3524.             foreach ($arrayInvoicedItems as $itemInvoice) {
  3525.                 if ($itemInvoice->getItemType() == 'PAYMENT') {
  3526. //                    $pago = $em->getRepository(ReservationPaymentsClient::class)->findOneById($key);
  3527. //
  3528. //                    $itemInvoice = new ReservationInvoiceItems();
  3529. //                    $itemInvoice->setReservationId($id);
  3530. //                    $itemInvoice->setInvoiceId($invoiceId);
  3531. //                    $itemInvoice->setItemType('PAYMENT');
  3532. //                    $itemInvoice->setPayControlId($key);
  3533. //                    $itemInvoice->setPayAmount($pago->getAmount());
  3534. //                    $itemInvoice->setPayDatePayAt($pago->getDatePayAt());
  3535. //                    $itemInvoice->setPayWayToPay($pago->getWayToPay());
  3536. //                    $itemInvoice->setCreatedAt(new DateTime('now'));
  3537. //                    $itemInvoice->setUpdatedAt(new DateTime('now'));
  3538. //                    $itemInvoice->setCreatedId($user_id);
  3539. //                    $itemInvoice->setUpdatedId($user_id);
  3540. //
  3541. //                    $em->persist($itemInvoice);
  3542. //                    $em->flush();
  3543.                     //Acumulamos neto e iva para la factura
  3544.                     //$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();    // El pago no puede afectar el neto de la factura
  3545.                 }
  3546.             }
  3547.         }
  3548.         //FIN: Creamos los items de la factura
  3549.         $valorTotal $valorTotalNet $valorVat;
  3550.         //INICIO: Creamos la factura
  3551. //        $newInvoice = new ReservationInvoice();
  3552. //        $newInvoice->setNumber("GPF-".date('dmy')."-".$id);
  3553. //        $newInvoice->setDateAt(new DateTime('now'));
  3554. //        $newInvoice->setType('Invoice');
  3555. //        $newInvoice->setReservationId($id);
  3556. //        $newInvoice->setTotalNet($valorTotalNet);
  3557. //        $newInvoice->setVat($valorVat);
  3558. //        $newInvoice->setTotal($valorTotal);
  3559. //        $newInvoice->setCreatedAt(new DateTime('now'));
  3560. //        $newInvoice->setCreatedId($user_id);
  3561. //        $newInvoice->setUpdatedAt(new DateTime('now'));
  3562. //        $newInvoice->setUpdatedId($user_id);
  3563. //        $newInvoice->setMaster('master');
  3564. //
  3565. //        $em->persist($newInvoice);
  3566. //        $em->flush();
  3567. //
  3568. //        $newInvoice->setNumber($newInvoice->getNumber().'-'.$newInvoice->getId());
  3569. //
  3570. //        $em->persist($newInvoice);
  3571. //        $em->flush();
  3572.         $newInvoice $em->getRepository(ReservationInvoice::class)->findOneById($id);
  3573.         //FIN: Creamos la factura
  3574.         $data = array();
  3575.         $data $this->baseInvoiceDoneReservation($newInvoice->getReservationId(), $id,'I');
  3576.         $paymentsClient = new ReservationPaymentsClient();
  3577.         $paymentsClient->setReservationId($id);
  3578.         $reservaInv = new ReservationInvoice();
  3579.         $reservaInv->setReservationId($id);
  3580.         $idLounges = array();
  3581.         $loungesBoolToInvoice = array();
  3582.         if (array_key_exists('lounge',$data['datasupplier'])) {
  3583.             foreach ($data['datasupplier']['lounge'] as $item) {
  3584.                 $idLounges[] = $item['id'];
  3585.                 $loungesBoolToInvoice[] = 1;
  3586.             }
  3587.             $idLounges implode(','$idLounges);
  3588.             $loungesBoolToInvoice implode(','$loungesBoolToInvoice);
  3589.         } else {
  3590.             $idLounges '0';
  3591.             $loungesBoolToInvoice '0';
  3592.         }
  3593.         $idPayments = array();
  3594.         $paymentsBoolToInvoice = array();
  3595.         if (array_key_exists('payment',$data['datasupplier'])) {
  3596.             foreach ($data['datasupplier']['payment'] as $item) {
  3597.                 $idPayments[] = $item['id'];
  3598.                 $paymentsBoolToInvoice[] = 1;
  3599.             }
  3600.             $idPayments implode(','$idPayments);
  3601.             $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  3602.             // Se han generado dos arreglos, cada uno dividido en 2 strings
  3603.             // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  3604.             // Para manipularlos entre la vista y el JS
  3605.         } else {
  3606.             $idPayments '0';
  3607.             $paymentsBoolToInvoice '0';
  3608.         }
  3609.         // Una factura solo se puede rectificar una vez
  3610.         $rectf $em->getRepository(ReservationInvoiceRec::class)->findBy( array('number' => 'REC-'.$newInvoice->getNumber()));
  3611.         $boolToRec = empty($rectf);
  3612.         $allInvoices $em->getRepository(ReservationInvoice::class)->findByReservationId($newInvoice->getReservationId());
  3613.         $allInvoicesRec $em->getRepository(ReservationInvoiceRec::class)->findByReservationId($newInvoice->getReservationId());
  3614.         foreach ($allInvoicesRec as $item){
  3615.             array_push($allInvoices$item);
  3616.         }
  3617.         $allProformas $em->getRepository(ReservationProforma::class)->findByReservationId($newInvoice->getReservationId());
  3618.         if(empty($data['type'])){$data['type'] = 'Invoice';}
  3619.         $reservaEquis $em->getRepository(Reservation::class)->findOneById($newInvoice->getReservationId());
  3620.         if(empty($newInvoice->getClientName()) and empty($newInvoice->getClientAddress()) and empty($newInvoice->getClientDocument())){
  3621.             $newInvoice $this->clientDataToInvoice($newInvoice'Client'$reservaEquis->getClient(), $newInvoice->getReservationId());
  3622.         }
  3623.         return $this->render('MDS/GreenPatioBundle/reservations/invoice-new-invoice.html.twig',
  3624.             array(
  3625.                 'id' => $newInvoice->getReservationId(),
  3626.                 'cid' => '',
  3627.                 'fid' => $id,
  3628.                 'invoice' => $allInvoices,
  3629.                 'proformas' => $allProformas,
  3630.                 'boolToRec' => $boolToRec,
  3631.                 'numberadmin' => '',
  3632.                 'type' => $data['type'],
  3633.                 'number' => $newInvoice->getId(),
  3634.                 'prefix' => $data['prefix'],
  3635.                 'date' => $data['date'],
  3636.                 'token' =>  $data['token'],
  3637.                 'reservation' => $data['reservation'],
  3638.                 'company' => $data['company'],
  3639.                 'clients' => $data['clients'],
  3640.                 'user' => $user_logueado,
  3641.                 'invoicedeposititems' => '',
  3642.                 'arrayItems' => $data['arrayItems'],
  3643.                 'datasupplier' => $data['datasupplier'],
  3644.                 'totales_neto' => $data['totales_neto'],
  3645.                 'totales_iva' => '',
  3646.                 'totales' => $data['totales'],
  3647.                 'bases_imponibles' => $data['bases_imponibles'],
  3648.                 'balance' => $data['balance'],
  3649.                 'paymentInvoice' => $data['paymentInvoice'],
  3650.                 'currency' => $data['currency'],
  3651.                 'clientName' => $newInvoice->getClientName(),
  3652.                 'clientAddress' => $newInvoice->getClientAddress(),
  3653.                 'clientDocument' => $newInvoice->getClientDocument(),
  3654.             )
  3655.         );
  3656.     }
  3657.     /**
  3658.      * @Route("/reservations/invoice/viewnewprof/{id}",  name="reservations_viewnew_proforma")
  3659.      */
  3660.     public function viewNewProformaAction($idRequest $request)
  3661.     {
  3662.         $em $this->getDoctrine()->getManager();
  3663.         // Se genera y muestra en nueva pantalla la nueva proforma
  3664.         $arrayBools = array(
  3665.             'lounge' => null,
  3666.             'service' => null,
  3667.             'payment' => null,
  3668.         );
  3669.         $arrayBools['lounge'] = $request->request->get('inv_lounge_hidden_bool');
  3670.         $arrayBools['service'] = $request->request->get('inv_service_hidden_bool');
  3671.         $arrayBools['payment'] = $request->request->get('inv_payment_hidden_bool');
  3672. //        $id = $request->request->get('inv_reservation_id');
  3673.         //INICIO: buscamos el ID de la factura
  3674. //        $allFacturas = $em->getRepository(ReservationInvoice::class)->findAll();
  3675. //        $invoiceId = end($allFacturas)->getId() + 1;
  3676.         //FIN: buscamos el ID de la factura
  3677.         /* Obtengo usuario logueado */
  3678.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  3679.         $user_id $user_logueado->getId();
  3680.         //Acumuladores de datos globales de la factura
  3681.         $valorTotalNet 0;
  3682.         $valorVat 0;
  3683. //        $valorTotal = 0;
  3684.         //INICIO: Creamos los items de la proforma
  3685.         $arrayInvoicedItems $em->getRepository(ReservationInvoiceProformaItems::class)->findByProformaId($id);
  3686.         if (!empty($arrayInvoicedItems)) {
  3687.             foreach ($arrayInvoicedItems as $itemInvoice) {
  3688.                 if ($itemInvoice->getType() == 'LOUNGE') {
  3689.                     $salaPro $em->getRepository(ReservationLoungeSimple::class)->findOneById($itemInvoice->getControlId());
  3690.                     if(!empty($salaPro)) {
  3691.                         //Acumulamos neto e iva para la factura
  3692.                         $valorTotalNet $valorTotalNet $salaPro->getServicePrice();
  3693.                         $valorVat $valorVat round(($salaPro->getServicePrice() * 0.21), 2PHP_ROUND_HALF_UP);
  3694.                     }
  3695.                 }
  3696.             }
  3697.         }
  3698.         if (!empty($arrayInvoicedItems)) {
  3699.             foreach ($arrayInvoicedItems as $itemInvoice) {
  3700.                 if ($itemInvoice->getType() == 'SERVICE') {
  3701.                     $servicePro $em->getRepository(ReservationService::class)->findOneById($itemInvoice->getControlId());
  3702.                     if(!empty($servicePro)) {
  3703.                         //Acumulamos neto e iva para la factura
  3704.                         if (is_null($servicePro->getPrice()) or empty($servicePro->getPrice())) {
  3705.                             $subtotal 0;
  3706.                             $neto 0;
  3707.                             $subtotalService 0;
  3708.                         } else {
  3709.                             $subtotalService $servicePro->getPrice();
  3710.                             $subneto $servicePro->getPrice();
  3711.                             // Commission
  3712.                             if ($servicePro->getOpCommission() == '1') {
  3713.                                 $subtotalService $subtotalService * (+ ($servicePro->getCommission() / 100));
  3714.                                 $subneto $subneto * (+ ($servicePro->getCommission() / 100));
  3715.                             } else {
  3716.                                 $subtotalService $subtotalService * (- ($servicePro->getCommission() / 100));
  3717.                                 $subneto $subneto * (- ($servicePro->getCommission() / 100));
  3718.                             }
  3719.                             // Over
  3720.                             if ($servicePro->getOpOver() == '1') {
  3721.                                 $subtotalService $subtotalService $servicePro->getOver();
  3722.                                 $subneto $subneto $servicePro->getOver();
  3723.                             } else {
  3724.                                 $subtotalService $subtotalService $servicePro->getOver();
  3725.                                 $subneto $subneto $servicePro->getOver();
  3726.                             }
  3727.                             // IVA
  3728.                             if ($servicePro->getOpIva() == '1') {
  3729.                                 $subtotalService $subtotalService * (+ ($servicePro->getIva() / 100));
  3730.                             } else {
  3731.                                 $subtotalService $servicePro->getPrice();
  3732.                                 $subneto = ($subneto 100) / (100 $servicePro->getIva());
  3733.                             }
  3734.                             switch ($servicePro->getServiceCatId()) {
  3735.                                 case 1// Alojamiento
  3736.                                     // el numero de noches $numNoches; precio unitario $subneto
  3737.                                     $numNoches = (($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days;
  3738.                                     // La personas no afectan este calculo
  3739.                                     $subtotal $subtotalService $numNoches $servicePro->getUnits();
  3740.                                     $subnetoUnit $subneto;
  3741.                                     $subneto $subneto $numNoches $servicePro->getUnits();
  3742.                                     break;
  3743.                                 case 2//Actividades
  3744.                                     // El número de personas es considerado en el calculo
  3745.                                     $pax $servicePro->getPax();
  3746.                                     if (empty($pax) or $pax == "0") {
  3747.                                         $pax 1;
  3748.                                     }
  3749.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  3750.                                     if ($days 1) {
  3751.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y');
  3752.                                     } else {
  3753.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y');
  3754.                                     }
  3755.                                     $subtotal $subtotalService $days $servicePro->getUnits();
  3756.                                     $subnetoUnit $subneto;
  3757.                                     $subneto $subneto $days $servicePro->getUnits();
  3758.                                     break;
  3759.                                 case 3// AV
  3760.                                     $pax $servicePro->getPax();
  3761.                                     if (empty($pax) or $pax == "0") {
  3762.                                         $pax 1;
  3763.                                     }
  3764.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  3765.                                     if ($days 1) {
  3766.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y');
  3767.                                     } else {
  3768.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y');
  3769.                                     }
  3770.                                     $unitsServ $servicePro->getUnits();
  3771.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3772.                                         $unitsServ 1;
  3773.                                     }
  3774.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3775.                                     $subnetoUnit $subneto;
  3776.                                     $subneto $subneto $days $unitsServ $pax;
  3777.                                     break;
  3778.                                 case 4//Creative
  3779.                                     $pax $servicePro->getPax();
  3780.                                     if (empty($pax) or $pax == "0") {
  3781.                                         $pax 1;
  3782.                                     }
  3783.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  3784.                                     if ($days 1) {
  3785.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y');
  3786.                                     } else {
  3787.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y');
  3788.                                     }
  3789.                                     $unitsServ $servicePro->getUnits();
  3790.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3791.                                         $unitsServ 1;
  3792.                                     }
  3793.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3794.                                     $subnetoUnit $subneto;
  3795.                                     $subneto $subneto $days $unitsServ $pax;
  3796.                                     break;
  3797.                                 case 5//Cruise
  3798.                                     $pax $servicePro->getPax();
  3799.                                     if (empty($pax) or $pax == "0") {
  3800.                                         $pax 1;
  3801.                                     }
  3802.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days);
  3803.                                     if ($days 1) {
  3804.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y');
  3805.                                     } else {
  3806.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y');
  3807.                                     }
  3808.                                     $unitsServ $servicePro->getUnits();
  3809.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3810.                                         $unitsServ 1;
  3811.                                     }
  3812.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3813.                                     $subnetoUnit $subneto;
  3814.                                     $subneto $subneto $days $unitsServ $pax;
  3815.                                     break;
  3816.                                 case 6//Entertaiment
  3817.                                     $pax $servicePro->getPax();
  3818.                                     if (empty($pax) or $pax == "0") {
  3819.                                         $pax 1;
  3820.                                     }
  3821.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  3822.                                     if ($days 1) {
  3823.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y');
  3824.                                     } else {
  3825.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y');
  3826.                                     }
  3827.                                     $unitsServ $servicePro->getUnits();
  3828.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3829.                                         $unitsServ 1;
  3830.                                     }
  3831.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3832.                                     $subnetoUnit $subneto;
  3833.                                     $subneto $subneto $days $unitsServ $pax;
  3834.                                     break;
  3835.                                 case 7// Gifts
  3836.                                     $pax $servicePro->getPax();
  3837.                                     if (empty($pax) or $pax == "0") {
  3838.                                         $pax 1;
  3839.                                     }
  3840.                                     $days 1;
  3841.                                     if ($days 1) {
  3842.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y');
  3843.                                     } else {
  3844.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y');
  3845.                                     }
  3846.                                     $unitsServ $servicePro->getUnits();
  3847.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3848.                                         $unitsServ 1;
  3849.                                     }
  3850.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3851.                                     $subnetoUnit $subneto;
  3852.                                     $subneto $subneto $days $unitsServ $pax;
  3853.                                     break;
  3854.                                 case 8//Guide
  3855.                                     $pax $servicePro->getPax();
  3856.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  3857.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  3858.                                     $dateServ = ($days 1) ? ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y') : ($servicePro->getDateInAt())->format('d/m/Y');
  3859.                                     $unitsServ $servicePro->getUnits();
  3860.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  3861.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3862.                                     $subnetoUnit $subneto;
  3863.                                     $subneto $subneto $days $unitsServ $pax;
  3864.                                     break;
  3865.                                 case 9//Itineraries
  3866.                                     $pax $servicePro->getPax();
  3867.                                     if (empty($pax) or $pax == "0") {
  3868.                                         $pax 1;
  3869.                                     }
  3870.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  3871.                                     if ($days 1) {
  3872.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y');
  3873.                                     } else {
  3874.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y');
  3875.                                     }
  3876.                                     $unitsServ $servicePro->getUnits();
  3877.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3878.                                         $unitsServ 1;
  3879.                                     }
  3880.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3881.                                     $subnetoUnit $subneto;
  3882.                                     $subneto $subneto $days $unitsServ $pax;
  3883.                                     break;
  3884.                                 case 10//Lounge  -- No Aplica
  3885.                                     break;
  3886.                                 case 11//Menu
  3887.                                     $pax $servicePro->getPax();
  3888.                                     if (empty($pax) or $pax == "0") {
  3889.                                         $pax 1;
  3890.                                     }
  3891.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  3892.                                     if ($days 1) {
  3893.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y');
  3894.                                     } else {
  3895.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y');
  3896.                                     }
  3897.                                     $unitsServ $servicePro->getUnits();
  3898.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3899.                                         $unitsServ 1;
  3900.                                     }
  3901.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3902.                                     $subnetoUnit $subneto;
  3903.                                     $subneto $subneto $days $unitsServ $pax;
  3904.                                     break;
  3905.                                 case 12//Others
  3906.                                     $pax $servicePro->getPax();
  3907.                                     if (empty($pax) or $pax == "0") {
  3908.                                         $pax 1;
  3909.                                     }
  3910.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  3911.                                     if ($days 1) {
  3912.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y');
  3913.                                     } else {
  3914.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y');
  3915.                                     }
  3916.                                     $unitsServ $servicePro->getUnits();
  3917.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3918.                                         $unitsServ 1;
  3919.                                     }
  3920.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3921.                                     $subnetoUnit $subneto;
  3922.                                     $subneto $subneto $days $unitsServ $pax;
  3923.                                     break;
  3924.                                 case 13//Transport
  3925.                                     $pax $servicePro->getPax();
  3926.                                     if (empty($pax) or $pax == "0") {
  3927.                                         $pax 1;
  3928.                                     }
  3929.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  3930.                                     if ($days 1) {
  3931.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y');
  3932.                                     } else {
  3933.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y');
  3934.                                     }
  3935.                                     $unitsServ $servicePro->getUnits();
  3936.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3937.                                         $unitsServ 1;
  3938.                                     }
  3939.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3940.                                     $subnetoUnit $subneto;
  3941.                                     $subneto $subneto $days $unitsServ $pax;
  3942.                                     break;
  3943.                                 case 14//Technology
  3944.                                     $pax $servicePro->getPax();
  3945.                                     if (empty($pax) or $pax == "0") {
  3946.                                         $pax 1;
  3947.                                     }
  3948.                                     $days 1;
  3949.                                     $dateServ = ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y');
  3950.                                     $unitsServ $servicePro->getUnits();
  3951.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3952.                                         $unitsServ 1;
  3953.                                     }
  3954.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3955.                                     $subnetoUnit $subneto;
  3956.                                     $subneto $subneto $days $unitsServ $pax;
  3957.                                     break;
  3958.                                 case 15//Assisstant
  3959.                                     $pax $servicePro->getPax();
  3960.                                     if (empty($pax) or $pax == "0") {
  3961.                                         $pax 1;
  3962.                                     }
  3963.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  3964.                                     if ($days 1) {
  3965.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y');
  3966.                                     } else {
  3967.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y');
  3968.                                     }
  3969.                                     $unitsServ $servicePro->getUnits();
  3970.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3971.                                         $unitsServ 1;
  3972.                                     }
  3973.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3974.                                     $subnetoUnit $subneto;
  3975.                                     $subneto $subneto $days $unitsServ $pax;
  3976.                                     break;
  3977.                                 case 16//DDR
  3978.                                     $pax $servicePro->getPax();
  3979.                                     if (empty($pax) or $pax == "0") {
  3980.                                         $pax 1;
  3981.                                     }
  3982.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  3983.                                     if ($days 1) {
  3984.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y');
  3985.                                     } else {
  3986.                                         $dateServ = ($servicePro->getDateInAt())->format('d/m/Y');
  3987.                                     }
  3988.                                     $unitsServ $servicePro->getUnits();
  3989.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3990.                                         $unitsServ 1;
  3991.                                     }
  3992.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3993.                                     $subnetoUnit $subneto;
  3994.                                     $subneto $subneto $days $unitsServ $pax;
  3995.                                     break;
  3996.                                 case 17//Seguridad
  3997.                                     $pax $servicePro->getPax();
  3998.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  3999.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  4000.                                     $dateServ = ($days 1) ? ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y') : ($servicePro->getDateInAt())->format('d/m/Y');
  4001.                                     $unitsServ $servicePro->getUnits();
  4002.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  4003.                                     $subtotal $subtotalService $days $unitsServ $pax;
  4004.                                     $subnetoUnit $subneto;
  4005.                                     $subneto $subneto $days $unitsServ $pax;
  4006.                                     break;
  4007.                                 case 18//WiFi
  4008.                                     $pax $servicePro->getPax();
  4009.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  4010.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  4011.                                     $dateServ = ($days 1) ? ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y') : ($servicePro->getDateInAt())->format('d/m/Y');
  4012.                                     $unitsServ $servicePro->getUnits();
  4013.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  4014.                                     $subtotal $subtotalService $days $unitsServ $pax;
  4015.                                     $subnetoUnit $subneto;
  4016.                                     $subneto $subneto $days $unitsServ $pax;
  4017.                                     break;
  4018.                                 case 19//Mobiliario
  4019.                                     $pax $servicePro->getPax();
  4020.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  4021.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  4022.                                     $dateServ = ($days 1) ? ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y') : ($servicePro->getDateInAt())->format('d/m/Y');
  4023.                                     $unitsServ $servicePro->getUnits();
  4024.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  4025.                                     $subtotal $subtotalService $days $unitsServ $pax;
  4026.                                     $subnetoUnit $subneto;
  4027.                                     $subneto $subneto $days $unitsServ $pax;
  4028.                                     break;
  4029.                                 case 20//Parking
  4030.                                     $pax $servicePro->getPax();
  4031.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  4032.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  4033.                                     $dateServ = ($days 1) ? ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y') : ($servicePro->getDateInAt())->format('d/m/Y');
  4034.                                     $unitsServ $servicePro->getUnits();
  4035.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  4036.                                     $subtotal $subtotalService $days $unitsServ $pax;
  4037.                                     $subnetoUnit $subneto;
  4038.                                     $subneto $subneto $days $unitsServ $pax;
  4039.                                     break;
  4040.                                 case 21//Limpieza
  4041.                                     $pax $servicePro->getPax();
  4042.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  4043.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  4044.                                     $dateServ = ($days 1) ? ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y') : ($servicePro->getDateInAt())->format('d/m/Y');
  4045.                                     $unitsServ $servicePro->getUnits();
  4046.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  4047.                                     $subtotal $subtotalService $days $unitsServ $pax;
  4048.                                     $subnetoUnit $subneto;
  4049.                                     $subneto $subneto $days $unitsServ $pax;
  4050.                                     break;
  4051.                                 default:  //Others (por default)
  4052.                                     $pax $servicePro->getPax();
  4053.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  4054.                                     $days = ((($servicePro->getDateOutAt())->diff($servicePro->getDateInAt()))->days 1);
  4055.                                     $dateServ = ($days 1) ? ($servicePro->getDateInAt())->format('d/m/Y') . ' - ' . ($servicePro->getDateOutAt())->format('d/m/Y') : ($servicePro->getDateInAt())->format('d/m/Y');
  4056.                                     $unitsServ $servicePro->getUnits();
  4057.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  4058.                                     $subtotal $subtotalService $days $unitsServ $pax;
  4059.                                     $subnetoUnit $subneto;
  4060.                                     $subneto $subneto $days $unitsServ $pax;
  4061.                                     break;
  4062.                             }
  4063.                             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  4064.                             $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  4065.                             $neto round($subneto2PHP_ROUND_HALF_UP);
  4066.                             $valorTotalNet $valorTotalNet $neto;
  4067.                             $valorVat $valorVat + ($subtotal $neto);
  4068.                         }
  4069.                     }
  4070.                 }
  4071.             }
  4072.         }
  4073.         if (!empty($arrayInvoicedItems)) {
  4074.             foreach ($arrayInvoicedItems as $itemInvoice) {
  4075.                 if ($itemInvoice->getType() == 'PAYMENT') {
  4076. //                    $pago = $em->getRepository(ReservationPaymentsClient::class)->findOneById($key);
  4077. //
  4078. //                    $itemInvoice = new ReservationInvoiceItems();
  4079. //                    $itemInvoice->setReservationId($id);
  4080. //                    $itemInvoice->setInvoiceId($invoiceId);
  4081. //                    $itemInvoice->setItemType('PAYMENT');
  4082. //                    $itemInvoice->setPayControlId($key);
  4083. //                    $itemInvoice->setPayAmount($pago->getAmount());
  4084. //                    $itemInvoice->setPayDatePayAt($pago->getDatePayAt());
  4085. //                    $itemInvoice->setPayWayToPay($pago->getWayToPay());
  4086. //                    $itemInvoice->setCreatedAt(new DateTime('now'));
  4087. //                    $itemInvoice->setUpdatedAt(new DateTime('now'));
  4088. //                    $itemInvoice->setCreatedId($user_id);
  4089. //                    $itemInvoice->setUpdatedId($user_id);
  4090. //
  4091. //                    $em->persist($itemInvoice);
  4092. //                    $em->flush();
  4093.                     //Acumulamos neto e iva para la factura
  4094.                     //$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();    // El pago no puede afectar el neto de la factura
  4095.                 }
  4096.             }
  4097.         }
  4098.         //FIN: Creamos los items de la proforma
  4099.         $valorTotal $valorTotalNet $valorVat;
  4100.         $newInvoice $em->getRepository(ReservationProforma::class)->findOneById($id);
  4101.         //FIN: Creamos la proforma
  4102.         $data = array();
  4103.         $data $this->baseInvoiceDoneReservation($newInvoice->getReservationId(), $id,'P');
  4104.         $paymentsClient = new ReservationPaymentsClient();
  4105.         $paymentsClient->setReservationId($id);
  4106.         $reservaInv = new ReservationInvoice();
  4107.         $reservaInv->setReservationId($id);
  4108.         $idLounges = array();
  4109.         $loungesBoolToInvoice = array();
  4110.         if (array_key_exists('lounge',$data['datasupplier'])) {
  4111.             foreach ($data['datasupplier']['lounge'] as $item) {
  4112.                 $idLounges[] = $item['id'];
  4113.                 $loungesBoolToInvoice[] = 1;
  4114.             }
  4115.             $idLounges implode(','$idLounges);
  4116.             $loungesBoolToInvoice implode(','$loungesBoolToInvoice);
  4117.         } else {
  4118.             $idLounges '0';
  4119.             $loungesBoolToInvoice '0';
  4120.         }
  4121.         $idPayments = array();
  4122.         $paymentsBoolToInvoice = array();
  4123.         if (array_key_exists('payment',$data['datasupplier'])) {
  4124.             foreach ($data['datasupplier']['payment'] as $item) {
  4125.                 $idPayments[] = $item['id'];
  4126.                 $paymentsBoolToInvoice[] = 1;
  4127.             }
  4128.             $idPayments implode(','$idPayments);
  4129.             $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  4130.             // Se han generado dos arreglos, cada uno dividido en 2 strings
  4131.             // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  4132.             // Para manipularlos entre la vista y el JS
  4133.         } else {
  4134.             $idPayments '0';
  4135.             $paymentsBoolToInvoice '0';
  4136.         }
  4137.         // Una factura solo se puede rectificar una vez (Las proformas no se rectifican)
  4138.         $boolToRec false;
  4139.         $allInvoices $em->getRepository(ReservationInvoice::class)->findByReservationId($newInvoice->getReservationId());
  4140.         $allInvoicesRec $em->getRepository(ReservationInvoiceRec::class)->findByReservationId($newInvoice->getReservationId());
  4141.         foreach ($allInvoicesRec as $item){
  4142.             array_push($allInvoices$item);
  4143.         }
  4144.         $allProformas $em->getRepository(ReservationProforma::class)->findByReservationId($newInvoice->getReservationId());
  4145.         if(empty($data['type'])){$data['type'] = 'Proforma';}
  4146.         $reservaEquis $em->getRepository(Reservation::class)->findOneById($newInvoice->getReservationId());
  4147. //        if(empty($newInvoice->getClientName()) and empty($newInvoice->getClientAddress()) and empty($newInvoice->getClientDocument())){
  4148.         if(true){ $newInvoiceProf $this->clientDataToInvoice(nullnullnull$newInvoice->getReservationId()); }
  4149.         return $this->render('MDS/GreenPatioBundle/reservations/invoice-new-invoice.html.twig',
  4150.             array(
  4151.                 'id' => $newInvoice->getReservationId(),
  4152.                 'cid' => '',
  4153.                 'fid' => $id,
  4154.                 'invoice' => $allInvoices,
  4155.                 'proformas' => $allProformas,
  4156.                 'boolToRec' => $boolToRec,
  4157.                 'numberadmin' => '',
  4158.                 'type' => $data['type'],
  4159.                 'number' => $newInvoice->getId(),
  4160.                 'prefix' => $data['prefix'],
  4161.                 'date' => $data['date'],
  4162.                 'token' =>  $data['token'],
  4163.                 'reservation' => $data['reservation'],
  4164.                 'company' => $data['company'],
  4165.                 'clients' => $data['clients'],
  4166.                 'user' => $user_logueado,
  4167.                 'invoicedeposititems' => '',
  4168.                 'arrayItems' => $data['arrayItems'],
  4169.                 'datasupplier' => $data['datasupplier'],
  4170.                 'totales_neto' => $data['totales_neto'],
  4171.                 'totales_iva' => '',
  4172.                 'totales' => $data['totales'],
  4173.                 'bases_imponibles' => $data['bases_imponibles'],
  4174.                 'balance' => $data['balance'],
  4175.                 'paymentInvoice' => $data['paymentInvoice'],
  4176.                 'currency' => $data['currency'],
  4177.                 'clientName' => $newInvoiceProf->getClientName(),
  4178.                 'clientAddress' => $newInvoiceProf->getClientAddress(),
  4179.                 'clientDocument' => $newInvoiceProf->getClientDocument(),
  4180.             )
  4181.         );
  4182.     }
  4183.     /**
  4184.      * @Route("/reservations/invoice/viewrec/{id}",  name="reservations_viewrec_invoice")
  4185.      */
  4186.     public function viewRecInvoiceAction($idRequest $request)
  4187.     {
  4188.         $em $this->getDoctrine()->getManager();
  4189.         // Se genera y muestra en nueva pantalla la nueva proforma
  4190.         $arrayBools = array(
  4191.             'lounge' => null,
  4192.             'service' => null,
  4193.             'payment' => null,
  4194.         );
  4195.         $arrayBools['lounge'] = $request->request->get('inv_lounge_hidden_bool');
  4196.         $arrayBools['service'] = $request->request->get('inv_service_hidden_bool');
  4197.         $arrayBools['payment'] = $request->request->get('inv_payment_hidden_bool');
  4198.         /* Obtengo usuario logueado */
  4199.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  4200.         $user_id $user_logueado->getId();
  4201.         //Acumuladores de datos globales de la factura
  4202.         $valorTotalNet 0;
  4203.         $valorVat 0;
  4204. //        $valorTotal = 0;
  4205.         //INICIO: Creamos los items de la factura
  4206.         $arrayInvoicedItems $em->getRepository(ReservationInvoiceRecItems::class)->findByInvoiceId($id);
  4207.         if (!empty($arrayInvoicedItems)) {
  4208.             foreach ($arrayInvoicedItems as $itemInvoice) {
  4209.                 if ($itemInvoice->getItemType() == 'LOUNGE') {
  4210.                     //Acumulamos neto e iva para la factura
  4211.                     $valorTotalNet $valorTotalNet $itemInvoice->getLngServicePrice();
  4212.                     $valorVat $valorVat round(($itemInvoice->getLngServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
  4213.                 }
  4214.             }
  4215.         }
  4216.         if (!empty($arrayInvoicedItems)) {
  4217.             foreach ($arrayInvoicedItems as $itemInvoice) {
  4218.                 if ($itemInvoice->getItemType() == 'SERVICE') {
  4219.                     //Acumulamos neto e iva para la factura
  4220.                     if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())){
  4221.                         $subtotal 0;
  4222.                         $neto 0;
  4223.                         $subtotalService 0;
  4224.                     } else {
  4225.                         $subtotalService $itemInvoice->getSrvPrice();
  4226.                         $subneto $itemInvoice->getSrvPrice();
  4227.                         // Commission
  4228.                         if ($itemInvoice->getSrvOpCommission()=='1'){
  4229.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvCommission()/100));
  4230.                             $subneto $subneto  * (+ ($itemInvoice->getSrvCommission()/100));
  4231.                         } else {
  4232.                             $subtotalService $subtotalService * (- ($itemInvoice->getSrvCommission()/100));
  4233.                             $subneto $subneto * (- ($itemInvoice->getSrvCommission()/100));
  4234.                         }
  4235.                         // Over
  4236.                         if ($itemInvoice->getSrvOpOver()=='1'){
  4237.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  4238.                             $subneto $subneto $itemInvoice->getSrvOver();
  4239.                         } else {
  4240.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  4241.                             $subneto $subneto $itemInvoice->getSrvOver();
  4242.                         }
  4243.                         // IVA
  4244.                         if ($itemInvoice->getSrvOpIva()=='1'){
  4245.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvIva()/100));
  4246.                         } else {
  4247.                             $subtotalService $itemInvoice->getSrvPrice();
  4248.                             $subneto = ($subneto 100) / (100 $itemInvoice->getSrvIva());
  4249.                         }
  4250.                         switch ($itemInvoice->getSrvServiceCatId()){
  4251.                             case 1// Alojamiento
  4252.                                 // el numero de noches $numNoches; precio unitario $subneto
  4253.                                 $numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
  4254.                                 // La personas no afectan este calculo
  4255.                                 $subtotal $subtotalService $numNoches $itemInvoice->getSrvUnits();
  4256.                                 $subnetoUnit $subneto;
  4257.                                 $subneto $subneto $numNoches $itemInvoice->getSrvUnits();
  4258.                                 break;
  4259.                             case 2//Actividades
  4260.                                 // El número de personas es considerado en el calculo
  4261.                                 $pax $itemInvoice->getSrvPax();
  4262.                                 if (empty($pax) or $pax == "0") {
  4263.                                     $pax 1;
  4264.                                 }
  4265.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4266.                                 if ($days 1){
  4267.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4268.                                 } else {
  4269.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4270.                                 }
  4271.                                 $subtotal $subtotalService $days $itemInvoice->getSrvUnits();
  4272.                                 $subnetoUnit $subneto;
  4273.                                 $subneto $subneto $days $itemInvoice->getSrvUnits();
  4274.                                 break;
  4275.                             case 3// AV
  4276.                                 $pax $itemInvoice->getSrvPax();
  4277.                                 if (empty($pax) or $pax == "0") {
  4278.                                     $pax 1;
  4279.                                 }
  4280.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4281.                                 if ($days 1){
  4282.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4283.                                 } else {
  4284.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4285.                                 }
  4286.                                 $unitsServ $itemInvoice->getSrvUnits();
  4287.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4288.                                     $unitsServ 1;
  4289.                                 }
  4290.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4291.                                 $subnetoUnit $subneto;
  4292.                                 $subneto $subneto $days $unitsServ $pax;
  4293.                                 break;
  4294.                             case 4//Creative
  4295.                                 $pax $itemInvoice->getSrvPax();
  4296.                                 if (empty($pax) or $pax == "0") {
  4297.                                     $pax 1;
  4298.                                 }
  4299.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4300.                                 if ($days 1){
  4301.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4302.                                 } else {
  4303.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4304.                                 }
  4305.                                 $unitsServ $itemInvoice->getSrvUnits();
  4306.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4307.                                     $unitsServ 1;
  4308.                                 }
  4309.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4310.                                 $subnetoUnit $subneto;
  4311.                                 $subneto $subneto $days $unitsServ $pax;
  4312.                                 break;
  4313.                             case 5//Cruise
  4314.                                 $pax $itemInvoice->getSrvPax();
  4315.                                 if (empty($pax) or $pax == "0") {
  4316.                                     $pax 1;
  4317.                                 }
  4318.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
  4319.                                 if ($days 1){
  4320.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4321.                                 } else {
  4322.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4323.                                 }
  4324.                                 $unitsServ $itemInvoice->getSrvUnits();
  4325.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4326.                                     $unitsServ 1;
  4327.                                 }
  4328.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4329.                                 $subnetoUnit $subneto;
  4330.                                 $subneto $subneto $days $unitsServ $pax;
  4331.                                 break;
  4332.                             case 6//Entertaiment
  4333.                                 $pax $itemInvoice->getSrvPax();
  4334.                                 if (empty($pax) or $pax == "0") {
  4335.                                     $pax 1;
  4336.                                 }
  4337.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4338.                                 if ($days 1){
  4339.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4340.                                 } else {
  4341.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4342.                                 }
  4343.                                 $unitsServ $itemInvoice->getSrvUnits();
  4344.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4345.                                     $unitsServ 1;
  4346.                                 }
  4347.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4348.                                 $subnetoUnit $subneto;
  4349.                                 $subneto $subneto $days $unitsServ $pax;
  4350.                                 break;
  4351.                             case 7// Gifts
  4352.                                 $pax $itemInvoice->getSrvPax();
  4353.                                 if (empty($pax) or $pax == "0") {
  4354.                                     $pax 1;
  4355.                                 }
  4356.                                 $days 1;
  4357.                                 if ($days 1){
  4358.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4359.                                 } else {
  4360.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4361.                                 }
  4362.                                 $unitsServ $itemInvoice->getSrvUnits();
  4363.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4364.                                     $unitsServ 1;
  4365.                                 }
  4366.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4367.                                 $subnetoUnit $subneto;
  4368.                                 $subneto $subneto $days $unitsServ $pax;
  4369.                                 break;
  4370.                             case 8//Guide
  4371.                                 $pax $itemInvoice->getSrvPax();
  4372.                                 if (empty($pax) or $pax == "0") {
  4373.                                     $pax 1;
  4374.                                 }
  4375.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4376.                                 if ($days 1){
  4377.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4378.                                 } else {
  4379.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4380.                                 }
  4381.                                 $unitsServ $itemInvoice->getSrvUnits();
  4382.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4383.                                     $unitsServ 1;
  4384.                                 }
  4385.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4386.                                 $subnetoUnit $subneto;
  4387.                                 $subneto $subneto $days $unitsServ $pax;
  4388.                                 break;
  4389.                             case 9//Itineraries
  4390.                                 $pax $itemInvoice->getSrvPax();
  4391.                                 if (empty($pax) or $pax == "0") {
  4392.                                     $pax 1;
  4393.                                 }
  4394.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4395.                                 if ($days 1){
  4396.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4397.                                 } else {
  4398.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4399.                                 }
  4400.                                 $unitsServ $itemInvoice->getSrvUnits();
  4401.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4402.                                     $unitsServ 1;
  4403.                                 }
  4404.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4405.                                 $subnetoUnit $subneto;
  4406.                                 $subneto $subneto $days $unitsServ $pax;
  4407.                                 break;
  4408.                             case 10//Lounge  -- No Aplica
  4409.                                 break;
  4410.                             case 11//Menu
  4411.                                 $pax $itemInvoice->getSrvPax();
  4412.                                 if (empty($pax) or $pax == "0") {
  4413.                                     $pax 1;
  4414.                                 }
  4415.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4416.                                 if ($days 1){
  4417.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4418.                                 } else {
  4419.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4420.                                 }
  4421.                                 $unitsServ $itemInvoice->getSrvUnits();
  4422.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4423.                                     $unitsServ 1;
  4424.                                 }
  4425.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4426.                                 $subnetoUnit $subneto;
  4427.                                 $subneto $subneto $days $unitsServ $pax;
  4428.                                 break;
  4429.                             case 12//Others
  4430.                                 $pax $itemInvoice->getSrvPax();
  4431.                                 if (empty($pax) or $pax == "0") {
  4432.                                     $pax 1;
  4433.                                 }
  4434.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4435.                                 if ($days 1){
  4436.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4437.                                 } else {
  4438.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4439.                                 }
  4440.                                 $unitsServ $itemInvoice->getSrvUnits();
  4441.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4442.                                     $unitsServ 1;
  4443.                                 }
  4444.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4445.                                 $subnetoUnit $subneto;
  4446.                                 $subneto $subneto $days $unitsServ $pax;
  4447.                                 break;
  4448.                             case 13//Transport
  4449.                                 $pax $itemInvoice->getSrvPax();
  4450.                                 if (empty($pax) or $pax == "0") {
  4451.                                     $pax 1;
  4452.                                 }
  4453.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4454.                                 if ($days 1){
  4455.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4456.                                 } else {
  4457.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4458.                                 }
  4459.                                 $unitsServ $itemInvoice->getSrvUnits();
  4460.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4461.                                     $unitsServ 1;
  4462.                                 }
  4463.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4464.                                 $subnetoUnit $subneto;
  4465.                                 $subneto $subneto $days $unitsServ $pax;
  4466.                                 break;
  4467.                             case 14//Technology
  4468.                                 $pax $itemInvoice->getSrvPax();
  4469.                                 if (empty($pax) or $pax == "0") {
  4470.                                     $pax 1;
  4471.                                 }
  4472.                                 $days 1;
  4473.                                 $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4474.                                 $unitsServ $itemInvoice->getSrvUnits();
  4475.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4476.                                     $unitsServ 1;
  4477.                                 }
  4478.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4479.                                 $subnetoUnit $subneto;
  4480.                                 $subneto $subneto $days $unitsServ $pax;
  4481.                                 break;
  4482.                             case 15//Assisstant
  4483.                                 $pax $itemInvoice->getSrvPax();
  4484.                                 if (empty($pax) or $pax == "0") {
  4485.                                     $pax 1;
  4486.                                 }
  4487.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4488.                                 if ($days 1){
  4489.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4490.                                 } else {
  4491.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4492.                                 }
  4493.                                 $unitsServ $itemInvoice->getSrvUnits();
  4494.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4495.                                     $unitsServ 1;
  4496.                                 }
  4497.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4498.                                 $subnetoUnit $subneto;
  4499.                                 $subneto $subneto $days $unitsServ $pax;
  4500.                                 break;
  4501.                             case 16//DDR
  4502.                                 $pax $itemInvoice->getSrvPax();
  4503.                                 if (empty($pax) or $pax == "0") {
  4504.                                     $pax 1;
  4505.                                 }
  4506.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4507.                                 if ($days 1){
  4508.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4509.                                 } else {
  4510.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4511.                                 }
  4512.                                 $unitsServ $itemInvoice->getSrvUnits();
  4513.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4514.                                     $unitsServ 1;
  4515.                                 }
  4516.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4517.                                 $subnetoUnit $subneto;
  4518.                                 $subneto $subneto $days $unitsServ $pax;
  4519.                                 break;
  4520.                             default:
  4521.                                 break;
  4522.                         }
  4523.                         // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  4524.                         $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  4525.                         $neto round($subneto,2,PHP_ROUND_HALF_UP);
  4526.                         $valorTotalNet $valorTotalNet $neto;
  4527.                         $valorVat $valorVat + ($subtotal $neto);
  4528.                     }
  4529.                 }
  4530.             }
  4531.         }
  4532.         if (!empty($arrayInvoicedItems)) {
  4533.             foreach ($arrayInvoicedItems as $itemInvoice) {
  4534.                 if ($itemInvoice->getItemType() == 'PAYMENT') {
  4535. //                    $pago = $em->getRepository(ReservationPaymentsClient::class)->findOneById($key);
  4536. //
  4537. //                    $itemInvoice = new ReservationInvoiceItems();
  4538. //                    $itemInvoice->setReservationId($id);
  4539. //                    $itemInvoice->setInvoiceId($invoiceId);
  4540. //                    $itemInvoice->setItemType('PAYMENT');
  4541. //                    $itemInvoice->setPayControlId($key);
  4542. //                    $itemInvoice->setPayAmount($pago->getAmount());
  4543. //                    $itemInvoice->setPayDatePayAt($pago->getDatePayAt());
  4544. //                    $itemInvoice->setPayWayToPay($pago->getWayToPay());
  4545. //                    $itemInvoice->setCreatedAt(new DateTime('now'));
  4546. //                    $itemInvoice->setUpdatedAt(new DateTime('now'));
  4547. //                    $itemInvoice->setCreatedId($user_id);
  4548. //                    $itemInvoice->setUpdatedId($user_id);
  4549. //
  4550. //                    $em->persist($itemInvoice);
  4551. //                    $em->flush();
  4552.                     //Acumulamos neto e iva para la factura
  4553.                     //$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();    // El pago no puede afectar el neto de la factura
  4554.                 }
  4555.             }
  4556.         }
  4557.         //FIN: Creamos los items de la factura
  4558.         $valorTotal $valorTotalNet $valorVat;
  4559.         //INICIO: Creamos la factura
  4560.         $newInvoice $em->getRepository(ReservationInvoiceRec::class)->findOneById($id);
  4561.         //FIN: Creamos la factura
  4562.         $data = array();
  4563.         $data $this->baseInvoiceDoneReservation($newInvoice->getReservationId(), $id,'R');
  4564.         $paymentsClient = new ReservationPaymentsClient();
  4565.         $paymentsClient->setReservationId($id);
  4566.         $reservaInv = new ReservationInvoice();
  4567.         $reservaInv->setReservationId($id);
  4568.         $idLounges = array();
  4569.         $loungesBoolToInvoice = array();
  4570.         if (array_key_exists('lounge',$data['datasupplier'])) {
  4571.             foreach ($data['datasupplier']['lounge'] as $item) {
  4572.                 $idLounges[] = $item['id'];
  4573.                 $loungesBoolToInvoice[] = 1;
  4574.             }
  4575.             $idLounges implode(','$idLounges);
  4576.             $loungesBoolToInvoice implode(','$loungesBoolToInvoice);
  4577.         } else {
  4578.             $idLounges '0';
  4579.             $loungesBoolToInvoice '0';
  4580.         }
  4581.         $idPayments = array();
  4582.         $paymentsBoolToInvoice = array();
  4583.         if (array_key_exists('payment',$data['datasupplier'])) {
  4584.             foreach ($data['datasupplier']['payment'] as $item) {
  4585.                 $idPayments[] = $item['id'];
  4586.                 $paymentsBoolToInvoice[] = 1;
  4587.             }
  4588.             $idPayments implode(','$idPayments);
  4589.             $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  4590.             // Se han generado dos arreglos, cada uno dividido en 2 strings
  4591.             // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  4592.             // Para manipularlos entre la vista y el JS
  4593.         } else {
  4594.             $idPayments '0';
  4595.             $paymentsBoolToInvoice '0';
  4596.         }
  4597.         // Una factura solo se puede rectificar una vez
  4598.         //$rectf = $em->getRepository(ReservationInvoiceRec::class)->findBy( array('number' => 'REC-'.$newInvoice->getNumber()));
  4599.         //$boolToRec = empty($rectf);
  4600.         $boolToRec false// Estas viendo una factura rectificativa
  4601.         $allInvoices $em->getRepository(ReservationInvoice::class)->findByReservationId($newInvoice->getReservationId());
  4602.         $allInvoicesRec $em->getRepository(ReservationInvoiceRec::class)->findByReservationId($newInvoice->getReservationId());
  4603.         foreach ($allInvoicesRec as $item){
  4604.             array_push($allInvoices$item);
  4605.         }
  4606.         $allProformas $em->getRepository(ReservationProforma::class)->findByReservationId($newInvoice->getReservationId());
  4607.         // Por ser una factura rectificativa multiplicamos por -1 el balance
  4608. //        $data['balance'] = $data['balance'] * (-1);
  4609.         if(empty($data['type'])){$data['type'] = 'Invoice Rec';}
  4610.         $reservaEquis $em->getRepository(Reservation::class)->findOneById($newInvoice->getReservationId());
  4611.         if(empty($newInvoice->getClientName()) and empty($newInvoice->getClientAddress()) and empty($newInvoice->getClientDocument())){
  4612.             $newInvoice $this->clientDataToInvoice($newInvoice'Client'$reservaEquis->getClient(), $newInvoice->getReservationId());
  4613.         }
  4614.         return $this->render('MDS/GreenPatioBundle/reservations/invoice-new-invoice.html.twig',
  4615.             array(
  4616.                 'id' => $newInvoice->getReservationId(),
  4617.                 'invoiceIdToRec' => $newInvoice->getInvoiceToRec(),
  4618.                 'cid' => '',
  4619.                 'fid' => $id,
  4620.                 'invoice' => $allInvoices,
  4621.                 'proformas' => $allProformas,
  4622.                 'boolToRec' => $boolToRec,
  4623.                 'numberadmin' => '',
  4624.                 'type' => $data['type'],
  4625.                 'number' => $newInvoice->getId(),
  4626.                 'prefix' => $data['prefix'],
  4627.                 'date' => $data['date'],
  4628.                 'token' =>  $data['token'],
  4629.                 'reservation' => $data['reservation'],
  4630.                 'company' => $data['company'],
  4631.                 'clients' => $data['clients'],
  4632.                 'user' => $user_logueado,
  4633.                 'invoicedeposititems' => '',
  4634.                 'arrayItems' => $data['arrayItems'],
  4635.                 'datasupplier' => $data['datasupplier'],
  4636.                 'totales_neto' => $data['totales_neto'],
  4637.                 'totales_iva' => '',
  4638.                 'totales' => $data['totales'],
  4639.                 'bases_imponibles' => $data['bases_imponibles'],
  4640.                 'balance' => $data['balance'],
  4641.                 'paymentInvoice' => $data['paymentInvoice'],
  4642.                 'currency' => $data['currency'],
  4643.                 'clientName' => $newInvoice->getClientName(),
  4644.                 'clientAddress' => $newInvoice->getClientAddress(),
  4645.                 'clientDocument' => $newInvoice->getClientDocument(),
  4646.             )
  4647.         );
  4648.     }
  4649.     /**
  4650.      * @Route("/reservations/invoice/viewreservationinvoices/{id}",  name="reservations_viewreservation_invoices")
  4651.      */
  4652.     public function viewReservationInvoicesAction($idRequest $request)
  4653.     {
  4654.         $em $this->getDoctrine()->getManager();
  4655.         $allInvoices $em->getRepository(ReservationInvoice::class)->findByReservationId($id);
  4656.         $allInvoicesRec $em->getRepository(ReservationInvoiceRec::class)->findByReservationId($id);
  4657.         foreach ($allInvoicesRec as $item){
  4658.             array_push($allInvoices$item);
  4659.         }
  4660.         $reservation $em->getRepository(Reservation::class)->findOneById($id);
  4661.         $client $em->getRepository(Client::class)->findOneById($reservation->getClient());
  4662.         /* Obtengo usuario logueado */
  4663.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  4664.         $user_id $user_logueado->getId();
  4665.         $data = array();
  4666.         $data['clients'][0] = $client;
  4667.         $data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  4668.         $data['datasupplier'] = '';
  4669.         $data['totales_neto'] = '';
  4670.         $data['totales'] = '';
  4671.         $data['bases_imponibles'] = '';
  4672.         $data['balance'] = '';
  4673.         $data['paymentInvoice'] = '';
  4674.         $data['currency'] = '';
  4675.         // Una factura solo se puede rectificar una vez
  4676.         //$rectf = $em->getRepository(ReservationInvoiceRec::class)->findBy( array('number' => 'REC-'.$newInvoice->getNumber()));
  4677.         //$boolToRec = empty($rectf);
  4678.         $boolToRec false;
  4679.         return $this->render('MDS/GreenPatioBundle/reservations/invoice-new-invoice.html.twig',
  4680.             array(
  4681.                 'id' => $id,
  4682.                 'cid' => '',
  4683.                 'fid' => null,
  4684.                 'invoice' => $allInvoices,
  4685.                 'boolToRec' => $boolToRec,
  4686.                 'numberadmin' => '',
  4687.                 'type' => 'Invoice',
  4688.                 'number' => '',
  4689.                 'prefix' => '',
  4690.                 'date' => '',
  4691.                 'token' => '',
  4692.                 'reservation' => '',
  4693.                 'company' => $data['company'],
  4694.                 'clients' => $data['clients'],
  4695.                 'user' => $user_logueado,
  4696.                 'invoicedeposititems' => '',
  4697.                 'datasupplier' => $data['datasupplier'],
  4698.                 'totales_neto' => $data['totales_neto'],
  4699.                 'totales_iva' => '',
  4700.                 'totales' => $data['totales'],
  4701.                 'bases_imponibles' => $data['bases_imponibles'],
  4702.                 'balance' => $data['balance'],
  4703.                 'paymentInvoice' => $data['paymentInvoice'],
  4704.                 'currency' => $data['currency'],
  4705.             )
  4706.         );
  4707.     }
  4708.     /**
  4709.      * @Route("/reservations/invoice/viewreservationproformas/{id}",  name="reservations_viewreservation_proformas")
  4710.      */
  4711.     public function viewReservationProformasAction($idRequest $request)
  4712.     {
  4713.         $em $this->getDoctrine()->getManager();
  4714.         $allInvoices $em->getRepository(ReservationProforma::class)->findByReservationId($id);
  4715.         $allProformas $allInvoices;
  4716.         $reservation $em->getRepository(Reservation::class)->findOneById($id);
  4717.         $client $em->getRepository(Client::class)->findOneById($reservation->getClient());
  4718.         /* Obtengo usuario logueado */
  4719.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  4720.         $user_id $user_logueado->getId();
  4721.         $data = array();
  4722.         $data['clients'][0] = $client;
  4723.         $data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  4724.         $data['datasupplier'] = '';
  4725.         $data['totales_neto'] = '';
  4726.         $data['totales'] = '';
  4727.         $data['bases_imponibles'] = '';
  4728.         $data['balance'] = '';
  4729.         $data['paymentInvoice'] = '';
  4730.         $data['currency'] = '';
  4731.         // Una factura solo se puede rectificar una vez
  4732.         //$rectf = $em->getRepository(ReservationInvoiceRec::class)->findBy( array('number' => 'REC-'.$newInvoice->getNumber()));
  4733.         //$boolToRec = empty($rectf);
  4734.         $boolToRec false;
  4735.         return $this->render('MDS/GreenPatioBundle/reservations/invoice-new-invoice.html.twig',
  4736.             array(
  4737.                 'id' => $id,
  4738.                 'cid' => '',
  4739.                 'fid' => null,
  4740.                 'invoice' => $allInvoices,
  4741.                 'proformas' => $allProformas,
  4742.                 'boolToRec' => $boolToRec,
  4743.                 'numberadmin' => '',
  4744.                 'type' => 'Proforma',
  4745.                 'number' => '',
  4746.                 'prefix' => '',
  4747.                 'date' => '',
  4748.                 'token' => '',
  4749.                 'reservation' => '',
  4750.                 'company' => $data['company'],
  4751.                 'clients' => $data['clients'],
  4752.                 'user' => $user_logueado,
  4753.                 'invoicedeposititems' => '',
  4754.                 'datasupplier' => $data['datasupplier'],
  4755.                 'totales_neto' => $data['totales_neto'],
  4756.                 'totales_iva' => '',
  4757.                 'totales' => $data['totales'],
  4758.                 'bases_imponibles' => $data['bases_imponibles'],
  4759.                 'balance' => $data['balance'],
  4760.                 'paymentInvoice' => $data['paymentInvoice'],
  4761.                 'currency' => $data['currency'],
  4762.             )
  4763.         );
  4764.     }
  4765.     /**
  4766.      * @Route("/selinvoice/{id}",  name="reservations_newinvoice")
  4767.      */
  4768.     public function generateReservationNewInvoiceAction($idRequest $request)
  4769.     {
  4770.         $em $this->getDoctrine()->getManager();
  4771.         $paymentsClient = new ReservationPaymentsClient();
  4772.         $paymentsClient->setReservationId($id);
  4773.         $clientType 'Client';
  4774.         $clientRequest $request->request->get('reservation')['client'] ?? null;
  4775.         if (!empty($clientRequest)){
  4776.             $dataCliSup $this->clientOrSupplierDataSearchToInvoice($clientRequest$id);
  4777.             $clientName $dataCliSup['clientName'];
  4778.             $clientAddress $dataCliSup['clientAddress'];
  4779.             $clientDocument $dataCliSup['clientDocument'];
  4780.             $clientType $dataCliSup['clientType'];
  4781.         }
  4782.         if (empty($clientName) and empty($clientAddress) and empty($clientDocument)){
  4783.             $newInvoice $this->clientDataToInvoice(nullnullnull$id);
  4784.         } else {
  4785.             $newInvoice = new ReservationInvoice();
  4786.             $newInvoice->setClientName($clientName);
  4787.             $newInvoice->setClientAddress($clientAddress);
  4788.             $newInvoice->setClientDocument($clientDocument);
  4789.         }
  4790.         $form $this->createReservationPaymentsClientForm($paymentsClient);
  4791.         $reserva $em->getRepository(Reservation::class)->findOneById($id);
  4792.         $payments $em->getRepository(ReservationPaymentsClient::class)->findByReservationId($id);
  4793.         $services $em->getRepository(ReservationService::class)->findByReservationId($id);
  4794.         $proforma $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
  4795.         $allProformas $em->getRepository(ReservationProforma::class)->findAll();
  4796.         if (!empty($allProformas)){
  4797.             $number end($allProformas)->getId() + 1;
  4798.         } else {
  4799.             // Primer registro de proformas
  4800.             $number 1;
  4801.         }
  4802.         $type 'Proforma';
  4803.         $date = new DateTime('now');
  4804.         $prefix "GP-".$date->format('dmy')."-";
  4805.         $reservaInv = new ReservationInvoice();
  4806.         $reservaInv->setReservationId($id);
  4807.         $form1 $this->createReservationInvoiceProformaForm($reservaInv);
  4808.         $data $this->baseInvoiceReservation($id$type$number$prefix$date);
  4809.         $token $data['token'];
  4810.         $idLounges = array();
  4811.         if (array_key_exists('lounge',$data['datasupplier'])) {
  4812.             foreach ($data['datasupplier']['lounge'] as $key => $item) {
  4813.                 $existe $em->getRepository(ReservationInvoiceItems::class)->findOneByLngControlId($item['id']);
  4814.                 $existeCvr $em->getRepository(CvrReservationInvoiceItems::class)->findByLngControlId($item['id']);
  4815.                 $existe = (!empty($existe) or !empty($existeCvr));
  4816.                 if (empty($existe)){
  4817.                     $data['datasupplier']['lounge'][$key]['enabledToInvoice'] = true;
  4818.                 } else {
  4819.                     $data['datasupplier']['lounge'][$key]['enabledToInvoice'] = false;
  4820.                 }
  4821.             }
  4822.         }
  4823.         if (array_key_exists('service',$data['datasupplier'])) {
  4824.             foreach ($data['datasupplier']['service'] as $key => $item) {
  4825.                 $existe $em->getRepository(ReservationInvoiceItems::class)->findOneBySrvControlId($item['id']);
  4826.                 $existeCvr $em->getRepository(CvrReservationInvoiceItems::class)->findBySrvControlId($item['id']);
  4827.                 $existe = (!empty($existe) or !empty($existeCvr));
  4828.                 if (empty($existe)){
  4829.                     $data['datasupplier']['service'][$key]['enabledToInvoice'] = true;
  4830.                 } else {
  4831.                     $data['datasupplier']['service'][$key]['enabledToInvoice'] = false;
  4832.                 }
  4833.             }
  4834.         }
  4835.         $idPayments = array();
  4836.         if (array_key_exists('payment',$data['datasupplier'])) {
  4837.             foreach ($data['datasupplier']['payment'] as $key => $item) {
  4838.                 $existe $em->getRepository(ReservationInvoiceItems::class)->findOneByPayControlId($item['id']);
  4839.                 $existeCvr $em->getRepository(CvrReservationInvoiceItems::class)->findByPayControlId($item['id']);
  4840.                 $existe = (!empty($existe) or !empty($existeCvr));
  4841.                 if (empty($existe)){
  4842.                     $data['datasupplier']['payment'][$key]['enabledToInvoice'] = true;
  4843.                 } else {
  4844.                     $data['datasupplier']['payment'][$key]['enabledToInvoice'] = false;
  4845.                 }
  4846.             }
  4847.         }
  4848.         /* Obtengo usuario logueado */
  4849.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  4850.         $user_id $user_logueado->getId();
  4851.         if ($reserva) {
  4852.             $url "https://proposal.lolita.events/greenpatio/proposal/index.php?token=".$reserva->getToken();
  4853.         }
  4854.         // Si el Status no lo permite solo se podra sacar proformas
  4855.         if ($reserva->getStatus() == 'Invoiced' or $reserva->getStatus() == 'Confirmed'){ $cotizarPorEstado true; } else { $cotizarPorEstado false; }
  4856.         return $this->render('MDS/GreenPatioBundle/reservations/services-invoice-select-items.html.twig',
  4857.             array(
  4858.                 'id' => $id,
  4859.                 'idLounges' => $idLounges,
  4860.                 'reserva' => $reserva,
  4861.                 'idPayments' => $idPayments,
  4862.                 'type' => $data['type'],
  4863.                 'number' => $data['number'],
  4864.                 'prefix' => $data['prefix'],
  4865.                 'date' => $data['date'],
  4866.                 'token' => $token,
  4867.                 'company' => $data['company'],
  4868.                 'clients' => $data['clients'],
  4869.                 'datasupplier' => $data['datasupplier'],
  4870.                 'currency' => $data['currency'],
  4871.                 'totales_neto' => $data['totales_neto'],
  4872.                 'bases_imponibles' => $data['bases_imponibles'],
  4873.                 'totales' => $data['totales'],
  4874.                 'balance' => $data['balance'],
  4875.                 'paymentInvoice' => $data['paymentInvoice'],
  4876.                 'payments' => $payments,
  4877.                 'user_id' => $user_id,
  4878.                 'form' => $form->createView(),
  4879.                 'form1' => $form1->createView(),
  4880.                 'cotizarPorEstado' => $cotizarPorEstado,
  4881.                 'clientName' => $newInvoice->getClientName(),
  4882.                 'clientAddress' => $newInvoice->getClientAddress(),
  4883.                 'clientDocument' => $newInvoice->getClientDocument(),
  4884.                 'clientType' => $clientType,
  4885.                 'url' => $url,
  4886.             )
  4887.         );
  4888.     }
  4889.     /**
  4890.      * @Route("/reservations/invoice/invoice-proforma/print/{type}/{id}",  name="reservations_invoiceorproforma_print")
  4891.      */
  4892.     public function detailsInvoiceProformaPrintAction($type$idRequest $request)
  4893.     {
  4894.         $data = array();
  4895.         $em $this->getDoctrine()->getManager();
  4896.         // Si el ID de factura viene vacio regresamos a ver facturas
  4897.         if (empty($type)){
  4898.             return $this->redirectToRoute('reservations_viewreservation_invoices',array('id' => $id));
  4899.         }
  4900.         //Acumuladores de datos globales de la factura o proforma
  4901.         $valorTotalNet 0;
  4902.         $valorVat 0;
  4903.         if ($type == 'I'){
  4904.             //Es una factura
  4905.             //INICIO: Creamos los items de la factura
  4906.             $arrayInvoicedItems $em->getRepository(ReservationInvoiceItems::class)->findByInvoiceId($id);
  4907.             if (!empty($arrayInvoicedItems)) {
  4908.                 foreach ($arrayInvoicedItems as $itemInvoice) {
  4909.                     if ($itemInvoice->getItemType() == 'LOUNGE') {
  4910.                         //Acumulamos neto e iva para la factura
  4911.                         $valorTotalNet $valorTotalNet $itemInvoice->getLngServicePrice();
  4912.                         $valorVat $valorVat round(($itemInvoice->getLngServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
  4913.                     }
  4914.                 }
  4915.             }
  4916.             if (!empty($arrayInvoicedItems)) {
  4917.                 foreach ($arrayInvoicedItems as $itemInvoice) {
  4918.                     if ($itemInvoice->getItemType() == 'SERVICE') {
  4919.                         //Acumulamos neto e iva para la factura
  4920.                         if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())){
  4921.                             $subtotal 0;
  4922.                             $neto 0;
  4923.                             $subtotalService 0;
  4924.                         } else {
  4925.                             $subtotalService $itemInvoice->getSrvPrice();
  4926.                             $subtotalService str_replace(',','.',$subtotalService);
  4927.                             $subtotalService floatval($subtotalService);
  4928.                             $subneto $itemInvoice->getSrvPrice();
  4929.                             $subneto str_replace(',','.',$subneto);
  4930.                             $subneto floatval($subneto);
  4931.                             // Commission
  4932.                             if ($itemInvoice->getSrvOpCommission()=='1'){
  4933.                                 $subtotalService $subtotalService * (+ ($itemInvoice->getSrvCommission()/100));
  4934.                                 $subneto $subneto  * (+ ($itemInvoice->getSrvCommission()/100));
  4935.                             } else {
  4936.                                 $subtotalService $subtotalService * (- ($itemInvoice->getSrvCommission()/100));
  4937.                                 $subneto $subneto * (- ($itemInvoice->getSrvCommission()/100));
  4938.                             }
  4939.                             // Over
  4940.                             if ($itemInvoice->getSrvOpOver()=='1'){
  4941.                                 $subtotalService $subtotalService $itemInvoice->getSrvOver();
  4942.                                 $subneto $subneto $itemInvoice->getSrvOver();
  4943.                             } else {
  4944.                                 $subtotalService $subtotalService $itemInvoice->getSrvOver();
  4945.                                 $subneto $subneto $itemInvoice->getSrvOver();
  4946.                             }
  4947.                             // IVA
  4948.                             if ($itemInvoice->getSrvOpIva()=='1'){
  4949.                                 $subtotalService $subtotalService * (+ ($itemInvoice->getSrvIva()/100));
  4950.                             } else {
  4951.                                 $subtotalService $itemInvoice->getSrvPrice();
  4952.                                 $subneto = ($subneto 100) / (100 $itemInvoice->getSrvIva());
  4953.                             }
  4954.                             switch ($itemInvoice->getSrvServiceCatId()){
  4955.                                 case 1// Alojamiento
  4956.                                     // el numero de noches $numNoches; precio unitario $subneto
  4957.                                     $numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
  4958.                                     // La personas no afectan este calculo
  4959.                                     $subtotal $subtotalService $numNoches $itemInvoice->getSrvUnits();
  4960.                                     $subnetoUnit $subneto;
  4961.                                     $subneto $subneto $numNoches $itemInvoice->getSrvUnits();
  4962.                                     break;
  4963.                                 case 2//Actividades
  4964.                                     // El número de personas es considerado en el calculo
  4965.                                     $pax $itemInvoice->getSrvPax();
  4966.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  4967.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4968.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4969.                                     $subtotal $subtotalService $days $itemInvoice->getSrvUnits();
  4970.                                     $subnetoUnit $subneto;
  4971.                                     $subneto $subneto $days $itemInvoice->getSrvUnits();
  4972.                                     break;
  4973.                                 case 3// AV
  4974.                                     $pax $itemInvoice->getSrvPax();
  4975.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  4976.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4977.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4978.                                     $unitsServ $itemInvoice->getSrvUnits();
  4979.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  4980.                                     $subtotal $subtotalService $days $unitsServ $pax;
  4981.                                     $subnetoUnit $subneto;
  4982.                                     $subneto $subneto $days $unitsServ $pax;
  4983.                                     break;
  4984.                                 case 4//Creative
  4985.                                     $pax $itemInvoice->getSrvPax();
  4986.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  4987.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4988.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4989.                                     $unitsServ $itemInvoice->getSrvUnits();
  4990.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  4991.                                     $subtotal $subtotalService $days $unitsServ $pax;
  4992.                                     $subnetoUnit $subneto;
  4993.                                     $subneto $subneto $days $unitsServ $pax;
  4994.                                     break;
  4995.                                 case 5//Cruise
  4996.                                     $pax $itemInvoice->getSrvPax();
  4997.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  4998.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
  4999.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5000.                                     $unitsServ $itemInvoice->getSrvUnits();
  5001.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5002.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5003.                                     $subnetoUnit $subneto;
  5004.                                     $subneto $subneto $days $unitsServ $pax;
  5005.                                     break;
  5006.                                 case 6//Entertaiment
  5007.                                     $pax $itemInvoice->getSrvPax();
  5008.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5009.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5010.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5011.                                     $unitsServ $itemInvoice->getSrvUnits();
  5012.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5013.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5014.                                     $subnetoUnit $subneto;
  5015.                                     $subneto $subneto $days $unitsServ $pax;
  5016.                                     break;
  5017.                                 case 7// Gifts
  5018.                                     $pax $itemInvoice->getSrvPax();
  5019.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5020.                                     $days 1;
  5021.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5022.                                     $unitsServ $itemInvoice->getSrvUnits();
  5023.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5024.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5025.                                     $subnetoUnit $subneto;
  5026.                                     $subneto $subneto $days $unitsServ $pax;
  5027.                                     break;
  5028.                                 case 8//Guide
  5029.                                     $pax $itemInvoice->getSrvPax();
  5030.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5031.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5032.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5033.                                     $unitsServ $itemInvoice->getSrvUnits();
  5034.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5035.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5036.                                     $subnetoUnit $subneto;
  5037.                                     $subneto $subneto $days $unitsServ $pax;
  5038.                                     break;
  5039.                                 case 9//Itineraries
  5040.                                     $pax $itemInvoice->getSrvPax();
  5041.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5042.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5043.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5044.                                     $unitsServ $itemInvoice->getSrvUnits();
  5045.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5046.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5047.                                     $subnetoUnit $subneto;
  5048.                                     $subneto $subneto $days $unitsServ $pax;
  5049.                                     break;
  5050.                                 case 10//Lounge  -- No Aplica
  5051.                                     break;
  5052.                                 case 11//Menu (Catering)
  5053.                                     $pax $itemInvoice->getSrvPax();
  5054.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5055.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5056.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5057.                                     $unitsServ $itemInvoice->getSrvUnits();
  5058.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5059.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5060.                                     $subnetoUnit $subneto;
  5061.                                     $subneto $subneto $days $unitsServ $pax;
  5062.                                     break;
  5063.                                 case 12//Others
  5064.                                     $pax $itemInvoice->getSrvPax();
  5065.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5066.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5067.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5068.                                     $unitsServ $itemInvoice->getSrvUnits();
  5069.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5070.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5071.                                     $subnetoUnit $subneto;
  5072.                                     $subneto $subneto $days $unitsServ $pax;
  5073.                                     break;
  5074.                                 case 13//Transport
  5075.                                     $pax $itemInvoice->getSrvPax();
  5076.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5077.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5078.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5079.                                     $unitsServ $itemInvoice->getSrvUnits();
  5080.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5081.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5082.                                     $subnetoUnit $subneto;
  5083.                                     $subneto $subneto $days $unitsServ $pax;
  5084.                                     break;
  5085.                                 case 14//Technology
  5086.                                     $pax $itemInvoice->getSrvPax();
  5087.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5088.                                     $days 1;
  5089.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  5090.                                     $unitsServ $itemInvoice->getSrvUnits();
  5091.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5092.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5093.                                     $subnetoUnit $subneto;
  5094.                                     $subneto $subneto $days $unitsServ $pax;
  5095.                                     break;
  5096.                                 case 15//Assisstant
  5097.                                     $pax $itemInvoice->getSrvPax();
  5098.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5099.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5100.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5101.                                     $unitsServ $itemInvoice->getSrvUnits();
  5102.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5103.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5104.                                     $subnetoUnit $subneto;
  5105.                                     $subneto $subneto $days $unitsServ $pax;
  5106.                                     break;
  5107.                                 case 16//DDR
  5108.                                     $pax $itemInvoice->getSrvPax();
  5109.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5110.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5111.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5112.                                     $unitsServ $itemInvoice->getSrvUnits();
  5113.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5114.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5115.                                     $subnetoUnit $subneto;
  5116.                                     $subneto $subneto $days $unitsServ $pax;
  5117.                                     break;
  5118.                                 case 17//Seguridad
  5119.                                     $pax $itemInvoice->getSrvPax();
  5120.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5121.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5122.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5123.                                     $unitsServ $itemInvoice->getSrvUnits();
  5124.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5125.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5126.                                     $subnetoUnit $subneto;
  5127.                                     $subneto $subneto $days $unitsServ $pax;
  5128.                                     break;
  5129.                                 case 18//WiFi
  5130.                                     $pax $itemInvoice->getSrvPax();
  5131.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5132.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5133.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5134.                                     $unitsServ $itemInvoice->getSrvUnits();
  5135.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5136.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5137.                                     $subnetoUnit $subneto;
  5138.                                     $subneto $subneto $days $unitsServ $pax;
  5139.                                     break;
  5140.                                 case 19//Mobiliario
  5141.                                     $pax $itemInvoice->getSrvPax();
  5142.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5143.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5144.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5145.                                     $unitsServ $itemInvoice->getSrvUnits();
  5146.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5147.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5148.                                     $subnetoUnit $subneto;
  5149.                                     $subneto $subneto $days $unitsServ $pax;
  5150.                                     break;
  5151.                                 case 20//Parking
  5152.                                     $pax $itemInvoice->getSrvPax();
  5153.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5154.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5155.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5156.                                     $unitsServ $itemInvoice->getSrvUnits();
  5157.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5158.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5159.                                     $subnetoUnit $subneto;
  5160.                                     $subneto $subneto $days $unitsServ $pax;
  5161.                                     break;
  5162.                                 case 21//Limpieza
  5163.                                     $pax $itemInvoice->getSrvPax();
  5164.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5165.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5166.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5167.                                     $unitsServ $itemInvoice->getSrvUnits();
  5168.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5169.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5170.                                     $subnetoUnit $subneto;
  5171.                                     $subneto $subneto $days $unitsServ $pax;
  5172.                                     break;
  5173.                                 default: //Others (por default)
  5174.                                     $pax $itemInvoice->getSrvPax();
  5175.                                     if (empty($pax) or $pax == "0") { $pax 1; }
  5176.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5177.                                     $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5178.                                     $unitsServ $itemInvoice->getSrvUnits();
  5179.                                     if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5180.                                     $subtotal $subtotalService $days $unitsServ $pax;
  5181.                                     $subnetoUnit $subneto;
  5182.                                     $subneto $subneto $days $unitsServ $pax;
  5183.                                     break;
  5184.                             }
  5185.                             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  5186.                             $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  5187.                             $neto round($subneto,2,PHP_ROUND_HALF_UP);
  5188.                             $valorTotalNet $valorTotalNet $neto;
  5189.                             $valorVat $valorVat + ($subtotal $neto);
  5190.                         }
  5191.                     }
  5192.                 }
  5193.             }
  5194.             if (!empty($arrayInvoicedItems)) {
  5195.                 foreach ($arrayInvoicedItems as $itemInvoice) {
  5196.                     if ($itemInvoice->getItemType() == 'PAYMENT') {
  5197.                         //Acumulamos neto e iva para la factura
  5198.                         //$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();    // El pago no puede afectar el neto de la factura
  5199.                     }
  5200.                 }
  5201.             }
  5202.             //FIN: Creamos los items de la factura
  5203.             $valorTotal $valorTotalNet $valorVat;
  5204.             //INICIO: Creamos la factura
  5205.             $newInvoice $em->getRepository(ReservationInvoice::class)->findOneById($id);
  5206.             //FIN: Creamos la factura
  5207.             $data = array();
  5208.             $data $this->baseInvoiceDoneReservation($newInvoice->getReservationId(), $id,'I');
  5209.             $paymentsClient = new ReservationPaymentsClient();
  5210.             $paymentsClient->setReservationId($id);
  5211.             $reservaInv = new ReservationInvoice();
  5212.             $reservaInv->setReservationId($id);
  5213.             $idLounges = array();
  5214.             $loungesBoolToInvoice = array();
  5215.             if (array_key_exists('lounge',$data['datasupplier'])) {
  5216.                 foreach ($data['datasupplier']['lounge'] as $item) {
  5217.                     $idLounges[] = $item['id'];
  5218.                     $loungesBoolToInvoice[] = 1;
  5219.                 }
  5220.                 $idLounges implode(','$idLounges);
  5221.                 $loungesBoolToInvoice implode(','$loungesBoolToInvoice);
  5222.             } else {
  5223.                 $idLounges '0';
  5224.                 $loungesBoolToInvoice '0';
  5225.             }
  5226.             $idPayments = array();
  5227.             $paymentsBoolToInvoice = array();
  5228.             if (array_key_exists('payment',$data['datasupplier'])) {
  5229.                 foreach ($data['datasupplier']['payment'] as $item) {
  5230.                     $idPayments[] = $item['id'];
  5231.                     $paymentsBoolToInvoice[] = 1;
  5232.                 }
  5233.                 $idPayments implode(','$idPayments);
  5234.                 $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  5235.                 // Se han generado dos arreglos, cada uno dividido en 2 strings
  5236.                 // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  5237.                 // Para manipularlos entre la vista y el JS
  5238.             } else {
  5239.                 $idPayments '0';
  5240.                 $paymentsBoolToInvoice '0';
  5241.             }
  5242.             $allInvoices $em->getRepository(ReservationInvoice::class)->findByReservationId($newInvoice->getReservationId());
  5243.             //Es una proforma
  5244.             $proforma $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
  5245.             $invoiceIdToRec null;
  5246.             $reservaEquis $em->getRepository(Reservation::class)->findOneById($newInvoice->getReservationId());
  5247.             if(empty($newInvoice->getClientName()) and empty($newInvoice->getClientAddress()) and empty($newInvoice->getClientDocument())){
  5248.                 $newInvoice $this->clientDataToInvoice($newInvoice'Client'$reservaEquis->getClient(), $newInvoice->getReservationId());
  5249.             }
  5250.         } else {
  5251.             if ($type == 'R'){
  5252.                 //El tipo es una factura rectificativa
  5253.                 //INICIO: Creamos los items de la factura rectficativa
  5254.                 $arrayInvoicedItems $em->getRepository(ReservationInvoiceRecItems::class)->findByInvoiceRecId($id);
  5255.                 if (!empty($arrayInvoicedItems)) {
  5256.                     foreach ($arrayInvoicedItems as $itemInvoice) {
  5257.                         if ($itemInvoice->getItemType() == 'LOUNGE') {
  5258.                             //Acumulamos neto e iva para la factura rectificativa
  5259.                             $valorTotalNet $valorTotalNet $itemInvoice->getLngServicePrice();
  5260.                             $valorVat $valorVat round(($itemInvoice->getLngServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
  5261.                         }
  5262.                     }
  5263.                 }
  5264.                 if (!empty($arrayInvoicedItems)) {
  5265.                     foreach ($arrayInvoicedItems as $itemInvoice) {
  5266.                         if ($itemInvoice->getItemType() == 'SERVICE') {
  5267.                             //Acumulamos neto e iva para la factura
  5268.                             if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())){
  5269.                                 $subtotal 0;
  5270.                                 $neto 0;
  5271.                                 $subtotalService 0;
  5272.                             } else {
  5273.                                 $subtotalService $itemInvoice->getSrvPrice();
  5274.                                 $subneto $itemInvoice->getSrvPrice();
  5275.                                 // Commission
  5276.                                 if ($itemInvoice->getSrvOpCommission()=='1'){
  5277.                                     $subtotalService $subtotalService * (+ ($itemInvoice->getSrvCommission()/100));
  5278.                                     $subneto $subneto  * (+ ($itemInvoice->getSrvCommission()/100));
  5279.                                 } else {
  5280.                                     $subtotalService $subtotalService * (- ($itemInvoice->getSrvCommission()/100));
  5281.                                     $subneto $subneto * (- ($itemInvoice->getSrvCommission()/100));
  5282.                                 }
  5283.                                 // Over
  5284.                                 if ($itemInvoice->getSrvOpOver()=='1'){
  5285.                                     $subtotalService $subtotalService $itemInvoice->getSrvOver();
  5286.                                     $subneto $subneto $itemInvoice->getSrvOver();
  5287.                                 } else {
  5288.                                     $subtotalService $subtotalService $itemInvoice->getSrvOver();
  5289.                                     $subneto $subneto $itemInvoice->getSrvOver();
  5290.                                 }
  5291.                                 // IVA
  5292.                                 if ($itemInvoice->getSrvOpIva()=='1'){
  5293.                                     $subtotalService $subtotalService * (+ ($itemInvoice->getSrvIva()/100));
  5294.                                 } else {
  5295.                                     $subtotalService $itemInvoice->getSrvPrice();
  5296.                                     $subneto = ($subneto 100) / (100 $itemInvoice->getSrvIva());
  5297.                                 }
  5298.                                 switch ($itemInvoice->getSrvServiceCatId()){
  5299.                                     case 1// Alojamiento
  5300.                                         // el numero de noches $numNoches; precio unitario $subneto
  5301.                                         $numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
  5302.                                         // La personas no afectan este calculo
  5303.                                         $subtotal $subtotalService $numNoches $itemInvoice->getSrvUnits();
  5304.                                         $subnetoUnit $subneto;
  5305.                                         $subneto $subneto $numNoches $itemInvoice->getSrvUnits();
  5306.                                         break;
  5307.                                     case 2//Actividades
  5308.                                         // El número de personas es considerado en el calculo
  5309.                                         $pax $itemInvoice->getSrvPax();
  5310.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5311.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5312.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5313.                                         $subtotal $subtotalService $days $itemInvoice->getSrvUnits();
  5314.                                         $subnetoUnit $subneto;
  5315.                                         $subneto $subneto $days $itemInvoice->getSrvUnits();
  5316.                                         break;
  5317.                                     case 3// AV
  5318.                                         $pax $itemInvoice->getSrvPax();
  5319.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5320.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5321.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5322.                                         $unitsServ $itemInvoice->getSrvUnits();
  5323.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5324.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5325.                                         $subnetoUnit $subneto;
  5326.                                         $subneto $subneto $days $unitsServ $pax;
  5327.                                         break;
  5328.                                     case 4//Creative
  5329.                                         $pax $itemInvoice->getSrvPax();
  5330.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5331.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5332.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5333.                                         $unitsServ $itemInvoice->getSrvUnits();
  5334.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5335.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5336.                                         $subnetoUnit $subneto;
  5337.                                         $subneto $subneto $days $unitsServ $pax;
  5338.                                         break;
  5339.                                     case 5//Cruise
  5340.                                         $pax $itemInvoice->getSrvPax();
  5341.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5342.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
  5343.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5344.                                         $unitsServ $itemInvoice->getSrvUnits();
  5345.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5346.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5347.                                         $subnetoUnit $subneto;
  5348.                                         $subneto $subneto $days $unitsServ $pax;
  5349.                                         break;
  5350.                                     case 6//Entertaiment
  5351.                                         $pax $itemInvoice->getSrvPax();
  5352.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5353.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5354.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5355.                                         $unitsServ $itemInvoice->getSrvUnits();
  5356.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5357.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5358.                                         $subnetoUnit $subneto;
  5359.                                         $subneto $subneto $days $unitsServ $pax;
  5360.                                         break;
  5361.                                     case 7// Gifts
  5362.                                         $pax $itemInvoice->getSrvPax();
  5363.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5364.                                         $days 1;
  5365.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5366.                                         $unitsServ $itemInvoice->getSrvUnits();
  5367.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5368.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5369.                                         $subnetoUnit $subneto;
  5370.                                         $subneto $subneto $days $unitsServ $pax;
  5371.                                         break;
  5372.                                     case 8//Guide
  5373.                                         $pax $itemInvoice->getSrvPax();
  5374.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5375.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5376.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5377.                                         $unitsServ $itemInvoice->getSrvUnits();
  5378.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5379.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5380.                                         $subnetoUnit $subneto;
  5381.                                         $subneto $subneto $days $unitsServ $pax;
  5382.                                         break;
  5383.                                     case 9//Itineraries
  5384.                                         $pax $itemInvoice->getSrvPax();
  5385.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5386.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5387.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5388.                                         $unitsServ $itemInvoice->getSrvUnits();
  5389.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5390.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5391.                                         $subnetoUnit $subneto;
  5392.                                         $subneto $subneto $days $unitsServ $pax;
  5393.                                         break;
  5394.                                     case 10//Lounge  -- No Aplica
  5395.                                         break;
  5396.                                     case 11//Catering
  5397.                                         $pax $itemInvoice->getSrvPax();
  5398.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5399.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5400.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5401.                                         $unitsServ $itemInvoice->getSrvUnits();
  5402.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5403.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5404.                                         $subnetoUnit $subneto;
  5405.                                         $subneto $subneto $days $unitsServ $pax;
  5406.                                         break;
  5407.                                     case 12//Others
  5408.                                         $pax $itemInvoice->getSrvPax();
  5409.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5410.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5411.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5412.                                         $unitsServ $itemInvoice->getSrvUnits();
  5413.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5414.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5415.                                         $subnetoUnit $subneto;
  5416.                                         $subneto $subneto $days $unitsServ $pax;
  5417.                                         break;
  5418.                                     case 13//Transport
  5419.                                         $pax $itemInvoice->getSrvPax();
  5420.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5421.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5422.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5423.                                         $unitsServ $itemInvoice->getSrvUnits();
  5424.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5425.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5426.                                         $subnetoUnit $subneto;
  5427.                                         $subneto $subneto $days $unitsServ $pax;
  5428.                                         break;
  5429.                                     case 14//Technology
  5430.                                         $pax $itemInvoice->getSrvPax();
  5431.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5432.                                         $days 1;
  5433.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  5434.                                         $unitsServ $itemInvoice->getSrvUnits();
  5435.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5436.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5437.                                         $subnetoUnit $subneto;
  5438.                                         $subneto $subneto $days $unitsServ $pax;
  5439.                                         break;
  5440.                                     case 15//Assisstant
  5441.                                         $pax $itemInvoice->getSrvPax();
  5442.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5443.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5444.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5445.                                         $unitsServ $itemInvoice->getSrvUnits();
  5446.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5447.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5448.                                         $subnetoUnit $subneto;
  5449.                                         $subneto $subneto $days $unitsServ $pax;
  5450.                                         break;
  5451.                                     case 16//DDR
  5452.                                         $pax $itemInvoice->getSrvPax();
  5453.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5454.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5455.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5456.                                         $unitsServ $itemInvoice->getSrvUnits();
  5457.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5458.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5459.                                         $subnetoUnit $subneto;
  5460.                                         $subneto $subneto $days $unitsServ $pax;
  5461.                                         break;
  5462.                                     case 17//Seguridad
  5463.                                         $pax $itemInvoice->getSrvPax();
  5464.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5465.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5466.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5467.                                         $unitsServ $itemInvoice->getSrvUnits();
  5468.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5469.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5470.                                         $subnetoUnit $subneto;
  5471.                                         $subneto $subneto $days $unitsServ $pax;
  5472.                                         break;
  5473.                                     case 18//WiFi
  5474.                                         $pax $itemInvoice->getSrvPax();
  5475.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5476.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5477.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5478.                                         $unitsServ $itemInvoice->getSrvUnits();
  5479.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5480.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5481.                                         $subnetoUnit $subneto;
  5482.                                         $subneto $subneto $days $unitsServ $pax;
  5483.                                         break;
  5484.                                     case 19//Mobiliario
  5485.                                         $pax $itemInvoice->getSrvPax();
  5486.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5487.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5488.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5489.                                         $unitsServ $itemInvoice->getSrvUnits();
  5490.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5491.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5492.                                         $subnetoUnit $subneto;
  5493.                                         $subneto $subneto $days $unitsServ $pax;
  5494.                                         break;
  5495.                                     case 20//Parking
  5496.                                         $pax $itemInvoice->getSrvPax();
  5497.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5498.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5499.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5500.                                         $unitsServ $itemInvoice->getSrvUnits();
  5501.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5502.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5503.                                         $subnetoUnit $subneto;
  5504.                                         $subneto $subneto $days $unitsServ $pax;
  5505.                                         break;
  5506.                                     case 21//Limpieza
  5507.                                         $pax $itemInvoice->getSrvPax();
  5508.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5509.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5510.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5511.                                         $unitsServ $itemInvoice->getSrvUnits();
  5512.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5513.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5514.                                         $subnetoUnit $subneto;
  5515.                                         $subneto $subneto $days $unitsServ $pax;
  5516.                                         break;
  5517.                                     default: //Others (por default)
  5518.                                         $pax $itemInvoice->getSrvPax();
  5519.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5520.                                         $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  5521.                                         $dateServ = ($days 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  5522.                                         $unitsServ $itemInvoice->getSrvUnits();
  5523.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5524.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5525.                                         $subnetoUnit $subneto;
  5526.                                         $subneto $subneto $days $unitsServ $pax;
  5527.                                         break;
  5528.                                 }
  5529.                                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  5530.                                 $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  5531.                                 $neto round($subneto,2,PHP_ROUND_HALF_UP);
  5532.                                 $valorTotalNet $valorTotalNet $neto;
  5533.                                 $valorVat $valorVat + ($subtotal $neto);
  5534.                             }
  5535.                         }
  5536.                     }
  5537.                 }
  5538.                 if (!empty($arrayInvoicedItems)) {
  5539.                     foreach ($arrayInvoicedItems as $itemInvoice) {
  5540.                         if ($itemInvoice->getItemType() == 'PAYMENT') {
  5541.                             //Acumulamos neto e iva para la factura
  5542.                             //$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();    // El pago no puede afectar el neto de la factura
  5543.                         }
  5544.                     }
  5545.                 }
  5546.                 //FIN: Creamos los items de la factura
  5547.                 $valorTotal $valorTotalNet $valorVat;
  5548.                 //INICIO: Creamos la factura rectificativa
  5549.                 $newInvoice $em->getRepository(ReservationInvoiceRec::class)->findOneById($id);
  5550.                 //FIN: Creamos la factura rectificativa
  5551.                 $data = array();
  5552.                 $data $this->baseInvoiceDoneReservation($newInvoice->getReservationId(), $id,'R');
  5553.                 $paymentsClient = new ReservationPaymentsClient();
  5554.                 $paymentsClient->setReservationId($id);
  5555.                 $reservaInv = new ReservationInvoice();
  5556.                 $reservaInv->setReservationId($id);
  5557.                 $idLounges = array();
  5558.                 $loungesBoolToInvoice = array();
  5559.                 if (array_key_exists('lounge',$data['datasupplier'])) {
  5560.                     foreach ($data['datasupplier']['lounge'] as $item) {
  5561.                         $idLounges[] = $item['id'];
  5562.                         $loungesBoolToInvoice[] = 1;
  5563.                     }
  5564.                     $idLounges implode(','$idLounges);
  5565.                     $loungesBoolToInvoice implode(','$loungesBoolToInvoice);
  5566.                 } else {
  5567.                     $idLounges '0';
  5568.                     $loungesBoolToInvoice '0';
  5569.                 }
  5570.                 $idPayments = array();
  5571.                 $paymentsBoolToInvoice = array();
  5572.                 if (array_key_exists('payment',$data['datasupplier'])) {
  5573.                     foreach ($data['datasupplier']['payment'] as $item) {
  5574.                         $idPayments[] = $item['id'];
  5575.                         $paymentsBoolToInvoice[] = 1;
  5576.                     }
  5577.                     $idPayments implode(','$idPayments);
  5578.                     $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  5579.                     // Se han generado dos arreglos, cada uno dividido en 2 strings
  5580.                     // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  5581.                     // Para manipularlos entre la vista y el JS
  5582.                 } else {
  5583.                     $idPayments '0';
  5584.                     $paymentsBoolToInvoice '0';
  5585.                 }
  5586.                 $allInvoices $em->getRepository(ReservationInvoice::class)->findByReservationId($newInvoice->getReservationId());
  5587.                 //Es una proforma
  5588.                 $proforma $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
  5589.                 $invoiceIdToRec $newInvoice->getInvoiceToRec();
  5590.                 $data['number'] = $data['number']->getNumber();
  5591.                 $data['balance'] = $data['balance'] *(-1);
  5592.                 $reservaEquis $em->getRepository(Reservation::class)->findOneById($newInvoice->getReservationId());
  5593.                 if(empty($newInvoice->getClientName()) and empty($newInvoice->getClientAddress()) and empty($newInvoice->getClientDocument())){
  5594.                     $newInvoice $this->clientDataToInvoice($newInvoice'Client'$reservaEquis->getClient(), $newInvoice->getReservationId());
  5595.                 }
  5596.             } else {
  5597.                 // El tipo es una proforma
  5598.                 //INICIO: Creamos los items de la proforma
  5599.                 $arrayInvoicedItems $em->getRepository(ReservationInvoiceProformaItems::class)->findByProformaId($id);
  5600.                 if (!empty($arrayInvoicedItems)) {
  5601.                     foreach ($arrayInvoicedItems as $itemInvoice) {
  5602.                         if ($itemInvoice->getType() == 'LOUNGE') {
  5603.                             $itemPro $em->getRepository(ReservationLoungeSimple::class)->findOneById($itemInvoice->getControlId());
  5604.                             //Acumulamos neto e iva para la factura
  5605.                             $valorTotalNet $valorTotalNet $itemPro->getServicePrice();
  5606.                             $valorVat $valorVat round(($itemPro->getServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
  5607.                         }
  5608.                     }
  5609.                 }
  5610.                 if (!empty($arrayInvoicedItems)) {
  5611.                     foreach ($arrayInvoicedItems as $itemInvoice) {
  5612.                         if ($itemInvoice->getType() == 'SERVICE') {
  5613.                             $itemPro $em->getRepository(ReservationService::class)->findOneById($itemInvoice->getControlId());
  5614.                             //Acumulamos neto e iva para la factura
  5615.                             if (is_null($itemPro->getPrice()) or empty($itemPro->getPrice())){
  5616.                                 $subtotal 0;
  5617.                                 $neto 0;
  5618.                                 $subtotalService 0;
  5619.                             } else {
  5620.                                 $subtotalService $itemPro->getPrice();
  5621.                                 $subneto $itemPro->getPrice();
  5622.                                 // Commission
  5623.                                 if ($itemPro->getOpCommission()=='1'){
  5624.                                     $subtotalService $subtotalService * (+ ($itemPro->getCommission()/100));
  5625.                                     $subneto $subneto  * (+ ($itemPro->getCommission()/100));
  5626.                                 } else {
  5627.                                     $subtotalService $subtotalService * (- ($itemPro->getCommission()/100));
  5628.                                     $subneto $subneto * (- ($itemPro->getCommission()/100));
  5629.                                 }
  5630.                                 // Over
  5631.                                 if ($itemPro->getOpOver()=='1'){
  5632.                                     $subtotalService $subtotalService $itemPro->getOver();
  5633.                                     $subneto $subneto $itemPro->getOver();
  5634.                                 } else {
  5635.                                     $subtotalService $subtotalService $itemPro->getOver();
  5636.                                     $subneto $subneto $itemPro->getOver();
  5637.                                 }
  5638.                                 // IVA
  5639.                                 if ($itemPro->getOpIva()=='1'){
  5640.                                     $subtotalService $subtotalService * (+ ($itemPro->getIva()/100));
  5641.                                 } else {
  5642.                                     $subtotalService $itemPro->getPrice();
  5643.                                     $subneto = ($subneto 100) / (100 $itemPro->getIva());
  5644.                                 }
  5645.                                 switch ($itemPro->getServiceCatId()){
  5646.                                     case 1// Alojamiento
  5647.                                         // el numero de noches $numNoches; precio unitario $subneto
  5648.                                         $numNoches = (($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days;
  5649.                                         // La personas no afectan este calculo
  5650.                                         $subtotal $subtotalService $numNoches $itemPro->getUnits();
  5651.                                         $subnetoUnit $subneto;
  5652.                                         $subneto $subneto $numNoches $itemPro->getUnits();
  5653.                                         break;
  5654.                                     case 2//Actividades
  5655.                                         // El número de personas es considerado en el calculo
  5656.                                         $pax $itemPro->getPax();
  5657.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5658.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5659.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5660.                                         $subtotal $subtotalService $days $itemPro->getUnits();
  5661.                                         $subnetoUnit $subneto;
  5662.                                         $subneto $subneto $days $itemPro->getUnits();
  5663.                                         break;
  5664.                                     case 3// AV
  5665.                                         $pax $itemPro->getPax();
  5666.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5667.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5668.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5669.                                         $unitsServ $itemPro->getUnits();
  5670.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5671.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5672.                                         $subnetoUnit $subneto;
  5673.                                         $subneto $subneto $days $unitsServ $pax;
  5674.                                         break;
  5675.                                     case 4//Creative
  5676.                                         $pax $itemPro->getPax();
  5677.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5678.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5679.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5680.                                         $unitsServ $itemPro->getUnits();
  5681.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5682.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5683.                                         $subnetoUnit $subneto;
  5684.                                         $subneto $subneto $days $unitsServ $pax;
  5685.                                         break;
  5686.                                     case 5//Cruise
  5687.                                         $pax $itemPro->getPax();
  5688.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5689.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days);
  5690.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5691.                                         $unitsServ $itemPro->getUnits();
  5692.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5693.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5694.                                         $subnetoUnit $subneto;
  5695.                                         $subneto $subneto $days $unitsServ $pax;
  5696.                                         break;
  5697.                                     case 6//Entertaiment
  5698.                                         $pax $itemPro->getPax();
  5699.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5700.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5701.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5702.                                         $unitsServ $itemPro->getUnits();
  5703.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5704.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5705.                                         $subnetoUnit $subneto;
  5706.                                         $subneto $subneto $days $unitsServ $pax;
  5707.                                         break;
  5708.                                     case 7// Gifts
  5709.                                         $pax $itemPro->getPax();
  5710.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5711.                                         $days 1;
  5712.                                         $dateServ = ($itemPro->getDateInAt())->format('d/m/Y');
  5713.                                         $unitsServ $itemPro->getUnits();
  5714.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5715.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5716.                                         $subnetoUnit $subneto;
  5717.                                         $subneto $subneto $days $unitsServ $pax;
  5718.                                         break;
  5719.                                     case 8//Guide
  5720.                                         $pax $itemPro->getPax();
  5721.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5722.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5723.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5724.                                         $unitsServ $itemPro->getUnits();
  5725.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5726.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5727.                                         $subnetoUnit $subneto;
  5728.                                         $subneto $subneto $days $unitsServ $pax;
  5729.                                         break;
  5730.                                     case 9//Itineraries
  5731.                                         $pax $itemPro->getPax();
  5732.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5733.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5734.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5735.                                         $unitsServ $itemPro->getUnits();
  5736.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5737.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5738.                                         $subnetoUnit $subneto;
  5739.                                         $subneto $subneto $days $unitsServ $pax;
  5740.                                         break;
  5741.                                     case 10//Lounge  -- No Aplica
  5742.                                         break;
  5743.                                     case 11//Menu
  5744.                                         $pax $itemPro->getPax();
  5745.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5746.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5747.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5748.                                         $unitsServ $itemPro->getUnits();
  5749.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5750.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5751.                                         $subnetoUnit $subneto;
  5752.                                         $subneto $subneto $days $unitsServ $pax;
  5753.                                         break;
  5754.                                     case 12//Others
  5755.                                         $pax $itemPro->getPax();
  5756.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5757.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5758.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5759.                                         $unitsServ $itemPro->getUnits();
  5760.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5761.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5762.                                         $subnetoUnit $subneto;
  5763.                                         $subneto $subneto $days $unitsServ $pax;
  5764.                                         break;
  5765.                                     case 13//Transport
  5766.                                         $pax $itemPro->getPax();
  5767.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5768.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5769.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5770.                                         $unitsServ $itemPro->getUnits();
  5771.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5772.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5773.                                         $subnetoUnit $subneto;
  5774.                                         $subneto $subneto $days $unitsServ $pax;
  5775.                                         break;
  5776.                                     case 14//Technology
  5777.                                         $pax $itemPro->getPax();
  5778.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5779.                                         $days 1;
  5780.                                         $dateServ = ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y');
  5781.                                         $unitsServ $itemPro->getUnits();
  5782.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5783.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5784.                                         $subnetoUnit $subneto;
  5785.                                         $subneto $subneto $days $unitsServ $pax;
  5786.                                         break;
  5787.                                     case 15//Assisstant
  5788.                                         $pax $itemPro->getPax();
  5789.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5790.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5791.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5792.                                         $unitsServ $itemPro->getUnits();
  5793.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5794.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5795.                                         $subnetoUnit $subneto;
  5796.                                         $subneto $subneto $days $unitsServ $pax;
  5797.                                         break;
  5798.                                     case 16//DDR
  5799.                                         $pax $itemPro->getPax();
  5800.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5801.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5802.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5803.                                         $unitsServ $itemPro->getUnits();
  5804.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5805.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5806.                                         $subnetoUnit $subneto;
  5807.                                         $subneto $subneto $days $unitsServ $pax;
  5808.                                         break;
  5809.                                     case 17//Seguridad
  5810.                                         $pax $itemPro->getPax();
  5811.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5812.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5813.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5814.                                         $unitsServ $itemPro->getUnits();
  5815.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5816.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5817.                                         $subnetoUnit $subneto;
  5818.                                         $subneto $subneto $days $unitsServ $pax;
  5819.                                         break;
  5820.                                     case 18//WiFi
  5821.                                         $pax $itemPro->getPax();
  5822.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5823.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5824.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5825.                                         $unitsServ $itemPro->getUnits();
  5826.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5827.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5828.                                         $subnetoUnit $subneto;
  5829.                                         $subneto $subneto $days $unitsServ $pax;
  5830.                                         break;
  5831.                                     case 19//Mobiliario
  5832.                                         $pax $itemPro->getPax();
  5833.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5834.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5835.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5836.                                         $unitsServ $itemPro->getUnits();
  5837.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5838.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5839.                                         $subnetoUnit $subneto;
  5840.                                         $subneto $subneto $days $unitsServ $pax;
  5841.                                         break;
  5842.                                     case 20//Parking
  5843.                                         $pax $itemPro->getPax();
  5844.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5845.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5846.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5847.                                         $unitsServ $itemPro->getUnits();
  5848.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5849.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5850.                                         $subnetoUnit $subneto;
  5851.                                         $subneto $subneto $days $unitsServ $pax;
  5852.                                         break;
  5853.                                     case 21//Limpieza
  5854.                                         $pax $itemPro->getPax();
  5855.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5856.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5857.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5858.                                         $unitsServ $itemPro->getUnits();
  5859.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5860.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5861.                                         $subnetoUnit $subneto;
  5862.                                         $subneto $subneto $days $unitsServ $pax;
  5863.                                         break;
  5864.                                     default: //Others (por default)
  5865.                                         $pax $itemPro->getPax();
  5866.                                         if (empty($pax) or $pax == "0") { $pax 1; }
  5867.                                         $days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days 1);
  5868.                                         $dateServ = ($days 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
  5869.                                         $unitsServ $itemPro->getUnits();
  5870.                                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  5871.                                         $subtotal $subtotalService $days $unitsServ $pax;
  5872.                                         $subnetoUnit $subneto;
  5873.                                         $subneto $subneto $days $unitsServ $pax;
  5874.                                         break;
  5875.                                 }
  5876.                                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  5877.                                 $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  5878.                                 $neto round($subneto,2,PHP_ROUND_HALF_UP);
  5879.                                 $valorTotalNet $valorTotalNet $neto;
  5880.                                 $valorVat $valorVat + ($subtotal $neto);
  5881.                             }
  5882.                         }
  5883.                     }
  5884.                 }
  5885.                 if (!empty($arrayInvoicedItems)) {
  5886.                     foreach ($arrayInvoicedItems as $itemInvoice) {
  5887.                         if ($itemInvoice->getType() == 'PAYMENT') {
  5888.                             //Acumulamos neto e iva para la factura
  5889.                             //$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();    // El pago no puede afectar el neto de la factura
  5890.                         }
  5891.                     }
  5892.                 }
  5893.                 //FIN: Creamos los items de la factura
  5894.                 $valorTotal $valorTotalNet $valorVat;
  5895.                 //INICIO: Creamos la factura
  5896.                 $newInvoice $em->getRepository(ReservationProforma::class)->findOneById($id);
  5897.                 //FIN: Creamos la factura
  5898.                 $data = array();
  5899.                 $data $this->baseInvoiceDoneReservation($newInvoice->getReservationId(), $id,'P');
  5900.                 $paymentsClient = new ReservationPaymentsClient();
  5901.                 $paymentsClient->setReservationId($id);
  5902.                 $reservaInv = new ReservationInvoice();
  5903.                 $reservaInv->setReservationId($id);
  5904.                 $idLounges = array();
  5905.                 $loungesBoolToInvoice = array();
  5906.                 if (array_key_exists('lounge',$data['datasupplier'])) {
  5907.                     foreach ($data['datasupplier']['lounge'] as $item) {
  5908.                         $idLounges[] = $item['id'];
  5909.                         $loungesBoolToInvoice[] = 1;
  5910.                     }
  5911.                     $idLounges implode(','$idLounges);
  5912.                     $loungesBoolToInvoice implode(','$loungesBoolToInvoice);
  5913.                 } else {
  5914.                     $idLounges '0';
  5915.                     $loungesBoolToInvoice '0';
  5916.                 }
  5917.                 $idPayments = array();
  5918.                 $paymentsBoolToInvoice = array();
  5919.                 if (array_key_exists('payment',$data['datasupplier'])) {
  5920.                     foreach ($data['datasupplier']['payment'] as $item) {
  5921.                         $idPayments[] = $item['id'];
  5922.                         $paymentsBoolToInvoice[] = 1;
  5923.                     }
  5924.                     $idPayments implode(','$idPayments);
  5925.                     $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  5926.                     // Se han generado dos arreglos, cada uno dividido en 2 strings
  5927.                     // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  5928.                     // Para manipularlos entre la vista y el JS
  5929.                 } else {
  5930.                     $idPayments '0';
  5931.                     $paymentsBoolToInvoice '0';
  5932.                 }
  5933.                 $allInvoices $em->getRepository(ReservationInvoice::class)->findByReservationId($newInvoice->getReservationId());
  5934.                 //Es una proforma
  5935.                 $proforma $em->getRepository(ReservationProforma::class)->findOneById($id);
  5936.                 $invoiceIdToRec null;
  5937.                 $reservaEquis $em->getRepository(Reservation::class)->findOneById($proforma->getReservationId());
  5938. //                if(empty($newInvoice->getClientName()) and empty($newInvoice->getClientAddress()) and empty($newInvoice->getClientDocument())){
  5939.                 if(true){ $newInvoice $this->clientDataToInvoice(null'Client'$reservaEquis->getClient(), $reservaEquis->getId()); }
  5940.             }
  5941.         }
  5942.         return $this->render('MDS/GreenPatioBundle/reservations/services-proforma-print-reservation.html.twig',
  5943.             array(
  5944.                 'id' => $id,
  5945.                 'type' => $data['type'],
  5946.                 'number' => $data['number'],
  5947.                 'invoiceIdToRec' => $invoiceIdToRec,
  5948.                 'prefix' => $data['prefix'],
  5949.                 'date' => $data['date'],
  5950.                 'token' => '',
  5951.                 'company' => $data['company'],
  5952.                 'clients' => $data['clients'],
  5953.                 'datasupplier' => $data['datasupplier'],
  5954.                 'totales_neto' => $data['totales_neto'],
  5955.                 'bases_imponibles' => $data['bases_imponibles'],
  5956.                 'totales' => $data['totales'],
  5957.                 'balance' => $data['balance'],
  5958.                 'currency' => $data['currency'],
  5959.                 'paymentInvoice' => $data['paymentInvoice'],
  5960.                 'clientName' => $newInvoice->getClientName(),
  5961.                 'clientAddress' => $newInvoice->getClientAddress(),
  5962.                 'clientDocument' => $newInvoice->getClientDocument(),
  5963.             )
  5964.         );
  5965.     }
  5966.     /**
  5967.      * @Route("/reservations/invoice/proforma/printnew",  name="reservations_invoice_printnew")
  5968.      */
  5969.     public function detailsProformaPrintNewAction(Request $request){
  5970.         $em $this->getDoctrine()->getManager();
  5971.         // Se genera y muestra en nueva pantalla la nueva proforma
  5972.         $arrayBools = array(
  5973.             'lounge' => null,
  5974.             'service' => null,
  5975.             'payment' => null,
  5976.         );
  5977.         $arrayBools['lounge'] = $request->request->get('lounge_hidden_bool');
  5978.         $arrayBools['service'] = $request->request->get('service_hidden_bool');
  5979.         $arrayBools['payment'] = $request->request->get('payment_hidden_bool');
  5980.         $id $request->request->get('reservation_id');
  5981.         $proformaPrefix $request->request->get('proforma_prefix');
  5982.         //INICIO: Verificamos que el ID de la proforma se exactamente el ultimo
  5983.         $proformaId $request->request->get('proforma_number');
  5984.         $allProformas $em->getRepository(ReservationProforma::class)->findAll();
  5985.         if (!empty($allProformas)){
  5986.             $numberLast end($allProformas)->getId() + 1;
  5987.         } else {
  5988.             // Primer registro de proformas
  5989.             $numberLast 1;
  5990.         }
  5991.         if ($numberLast $proformaId){
  5992.             $proformaId $numberLast;
  5993.         }
  5994.         //FIN: Verificamos que el ID de la proforma se exactamente el ultimo
  5995.         /* Obtengo usuario logueado */
  5996.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5997.         $user_id $user_logueado->getId();
  5998.         //INICIO: Creamos los items de la proforma
  5999.         if (!empty($arrayBools['lounge'])) {
  6000.             foreach ($arrayBools['lounge'] as $key => $item) {
  6001.                 if ($item == 'true') {
  6002.                     $itemProforma = new ReservationInvoiceProformaItems();
  6003.                     $itemProforma->setControlId($key);
  6004.                     $itemProforma->setProformaId($proformaId);
  6005.                     $itemProforma->setReservationId($id);
  6006.                     $itemProforma->setType('LOUNGE');
  6007.                     $em->persist($itemProforma);
  6008.                     $em->flush();
  6009.                 }
  6010.             }
  6011.         }
  6012.         if (!empty($arrayBools['service'])) {
  6013.             foreach ($arrayBools['service'] as $key => $item) {
  6014.                 if ($item == 'true') {
  6015.                     $itemProforma = new ReservationInvoiceProformaItems();
  6016.                     $itemProforma->setControlId($key);
  6017.                     $itemProforma->setProformaId($proformaId);
  6018.                     $itemProforma->setReservationId($id);
  6019.                     $itemProforma->setType('SERVICE');
  6020.                     $em->persist($itemProforma);
  6021.                     $em->flush();
  6022.                 }
  6023.             }
  6024.         }
  6025.         if (!empty($arrayBools['payment'])) {
  6026.             foreach ($arrayBools['payment'] as $key => $item) {
  6027.                 if ($item == 'true') {
  6028.                     $itemProforma = new ReservationInvoiceProformaItems();
  6029.                     $itemProforma->setControlId($key);
  6030.                     $itemProforma->setProformaId($proformaId);
  6031.                     $itemProforma->setReservationId($id);
  6032.                     $itemProforma->setType('PAYMENT');
  6033.                     $em->persist($itemProforma);
  6034.                     $em->flush();
  6035.                 }
  6036.             }
  6037.         }
  6038.         //FIN: Creamos los items de la proforma
  6039.         //INICIO: Creamos la proforma
  6040.         $newProforma = new ReservationProforma();
  6041.         $newProforma->setDateAt(new DateTime('now'));
  6042.         $newProforma->setPrefix("GP-".date('dmy')."-");
  6043.         $newProforma->setReservationId($id);
  6044.         $newProforma->setCreatedAt(new DateTime('now'));
  6045.         $newProforma->setCreatedId($user_id);
  6046.         $newProforma->setUpdatedAt(new DateTime('now'));
  6047.         $newProforma->setUpdatedId($user_id);
  6048.         $accessKey md5('CR-JDEF'rand() * time());
  6049.         $newProforma->setAccessKey($accessKey);
  6050.         $em->persist($newProforma);
  6051.         $em->flush();
  6052.         //FIN: Creamos la proforma
  6053.         $data = array();
  6054.         $data $this->baseInvoiceSelectedReservation($id$arrayBools'P'.$newProforma->getId());
  6055.         $paymentsClient = new ReservationPaymentsClient();
  6056.         $paymentsClient->setReservationId($id);
  6057.         $form $this->createReservationPaymentsClientForm($paymentsClient);
  6058.         $reserva $em->getRepository(Reservation::class)->findOneById($id);
  6059.         $payments $em->getRepository(ReservationPaymentsClient::class)->findByReservationId($id);
  6060.         $services $em->getRepository(ReservationService::class)->findByReservationId($id);
  6061.         $proforma $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
  6062.         $reservaInv = new ReservationInvoice();
  6063.         $reservaInv->setReservationId($id);
  6064.         $form1 $this->createReservationInvoiceProformaForm($reservaInv);
  6065.         $idLounges = array();
  6066.         $loungesBoolToInvoice = array();
  6067.         if (array_key_exists('lounge',$data['datasupplier'])) {
  6068.             foreach ($data['datasupplier']['lounge'] as $item) {
  6069.                 $idLounges[] = $item['id'];
  6070.                 $loungesBoolToInvoice[] = 1;
  6071.             }
  6072.             $idLounges implode(','$idLounges);
  6073.             $loungesBoolToInvoice implode(','$loungesBoolToInvoice);
  6074.         } else {
  6075.             $idLounges '0';
  6076.             $loungesBoolToInvoice '0';
  6077.         }
  6078.         $idPayments = array();
  6079.         $paymentsBoolToInvoice = array();
  6080.         if (array_key_exists('payment',$data['datasupplier'])) {
  6081.             foreach ($data['datasupplier']['payment'] as $item) {
  6082.                 $idPayments[] = $item['id'];
  6083.                 $paymentsBoolToInvoice[] = 1;
  6084.             }
  6085.             $idPayments implode(','$idPayments);
  6086.             $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  6087.             // Se han generado dos arreglos, cada uno dividido en 2 strings
  6088.             // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  6089.             // Para manipularlos entre la vista y el JS
  6090.         } else {
  6091.             $idPayments '0';
  6092.             $paymentsBoolToInvoice '0';
  6093.         }
  6094.         return $this->render('MDS/GreenPatioBundle/reservations/services-proforma-print-reservation.html.twig',
  6095.             array(
  6096.                 'id' => $id,
  6097.                 'idLounges' => $idLounges,
  6098.                 'reserva' => $reserva,
  6099.                 'idPayments' => $idPayments,
  6100.                 'loungesBoolToInvoice' => $loungesBoolToInvoice,
  6101.                 'paymentsBoolToInvoice' => $paymentsBoolToInvoice,
  6102.                 'type' => $data['type'],
  6103.                 'number' => $proformaId,
  6104.                 'prefix' => $proformaPrefix,
  6105.                 'date' => $data['date'],
  6106.                 'token' => $data['token'],
  6107.                 'company' => $data['company'],
  6108.                 'clients' => $data['clients'],
  6109.                 'datasupplier' => $data['datasupplier'],
  6110.                 'currency' => $data['currency'],
  6111.                 'totales_neto' => $data['totales_neto'],
  6112.                 'bases_imponibles' => $data['bases_imponibles'],
  6113.                 'totales' => $data['totales'],
  6114.                 'balance' => $data['balance'],
  6115.                 'paymentInvoice' => $data['paymentInvoice'],
  6116.                 'payments' => $payments,
  6117.                 'user_id' => $user_id,
  6118.                 'form' => $form->createView(),
  6119.                 'form1' => $form1->createView(),
  6120.             )
  6121.         );
  6122.     }
  6123.     private function baseInvoiceSelectedReservation($id$arrayBools$number)
  6124.     {
  6125.         $em $this->getDoctrine()->getManager();
  6126.         $reservation $em->getRepository(Reservation::class)->findOneById($id);
  6127.         $items $em->getRepository(ReservationInvoiceProformaItems::class)->findByReservationId($reservation->getId());
  6128.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  6129.         $client $em->getRepository(Client::class)->findById($reservation->getClient());
  6130.         if (!empty($client)){
  6131.             $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  6132.             $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  6133.             $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  6134.             $client['city'] = $city$client['region'] = $region$client['country'] = $country;
  6135.         } else {
  6136.             $client[0] = new Client();
  6137.             $client[0]->setName('');
  6138.             $client[0]->setTitle('');
  6139.             $client[0]->setIdDocument('');
  6140.             $client[0]->setPopulation('');
  6141.             $client[0]->setRegion('');
  6142.             $client[0]->setCountry('');
  6143.         }
  6144.         // Acumuladores de los calculos
  6145.         $totales_neto_all 0;
  6146.         $data_iva = array(
  6147.             'iva' => 21,
  6148.             'ivaMontoVeintiUno' => 0,
  6149.             'ivaMontoDiez' => 0,
  6150.             'ivaMontoCero' => 0,
  6151.         );
  6152.         //INICIO: Determinamos el numero de factura o proforma
  6153.         if (substr($number,0,1) == 'I'){
  6154.             // Es una Factura
  6155.             $numberInvoiceOrProforma substr($number,1);
  6156.             $number $numberInvoiceOrProforma;
  6157.             $number $em->getRepository(ReservationInvoice::class)->findOneById($number);
  6158.             $number $number->getNumber();
  6159.             $type 'Invoice';
  6160.         } else {
  6161.             // Es una Proforma
  6162.             $numberInvoiceOrProforma substr($number,1);
  6163.             $number $numberInvoiceOrProforma;
  6164.             $number $em->getRepository(ReservationProforma::class)->findOneById($number);
  6165.             $number $number->getPrefix().$number->getReservationId();
  6166.             $type 'Proforma';
  6167.         }
  6168.         //FIN: Determinamos el numero de factura o proforma
  6169.         // Buscamos las salas reservadas, pagos y servicios para el evento
  6170.         $arrayItems = array();
  6171.         $reservationLounges = array();
  6172.         if (!empty($arrayBools['lounge'])) {
  6173.             foreach ($arrayBools['lounge'] as $key => $item) {
  6174.                 if ($item == 'true') {
  6175.                     $reservationLounges[] = $em->getRepository(ReservationLoungeSimple::class)->findOneById($key);
  6176.                 }
  6177.             }
  6178.         }
  6179.         $payments = array();
  6180.         if (!empty($arrayBools['payment'])) {
  6181.             foreach ($arrayBools['payment'] as $key => $item) {
  6182.                 if ($item == 'true') {
  6183.                     $payments[] = $em->getRepository(ReservationPaymentsClient::class)->findOneById($key);
  6184.                 }
  6185.             }
  6186.         }
  6187.         $services = array();
  6188.         if (!empty($arrayBools['service'])) {
  6189.             foreach ($arrayBools['service'] as $key => $item) {
  6190.                 if ($item == 'true') {
  6191.                     $services[] = $em->getRepository(ReservationService::class)->findOneById($key);
  6192.                 }
  6193.             }
  6194.         }
  6195.         $data_supplier = array();
  6196.         $i 0;
  6197.         $iva '21';            // Esteban Rincon: "Por Ley de localización del impuesto, siempre será un 21%"
  6198.         $pax '-';
  6199.         $qty '1';
  6200.         $lounge = array(
  6201.             'neto' => 0,
  6202.             'sumSubT' => 0,
  6203.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  6204.         $service = array(
  6205.             'neto' => 0,
  6206.             'sumSubT' => 0,
  6207.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  6208.         foreach ($reservationLounges as $item){
  6209.             if (is_null($item->getServicePrice()) or empty($item->getServicePrice())){
  6210.                 $subtotal 0;
  6211.                 $neto 0;
  6212.                 $subnetoMounting 0;
  6213.                 $subtotalLounge 0;
  6214.                 $subnetoRemoval 0;
  6215.             } else {
  6216. //                if (!empty($item->getMountingPrice()) and ($item->getMountingPrice() != 0 )){
  6217. //                    $subtotalMounting = $item->getMountingPrice() * 1.21;
  6218. //                    $subnetoMounting = $item->getMountingPrice();
  6219. //                } else {
  6220. //                    $subtotalMounting = 0;
  6221. //                    $subnetoMounting = 0;
  6222. //                }
  6223.                 $subtotalLounge $item->getServicePrice() * 1.21;
  6224.                 $subneto $item->getServicePrice();
  6225. //                if (!empty($item->getRemovalPrice()) and ($item->getRemovalPrice() != 0 )){
  6226. //                    $subtotalRemoval = $item->getRemovalPrice() * 1.21;
  6227. //                    $subnetoRemoval = $item->getRemovalPrice();
  6228. //                } else {
  6229. //                    $subtotalRemoval = 0;
  6230. //                    $subnetoRemoval = 0;
  6231. //                }
  6232.                 $subtotal =  $subtotalLounge;
  6233.                 $neto =  $subneto;
  6234.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  6235.                 $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  6236.                 $neto round($neto,2,PHP_ROUND_HALF_UP);
  6237.                 $arrayItems[] = array(
  6238.                     'type' => 'Lounge',
  6239.                     'name' => $item->getLoungeName(),
  6240.                     'amount' => $neto,
  6241.                     'iva' => '21',
  6242.                     'total' => $subtotal,
  6243.                 );
  6244.             }
  6245.             // Acumula netos totales e IVA
  6246.             $totales_neto_all $totales_neto_all $neto;
  6247.             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  6248.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6249.             $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  6250.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  6251.             // Acumula netos totales e IVA
  6252.             $lounge['neto'] = $lounge['neto'] + $neto;
  6253.             $lounge['sumSubT'] = $lounge['sumSubT'] + $subtotal;
  6254.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6255.             $lounge['neto'] = round($lounge['neto'],2,PHP_ROUND_HALF_UP);
  6256.             $lounge['sumSubT'] = round($lounge['sumSubT'],2,PHP_ROUND_HALF_UP);
  6257.             $data_supplier['lounge'][$i] = array (
  6258.                 'id' => $item->getId(),
  6259.                 'loungeName' => $item->getLoungeName(),
  6260.                 'idLounge' => $item->getIdLounge(),
  6261.                 'dateStart' => $item->getDateStart(),
  6262.                 'dateEnd' => $item->getDateEnd(),
  6263.                 'servicePrice' => $item->getServicePrice(),
  6264.                 'subtotalLounge' => $subtotalLounge,
  6265.                 'iva' => $iva,
  6266.                 'pax' => $pax,
  6267.                 'qty' => $qty,
  6268.                 'type' => $item->getType(),
  6269.                 'subtotal' => $subtotal,
  6270.             );
  6271.             $i++;
  6272.         }
  6273.         $data_supplier['loungeSubTotal'] = array(
  6274.             'neto' => $lounge['neto'],
  6275.             'sumSubT' => $lounge['sumSubT'],
  6276.         );
  6277.         $payment = array(
  6278.             'neto' => 0,
  6279.             'sumSubT' => 0,
  6280.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  6281.         $i 0;
  6282.         foreach ($payments as $item){
  6283.             $payment['neto'] = $payment['neto'] + ($item->getAmount()*(-1));
  6284.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6285.             $payment['neto'] = round($payment['neto'],2,PHP_ROUND_HALF_UP);
  6286.             $payment['sumSubT'] = $payment['sumSubT'] + ($item->getAmountTotal()*(-1));
  6287.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6288.             $payment['sumSubT'] = round($payment['sumSubT'],2,PHP_ROUND_HALF_UP);
  6289.             $data_supplier['payment'][$i] = array (
  6290.                 'id' => $item->getId(),
  6291.                 'amount' => $item->getAmount()*(-1),
  6292.                 'amountTotal' => $item->getAmountTotal()*(-1),
  6293.                 'vat' => $item->getVat(),
  6294.                 'datePayAt' => $item->getDatePayAt(),
  6295.                 'wayToPay' => $item->getWayToPay(),
  6296.             );
  6297.             $arrayItems[] = array(
  6298.                 'type' => 'Payment',
  6299.                 'name' => $item->getWayToPay(),
  6300.                 'amount' => $item->getAmount()*(-1),
  6301.                 'total' => $item->getAmountTotal()*(-1),
  6302.                 'iva' => $item->getVat(),
  6303. //                    'iva' => '',
  6304. //                    'total' => $item->getAmount(),
  6305.             );
  6306.             // Acumula netos totales e IVA
  6307.             $totales_neto_all $totales_neto_all + ($item->getAmount()*(-1));
  6308.             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + (($item->getAmount()*(-1)) * 0.21);
  6309.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6310.             $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  6311.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  6312.             // Acumula netos totales e IVA
  6313.             $i++;
  6314.         }
  6315.         if (!empty($payments)) {
  6316.             $data_supplier['paymentSubTotal'] = array(
  6317.                 'neto' => $payment['neto'],
  6318.                 'sumSubT' => $payment['sumSubT'],
  6319.             );
  6320.         }
  6321.         foreach ($services as $item){
  6322.             if (is_null($item->getPrice()) or empty($item->getPrice())){
  6323.                 $subtotal 0;
  6324.                 $neto 0;
  6325.                 $subtotalService 0;
  6326.             } else {
  6327.                 $subtotalService $item->getPrice();
  6328.                 $subneto $item->getPrice();
  6329.                 // Commission
  6330.                 if ($item->getOpCommission()=='1'){
  6331.                     $subtotalService $subtotalService * (+ ($item->getCommission()/100));
  6332.                     $subneto $subneto  * (+ ($item->getCommission()/100));
  6333.                 } else {
  6334.                     $subtotalService $subtotalService * (- ($item->getCommission()/100));
  6335.                     $subneto $subneto * (- ($item->getCommission()/100));
  6336.                 }
  6337.                 // Over
  6338.                 if ($item->getOpOver()=='1'){
  6339.                     $subtotalService $subtotalService $item->getOver();
  6340.                     $subneto $subneto $item->getOver();
  6341.                 } else {
  6342.                     $subtotalService $subtotalService $item->getOver();
  6343.                     $subneto $subneto $item->getOver();
  6344.                 }
  6345.                 // IVA
  6346.                 if ($item->getOpIva()=='1'){
  6347.                     $subtotalService $subtotalService * (+ ($item->getIva()/100));
  6348.                 } else {
  6349.                     $subtotalService $item->getPrice();
  6350.                     $subneto = ($subneto 100) / (100 $item->getIva());
  6351.                 }
  6352.                 switch ($item->getServiceCatId()){
  6353.                     case 1// Alojamiento
  6354.                         // el numero de noches $numNoches; precio unitario $subneto
  6355.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  6356.                         // La personas no afectan este calculo
  6357.                         $subtotal $subtotalService $numNoches $item->getUnits();
  6358.                         $subnetoUnit $subneto;
  6359.                         $subneto $subneto $numNoches $item->getUnits();
  6360.                         $data_supplier['service'][$i] = array (
  6361.                             'id' => $item->getId(),
  6362.                             'serviceCatId' => $item->getServiceCatId(),
  6363.                             'serviceName' => $item->getName(),
  6364.                             'serviceType' => 'Hotel',
  6365.                             'date' => ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y'),
  6366.                             'qty' => $item->getUnits(),
  6367.                             'iva' => $item->getIva(),
  6368.                             'pax' => '-',
  6369.                             'precioUnit' => $subnetoUnit,
  6370.                             'subneto' => $subneto,
  6371.                             'subtotal' => $subtotal,
  6372.                         );
  6373.                         break;
  6374.                     case 2//Actividades
  6375.                         // El número de personas es considerado en el calculo
  6376.                         $pax $item->getPax();
  6377.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6378.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6379.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6380.                         $subtotal $subtotalService $days $item->getUnits();
  6381.                         $subnetoUnit $subneto;
  6382.                         $subneto $subneto $days $item->getUnits();
  6383.                         $data_supplier['service'][$i] = array (
  6384.                             'id' => $item->getId(),
  6385.                             'serviceCatId' => $item->getServiceCatId(),
  6386.                             'serviceName' => $item->getName(),
  6387.                             'serviceType' => 'Actividad',
  6388.                             'date' => $dateServ,
  6389.                             'qty' => $item->getUnits(),
  6390.                             'iva' => $item->getIva(),
  6391.                             'pax' => $item->getPax(),
  6392.                             'precioUnit' => $subnetoUnit,
  6393.                             'subneto' => $subneto,
  6394.                             'subtotal' => $subtotal,
  6395.                         );
  6396.                         break;
  6397.                     case 3// AV
  6398.                         $pax $item->getPax();
  6399.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6400.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6401.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6402.                         $unitsServ $item->getUnits();
  6403.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6404.                         $subtotal $subtotalService $days $unitsServ $pax;
  6405.                         $subnetoUnit $subneto;
  6406.                         $subneto $subneto $days $unitsServ $pax;
  6407.                         $data_supplier['service'][$i] = array (
  6408.                             'id' => $item->getId(),
  6409.                             'serviceCatId' => $item->getServiceCatId(),
  6410.                             'serviceName' => $item->getName(),
  6411.                             'serviceType' => 'AV',
  6412.                             'date' => $dateServ,
  6413.                             'qty' => $unitsServ,
  6414.                             'iva' => $item->getIva(),
  6415.                             'pax' => $item->getPax(),
  6416.                             'precioUnit' => $subnetoUnit,
  6417.                             'subneto' => $subneto,
  6418.                             'subtotal' => $subtotal,
  6419.                         );
  6420.                         break;
  6421.                     case 4//Creative
  6422.                         $pax $item->getPax();
  6423.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6424.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6425.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6426.                         $unitsServ $item->getUnits();
  6427.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6428.                         $subtotal $subtotalService $days $unitsServ $pax;
  6429.                         $subnetoUnit $subneto;
  6430.                         $subneto $subneto $days $unitsServ $pax;
  6431.                         $data_supplier['service'][$i] = array (
  6432.                             'id' => $item->getId(),
  6433.                             'serviceCatId' => $item->getServiceCatId(),
  6434.                             'serviceName' => $item->getName(),
  6435.                             'serviceType' => 'Creativo',
  6436.                             'date' => $dateServ,
  6437.                             'qty' => $unitsServ,
  6438.                             'iva' => $item->getIva(),
  6439.                             'pax' => $item->getPax(),
  6440.                             'precioUnit' => $subnetoUnit,
  6441.                             'subneto' => $subneto,
  6442.                             'subtotal' => $subtotal,
  6443.                         );
  6444.                         break;
  6445.                     case 5//Cruise
  6446.                         $pax $item->getPax();
  6447.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6448.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  6449.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6450.                         $unitsServ $item->getUnits();
  6451.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6452.                         $subtotal $subtotalService $days $unitsServ $pax;
  6453.                         $subnetoUnit $subneto;
  6454.                         $subneto $subneto $days $unitsServ $pax;
  6455.                         $data_supplier['service'][$i] = array (
  6456.                             'id' => $item->getId(),
  6457.                             'serviceCatId' => $item->getServiceCatId(),
  6458.                             'serviceName' => $item->getName(),
  6459.                             'serviceType' => 'Crucero',
  6460.                             'date' => $dateServ,
  6461.                             'qty' => $unitsServ,
  6462.                             'iva' => $item->getIva(),
  6463.                             'pax' => $item->getPax(),
  6464.                             'precioUnit' => $subnetoUnit,
  6465.                             'subneto' => $subneto,
  6466.                             'subtotal' => $subtotal,
  6467.                         );
  6468.                         break;
  6469.                     case 6//Entertaiment
  6470.                         $pax $item->getPax();
  6471.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6472.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6473.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6474.                         $unitsServ $item->getUnits();
  6475.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6476.                         $subtotal $subtotalService $days $unitsServ $pax;
  6477.                         $subnetoUnit $subneto;
  6478.                         $subneto $subneto $days $unitsServ $pax;
  6479.                         $data_supplier['service'][$i] = array (
  6480.                             'id' => $item->getId(),
  6481.                             'serviceCatId' => $item->getServiceCatId(),
  6482.                             'serviceName' => $item->getName(),
  6483.                             'serviceType' => 'Entretenimiento',
  6484.                             'date' => $dateServ,
  6485.                             'qty' => $unitsServ,
  6486.                             'iva' => $item->getIva(),
  6487.                             'pax' => $item->getPax(),
  6488.                             'precioUnit' => $subnetoUnit,
  6489.                             'subneto' => $subneto,
  6490.                             'subtotal' => $subtotal,
  6491.                         );
  6492.                         break;
  6493.                     case 7// Gifts
  6494.                         $pax $item->getPax();
  6495.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6496.                         $days 1;
  6497.                         $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6498.                         $unitsServ $item->getUnits();
  6499.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6500.                         $subtotal $subtotalService $days $unitsServ $pax;
  6501.                         $subnetoUnit $subneto;
  6502.                         $subneto $subneto $days $unitsServ $pax;
  6503.                         $data_supplier['service'][$i] = array (
  6504.                             'id' => $item->getId(),
  6505.                             'serviceCatId' => $item->getServiceCatId(),
  6506.                             'serviceName' => $item->getName(),
  6507.                             'serviceType' => 'Regalos',
  6508.                             'date' => $dateServ,
  6509.                             'qty' => $unitsServ,
  6510.                             'iva' => $item->getIva(),
  6511.                             'pax' => $item->getPax(),
  6512.                             'precioUnit' => $subnetoUnit,
  6513.                             'subneto' => $subneto,
  6514.                             'subtotal' => $subtotal,
  6515.                         );
  6516.                         break;
  6517.                     case 8//Guide
  6518.                         $pax $item->getPax();
  6519.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6520.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6521.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6522.                         $unitsServ $item->getUnits();
  6523.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6524.                         $subtotal $subtotalService $days $unitsServ $pax;
  6525.                         $subnetoUnit $subneto;
  6526.                         $subneto $subneto $days $unitsServ $pax;
  6527.                         $data_supplier['service'][$i] = array (
  6528.                             'id' => $item->getId(),
  6529.                             'serviceCatId' => $item->getServiceCatId(),
  6530.                             'serviceName' => $item->getName(),
  6531.                             'serviceType' => 'Guía',
  6532.                             'date' => $dateServ,
  6533.                             'qty' => $unitsServ,
  6534.                             'iva' => $item->getIva(),
  6535.                             'pax' => $item->getPax(),
  6536.                             'precioUnit' => $subnetoUnit,
  6537.                             'subneto' => $subneto,
  6538.                             'subtotal' => $subtotal,
  6539.                         );
  6540.                         break;
  6541.                     case 9//Itineraries
  6542.                         $pax $item->getPax();
  6543.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6544.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6545.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6546.                         $unitsServ $item->getUnits();
  6547.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6548.                         $subtotal $subtotalService $days $unitsServ $pax;
  6549.                         $subnetoUnit $subneto;
  6550.                         $subneto $subneto $days $unitsServ $pax;
  6551.                         $data_supplier['service'][$i] = array (
  6552.                             'id' => $item->getId(),
  6553.                             'serviceCatId' => $item->getServiceCatId(),
  6554.                             'serviceName' => $item->getName(),
  6555.                             'serviceType' => 'Itinerarios',
  6556.                             'date' => $dateServ,
  6557.                             'qty' => $unitsServ,
  6558.                             'iva' => $item->getIva(),
  6559.                             'pax' => $item->getPax(),
  6560.                             'precioUnit' => $subnetoUnit,
  6561.                             'subneto' => $subneto,
  6562.                             'subtotal' => $subtotal,
  6563.                         );
  6564.                         break;
  6565.                     case 10//Lounge  -- No Aplica
  6566.                         break;
  6567.                     case 11//Menu (Catering)
  6568.                         $pax $item->getPax();
  6569.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6570.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6571.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6572.                         $unitsServ $item->getUnits();
  6573.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6574.                         $subtotal $subtotalService $days $unitsServ $pax;
  6575.                         $subnetoUnit $subneto;
  6576.                         $subneto $subneto $days $unitsServ $pax;
  6577.                         $data_supplier['service'][$i] = array (
  6578.                             'id' => $item->getId(),
  6579.                             'serviceCatId' => $item->getServiceCatId(),
  6580.                             'serviceName' => $item->getName(),
  6581.                             'serviceType' => 'Catering',
  6582.                             'date' => $dateServ,
  6583.                             'qty' => $unitsServ,
  6584.                             'iva' => $item->getIva(),
  6585.                             'pax' => $item->getPax(),
  6586.                             'precioUnit' => $subnetoUnit,
  6587.                             'subneto' => $subneto,
  6588.                             'subtotal' => $subtotal,
  6589.                         );
  6590.                         break;
  6591.                     case 12//Others
  6592.                         $pax $item->getPax();
  6593.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6594.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6595.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6596.                         $unitsServ $item->getUnits();
  6597.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6598.                         $subtotal $subtotalService $days $unitsServ $pax;
  6599.                         $subnetoUnit $subneto;
  6600.                         $subneto $subneto $days $unitsServ $pax;
  6601.                         $data_supplier['service'][$i] = array (
  6602.                             'id' => $item->getId(),
  6603.                             'serviceCatId' => $item->getServiceCatId(),
  6604.                             'serviceName' => $item->getName(),
  6605.                             'serviceType' => 'Otros',
  6606.                             'date' => $dateServ,
  6607.                             'qty' => $unitsServ,
  6608.                             'iva' => $item->getIva(),
  6609.                             'pax' => $item->getPax(),
  6610.                             'precioUnit' => $subnetoUnit,
  6611.                             'subneto' => $subneto,
  6612.                             'subtotal' => $subtotal,
  6613.                         );
  6614.                         break;
  6615.                     case 13//Transport
  6616.                         $pax $item->getPax();
  6617.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6618.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6619.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6620.                         $unitsServ $item->getUnits();
  6621.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6622.                         $subtotal $subtotalService $days $unitsServ $pax;
  6623.                         $subnetoUnit $subneto;
  6624.                         $subneto $subneto $days $unitsServ $pax;
  6625.                         $data_supplier['service'][$i] = array (
  6626.                             'id' => $item->getId(),
  6627.                             'serviceCatId' => $item->getServiceCatId(),
  6628.                             'serviceName' => $item->getName(),
  6629.                             'serviceType' => 'Transporte',
  6630.                             'date' => $dateServ,
  6631.                             'qty' => $unitsServ,
  6632.                             'iva' => $item->getIva(),
  6633.                             'pax' => $item->getPax(),
  6634.                             'precioUnit' => $subnetoUnit,
  6635.                             'subneto' => $subneto,
  6636.                             'subtotal' => $subtotal,
  6637.                         );
  6638.                         break;
  6639.                     case 14//Technology
  6640.                         $pax $item->getPax();
  6641.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6642.                         $days 1;
  6643.                         $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  6644.                         $unitsServ $item->getUnits();
  6645.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6646.                         $subtotal $subtotalService $days $unitsServ $pax;
  6647.                         $subnetoUnit $subneto;
  6648.                         $subneto $subneto $days $unitsServ $pax;
  6649.                         $data_supplier['service'][$i] = array (
  6650.                             'id' => $item->getId(),
  6651.                             'serviceCatId' => $item->getServiceCatId(),
  6652.                             'serviceName' => $item->getName(),
  6653.                             'serviceType' => 'Tecnología',
  6654.                             'date' => $dateServ,
  6655.                             'qty' => $unitsServ,
  6656.                             'iva' => $item->getIva(),
  6657.                             'pax' => $item->getPax(),
  6658.                             'precioUnit' => $subnetoUnit,
  6659.                             'subneto' => $subneto,
  6660.                             'subtotal' => $subtotal,
  6661.                         );
  6662.                         break;
  6663.                     case 15//Assisstant
  6664.                         $pax $item->getPax();
  6665.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6666.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6667.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6668.                         $unitsServ $item->getUnits();
  6669.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6670.                         $subtotal $subtotalService $days $unitsServ $pax;
  6671.                         $subnetoUnit $subneto;
  6672.                         $subneto $subneto $days $unitsServ $pax;
  6673.                         $data_supplier['service'][$i] = array (
  6674.                             'id' => $item->getId(),
  6675.                             'serviceCatId' => $item->getServiceCatId(),
  6676.                             'serviceName' => $item->getName(),
  6677.                             'serviceType' => 'Asistente',
  6678.                             'date' => $dateServ,
  6679.                             'qty' => $unitsServ,
  6680.                             'iva' => $item->getIva(),
  6681.                             'pax' => $item->getPax(),
  6682.                             'precioUnit' => $subnetoUnit,
  6683.                             'subneto' => $subneto,
  6684.                             'subtotal' => $subtotal,
  6685.                         );
  6686.                         break;
  6687.                     case 16//DDR
  6688.                         $pax $item->getPax();
  6689.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6690.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6691.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6692.                         $unitsServ $item->getUnits();
  6693.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6694.                         $subtotal $subtotalService $days $unitsServ $pax;
  6695.                         $subnetoUnit $subneto;
  6696.                         $subneto $subneto $days $unitsServ $pax;
  6697.                         $data_supplier['service'][$i] = array (
  6698.                             'id' => $item->getId(),
  6699.                             'serviceCatId' => $item->getServiceCatId(),
  6700.                             'serviceName' => $item->getName(),
  6701.                             'serviceType' => 'DDR',
  6702.                             'date' => $dateServ,
  6703.                             'qty' => $unitsServ,
  6704.                             'iva' => $item->getIva(),
  6705.                             'pax' => $item->getPax(),
  6706.                             'precioUnit' => $subnetoUnit,
  6707.                             'subneto' => $subneto,
  6708.                             'subtotal' => $subtotal,
  6709.                         );
  6710.                         break;
  6711.                     case 17//Seguridad
  6712.                         $pax $item->getPax();
  6713.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6714.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6715.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6716.                         $unitsServ $item->getUnits();
  6717.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6718.                         $subtotal $subtotalService $days $unitsServ $pax;
  6719.                         $subnetoUnit $subneto;
  6720.                         $subneto $subneto $days $unitsServ $pax;
  6721.                         $data_supplier['service'][$i] = array (
  6722.                             'id' => $item->getId(),
  6723.                             'serviceCatId' => $item->getServiceCatId(),
  6724.                             'serviceName' => $item->getName(),
  6725.                             'serviceType' => 'Seguridad',
  6726.                             'date' => $dateServ,
  6727.                             'qty' => $unitsServ,
  6728.                             'iva' => $item->getIva(),
  6729.                             'pax' => $item->getPax(),
  6730.                             'precioUnit' => $subnetoUnit,
  6731.                             'subneto' => $subneto,
  6732.                             'subtotal' => $subtotal,
  6733.                         );
  6734.                         break;
  6735.                     case 18//WiFi
  6736.                         $pax $item->getPax();
  6737.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6738.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6739.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6740.                         $unitsServ $item->getUnits();
  6741.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6742.                         $subtotal $subtotalService $days $unitsServ $pax;
  6743.                         $subnetoUnit $subneto;
  6744.                         $subneto $subneto $days $unitsServ $pax;
  6745.                         $data_supplier['service'][$i] = array (
  6746.                             'id' => $item->getId(),
  6747.                             'serviceCatId' => $item->getServiceCatId(),
  6748.                             'serviceName' => $item->getName(),
  6749.                             'serviceType' => 'WiFi',
  6750.                             'date' => $dateServ,
  6751.                             'qty' => $unitsServ,
  6752.                             'iva' => $item->getIva(),
  6753.                             'pax' => $item->getPax(),
  6754.                             'precioUnit' => $subnetoUnit,
  6755.                             'subneto' => $subneto,
  6756.                             'subtotal' => $subtotal,
  6757.                         );
  6758.                         break;
  6759.                     case 19//Mobiliario
  6760.                         $pax $item->getPax();
  6761.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6762.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6763.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6764.                         $unitsServ $item->getUnits();
  6765.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6766.                         $subtotal $subtotalService $days $unitsServ $pax;
  6767.                         $subnetoUnit $subneto;
  6768.                         $subneto $subneto $days $unitsServ $pax;
  6769.                         $data_supplier['service'][$i] = array (
  6770.                             'id' => $item->getId(),
  6771.                             'serviceCatId' => $item->getServiceCatId(),
  6772.                             'serviceName' => $item->getName(),
  6773.                             'serviceType' => 'Mobiliario',
  6774.                             'date' => $dateServ,
  6775.                             'qty' => $unitsServ,
  6776.                             'iva' => $item->getIva(),
  6777.                             'pax' => $item->getPax(),
  6778.                             'precioUnit' => $subnetoUnit,
  6779.                             'subneto' => $subneto,
  6780.                             'subtotal' => $subtotal,
  6781.                         );
  6782.                         break;
  6783.                     case 20//Parking
  6784.                         $pax $item->getPax();
  6785.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6786.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6787.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6788.                         $unitsServ $item->getUnits();
  6789.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6790.                         $subtotal $subtotalService $days $unitsServ $pax;
  6791.                         $subnetoUnit $subneto;
  6792.                         $subneto $subneto $days $unitsServ $pax;
  6793.                         $data_supplier['service'][$i] = array (
  6794.                             'id' => $item->getId(),
  6795.                             'serviceCatId' => $item->getServiceCatId(),
  6796.                             'serviceName' => $item->getName(),
  6797.                             'serviceType' => 'Parking',
  6798.                             'date' => $dateServ,
  6799.                             'qty' => $unitsServ,
  6800.                             'iva' => $item->getIva(),
  6801.                             'pax' => $item->getPax(),
  6802.                             'precioUnit' => $subnetoUnit,
  6803.                             'subneto' => $subneto,
  6804.                             'subtotal' => $subtotal,
  6805.                         );
  6806.                         break;
  6807.                     case 21//Limpieza
  6808.                         $pax $item->getPax();
  6809.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6810.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6811.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6812.                         $unitsServ $item->getUnits();
  6813.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6814.                         $subtotal $subtotalService $days $unitsServ $pax;
  6815.                         $subnetoUnit $subneto;
  6816.                         $subneto $subneto $days $unitsServ $pax;
  6817.                         $data_supplier['service'][$i] = array (
  6818.                             'id' => $item->getId(),
  6819.                             'serviceCatId' => $item->getServiceCatId(),
  6820.                             'serviceName' => $item->getName(),
  6821.                             'serviceType' => 'Limpieza',
  6822.                             'date' => $dateServ,
  6823.                             'qty' => $unitsServ,
  6824.                             'iva' => $item->getIva(),
  6825.                             'pax' => $item->getPax(),
  6826.                             'precioUnit' => $subnetoUnit,
  6827.                             'subneto' => $subneto,
  6828.                             'subtotal' => $subtotal,
  6829.                         );
  6830.                         break;
  6831.                     default: //Others (por default)
  6832.                         $pax $item->getPax();
  6833.                         if (empty($pax) or $pax == "0") { $pax 1; }
  6834.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6835.                         $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  6836.                         $unitsServ $item->getUnits();
  6837.                         if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  6838.                         $subtotal $subtotalService $days $unitsServ $pax;
  6839.                         $subnetoUnit $subneto;
  6840.                         $subneto $subneto $days $unitsServ $pax;
  6841.                         $data_supplier['service'][$i] = array (
  6842.                             'id' => $item->getId(),
  6843.                             'serviceCatId' => $item->getServiceCatId(),
  6844.                             'serviceName' => $item->getName(),
  6845.                             'serviceType' => 'Otros',
  6846.                             'date' => $dateServ,
  6847.                             'qty' => $unitsServ,
  6848.                             'iva' => $item->getIva(),
  6849.                             'pax' => $item->getPax(),
  6850.                             'precioUnit' => $subnetoUnit,
  6851.                             'subneto' => $subneto,
  6852.                             'subtotal' => $subtotal,
  6853.                         );
  6854.                         break;
  6855.                 }
  6856.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  6857.                 $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  6858.                 $neto round($subneto,2,PHP_ROUND_HALF_UP);
  6859.                 $arrayItems[] = array(
  6860.                     'type' => 'Service',
  6861.                     'name' => $item->getName(),
  6862.                     'amount' => $neto,
  6863.                     'iva' => $item->getIva(),
  6864.                     'total' => $subtotal,
  6865.                 );
  6866.             }
  6867.             switch ($item->getIva()){
  6868.                 // Acumula IVA
  6869.                 case 21:
  6870.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva()/100));
  6871.                     break;
  6872.                 case 10:
  6873.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva()/100));
  6874.                     break;
  6875.                 case 0:
  6876.                     break;
  6877.                 default:
  6878.                     break;
  6879.             }
  6880.             $totales_neto_all $totales_neto_all $neto;
  6881.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6882.             $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  6883.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  6884.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'],2,PHP_ROUND_HALF_UP);
  6885.             // Acumula netos totales e IVA
  6886.             $service['neto'] = $service['neto'] + $neto;
  6887.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  6888.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6889.             $service['neto'] = round($service['neto'],2,PHP_ROUND_HALF_UP);
  6890.             $service['sumSubT'] = round($service['sumSubT'],2,PHP_ROUND_HALF_UP);
  6891.             $i++;
  6892.         }
  6893.         $data_supplier['serviceSubTotal'] = array(
  6894.             'neto' => $service['neto'],
  6895.             'sumSubT' => $service['sumSubT'],
  6896.         );
  6897.         $currency '€';
  6898.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  6899.         if (!empty($payments)) {
  6900.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  6901.         } else {
  6902.             $amount_pay 0;
  6903.         }
  6904.         $totales_all $totales_total $amount_pay;
  6905.         if ($type == 'Invoice'){
  6906.             $em->clear();   // sin este clear se producia error al guardar
  6907.             $newInvoice $em->getRepository(ReservationInvoice::class)->findOneById($numberInvoiceOrProforma);
  6908.             $newInvoice->setBalance($totales_all);
  6909.             $em->persist($newInvoice);
  6910.             $em->flush();
  6911.         }
  6912.         $data = array(
  6913.             'id' => $id,
  6914.             'type' => $type,
  6915.             'number' => $number,
  6916.             'prefix' => 'GPF-'.(new DateTime('now'))->format('dmy').'-',
  6917.             'date' => new DateTime('now'),
  6918.             'reservation' => $reservation,
  6919.             'token' => $reservation->getAccessKey(),
  6920.             'company' => $company,
  6921.             'clients' => $client,
  6922.             'arrayItems' => $arrayItems,
  6923.             'datasupplier' => $data_supplier,
  6924.             'currency' => $currency,
  6925.             'totales_neto' => $totales_neto_all,
  6926.             'bases_imponibles' => $data_iva,
  6927.             'totales' => $totales_total,
  6928.             'balance' => $totales_all,
  6929.             'paymentInvoice' => $amount_pay,
  6930.         );
  6931.         return $data;
  6932.     }
  6933.     private function baseInvoiceDoneReservation($reservationId$invoiceId$typeBase)
  6934.     {
  6935.         $em $this->getDoctrine()->getManager();
  6936.         $reservation $em->getRepository(Reservation::class)->findOneById($reservationId);
  6937.         $dateDocument null;                                                                           //Fecha final del documento
  6938.         if (($typeBase == 'I') or ($typeBase == 'P')) {
  6939.             if ($typeBase == 'I') {
  6940.                 $items $em->getRepository(ReservationInvoiceItems::class)->findBy(array('reservationId' => $reservationId'invoiceId' => $invoiceId));
  6941.             } else {
  6942.                 // Es factura ni proforma
  6943.                 $items $em->getRepository(ReservationInvoiceProformaItems::class)->findBy(array('reservationId' => $reservationId'proformaId' => $invoiceId));
  6944.             }
  6945.         } else {
  6946.             // No es factura ni proforma, es una rectificativa
  6947.             $items $em->getRepository(ReservationInvoiceRecItems::class)->findBy(array('reservationId' => $reservationId'invoiceRecId' => $invoiceId));
  6948.         }
  6949.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  6950.         $client $em->getRepository(Client::class)->findById($reservation->getClient());
  6951.         if (!empty($client)){
  6952.             $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  6953.             $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  6954.             $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  6955.             $client['city'] = $city$client['region'] = $region$client['country'] = $country;
  6956.         } else {
  6957.             $client[0] = new Client();
  6958.             $client[0]->setName('');
  6959.             $client[0]->setTitle('');
  6960.             $client[0]->setIdDocument('');
  6961.             $client[0]->setPopulation('');
  6962.             $client[0]->setRegion('');
  6963.             $client[0]->setCountry('');
  6964.         }
  6965.         // Acumuladores de los calculos
  6966.         $totales_neto_all 0;
  6967.         $data_iva = array(
  6968.             'iva' => 21,
  6969.             'ivaMontoVeintiUno' => 0,
  6970.             'ivaMontoDiez' => 0,
  6971.             'ivaMontoCero' => 0,
  6972.         );
  6973.         //INICIO: Determinamos el numero de factura o proforma
  6974.         if ($typeBase == 'I'){
  6975.             // Es una Factura
  6976.             $number $em->getRepository(ReservationInvoice::class)->findOneById($invoiceId);
  6977.             $dateDocument $number->getDateAt();
  6978.             $number $number->getNumber();
  6979.             $type 'Invoice';
  6980.         } else {
  6981.             if ($typeBase == 'R'){
  6982.                 // Es una factura rectificativa
  6983.                 $number $em->getRepository(ReservationInvoiceRec::class)->findOneById($invoiceId);
  6984.                 $dateDocument $number->getDateAt();
  6985.                 $type 'Invoice Rec';
  6986.             } else {
  6987.                 // Es una Proforma
  6988.                 $number $invoiceId;
  6989.                 $type 'Proforma';
  6990.             }
  6991.         }
  6992.         //FIN: Determinamos el numero de factura o proforma
  6993.         // Buscamos las salas reservadas, pagos y servicios para el evento
  6994.         $arrayItems = array();
  6995.         $reservationLounges = array();
  6996.         $payments = array();
  6997.         $services = array();
  6998.         if (!empty($items)) {
  6999.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  7000.                 foreach ($items as $item) {
  7001.                     switch ($item->getItemType()) {
  7002.                         case 'LOUNGE'// Salon
  7003.                             $reservationLounges[] = $item;
  7004.                             break;
  7005.                         case 'PAYMENT'// Pago
  7006.                             $payments[] = $item;
  7007.                             break;
  7008.                         case 'SERVICE'// Servicio
  7009.                             $services[] = $item;
  7010.                             break;
  7011.                         default:
  7012.                             break;
  7013.                     }
  7014.                 }
  7015.             } else {
  7016.                 // Es una proforma
  7017.                 foreach ($items as $item) {
  7018.                     switch ($item->getType()) {
  7019.                         case 'LOUNGE'// Salon
  7020.                             $loungePro $em->getRepository(ReservationLoungeSimple::class)->findOneById($item->getControlId());
  7021.                             if (!empty($loungePro)) {
  7022.                                 $reservationLounges[] = $loungePro;
  7023.                             }
  7024.                             break;
  7025.                         case 'PAYMENT'// Pago
  7026.                             $paymentPro $em->getRepository(ReservationPaymentsClient::class)->findOneById($item->getControlId());
  7027.                             if (!empty($paymentPro)) {
  7028.                                 $payments[] = $paymentPro;
  7029.                             }
  7030.                             break;
  7031.                         case 'SERVICE'// Servicio
  7032.                             $servicePro $em->getRepository(ReservationService::class)->findOneById($item->getControlId());
  7033.                             if (!empty($servicePro)) {
  7034.                                 $services[] = $servicePro;
  7035.                             }
  7036.                             break;
  7037.                         default:
  7038.                             break;
  7039.                     }
  7040.                 }
  7041.             }
  7042.         }
  7043.         $data_supplier = array();
  7044.         $i 0;
  7045.         $iva '21';            // Esteban Rincon: "Por Ley de localización del impuesto, siempre será un 21%"
  7046.         $pax '-';
  7047.         $qty '1';
  7048.         $lounge = array(
  7049.             'neto' => 0,
  7050.             'sumSubT' => 0,
  7051.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  7052.         $service = array(
  7053.             'neto' => 0,
  7054.             'sumSubT' => 0,
  7055.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  7056.         foreach ($reservationLounges as $item){
  7057.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  7058.                 if (is_null($item->getLngServicePrice()) or empty($item->getLngServicePrice())){
  7059.                     $subtotal 0;
  7060.                     $neto 0;
  7061.                     $subnetoMounting 0;
  7062.                     $subtotalLounge 0;
  7063.                     $subnetoRemoval 0;
  7064.                 } else {
  7065.                     $subtotalLounge $item->getLngServicePrice() * 1.21;
  7066.                     $subneto $item->getLngServicePrice();
  7067.                     $subtotal =  $subtotalLounge;
  7068.                     $neto =  $subneto;
  7069.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  7070.                     $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  7071.                     $neto round($neto,2,PHP_ROUND_HALF_UP);
  7072.                     $arrayItems[] = array(
  7073.                         'type' => 'Lounge',
  7074.                         'name' => $item->getLngLoungeName(),
  7075.                         'amount' => $neto,
  7076.                         'iva' => '21',
  7077.                         'total' => $subtotal,
  7078.                     );
  7079.                 }
  7080.             } else {
  7081.                 // Es proforma
  7082.                 if (is_null($item->getServicePrice()) or empty($item->getServicePrice())){
  7083.                     $subtotal 0;
  7084.                     $neto 0;
  7085.                     $subnetoMounting 0;
  7086.                     $subtotalLounge 0;
  7087.                     $subnetoRemoval 0;
  7088.                 } else {
  7089.                     $subtotalLounge $item->getServicePrice() * 1.21;
  7090.                     $subneto $item->getServicePrice();
  7091.                     $subtotal =  $subtotalLounge;
  7092.                     $neto =  $subneto;
  7093.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  7094.                     $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  7095.                     $neto round($neto,2,PHP_ROUND_HALF_UP);
  7096.                     $arrayItems[] = array(
  7097.                         'type' => 'Lounge',
  7098.                         'name' => $item->getLoungeName(),
  7099.                         'amount' => $neto,
  7100.                         'iva' => '21',
  7101.                         'total' => $subtotal,
  7102.                     );
  7103.                 }
  7104.             }
  7105.             // Acumula netos totales e IVA
  7106.             $totales_neto_all $totales_neto_all $neto;
  7107.             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  7108.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7109.             $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  7110.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  7111.             // Acumula netos totales e IVA
  7112.             $lounge['neto'] = $lounge['neto'] + $neto;
  7113.             $lounge['sumSubT'] = $lounge['sumSubT'] + $subtotal;
  7114.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7115.             $lounge['neto'] = round($lounge['neto'],2,PHP_ROUND_HALF_UP);
  7116.             $lounge['sumSubT'] = round($lounge['sumSubT'],2,PHP_ROUND_HALF_UP);
  7117.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  7118.                 $data_supplier['lounge'][$i] = array(
  7119.                     'id' => $item->getId(),
  7120.                     'loungeName' => $item->getLngLoungeName(),
  7121.                     'idLounge' => $item->getLngIdLounge(),
  7122.                     'dateStart' => $item->getLngDateStart(),
  7123.                     'dateEnd' => $item->getLngDateEnd(),
  7124.                     'servicePrice' => $item->getLngServicePrice(),
  7125.                     'subtotalLounge' => $subtotalLounge,
  7126.                     'iva' => $iva,
  7127.                     'pax' => $pax,
  7128.                     'qty' => $qty,
  7129.                     'type' => $item->getLngType(),
  7130.                     'subtotal' => $subtotal,
  7131.                 );
  7132.             } else {
  7133.                 // Es proforma
  7134.                 $data_supplier['lounge'][$i] = array(
  7135.                     'id' => $item->getId(),
  7136.                     'loungeName' => $item->getLoungeName(),
  7137.                     'idLounge' => $item->getIdLounge(),
  7138.                     'dateStart' => $item->getDateStart(),
  7139.                     'dateEnd' => $item->getDateEnd(),
  7140.                     'servicePrice' => $item->getServicePrice(),
  7141.                     'subtotalLounge' => $subtotalLounge,
  7142.                     'iva' => $iva,
  7143.                     'pax' => $pax,
  7144.                     'qty' => $qty,
  7145.                     'type' => $item->getType(),
  7146.                     'subtotal' => $subtotal,
  7147.                 );
  7148.             }
  7149.             $i++;
  7150.         }
  7151.         $data_supplier['loungeSubTotal'] = array(
  7152.             'neto' => $lounge['neto'],
  7153.             'sumSubT' => $lounge['sumSubT'],
  7154.         );
  7155.         $payment = array(
  7156.             'neto' => 0,
  7157.             'sumSubT' => 0,
  7158.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  7159.         $i 0;
  7160.         foreach ($payments as $item){
  7161.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  7162.                 if ($typeBase == 'I') {
  7163.                     $payment['neto'] = $payment['neto'] + ($item->getPayAmount() * (-1));
  7164.                     $payment['sumSubT'] = $payment['sumSubT'] + ($item->getPayAmountTotal() * (-1));
  7165.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7166.                     $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  7167.                     $payment['neto'] = round($payment['neto'], 2PHP_ROUND_HALF_UP);
  7168.                     // Acumula netos totales e IVA
  7169.                     $totales_neto_all $totales_neto_all + ($item->getPayAmount() * (-1));
  7170.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($item->getPayAmount() * (-0.21));
  7171.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7172.                     $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  7173.                     $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  7174.                     // Acumula netos totales e IVA
  7175.                     $data_supplier['payment'][$i] = array(
  7176.                         'id' => $item->getId(),
  7177.                         'amount' => $item->getPayAmount() * (-1),
  7178.                         'amountTotal' => $item->getPayAmountTotal() * (-1),
  7179.                         'vat' => $item->getPayVat(),
  7180.                         'datePayAt' => $item->getPayDatePayAt(),
  7181.                         'wayToPay' => $item->getPayWayToPay(),
  7182.                     );
  7183.                     $arrayItems[] = array(
  7184.                         'type' => 'Payment',
  7185.                         'name' => $item->getPayWayToPay(),
  7186.                         'amount' => $item->getPayAmount() * (-1),
  7187.                         'total' => $item->getPayAmountTotal() * (-1),
  7188.                         'iva' => $item->getPayVat(),
  7189. //                    'iva' => '',
  7190. //                    'total' => $item->getPayAmount(),
  7191.                     );
  7192.                 } else {
  7193.                     //Es una rectificativa
  7194.                     $payment['neto'] = $payment['neto'] + ($item->getPayAmount());
  7195.                     $payment['sumSubT'] = $payment['sumSubT'] + ($item->getPayAmountTotal());
  7196.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7197.                     $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  7198.                     $payment['neto'] = round($payment['neto'], 2PHP_ROUND_HALF_UP);
  7199.                     // Acumula netos totales e IVA
  7200.                     $totales_neto_all $totales_neto_all + ($item->getPayAmount());
  7201.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($item->getPayAmount()*(0.21));
  7202.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7203.                     $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  7204.                     $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  7205.                     // Acumula netos totales e IVA
  7206.                     $data_supplier['payment'][$i] = array(
  7207.                         'id' => $item->getId(),
  7208.                         'amount' => $item->getPayAmount(),
  7209.                         'amountTotal' => $item->getPayAmountTotal(),
  7210.                         'vat' => $item->getPayVat(),
  7211.                         'datePayAt' => $item->getPayDatePayAt(),
  7212.                         'wayToPay' => $item->getPayWayToPay(),
  7213.                     );
  7214.                     $arrayItems[] = array(
  7215.                         'type' => 'Payment',
  7216.                         'name' => $item->getPayWayToPay(),
  7217.                         'amount' => $item->getPayAmount(),
  7218.                         'total' => $item->getPayAmountTotal(),
  7219.                         'iva' => $item->getPayVat(),
  7220. //                    'iva' => '',
  7221. //                    'total' => $item->getPayAmount(),
  7222.                     );
  7223.                 }
  7224.             } else {
  7225.                 // Es una proforma
  7226.                 $payment['neto'] = $payment['neto'] + ($item->getAmount()*(-1));
  7227.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal()*(-1);
  7228.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7229.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  7230.                 $payment['neto'] = round($payment['neto'], 2PHP_ROUND_HALF_UP);
  7231.                 // Acumula netos totales e IVA
  7232.                 $totales_neto_all $totales_neto_all + ($item->getAmount()*(-1));
  7233.                 $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($item->getAmount()*(-0.21));
  7234.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7235.                 $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  7236.                 $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  7237.                 // Acumula netos totales e IVA
  7238.                 $data_supplier['payment'][$i] = array(
  7239.                     'id' => $item->getId(),
  7240.                     'amount' => $item->getAmount()*(-1),
  7241.                     'amountTotal' => $item->getAmountTotal()*(-1),
  7242.                     'vat' => $item->getVat(),
  7243.                     'datePayAt' => $item->getDatePayAt(),
  7244.                     'wayToPay' => $item->getWayToPay(),
  7245.                 );
  7246.                 $arrayItems[] = array(
  7247.                     'type' => 'Payment',
  7248.                     'name' => $item->getWayToPay(),
  7249.                     'amount' => $item->getAmount()*(-1),
  7250.                     'total' => $item->getAmountTotal()*(-1),
  7251.                     'iva' => $item->getVat(),
  7252. //                    'iva' => '',
  7253. //                    'total' => $item->getAmount(),
  7254.                 );
  7255.             }
  7256.             $i++;
  7257.         }
  7258.         if (!empty($payments)) {
  7259.             $data_supplier['paymentSubTotal'] = array(
  7260.                 'neto' => $payment['neto'],
  7261.                 'sumSubT' => $payment['sumSubT'],
  7262.             );
  7263.         }
  7264.         foreach ($services as $item){
  7265.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  7266.                 if (is_null($item->getSrvPrice()) or empty($item->getSrvPrice())) {
  7267.                     $subtotal 0;
  7268.                     $neto 0;
  7269.                     $subtotalService 0;
  7270.                 } else {
  7271.                     $subtotalService $item->getSrvPrice();
  7272.                     $subtotalService str_replace(',','.',$subtotalService);
  7273.                     $subtotalService floatval($subtotalService);
  7274.                     $subneto $item->getSrvPrice();
  7275.                     $subneto str_replace(',','.',$subneto);
  7276.                     $subneto floatval($subneto);
  7277.                         // Commission
  7278.                     if ($item->getSrvOpCommission() == '1') {
  7279.                         $subtotalService $subtotalService * (+ ($item->getSrvCommission() / 100));
  7280.                         $subneto $subneto * (+ ($item->getSrvCommission() / 100));
  7281.                     } else {
  7282.                         $subtotalService $subtotalService * (- ($item->getSrvCommission() / 100));
  7283.                         $subneto $subneto * (- ($item->getSrvCommission() / 100));
  7284.                     }
  7285.                     // Over
  7286.                     if ($item->getSrvOpOver() == '1') {
  7287.                         $subtotalService $subtotalService $item->getSrvOver();
  7288.                         $subneto $subneto $item->getSrvOver();
  7289.                     } else {
  7290.                         $subtotalService $subtotalService $item->getSrvOver();
  7291.                         $subneto $subneto $item->getSrvOver();
  7292.                     }
  7293.                     // IVA
  7294.                     if ($item->getSrvOpIva() == '1') {
  7295.                         $subtotalService $subtotalService * (+ ($item->getSrvIva() / 100));
  7296.                     } else {
  7297.                         $subtotalService $item->getSrvPrice();
  7298.                         $subneto = ($subneto 100) / (100 $item->getSrvIva());
  7299.                     }
  7300.                     switch ($item->getSrvServiceCatId()) {
  7301.                         case 1// Alojamiento
  7302.                             // el numero de noches $numNoches; precio unitario $subneto
  7303.                             $numNoches = (($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days;
  7304.                             // La personas no afectan este calculo
  7305.                             $subtotal $subtotalService $numNoches $item->getSrvUnits();
  7306.                             $subnetoUnit $subneto;
  7307.                             $subneto $subneto $numNoches $item->getSrvUnits();
  7308.                             $data_supplier['service'][$i] = array(
  7309.                                 'id' => $item->getId(),
  7310.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7311.                                 'serviceName' => $item->getSrvName(),
  7312.                                 'serviceType' => 'Hotel',
  7313.                                 'date' => ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y'),
  7314.                                 'qty' => $item->getSrvUnits(),
  7315.                                 'iva' => $item->getSrvIva(),
  7316.                                 'pax' => '-',
  7317.                                 'precioUnit' => $subnetoUnit,
  7318.                                 'subneto' => $subneto,
  7319.                                 'subtotal' => $subtotal,
  7320.                             );
  7321.                             break;
  7322.                         case 2//Actividades
  7323.                             // El número de personas es considerado en el calculo
  7324.                             $pax $item->getSrvPax();
  7325.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7326.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7327.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7328.                             $subtotal $subtotalService $days $item->getSrvUnits();
  7329.                             $subnetoUnit $subneto;
  7330.                             $subneto $subneto $days $item->getSrvUnits();
  7331.                             $data_supplier['service'][$i] = array(
  7332.                                 'id' => $item->getId(),
  7333.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7334.                                 'serviceName' => $item->getSrvName(),
  7335.                                 'serviceType' => 'Actividad',
  7336.                                 'date' => $dateServ,
  7337.                                 'qty' => $item->getSrvUnits(),
  7338.                                 'iva' => $item->getSrvIva(),
  7339.                                 'pax' => $item->getSrvPax(),
  7340.                                 'precioUnit' => $subnetoUnit,
  7341.                                 'subneto' => $subneto,
  7342.                                 'subtotal' => $subtotal,
  7343.                             );
  7344.                             break;
  7345.                         case 3// AV
  7346.                             $pax $item->getSrvPax();
  7347.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7348.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7349.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7350.                             $unitsServ $item->getSrvUnits();
  7351.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7352.                             $subtotal $subtotalService $days $unitsServ $pax;
  7353.                             $subnetoUnit $subneto;
  7354.                             $subneto $subneto $days $unitsServ $pax;
  7355.                             $data_supplier['service'][$i] = array(
  7356.                                 'id' => $item->getId(),
  7357.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7358.                                 'serviceName' => $item->getSrvName(),
  7359.                                 'serviceType' => 'AV',
  7360.                                 'date' => $dateServ,
  7361.                                 'qty' => $unitsServ,
  7362.                                 'iva' => $item->getSrvIva(),
  7363.                                 'pax' => $item->getSrvPax(),
  7364.                                 'precioUnit' => $subnetoUnit,
  7365.                                 'subneto' => $subneto,
  7366.                                 'subtotal' => $subtotal,
  7367.                             );
  7368.                             break;
  7369.                         case 4//Creative
  7370.                             $pax $item->getSrvPax();
  7371.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7372.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7373.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7374.                             $unitsServ $item->getSrvUnits();
  7375.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7376.                             $subtotal $subtotalService $days $unitsServ $pax;
  7377.                             $subnetoUnit $subneto;
  7378.                             $subneto $subneto $days $unitsServ $pax;
  7379.                             $data_supplier['service'][$i] = array(
  7380.                                 'id' => $item->getId(),
  7381.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7382.                                 'serviceName' => $item->getSrvName(),
  7383.                                 'serviceType' => 'Creativo',
  7384.                                 'date' => $dateServ,
  7385.                                 'qty' => $unitsServ,
  7386.                                 'iva' => $item->getSrvIva(),
  7387.                                 'pax' => $item->getSrvPax(),
  7388.                                 'precioUnit' => $subnetoUnit,
  7389.                                 'subneto' => $subneto,
  7390.                                 'subtotal' => $subtotal,
  7391.                             );
  7392.                             break;
  7393.                         case 5//Cruise
  7394.                             $pax $item->getSrvPax();
  7395.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7396.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days);
  7397.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7398.                             $unitsServ $item->getSrvUnits();
  7399.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7400.                             $subtotal $subtotalService $days $unitsServ $pax;
  7401.                             $subnetoUnit $subneto;
  7402.                             $subneto $subneto $days $unitsServ $pax;
  7403.                             $data_supplier['service'][$i] = array(
  7404.                                 'id' => $item->getId(),
  7405.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7406.                                 'serviceName' => $item->getSrvName(),
  7407.                                 'serviceType' => 'Crucero',
  7408.                                 'date' => $dateServ,
  7409.                                 'qty' => $unitsServ,
  7410.                                 'iva' => $item->getSrvIva(),
  7411.                                 'pax' => $item->getSrvPax(),
  7412.                                 'precioUnit' => $subnetoUnit,
  7413.                                 'subneto' => $subneto,
  7414.                                 'subtotal' => $subtotal,
  7415.                             );
  7416.                             break;
  7417.                         case 6//Entertaiment
  7418.                             $pax $item->getSrvPax();
  7419.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7420.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7421.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7422.                             $unitsServ $item->getSrvUnits();
  7423.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7424.                             $subtotal $subtotalService $days $unitsServ $pax;
  7425.                             $subnetoUnit $subneto;
  7426.                             $subneto $subneto $days $unitsServ $pax;
  7427.                             $data_supplier['service'][$i] = array(
  7428.                                 'id' => $item->getId(),
  7429.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7430.                                 'serviceName' => $item->getSrvName(),
  7431.                                 'serviceType' => 'Entretenimiento',
  7432.                                 'date' => $dateServ,
  7433.                                 'qty' => $unitsServ,
  7434.                                 'iva' => $item->getSrvIva(),
  7435.                                 'pax' => $item->getSrvPax(),
  7436.                                 'precioUnit' => $subnetoUnit,
  7437.                                 'subneto' => $subneto,
  7438.                                 'subtotal' => $subtotal,
  7439.                             );
  7440.                             break;
  7441.                         case 7// Gifts
  7442.                             $pax $item->getSrvPax();
  7443.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7444.                             $days 1;
  7445.                             $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  7446.                             $unitsServ $item->getSrvUnits();
  7447.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7448.                             $subtotal $subtotalService $days $unitsServ $pax;
  7449.                             $subnetoUnit $subneto;
  7450.                             $subneto $subneto $days $unitsServ $pax;
  7451.                             $data_supplier['service'][$i] = array(
  7452.                                 'id' => $item->getId(),
  7453.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7454.                                 'serviceName' => $item->getSrvName(),
  7455.                                 'serviceType' => 'Regalos',
  7456.                                 'date' => $dateServ,
  7457.                                 'qty' => $unitsServ,
  7458.                                 'iva' => $item->getSrvIva(),
  7459.                                 'pax' => $item->getSrvPax(),
  7460.                                 'precioUnit' => $subnetoUnit,
  7461.                                 'subneto' => $subneto,
  7462.                                 'subtotal' => $subtotal,
  7463.                             );
  7464.                             break;
  7465.                         case 8//Guide
  7466.                             $pax $item->getSrvPax();
  7467.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7468.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7469.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7470.                             $unitsServ $item->getSrvUnits();
  7471.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7472.                             $subtotal $subtotalService $days $unitsServ $pax;
  7473.                             $subnetoUnit $subneto;
  7474.                             $subneto $subneto $days $unitsServ $pax;
  7475.                             $data_supplier['service'][$i] = array(
  7476.                                 'id' => $item->getId(),
  7477.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7478.                                 'serviceName' => $item->getSrvName(),
  7479.                                 'serviceType' => 'Guía',
  7480.                                 'date' => $dateServ,
  7481.                                 'qty' => $unitsServ,
  7482.                                 'iva' => $item->getSrvIva(),
  7483.                                 'pax' => $item->getSrvPax(),
  7484.                                 'precioUnit' => $subnetoUnit,
  7485.                                 'subneto' => $subneto,
  7486.                                 'subtotal' => $subtotal,
  7487.                             );
  7488.                             break;
  7489.                         case 9//Itineraries
  7490.                             $pax $item->getSrvPax();
  7491.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7492.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7493.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7494.                             $unitsServ $item->getSrvUnits();
  7495.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7496.                             $subtotal $subtotalService $days $unitsServ $pax;
  7497.                             $subnetoUnit $subneto;
  7498.                             $subneto $subneto $days $unitsServ $pax;
  7499.                             $data_supplier['service'][$i] = array(
  7500.                                 'id' => $item->getId(),
  7501.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7502.                                 'serviceName' => $item->getSrvName(),
  7503.                                 'serviceType' => 'Itinerarios',
  7504.                                 'date' => $dateServ,
  7505.                                 'qty' => $unitsServ,
  7506.                                 'iva' => $item->getSrvIva(),
  7507.                                 'pax' => $item->getSrvPax(),
  7508.                                 'precioUnit' => $subnetoUnit,
  7509.                                 'subneto' => $subneto,
  7510.                                 'subtotal' => $subtotal,
  7511.                             );
  7512.                             break;
  7513.                         case 10//Lounge  -- No Aplica
  7514.                             break;
  7515.                         case 11//Menu (Catering)
  7516.                             $pax $item->getSrvPax();
  7517.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7518.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7519.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  7520.                             $unitsServ $item->getSrvUnits();
  7521.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7522.                             $subtotal $subtotalService $days $unitsServ $pax;
  7523.                             $subnetoUnit $subneto;
  7524.                             $subneto $subneto $days $unitsServ $pax;
  7525.                             $data_supplier['service'][$i] = array(
  7526.                                 'id' => $item->getId(),
  7527.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7528.                                 'serviceName' => $item->getSrvName(),
  7529.                                 'serviceType' => 'Catering',
  7530.                                 'date' => $dateServ,
  7531.                                 'qty' => $unitsServ,
  7532.                                 'iva' => $item->getSrvIva(),
  7533.                                 'pax' => $item->getSrvPax(),
  7534.                                 'precioUnit' => $subnetoUnit,
  7535.                                 'subneto' => $subneto,
  7536.                                 'subtotal' => $subtotal,
  7537.                             );
  7538.                             break;
  7539.                         case 12//Others
  7540.                             $pax $item->getSrvPax();
  7541.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7542.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7543.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7544.                             $unitsServ $item->getSrvUnits();
  7545.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7546.                             $subtotal $subtotalService $days $unitsServ $pax;
  7547.                             $subnetoUnit $subneto;
  7548.                             $subneto $subneto $days $unitsServ $pax;
  7549.                             $data_supplier['service'][$i] = array(
  7550.                                 'id' => $item->getId(),
  7551.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7552.                                 'serviceName' => $item->getSrvName(),
  7553.                                 'serviceType' => 'Otros',
  7554.                                 'date' => $dateServ,
  7555.                                 'qty' => $unitsServ,
  7556.                                 'iva' => $item->getSrvIva(),
  7557.                                 'pax' => $item->getSrvPax(),
  7558.                                 'precioUnit' => $subnetoUnit,
  7559.                                 'subneto' => $subneto,
  7560.                                 'subtotal' => $subtotal,
  7561.                             );
  7562.                             break;
  7563.                         case 13//Transport
  7564.                             $pax $item->getSrvPax();
  7565.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7566.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7567.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7568.                             $unitsServ $item->getSrvUnits();
  7569.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7570.                             $subtotal $subtotalService $days $unitsServ $pax;
  7571.                             $subnetoUnit $subneto;
  7572.                             $subneto $subneto $days $unitsServ $pax;
  7573.                             $data_supplier['service'][$i] = array(
  7574.                                 'id' => $item->getId(),
  7575.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7576.                                 'serviceName' => $item->getSrvName(),
  7577.                                 'serviceType' => 'Transporte',
  7578.                                 'date' => $dateServ,
  7579.                                 'qty' => $unitsServ,
  7580.                                 'iva' => $item->getSrvIva(),
  7581.                                 'pax' => $item->getSrvPax(),
  7582.                                 'precioUnit' => $subnetoUnit,
  7583.                                 'subneto' => $subneto,
  7584.                                 'subtotal' => $subtotal,
  7585.                             );
  7586.                             break;
  7587.                         case 14//Technology
  7588.                             $pax $item->getSrvPax();
  7589.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7590.                             $days 1;
  7591.                             $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  7592.                             $unitsServ $item->getSrvUnits();
  7593.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7594.                             $subtotal $subtotalService $days $unitsServ $pax;
  7595.                             $subnetoUnit $subneto;
  7596.                             $subneto $subneto $days $unitsServ $pax;
  7597.                             $data_supplier['service'][$i] = array(
  7598.                                 'id' => $item->getId(),
  7599.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7600.                                 'serviceName' => $item->getSrvName(),
  7601.                                 'serviceType' => 'Tecnología',
  7602.                                 'date' => $dateServ,
  7603.                                 'qty' => $unitsServ,
  7604.                                 'iva' => $item->getSrvIva(),
  7605.                                 'pax' => $item->getSrvPax(),
  7606.                                 'precioUnit' => $subnetoUnit,
  7607.                                 'subneto' => $subneto,
  7608.                                 'subtotal' => $subtotal,
  7609.                             );
  7610.                             break;
  7611.                         case 15//Assisstant
  7612.                             $pax $item->getSrvPax();
  7613.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7614.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7615.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7616.                             $unitsServ $item->getSrvUnits();
  7617.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7618.                             $subtotal $subtotalService $days $unitsServ $pax;
  7619.                             $subnetoUnit $subneto;
  7620.                             $subneto $subneto $days $unitsServ $pax;
  7621.                             $data_supplier['service'][$i] = array(
  7622.                                 'id' => $item->getId(),
  7623.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7624.                                 'serviceName' => $item->getSrvName(),
  7625.                                 'serviceType' => 'Asistente',
  7626.                                 'date' => $dateServ,
  7627.                                 'qty' => $unitsServ,
  7628.                                 'iva' => $item->getSrvIva(),
  7629.                                 'pax' => $item->getSrvPax(),
  7630.                                 'precioUnit' => $subnetoUnit,
  7631.                                 'subneto' => $subneto,
  7632.                                 'subtotal' => $subtotal,
  7633.                             );
  7634.                             break;
  7635.                         case 16//DDR
  7636.                             $pax $item->getSrvPax();
  7637.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7638.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7639.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7640.                             $unitsServ $item->getSrvUnits();
  7641.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7642.                             $subtotal $subtotalService $days $unitsServ $pax;
  7643.                             $subnetoUnit $subneto;
  7644.                             $subneto $subneto $days $unitsServ $pax;
  7645.                             $data_supplier['service'][$i] = array(
  7646.                                 'id' => $item->getId(),
  7647.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7648.                                 'serviceName' => $item->getSrvName(),
  7649.                                 'serviceType' => 'DDR',
  7650.                                 'date' => $dateServ,
  7651.                                 'qty' => $unitsServ,
  7652.                                 'iva' => $item->getSrvIva(),
  7653.                                 'pax' => $item->getSrvPax(),
  7654.                                 'precioUnit' => $subnetoUnit,
  7655.                                 'subneto' => $subneto,
  7656.                                 'subtotal' => $subtotal,
  7657.                             );
  7658.                             break;
  7659.                         case 17//Seguridad
  7660.                             $pax $item->getSrvPax();
  7661.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7662.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7663.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7664.                             $unitsServ $item->getSrvUnits();
  7665.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7666.                             $subtotal $subtotalService $days $unitsServ $pax;
  7667.                             $subnetoUnit $subneto;
  7668.                             $subneto $subneto $days $unitsServ $pax;
  7669.                             $data_supplier['service'][$i] = array(
  7670.                                 'id' => $item->getId(),
  7671.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7672.                                 'serviceName' => $item->getSrvName(),
  7673.                                 'serviceType' => 'Seguridad',
  7674.                                 'date' => $dateServ,
  7675.                                 'qty' => $unitsServ,
  7676.                                 'iva' => $item->getSrvIva(),
  7677.                                 'pax' => $item->getSrvPax(),
  7678.                                 'precioUnit' => $subnetoUnit,
  7679.                                 'subneto' => $subneto,
  7680.                                 'subtotal' => $subtotal,
  7681.                             );
  7682.                             break;
  7683.                         case 18//WiFi
  7684.                             $pax $item->getSrvPax();
  7685.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7686.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7687.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7688.                             $unitsServ $item->getSrvUnits();
  7689.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7690.                             $subtotal $subtotalService $days $unitsServ $pax;
  7691.                             $subnetoUnit $subneto;
  7692.                             $subneto $subneto $days $unitsServ $pax;
  7693.                             $data_supplier['service'][$i] = array(
  7694.                                 'id' => $item->getId(),
  7695.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7696.                                 'serviceName' => $item->getSrvName(),
  7697.                                 'serviceType' => 'WiFi',
  7698.                                 'date' => $dateServ,
  7699.                                 'qty' => $unitsServ,
  7700.                                 'iva' => $item->getSrvIva(),
  7701.                                 'pax' => $item->getSrvPax(),
  7702.                                 'precioUnit' => $subnetoUnit,
  7703.                                 'subneto' => $subneto,
  7704.                                 'subtotal' => $subtotal,
  7705.                             );
  7706.                             break;
  7707.                         case 19//Mobiliario
  7708.                             $pax $item->getSrvPax();
  7709.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7710.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7711.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7712.                             $unitsServ $item->getSrvUnits();
  7713.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7714.                             $subtotal $subtotalService $days $unitsServ $pax;
  7715.                             $subnetoUnit $subneto;
  7716.                             $subneto $subneto $days $unitsServ $pax;
  7717.                             $data_supplier['service'][$i] = array(
  7718.                                 'id' => $item->getId(),
  7719.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7720.                                 'serviceName' => $item->getSrvName(),
  7721.                                 'serviceType' => 'Mobiliario',
  7722.                                 'date' => $dateServ,
  7723.                                 'qty' => $unitsServ,
  7724.                                 'iva' => $item->getSrvIva(),
  7725.                                 'pax' => $item->getSrvPax(),
  7726.                                 'precioUnit' => $subnetoUnit,
  7727.                                 'subneto' => $subneto,
  7728.                                 'subtotal' => $subtotal,
  7729.                             );
  7730.                             break;
  7731.                         case 20//Parking
  7732.                             $pax $item->getSrvPax();
  7733.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7734.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7735.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7736.                             $unitsServ $item->getSrvUnits();
  7737.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7738.                             $subtotal $subtotalService $days $unitsServ $pax;
  7739.                             $subnetoUnit $subneto;
  7740.                             $subneto $subneto $days $unitsServ $pax;
  7741.                             $data_supplier['service'][$i] = array(
  7742.                                 'id' => $item->getId(),
  7743.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7744.                                 'serviceName' => $item->getSrvName(),
  7745.                                 'serviceType' => 'Parking',
  7746.                                 'date' => $dateServ,
  7747.                                 'qty' => $unitsServ,
  7748.                                 'iva' => $item->getSrvIva(),
  7749.                                 'pax' => $item->getSrvPax(),
  7750.                                 'precioUnit' => $subnetoUnit,
  7751.                                 'subneto' => $subneto,
  7752.                                 'subtotal' => $subtotal,
  7753.                             );
  7754.                             break;
  7755.                         case 21//Limpieza
  7756.                             $pax $item->getSrvPax();
  7757.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7758.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7759.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7760.                             $unitsServ $item->getSrvUnits();
  7761.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7762.                             $subtotal $subtotalService $days $unitsServ $pax;
  7763.                             $subnetoUnit $subneto;
  7764.                             $subneto $subneto $days $unitsServ $pax;
  7765.                             $data_supplier['service'][$i] = array(
  7766.                                 'id' => $item->getId(),
  7767.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7768.                                 'serviceName' => $item->getSrvName(),
  7769.                                 'serviceType' => 'Limpieza',
  7770.                                 'date' => $dateServ,
  7771.                                 'qty' => $unitsServ,
  7772.                                 'iva' => $item->getSrvIva(),
  7773.                                 'pax' => $item->getSrvPax(),
  7774.                                 'precioUnit' => $subnetoUnit,
  7775.                                 'subneto' => $subneto,
  7776.                                 'subtotal' => $subtotal,
  7777.                             );
  7778.                             break;
  7779.                         default: //Others (por default)
  7780.                             $pax $item->getSrvPax();
  7781.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7782.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  7783.                             $dateServ = ($days 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
  7784.                             $unitsServ $item->getSrvUnits();
  7785.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7786.                             $subtotal $subtotalService $days $unitsServ $pax;
  7787.                             $subnetoUnit $subneto;
  7788.                             $subneto $subneto $days $unitsServ $pax;
  7789.                             $data_supplier['service'][$i] = array(
  7790.                                 'id' => $item->getId(),
  7791.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  7792.                                 'serviceName' => $item->getSrvName(),
  7793.                                 'serviceType' => 'Otros',
  7794.                                 'date' => $dateServ,
  7795.                                 'qty' => $unitsServ,
  7796.                                 'iva' => $item->getSrvIva(),
  7797.                                 'pax' => $item->getSrvPax(),
  7798.                                 'precioUnit' => $subnetoUnit,
  7799.                                 'subneto' => $subneto,
  7800.                                 'subtotal' => $subtotal,
  7801.                             );
  7802.                             break;
  7803.                     }
  7804.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  7805.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  7806.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  7807.                     $arrayItems[] = array(
  7808.                         'type' => 'Service',
  7809.                         'name' => $item->getSrvName(),
  7810.                         'amount' => $neto,
  7811.                         'iva' => $item->getSrvIva(),
  7812.                         'total' => $subtotal,
  7813.                     );
  7814.                 }
  7815.                 switch ($item->getSrvIva()) {
  7816.                     // Acumula IVA
  7817.                     case 21:
  7818.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getSrvIva() / 100));
  7819.                         break;
  7820.                     case 10:
  7821.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getSrvIva() / 100));
  7822.                         break;
  7823.                     case 0:
  7824.                         break;
  7825.                     default:
  7826.                         break;
  7827.                 }
  7828.             } else {
  7829.                 // Es una proforma
  7830.                 if (is_null($item->getPrice()) or empty($item->getPrice())) {
  7831.                     $subtotal 0;
  7832.                     $neto 0;
  7833.                     $subtotalService 0;
  7834.                 } else {
  7835.                     $subtotalService $item->getPrice();
  7836.                     $subneto $item->getPrice();
  7837.                     // Commission
  7838.                     if ($item->getOpCommission() == '1') {
  7839.                         $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  7840.                         $subneto $subneto * (+ ($item->getCommission() / 100));
  7841.                     } else {
  7842.                         $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  7843.                         $subneto $subneto * (- ($item->getCommission() / 100));
  7844.                     }
  7845.                     // Over
  7846.                     if ($item->getOpOver() == '1') {
  7847.                         $subtotalService $subtotalService $item->getOver();
  7848.                         $subneto $subneto $item->getOver();
  7849.                     } else {
  7850.                         $subtotalService $subtotalService $item->getOver();
  7851.                         $subneto $subneto $item->getOver();
  7852.                     }
  7853.                     // IVA
  7854.                     if ($item->getOpIva() == '1') {
  7855.                         $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  7856.                     } else {
  7857.                         $subtotalService $item->getPrice();
  7858.                         $subneto = ($subneto 100) / (100 $item->getIva());
  7859.                     }
  7860.                     switch ($item->getServiceCatId()) {
  7861.                         case 1// Alojamiento
  7862.                             // el numero de noches $numNoches; precio unitario $subneto
  7863.                             $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  7864.                             // La personas no afectan este calculo
  7865.                             $subtotal $subtotalService $numNoches $item->getUnits();
  7866.                             $subnetoUnit $subneto;
  7867.                             $subneto $subneto $numNoches $item->getUnits();
  7868.                             $data_supplier['service'][$i] = array(
  7869.                                 'id' => $item->getId(),
  7870.                                 'serviceCatId' => $item->getServiceCatId(),
  7871.                                 'serviceName' => $item->getName(),
  7872.                                 'serviceType' => 'Hotel',
  7873.                                 'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  7874.                                 'qty' => $item->getUnits(),
  7875.                                 'iva' => $item->getIva(),
  7876.                                 'pax' => '-',
  7877.                                 'precioUnit' => $subnetoUnit,
  7878.                                 'subneto' => $subneto,
  7879.                                 'subtotal' => $subtotal,
  7880.                             );
  7881.                             break;
  7882.                         case 2//Actividades
  7883.                             // El número de personas es considerado en el calculo
  7884.                             $pax $item->getPax();
  7885.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7886.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7887.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  7888.                             $subtotal $subtotalService $days $item->getUnits();
  7889.                             $subnetoUnit $subneto;
  7890.                             $subneto $subneto $days $item->getUnits();
  7891.                             $data_supplier['service'][$i] = array(
  7892.                                 'id' => $item->getId(),
  7893.                                 'serviceCatId' => $item->getServiceCatId(),
  7894.                                 'serviceName' => $item->getName(),
  7895.                                 'serviceType' => 'Actividad',
  7896.                                 'date' => $dateServ,
  7897.                                 'qty' => $item->getUnits(),
  7898.                                 'iva' => $item->getIva(),
  7899.                                 'pax' => $item->getPax(),
  7900.                                 'precioUnit' => $subnetoUnit,
  7901.                                 'subneto' => $subneto,
  7902.                                 'subtotal' => $subtotal,
  7903.                             );
  7904.                             break;
  7905.                         case 3// AV
  7906.                             $pax $item->getPax();
  7907.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7908.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7909.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  7910.                             $unitsServ $item->getUnits();
  7911.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7912.                             $subtotal $subtotalService $days $unitsServ $pax;
  7913.                             $subnetoUnit $subneto;
  7914.                             $subneto $subneto $days $unitsServ $pax;
  7915.                             $data_supplier['service'][$i] = array(
  7916.                                 'id' => $item->getId(),
  7917.                                 'serviceCatId' => $item->getServiceCatId(),
  7918.                                 'serviceName' => $item->getName(),
  7919.                                 'serviceType' => 'AV',
  7920.                                 'date' => $dateServ,
  7921.                                 'qty' => $unitsServ,
  7922.                                 'iva' => $item->getIva(),
  7923.                                 'pax' => $item->getPax(),
  7924.                                 'precioUnit' => $subnetoUnit,
  7925.                                 'subneto' => $subneto,
  7926.                                 'subtotal' => $subtotal,
  7927.                             );
  7928.                             break;
  7929.                         case 4//Creative
  7930.                             $pax $item->getPax();
  7931.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7932.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7933.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  7934.                             $unitsServ $item->getUnits();
  7935.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7936.                             $subtotal $subtotalService $days $unitsServ $pax;
  7937.                             $subnetoUnit $subneto;
  7938.                             $subneto $subneto $days $unitsServ $pax;
  7939.                             $data_supplier['service'][$i] = array(
  7940.                                 'id' => $item->getId(),
  7941.                                 'serviceCatId' => $item->getServiceCatId(),
  7942.                                 'serviceName' => $item->getName(),
  7943.                                 'serviceType' => 'Creativo',
  7944.                                 'date' => $dateServ,
  7945.                                 'qty' => $unitsServ,
  7946.                                 'iva' => $item->getIva(),
  7947.                                 'pax' => $item->getPax(),
  7948.                                 'precioUnit' => $subnetoUnit,
  7949.                                 'subneto' => $subneto,
  7950.                                 'subtotal' => $subtotal,
  7951.                             );
  7952.                             break;
  7953.                         case 5//Cruise
  7954.                             $pax $item->getPax();
  7955.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7956.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  7957.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  7958.                             $unitsServ $item->getUnits();
  7959.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7960.                             $subtotal $subtotalService $days $unitsServ $pax;
  7961.                             $subnetoUnit $subneto;
  7962.                             $subneto $subneto $days $unitsServ $pax;
  7963.                             $data_supplier['service'][$i] = array(
  7964.                                 'id' => $item->getId(),
  7965.                                 'serviceCatId' => $item->getServiceCatId(),
  7966.                                 'serviceName' => $item->getName(),
  7967.                                 'serviceType' => 'Crucero',
  7968.                                 'date' => $dateServ,
  7969.                                 'qty' => $unitsServ,
  7970.                                 'iva' => $item->getIva(),
  7971.                                 'pax' => $item->getPax(),
  7972.                                 'precioUnit' => $subnetoUnit,
  7973.                                 'subneto' => $subneto,
  7974.                                 'subtotal' => $subtotal,
  7975.                             );
  7976.                             break;
  7977.                         case 6//Entertaiment
  7978.                             $pax $item->getPax();
  7979.                             if (empty($pax) or $pax == "0") { $pax 1; }
  7980.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7981.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  7982.                             $unitsServ $item->getUnits();
  7983.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  7984.                             $subtotal $subtotalService $days $unitsServ $pax;
  7985.                             $subnetoUnit $subneto;
  7986.                             $subneto $subneto $days $unitsServ $pax;
  7987.                             $data_supplier['service'][$i] = array(
  7988.                                 'id' => $item->getId(),
  7989.                                 'serviceCatId' => $item->getServiceCatId(),
  7990.                                 'serviceName' => $item->getName(),
  7991.                                 'serviceType' => 'Entretenimiento',
  7992.                                 'date' => $dateServ,
  7993.                                 'qty' => $unitsServ,
  7994.                                 'iva' => $item->getIva(),
  7995.                                 'pax' => $item->getPax(),
  7996.                                 'precioUnit' => $subnetoUnit,
  7997.                                 'subneto' => $subneto,
  7998.                                 'subtotal' => $subtotal,
  7999.                             );
  8000.                             break;
  8001.                         case 7// Gifts
  8002.                             $pax $item->getPax();
  8003.                             if (empty($pax) or $pax == "0") { $pax 1; }
  8004.                             $days 1;
  8005.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8006.                             $unitsServ $item->getUnits();
  8007.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  8008.                             $subtotal $subtotalService $days $unitsServ $pax;
  8009.                             $subnetoUnit $subneto;
  8010.                             $subneto $subneto $days $unitsServ $pax;
  8011.                             $data_supplier['service'][$i] = array(
  8012.                                 'id' => $item->getId(),
  8013.                                 'serviceCatId' => $item->getServiceCatId(),
  8014.                                 'serviceName' => $item->getName(),
  8015.                                 'serviceType' => 'Regalos',
  8016.                                 'date' => $dateServ,
  8017.                                 'qty' => $unitsServ,
  8018.                                 'iva' => $item->getIva(),
  8019.                                 'pax' => $item->getPax(),
  8020.                                 'precioUnit' => $subnetoUnit,
  8021.                                 'subneto' => $subneto,
  8022.                                 'subtotal' => $subtotal,
  8023.                             );
  8024.                             break;
  8025.                         case 8//Guide
  8026.                             $pax $item->getPax();
  8027.                             if (empty($pax) or $pax == "0") { $pax 1; }
  8028.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8029.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  8030.                             $unitsServ $item->getUnits();
  8031.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  8032.                             $subtotal $subtotalService $days $unitsServ $pax;
  8033.                             $subnetoUnit $subneto;
  8034.                             $subneto $subneto $days $unitsServ $pax;
  8035.                             $data_supplier['service'][$i] = array(
  8036.                                 'id' => $item->getId(),
  8037.                                 'serviceCatId' => $item->getServiceCatId(),
  8038.                                 'serviceName' => $item->getName(),
  8039.                                 'serviceType' => 'Guía',
  8040.                                 'date' => $dateServ,
  8041.                                 'qty' => $unitsServ,
  8042.                                 'iva' => $item->getIva(),
  8043.                                 'pax' => $item->getPax(),
  8044.                                 'precioUnit' => $subnetoUnit,
  8045.                                 'subneto' => $subneto,
  8046.                                 'subtotal' => $subtotal,
  8047.                             );
  8048.                             break;
  8049.                         case 9//Itineraries
  8050.                             $pax $item->getPax();
  8051.                             if (empty($pax) or $pax == "0") { $pax 1; }
  8052.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8053.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  8054.                             $unitsServ $item->getUnits();
  8055.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  8056.                             $subtotal $subtotalService $days $unitsServ $pax;
  8057.                             $subnetoUnit $subneto;
  8058.                             $subneto $subneto $days $unitsServ $pax;
  8059.                             $data_supplier['service'][$i] = array(
  8060.                                 'id' => $item->getId(),
  8061.                                 'serviceCatId' => $item->getServiceCatId(),
  8062.                                 'serviceName' => $item->getName(),
  8063.                                 'serviceType' => 'Itinerarios',
  8064.                                 'date' => $dateServ,
  8065.                                 'qty' => $unitsServ,
  8066.                                 'iva' => $item->getIva(),
  8067.                                 'pax' => $item->getPax(),
  8068.                                 'precioUnit' => $subnetoUnit,
  8069.                                 'subneto' => $subneto,
  8070.                                 'subtotal' => $subtotal,
  8071.                             );
  8072.                             break;
  8073.                         case 10//Lounge  -- No Aplica
  8074.                             break;
  8075.                         case 11//Catering (Menu)
  8076.                             $pax $item->getPax();
  8077.                             if (empty($pax) or $pax == "0") { $pax 1; }
  8078.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8079.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  8080.                             $unitsServ $item->getUnits();
  8081.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  8082.                             $subtotal $subtotalService $days $unitsServ $pax;
  8083.                             $subnetoUnit $subneto;
  8084.                             $subneto $subneto $days $unitsServ $pax;
  8085.                             $data_supplier['service'][$i] = array(
  8086.                                 'id' => $item->getId(),
  8087.                                 'serviceCatId' => $item->getServiceCatId(),
  8088.                                 'serviceName' => $item->getName(),
  8089.                                 'serviceType' => 'Catering',
  8090.                                 'date' => $dateServ,
  8091.                                 'qty' => $unitsServ,
  8092.                                 'iva' => $item->getIva(),
  8093.                                 'pax' => $item->getPax(),
  8094.                                 'precioUnit' => $subnetoUnit,
  8095.                                 'subneto' => $subneto,
  8096.                                 'subtotal' => $subtotal,
  8097.                             );
  8098.                             break;
  8099.                         case 12//Others
  8100.                             $pax $item->getPax();
  8101.                             if (empty($pax) or $pax == "0") { $pax 1; }
  8102.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8103.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  8104.                             $unitsServ $item->getUnits();
  8105.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  8106.                             $subtotal $subtotalService $days $unitsServ $pax;
  8107.                             $subnetoUnit $subneto;
  8108.                             $subneto $subneto $days $unitsServ $pax;
  8109.                             $data_supplier['service'][$i] = array(
  8110.                                 'id' => $item->getId(),
  8111.                                 'serviceCatId' => $item->getServiceCatId(),
  8112.                                 'serviceName' => $item->getName(),
  8113.                                 'serviceType' => 'Otros',
  8114.                                 'date' => $dateServ,
  8115.                                 'qty' => $unitsServ,
  8116.                                 'iva' => $item->getIva(),
  8117.                                 'pax' => $item->getPax(),
  8118.                                 'precioUnit' => $subnetoUnit,
  8119.                                 'subneto' => $subneto,
  8120.                                 'subtotal' => $subtotal,
  8121.                             );
  8122.                             break;
  8123.                         case 13//Transport
  8124.                             $pax $item->getPax();
  8125.                             if (empty($pax) or $pax == "0") { $pax 1; }
  8126.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8127.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  8128.                             $unitsServ $item->getUnits();
  8129.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  8130.                             $subtotal $subtotalService $days $unitsServ $pax;
  8131.                             $subnetoUnit $subneto;
  8132.                             $subneto $subneto $days $unitsServ $pax;
  8133.                             $data_supplier['service'][$i] = array(
  8134.                                 'id' => $item->getId(),
  8135.                                 'serviceCatId' => $item->getServiceCatId(),
  8136.                                 'serviceName' => $item->getName(),
  8137.                                 'serviceType' => 'Transporte',
  8138.                                 'date' => $dateServ,
  8139.                                 'qty' => $unitsServ,
  8140.                                 'iva' => $item->getIva(),
  8141.                                 'pax' => $item->getPax(),
  8142.                                 'precioUnit' => $subnetoUnit,
  8143.                                 'subneto' => $subneto,
  8144.                                 'subtotal' => $subtotal,
  8145.                             );
  8146.                             break;
  8147.                         case 14//Technology
  8148.                             $pax $item->getPax();
  8149.                             if (empty($pax) or $pax == "0") { $pax 1; }
  8150.                             $days 1;
  8151.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8152.                             $unitsServ $item->getUnits();
  8153.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  8154.                             $subtotal $subtotalService $days $unitsServ $pax;
  8155.                             $subnetoUnit $subneto;
  8156.                             $subneto $subneto $days $unitsServ $pax;
  8157.                             $data_supplier['service'][$i] = array(
  8158.                                 'id' => $item->getId(),
  8159.                                 'serviceCatId' => $item->getServiceCatId(),
  8160.                                 'serviceName' => $item->getName(),
  8161.                                 'serviceType' => 'Tecnología',
  8162.                                 'date' => $dateServ,
  8163.                                 'qty' => $unitsServ,
  8164.                                 'iva' => $item->getIva(),
  8165.                                 'pax' => $item->getPax(),
  8166.                                 'precioUnit' => $subnetoUnit,
  8167.                                 'subneto' => $subneto,
  8168.                                 'subtotal' => $subtotal,
  8169.                             );
  8170.                             break;
  8171.                         case 15//Assisstant
  8172.                             $pax $item->getPax();
  8173.                             if (empty($pax) or $pax == "0") { $pax 1; }
  8174.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8175.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  8176.                             $unitsServ $item->getUnits();
  8177.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  8178.                             $subtotal $subtotalService $days $unitsServ $pax;
  8179.                             $subnetoUnit $subneto;
  8180.                             $subneto $subneto $days $unitsServ $pax;
  8181.                             $data_supplier['service'][$i] = array(
  8182.                                 'id' => $item->getId(),
  8183.                                 'serviceCatId' => $item->getServiceCatId(),
  8184.                                 'serviceName' => $item->getName(),
  8185.                                 'serviceType' => 'Asistente',
  8186.                                 'date' => $dateServ,
  8187.                                 'qty' => $unitsServ,
  8188.                                 'iva' => $item->getIva(),
  8189.                                 'pax' => $item->getPax(),
  8190.                                 'precioUnit' => $subnetoUnit,
  8191.                                 'subneto' => $subneto,
  8192.                                 'subtotal' => $subtotal,
  8193.                             );
  8194.                             break;
  8195.                         case 16//DDR
  8196.                             $pax $item->getPax();
  8197.                             if (empty($pax) or $pax == "0") { $pax 1; }
  8198.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8199.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  8200.                             $unitsServ $item->getUnits();
  8201.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  8202.                             $subtotal $subtotalService $days $unitsServ $pax;
  8203.                             $subnetoUnit $subneto;
  8204.                             $subneto $subneto $days $unitsServ $pax;
  8205.                             $data_supplier['service'][$i] = array(
  8206.                                 'id' => $item->getId(),
  8207.                                 'serviceCatId' => $item->getServiceCatId(),
  8208.                                 'serviceName' => $item->getName(),
  8209.                                 'serviceType' => 'DDR',
  8210.                                 'date' => $dateServ,
  8211.                                 'qty' => $unitsServ,
  8212.                                 'iva' => $item->getIva(),
  8213.                                 'pax' => $item->getPax(),
  8214.                                 'precioUnit' => $subnetoUnit,
  8215.                                 'subneto' => $subneto,
  8216.                                 'subtotal' => $subtotal,
  8217.                             );
  8218.                             break;
  8219.                         case 17//Seguridad
  8220.                             $pax $item->getPax();
  8221.                             if (empty($pax) or $pax == "0") { $pax 1; }
  8222.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8223.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  8224.                             $unitsServ $item->getUnits();
  8225.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  8226.                             $subtotal $subtotalService $days $unitsServ $pax;
  8227.                             $subnetoUnit $subneto;
  8228.                             $subneto $subneto $days $unitsServ $pax;
  8229.                             $data_supplier['service'][$i] = array(
  8230.                                 'id' => $item->getId(),
  8231.                                 'serviceCatId' => $item->getServiceCatId(),
  8232.                                 'serviceName' => $item->getName(),
  8233.                                 'serviceType' => 'Seguridad',
  8234.                                 'date' => $dateServ,
  8235.                                 'qty' => $unitsServ,
  8236.                                 'iva' => $item->getIva(),
  8237.                                 'pax' => $item->getPax(),
  8238.                                 'precioUnit' => $subnetoUnit,
  8239.                                 'subneto' => $subneto,
  8240.                                 'subtotal' => $subtotal,
  8241.                             );
  8242.                             break;
  8243.                         case 18//WiFi
  8244.                             $pax $item->getPax();
  8245.                             if (empty($pax) or $pax == "0") { $pax 1; }
  8246.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8247.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  8248.                             $unitsServ $item->getUnits();
  8249.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  8250.                             $subtotal $subtotalService $days $unitsServ $pax;
  8251.                             $subnetoUnit $subneto;
  8252.                             $subneto $subneto $days $unitsServ $pax;
  8253.                             $data_supplier['service'][$i] = array(
  8254.                                 'id' => $item->getId(),
  8255.                                 'serviceCatId' => $item->getServiceCatId(),
  8256.                                 'serviceName' => $item->getName(),
  8257.                                 'serviceType' => 'WiFi',
  8258.                                 'date' => $dateServ,
  8259.                                 'qty' => $unitsServ,
  8260.                                 'iva' => $item->getIva(),
  8261.                                 'pax' => $item->getPax(),
  8262.                                 'precioUnit' => $subnetoUnit,
  8263.                                 'subneto' => $subneto,
  8264.                                 'subtotal' => $subtotal,
  8265.                             );
  8266.                             break;
  8267.                         case 19//Mobiliario
  8268.                             $pax $item->getPax();
  8269.                             if (empty($pax) or $pax == "0") { $pax 1; }
  8270.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8271.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  8272.                             $unitsServ $item->getUnits();
  8273.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  8274.                             $subtotal $subtotalService $days $unitsServ $pax;
  8275.                             $subnetoUnit $subneto;
  8276.                             $subneto $subneto $days $unitsServ $pax;
  8277.                             $data_supplier['service'][$i] = array(
  8278.                                 'id' => $item->getId(),
  8279.                                 'serviceCatId' => $item->getServiceCatId(),
  8280.                                 'serviceName' => $item->getName(),
  8281.                                 'serviceType' => 'Mobiliario',
  8282.                                 'date' => $dateServ,
  8283.                                 'qty' => $unitsServ,
  8284.                                 'iva' => $item->getIva(),
  8285.                                 'pax' => $item->getPax(),
  8286.                                 'precioUnit' => $subnetoUnit,
  8287.                                 'subneto' => $subneto,
  8288.                                 'subtotal' => $subtotal,
  8289.                             );
  8290.                             break;
  8291.                         case 20//Parking
  8292.                             $pax $item->getPax();
  8293.                             if (empty($pax) or $pax == "0") { $pax 1; }
  8294.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8295.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  8296.                             $unitsServ $item->getUnits();
  8297.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  8298.                             $subtotal $subtotalService $days $unitsServ $pax;
  8299.                             $subnetoUnit $subneto;
  8300.                             $subneto $subneto $days $unitsServ $pax;
  8301.                             $data_supplier['service'][$i] = array(
  8302.                                 'id' => $item->getId(),
  8303.                                 'serviceCatId' => $item->getServiceCatId(),
  8304.                                 'serviceName' => $item->getName(),
  8305.                                 'serviceType' => 'Parking',
  8306.                                 'date' => $dateServ,
  8307.                                 'qty' => $unitsServ,
  8308.                                 'iva' => $item->getIva(),
  8309.                                 'pax' => $item->getPax(),
  8310.                                 'precioUnit' => $subnetoUnit,
  8311.                                 'subneto' => $subneto,
  8312.                                 'subtotal' => $subtotal,
  8313.                             );
  8314.                             break;
  8315.                         case 21//Limpieza
  8316.                             $pax $item->getPax();
  8317.                             if (empty($pax) or $pax == "0") { $pax 1; }
  8318.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8319.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  8320.                             $unitsServ $item->getUnits();
  8321.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  8322.                             $subtotal $subtotalService $days $unitsServ $pax;
  8323.                             $subnetoUnit $subneto;
  8324.                             $subneto $subneto $days $unitsServ $pax;
  8325.                             $data_supplier['service'][$i] = array(
  8326.                                 'id' => $item->getId(),
  8327.                                 'serviceCatId' => $item->getServiceCatId(),
  8328.                                 'serviceName' => $item->getName(),
  8329.                                 'serviceType' => 'Limpieza',
  8330.                                 'date' => $dateServ,
  8331.                                 'qty' => $unitsServ,
  8332.                                 'iva' => $item->getIva(),
  8333.                                 'pax' => $item->getPax(),
  8334.                                 'precioUnit' => $subnetoUnit,
  8335.                                 'subneto' => $subneto,
  8336.                                 'subtotal' => $subtotal,
  8337.                             );
  8338.                             break;
  8339.                         default: //Others (por default)
  8340.                             $pax $item->getPax();
  8341.                             if (empty($pax) or $pax == "0") { $pax 1; }
  8342.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8343.                             $dateServ = ($days 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
  8344.                             $unitsServ $item->getUnits();
  8345.                             if (empty($unitsServ) or $unitsServ == "0") { $unitsServ 1; }
  8346.                             $subtotal $subtotalService $days $unitsServ $pax;
  8347.                             $subnetoUnit $subneto;
  8348.                             $subneto $subneto $days $unitsServ $pax;
  8349.                             $data_supplier['service'][$i] = array(
  8350.                                 'id' => $item->getId(),
  8351.                                 'serviceCatId' => $item->getServiceCatId(),
  8352.                                 'serviceName' => $item->getName(),
  8353.                                 'serviceType' => 'Otros',
  8354.                                 'date' => $dateServ,
  8355.                                 'qty' => $unitsServ,
  8356.                                 'iva' => $item->getIva(),
  8357.                                 'pax' => $item->getPax(),
  8358.                                 'precioUnit' => $subnetoUnit,
  8359.                                 'subneto' => $subneto,
  8360.                                 'subtotal' => $subtotal,
  8361.                             );
  8362.                             break;
  8363.                     }
  8364.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  8365.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  8366.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  8367.                     $arrayItems[] = array(
  8368.                         'type' => 'Service',
  8369.                         'name' => $item->getName(),
  8370.                         'amount' => $neto,
  8371.                         'iva' => $item->getIva(),
  8372.                         'total' => $subtotal,
  8373.                     );
  8374.                 }
  8375.                 switch ($item->getIva()) {
  8376.                     // Acumula IVA
  8377.                     case 21$data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100)); break;
  8378.                     case 10$data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100)); break;
  8379.                     case 0: break;
  8380.                     default: break;
  8381.                 }
  8382.             }
  8383.             $totales_neto_all $totales_neto_all $neto;
  8384.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  8385.             $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  8386.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  8387.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'],2,PHP_ROUND_HALF_UP);
  8388.             // Acumula netos totales e IVA
  8389.             $service['neto'] = $service['neto'] + $neto;
  8390.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  8391.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  8392.             $service['neto'] = round($service['neto'],2,PHP_ROUND_HALF_UP);
  8393.             $service['sumSubT'] = round($service['sumSubT'],2,PHP_ROUND_HALF_UP);
  8394.             $i++;
  8395.         }
  8396.         $data_supplier['serviceSubTotal'] = array(
  8397.             'neto' => $service['neto'],
  8398.             'sumSubT' => $service['sumSubT'],
  8399.         );
  8400.         $currency '€';
  8401.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  8402.         if (!empty($payments)) {
  8403.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  8404.         } else {
  8405.             $amount_pay 0;
  8406.         }
  8407.         $totales_all $totales_total $amount_pay;
  8408.         if (empty($dateDocument)){
  8409.             $dateDocument = new DateTime('now');
  8410.         }
  8411.         $data = array(
  8412.             'id' => $reservationId,
  8413.             'type' => $type,
  8414.             'number' => $number,
  8415.             'prefix' => 'GP-'.(new DateTime('now'))->format('dmy').'-',
  8416.             'date' => $dateDocument,
  8417.             'reservation' => $reservation,
  8418.             'token' => $reservation->getAccessKey(),
  8419.             'company' => $company,
  8420.             'clients' => $client,
  8421.             'arrayItems' => $arrayItems,
  8422.             'datasupplier' => $data_supplier,
  8423.             'currency' => $currency,
  8424.             'totales_neto' => $totales_neto_all,
  8425.             'bases_imponibles' => $data_iva,
  8426.             'totales' => $totales_total,
  8427.             'balance' => $totales_all,
  8428.             'paymentInvoice' => $amount_pay,
  8429.         );
  8430.         return $data;
  8431.     }
  8432.     /**
  8433.      * @Route("/reservations/newinvoicedeposit/proforma/{id}",  name="reservation_new_invoice_deposit_proforma")
  8434.      */
  8435.     public function detailsNewProformaInvoiceDepositAction($idRequest $request){
  8436.         // Generamos Proforma de deposito
  8437.        $proformaDeposit $request->request->get('invoicedep');
  8438.        if (empty($proformaDeposit['name']) or empty($proformaDeposit['amount']) or empty($proformaDeposit['iva'])){
  8439.            // Se necesitan todos los datos
  8440.            return $this->redirectToRoute('reservations_payment',
  8441.                array(
  8442.                    'id' => $id
  8443.                )
  8444.            );
  8445.        }
  8446.         $em $this->getDoctrine()->getManager();
  8447.         /* Obtengo usuario logueado */
  8448.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  8449.         $user_id $user_logueado->getId();
  8450.         // Obtenemos el Id a asignar a la proforma de deposito y se guarda en Number
  8451.         $allInvoicedeposititems $em->getRepository(ReservationProformaDeposit::class)->findAll();
  8452.         if (!empty($allInvoicedeposititems)){
  8453.             $number end($allInvoicedeposititems)->getId() + 1;
  8454.         } else {
  8455.             $number 1;
  8456.         }
  8457.         $total floatval(str_replace',''.'$proformaDeposit['amount'])) + ((floatval(str_replace',''.'$proformaDeposit['amount'])) * $proformaDeposit['iva'])/100);
  8458.         $total round($total2);
  8459.         $newProformaDeposit = new ReservationProformaDeposit();
  8460.         $newProformaDeposit->setDateAt(new DateTime('now'));
  8461.         $newProformaDeposit->setReservationId($id);
  8462.         $newProformaDeposit->setName($proformaDeposit['name']);
  8463.         $newProformaDeposit->setAmount(str_replace',''.'$proformaDeposit['amount']));
  8464.         $newProformaDeposit->setIva($proformaDeposit['iva']);
  8465.         $newProformaDeposit->setNumber($number);
  8466.         $newProformaDeposit->setTotal($total);
  8467.         $newProformaDeposit->setPrefix('IFD-');
  8468.         $newProformaDeposit->setCreatedId($user_id);
  8469.         $newProformaDeposit->setUpdatedId($user_id);
  8470.         $newProformaDeposit->setCreatedAt(new DateTime('now'));
  8471.         $newProformaDeposit->setUpdatedAt(new DateTime('now'));
  8472.         $em->persist($newProformaDeposit);
  8473.         $em->flush();
  8474.         $invoicedeposititems $em->getRepository(ReservationProformaDeposit::class)->findBy(
  8475.             array(
  8476.                 'reservationId' => $id,
  8477.                 'number' => $number,
  8478.             )
  8479.         );
  8480.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  8481.         // Buscamos el cliente
  8482.         $reservation $em->getRepository(Reservation::class)->findOneById($id);
  8483.         $client $em->getRepository(Client::class)->findById($reservation->getClient());
  8484.         if (!empty($client)){
  8485.             $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  8486.             $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  8487.             $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  8488.             $client['city'] = $city$client['region'] = $region$client['country'] = $country;
  8489.         } else {
  8490.             $client[0] = new Client();
  8491.             $client[0]->setName('');
  8492.             $client[0]->setTitle('');
  8493.             $client[0]->setIdDocument('');
  8494.             $client[0]->setPopulation('');
  8495.             $client[0]->setRegion('');
  8496.             $client[0]->setCountry('');
  8497.         }
  8498.         // Buscamos el cliente
  8499.         $allInvoiceDeposit $em->getRepository(ReservationProformaDeposit::class)->findBy(
  8500.             array(
  8501.                 'reservationId' => $id,
  8502.             )
  8503.         );
  8504.         $totales_iva = (str_replace',''.'$proformaDeposit['amount']) * $proformaDeposit['iva'])/100;
  8505.         $totales str_replace',''.'$proformaDeposit['amount']) + $totales_iva;
  8506.         $boolToRec false;
  8507.         return $this->redirectToRoute('reservation_view_new_invoice_deposit_proforma',array('id' => $newProformaDeposit->getId()));
  8508.     }
  8509.     /**
  8510.      * @Route("/reservations/newinvoicedeposit/viewproforma/{id}",  name="reservation_view_new_invoice_deposit_proforma")
  8511.      */
  8512.     public function detailsViewNewProformaInvoiceDepositAction($idRequest $request){
  8513.         // Visualizar Proforma de Deposito
  8514.         $em $this->getDoctrine()->getManager();
  8515.         /* Obtengo usuario logueado */
  8516.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  8517.         $user_id $user_logueado->getId();
  8518.         $newProformaDeposit $em->getRepository(ReservationProformaDeposit::class)->findOneById($id);
  8519.         $total $newProformaDeposit->getAmount() + (($newProformaDeposit->getAmount() * $newProformaDeposit->getIva())/100);
  8520.         $invoicedeposititems $em->getRepository(ReservationProformaDeposit::class)->findBy(
  8521.             array(
  8522.                 'reservationId' => $newProformaDeposit->getReservationId(),
  8523.                 'number' => $id,
  8524.             )
  8525.         );
  8526.         $invoiceDeposit $em->getRepository(ReservationProformaDeposit::class)->findOneById($id);
  8527.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  8528.         // Buscamos el cliente
  8529.         $reservation $em->getRepository(Reservation::class)->findOneById($invoiceDeposit->getReservationId());
  8530.         $client $em->getRepository(Client::class)->findById($reservation->getClient());
  8531.         if (!empty($client)){
  8532.             $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  8533.             $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  8534.             $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  8535.             $client['city'] = $city$client['region'] = $region$client['country'] = $country;
  8536.         } else {
  8537.             $client[0] = new Client();
  8538.             $client[0]->setName('');
  8539.             $client[0]->setTitle('');
  8540.             $client[0]->setIdDocument('');
  8541.             $client[0]->setPopulation('');
  8542.             $client[0]->setRegion('');
  8543.             $client[0]->setCountry('');
  8544.         }
  8545.         // Buscamos el cliente
  8546.         $allInvoiceDeposit $em->getRepository(ReservationProformaDeposit::class)->findBy(
  8547.             array(
  8548.                 'reservationId' => $invoiceDeposit->getReservationId(),
  8549.             )
  8550.         );
  8551.         $totales_iva = ($newProformaDeposit->getAmount() * $newProformaDeposit->getIva())/100;
  8552.         $totales $newProformaDeposit->getAmount() + $totales_iva;
  8553.         $boolToRec false// Una proforma no se va a rectificar
  8554.         $reservaEquis $em->getRepository(Reservation::class)->findOneById($invoiceDeposit->getReservationId());
  8555. //                if(empty($newInvoice->getClientName()) and empty($newInvoice->getClientAddress()) and empty($newInvoice->getClientDocument())){
  8556.         if(true){ $newInvoice $this->clientDataToInvoice(null'Client'$reservaEquis->getClient(), $reservaEquis->getId()); }
  8557.         return $this->render('MDS/GreenPatioBundle/reservations/invoice-deposit-invoice.html.twig',
  8558.             array(
  8559.                 'id' => $invoiceDeposit->getReservationId(),
  8560.                 'cid' => '',
  8561.                 'fid' => $newProformaDeposit->getId(),
  8562.                 'invoice' => '',
  8563.                 'numberadmin' => $newProformaDeposit->getId(),
  8564.                 'type' => 'Proforma Deposit',
  8565.                 'number' => $newProformaDeposit->getId(),
  8566.                 'prefix' => '',
  8567.                 'date' => '',
  8568.                 'token' =>  '',
  8569.                 'company' => $company,
  8570.                 'clients' => $client,
  8571.                 'user' => $user_logueado,
  8572.                 'boolToRec' => $boolToRec,
  8573.                 'invoicedeposititems' => $invoicedeposititems,
  8574.                 'allProformaDeposit' => $allInvoiceDeposit,
  8575.                 'totales_neto' => $newProformaDeposit->getAmount(),
  8576.                 'totales_iva' => $totales_iva,
  8577.                 'totales' => $totales,
  8578.                 'bases_imponibles' => $newProformaDeposit->getIva(),
  8579.                 'currency' => '€',
  8580.                 'clientName' => $newInvoice->getClientName(),
  8581.                 'clientAddress' => $newInvoice->getClientAddress(),
  8582.                 'clientDocument' => $newInvoice->getClientDocument(),
  8583. //                'mcp' => $proposal->getMcp(),
  8584.             )
  8585.         );
  8586.     }
  8587.     /**
  8588.      * @Route("/reservations/newinvoicedeposit/invoice/{id}",  name="reservation_new_invoice_deposit_invoice")
  8589.      */
  8590.     public function detailsNewInvoiceDepositAction($idRequest $request){
  8591.         // Generamos la nueva factura de deposito
  8592.         $em $this->getDoctrine()->getManager();
  8593.         $proformaDeposit $em->getRepository(ReservationProformaDeposit::class)->findOneById($id);
  8594.         $vat = ($proformaDeposit->getAmount() * $proformaDeposit->getIva())/100;
  8595.         $vat round($vat,2);
  8596.         $totalInvoiceDep $proformaDeposit->getAmount() + $vat;
  8597.         $totalInvoiceDep round($totalInvoiceDep2);
  8598.         $balanceInvoiceDep $totalInvoiceDep * (-1);  // una factura de deposito es ingreso a caja por eso multiplicamos por -1
  8599.         if (empty($proformaDeposit->getName()) or empty($proformaDeposit->getAmount()) or empty($proformaDeposit->getIva())){
  8600.             // Se necesitan todos los datos
  8601.             return $this->redirectToRoute('reservations_payment',
  8602.                 array(
  8603.                     'id' => $proformaDeposit->getReservationId()
  8604.                 )
  8605.             );
  8606.         }
  8607.         // INICIO: Verificamos la linea de facturacion
  8608.         $parameters = array( 'id' => $proformaDeposit->getReservationId(), );
  8609.         $dql 'SELECT p
  8610.                 FROM GreenPatioBundle:ReservationLoungeSimple p
  8611.                 WHERE p.idReservation = :id AND p.idLounge > 21';
  8612.         $query $em->createQuery($dql)->setParameters($parameters);
  8613.         $loungesSimples $query->getResult();
  8614.         if (!empty($loungesSimples)){
  8615.             // Redirigir a Covarrubias
  8616.             return $this->redirectToRoute('reservation_new_invoice_deposit_invoice_cvr', array( 'id' => $id, ) );
  8617.         }
  8618.         // FIN: Verificamos la linea de facturacion
  8619.         /* Obtengo usuario logueado */
  8620.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  8621.         $user_id $user_logueado->getId();
  8622.         // INICIO: Generamos la factura
  8623.         $invoice = new ReservationInvoice();
  8624.         $invoice->setNumber('GPF-'.date('d').date('m').substr(date('Y'),-2).'-'.$proformaDeposit->getReservationId());
  8625.         $invoice->setPrefix(null);
  8626.         $invoice->setDateAt(new DateTime('now'));
  8627.         $invoice->setType('Invoice Deposit');
  8628.         $invoice->setReservationId($proformaDeposit->getReservationId());;
  8629.         $invoice->setTotalNet($proformaDeposit->getAmount());
  8630.         $invoice->setVat($vat);
  8631.         $invoice->setTotal($totalInvoiceDep);
  8632.         $invoice->setBalance($balanceInvoiceDep);
  8633.         $invoice->setMaster('master');
  8634.         $invoice->setCreatedAt(new DateTime('now'));
  8635.         $invoice->setUpdatedAt(new DateTime('now'));
  8636.         $invoice->setCreatedId($user_id);
  8637.         $invoice->setUpdatedId($user_id);
  8638.         $reservaEquis $em->getRepository(Reservation::class)->findOneById($proformaDeposit->getReservationId());
  8639.         if(true){ $invoice $this->clientDataToInvoice($invoice'Client'$reservaEquis->getClient(), $reservaEquis->getId()); }
  8640.         $em->persist($invoice);
  8641.         $em->flush();
  8642.         // FIN: Generamos la factura
  8643.         // INICIO: Generamos el invoice deposit Control
  8644.         $control = new ReservationInvoiceDepositControl();
  8645.         $control->setPrefix('IFD-');
  8646.         $control->setNumber($invoice->getId());
  8647.         $control->setDateAt(new DateTime('now'));
  8648.         $control->setReservationId($proformaDeposit->getReservationId());
  8649.         $control->setCreatedAt(new DateTime('now'));
  8650.         $control->setUpdatedAt(new DateTime('now'));
  8651.         $control->setCreatedId($user_id);
  8652.         $control->setUpdatedId($user_id);
  8653.         $em->persist($control);
  8654.         $em->flush();
  8655.         // FIN: Generamos el invoice deposit Control
  8656.         // INICIO: Generamos el invoice deposit item
  8657.         $invDepositItem = new ReservationInvoiceDepositItems();
  8658.         $invDepositItem->setControlId($control->getId());
  8659.         $invDepositItem->setName($proformaDeposit->getName());
  8660.         $invDepositItem->setAmount($proformaDeposit->getAmount());
  8661.         $invDepositItem->setIva($proformaDeposit->getIva());
  8662.         $invDepositItem->setReservationId($proformaDeposit->getReservationId());
  8663.         $invDepositItem->setCreatedAt(new DateTime('now'));
  8664.         $invDepositItem->setUpdatedAt(new DateTime('now'));
  8665.         $invDepositItem->setCreatedId($user_id);
  8666.         $invDepositItem->setUpdatedId($user_id);
  8667.         $em->persist($invDepositItem);
  8668.         $em->flush();
  8669.         // FIN: Generamos el invoice deposit item
  8670.         // INICIO: Generamos el pago asociado
  8671.         // Por solicitud de Esteban Rincon se genera de forma automatica un pago para representar en la factura final el descuento por concepto de factura de deposito
  8672.         $payment = new ReservationPaymentsClient();
  8673.         $payment->setDatePayAt(new DateTime('now'));
  8674.         $payment->setAmount($proformaDeposit->getAmount());
  8675.         $payment->setVat($proformaDeposit->getIva());
  8676.         $payment->setAmountTotal($proformaDeposit->getAmount() + ($proformaDeposit->getAmount() * $proformaDeposit->getIva())/100);
  8677.         $payment->setWayToPay('FACTURA DE DEPOSITO');
  8678.         $payment->setReservationId($proformaDeposit->getReservationId());;
  8679.         $payment->setInvoiceId($invoice->getId());
  8680.         $payment->setCreatedAt(new DateTime('now'));
  8681.         $payment->setUpdatedAt(new DateTime('now'));
  8682.         $payment->setCreatedId($user_id);
  8683.         $payment->setUpdatedId($user_id);
  8684.         $em->persist($payment);
  8685.         $em->flush();
  8686.         $payment->setWayToPay($payment->getWayToPay().' - '.$invoice->getId());
  8687.         $em->persist($payment);
  8688.         $em->flush();
  8689.         // INICIO: Generamos el pago asociado
  8690.         $total $totalInvoiceDep;
  8691.         $invoicedeposititems = array();
  8692.         $invoicedeposititems[] = $invDepositItem;
  8693.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  8694.         // Buscamos el cliente
  8695.         $reservation $em->getRepository(Reservation::class)->findOneById($proformaDeposit->getReservationId());
  8696.         $client $em->getRepository(Client::class)->findById($reservation->getClient());
  8697.         if (!empty($client)){
  8698.             $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  8699.             $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  8700.             $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  8701.             $client['city'] = $city$client['region'] = $region$client['country'] = $country;
  8702.         } else {
  8703.             $client[0] = new Client();
  8704.             $client[0]->setName('');
  8705.             $client[0]->setTitle('');
  8706.             $client[0]->setIdDocument('');
  8707.             $client[0]->setPopulation('');
  8708.             $client[0]->setRegion('');
  8709.             $client[0]->setCountry('');
  8710.         }
  8711.         // Buscamos el cliente
  8712.         $allInvoiceDeposit $em->getRepository(ReservationInvoice::class)->findBy(
  8713.             array(
  8714.                 'reservationId' => $invoice->getReservationId(),
  8715.             )
  8716.         );
  8717.         $totales_iva $vat;
  8718.         $totales $invoice->getTotalNet() + $totales_iva;
  8719.         // Una factura solo se puede rectificar una vez
  8720.         $rectf $em->getRepository(ReservationInvoiceRec::class)->findBy( array('invoiceToRec' => $invoice->getId()));
  8721.         $boolToRec = empty($rectf);
  8722.         return $this->redirectToRoute('reservation_view_new_invoice_deposit',array('id' => $invoice->getId()));
  8723.     }
  8724.     /**
  8725.      * @Route("/reservations/newinvoicedeposit/viewinvoicedeposit/{id}",  name="reservation_view_new_invoice_deposit")
  8726.      */
  8727.     public function detailsViewNewInvoiceDepositAction($idRequest $request){
  8728.         // Visualizar Factura de Deposito
  8729.         $em $this->getDoctrine()->getManager();
  8730.         $dateDocument null;                                           // Fecha del documento
  8731.         /* Obtengo usuario logueado */
  8732.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  8733.         $user_id $user_logueado->getId();
  8734.         $newProformaDeposit $em->getRepository(ReservationInvoice::class)->findOneById($id);
  8735.         if(!empty($newProformaDeposit)){ $dateDocument $newProformaDeposit->getDateAt(); }
  8736.         $total $newProformaDeposit->getTotal();
  8737.         $controlInvDep $em->getRepository(ReservationInvoiceDepositControl::class)->findOneByNumber($id);
  8738.         $invoicedeposititems $em->getRepository(ReservationInvoiceDepositItems::class)->findBy(
  8739.             array(
  8740.                 'reservationId' => $newProformaDeposit->getReservationId(),
  8741.                 'controlId' => $controlInvDep->getId(),
  8742.             )
  8743.         );
  8744.         if (!empty($invoicedeposititems)){$bases_imponibles $invoicedeposititems[0]->getIva();} else {$bases_imponibles '';}
  8745.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  8746.         // Buscamos el cliente
  8747.         $reservation $em->getRepository(Reservation::class)->findOneById($newProformaDeposit->getReservationId());
  8748.         $client $em->getRepository(Client::class)->findById($reservation->getClient());
  8749.         if (!empty($client)){
  8750.             $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  8751.             $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  8752.             $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  8753.             $client['city'] = $city$client['region'] = $region$client['country'] = $country;
  8754.         } else {
  8755.             $client[0] = new Client();
  8756.             $client[0]->setName('');
  8757.             $client[0]->setTitle('');
  8758.             $client[0]->setIdDocument('');
  8759.             $client[0]->setPopulation('');
  8760.             $client[0]->setRegion('');
  8761.             $client[0]->setCountry('');
  8762.         }
  8763.         // Buscamos el cliente
  8764.         $allInvoiceDeposit $em->getRepository(ReservationInvoice::class)->findBy(
  8765.             array(
  8766.                 'reservationId' => $newProformaDeposit->getReservationId(),
  8767.             )
  8768.         );
  8769.         $totales_iva $newProformaDeposit->getVat();
  8770.         $totales $newProformaDeposit->getTotal();
  8771.         // Una factura solo se puede rectificar una vez
  8772.         $rectf $em->getRepository(ReservationInvoiceRec::class)->findBy( array('invoiceToRec' => $newProformaDeposit->getId()));
  8773.         $boolToRec = empty($rectf);
  8774.         $reservaEquis $em->getRepository(Reservation::class)->findOneById($newProformaDeposit->getReservationId());
  8775.         if(empty($newProformaDeposit->getClientName()) and empty($newProformaDeposit->getClientAddress()) and empty($newProformaDeposit->getClientDocument())){
  8776.             $newProformaDeposit $this->clientDataToInvoice($newProformaDeposit'Client'$reservaEquis->getClient(), $newProformaDeposit->getReservationId());
  8777.         }
  8778.         return $this->render('MDS/GreenPatioBundle/reservations/invoice-deposit-invoice.html.twig',
  8779.             array(
  8780.                 'id' => $newProformaDeposit->getReservationId(),
  8781.                 'cid' => '',
  8782.                 'fid' => $newProformaDeposit->getId(),
  8783.                 'invoice' => '',
  8784.                 'numberadmin' => $newProformaDeposit->getId(),
  8785.                 'type' => 'Invoice Deposit',
  8786.                 'number' => $newProformaDeposit->getId(),
  8787.                 'prefix' => '',
  8788.                 'date' => $dateDocument,
  8789.                 'token' =>  '',
  8790.                 'company' => $company,
  8791.                 'clients' => $client,
  8792.                 'user' => $user_logueado,
  8793.                 'boolToRec' => $boolToRec,
  8794.                 'invoicedeposititems' => $invoicedeposititems,
  8795.                 'allProformaDeposit' => $allInvoiceDeposit,
  8796.                 'totales_neto' => $newProformaDeposit->getTotalNet(),
  8797.                 'totales_iva' => $totales_iva,
  8798.                 'totales' => $totales,
  8799.                 'bases_imponibles' => $bases_imponibles,
  8800.                 'currency' => '€',
  8801.                 'clientName' => $newProformaDeposit->getClientName(),
  8802.                 'clientAddress' => $newProformaDeposit->getClientAddress(),
  8803.                 'clientDocument' => $newProformaDeposit->getClientDocument(),
  8804.             )
  8805.         );
  8806.     }
  8807.     /**
  8808.      * @Route("/reservations/newinvoicedeposit/invoicerec/{id}",  name="reservation_new_invoice_deposit_invoicerec")
  8809.      */
  8810.     public function detailsNewInvoiceDepositRecAction($idRequest $request){
  8811.         // Generamos la factura de deposito rectificativa
  8812.         $em $this->getDoctrine()->getManager();
  8813.         if (true){
  8814.             // Verificamos que no exista una factura rectificativa previa sobre la misma factura
  8815.             $previusInvoiceRec $em->getRepository(ReservationInvoiceRec::class)->findOneByInvoiceToRec($id);
  8816.             if (!empty($previusInvoiceRec)){ return $this->redirectToRoute('reservation_view_new_invoice_deposit_rec', array('id' => $previusInvoiceRec->getId())); }
  8817.         }
  8818.         $proformaDeposit $em->getRepository(ReservationInvoice::class)->findOneById($id);
  8819.         $vat $proformaDeposit->getVat() * (-1);                   // En una rectificativa Esteban ha pedido todos los valores en negativo
  8820.         $totalInvoiceDep $proformaDeposit->getTotal() * (-1);
  8821.         $balanceInvoiceDep $proformaDeposit->getBalance() * (-1);  //una factura de deposito rectificativa  es egreso a caja por eso multiplicamos por -1 lo que teniamos como ingreso
  8822.         // Buscamos el Id del deposit item a partir de la factura
  8823.         $resDepControl $em->getRepository(ReservationInvoiceDepositControl::class)->findOneByNumber($id);
  8824.         $resInvDepItem $em->getRepository(ReservationInvoiceDepositItems::class)->findOneByControlId($resDepControl->getId());
  8825.         $equisInv $em->getRepository(ReservationInvoice::class)->findOneById($id);
  8826.         /* Obtengo usuario logueado */
  8827.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  8828.         $user_id $user_logueado->getId();
  8829.         // INICIO: Generamos la factura de deposito rectificativa
  8830.         $invoice = new ReservationInvoiceRec();
  8831.         $invoice->setNumber('REC-GPFD-'.date('d').date('m').substr(date('Y'),-2).'-'.$proformaDeposit->getReservationId());
  8832.         $invoice->setPrefix(null);
  8833.         $invoice->setDateAt(new DateTime('now'));
  8834.         $invoice->setType('Invoice Deposit Rec');
  8835.         $invoice->setInvoiceToRec($id);
  8836.         $invoice->setReservationId($proformaDeposit->getReservationId());;
  8837.         $invoice->setTotalNet($proformaDeposit->getTotalNet()*(-1));
  8838.         $invoice->setVat($vat);
  8839.         $invoice->setTotal($totalInvoiceDep);
  8840.         $invoice->setBalance($balanceInvoiceDep);
  8841.         $invoice->setMaster('master');
  8842.         $invoice->setCreatedAt(new DateTime('now'));
  8843.         $invoice->setUpdatedAt(new DateTime('now'));
  8844.         $invoice->setCreatedId($user_id);
  8845.         $invoice->setUpdatedId($user_id);
  8846.         $invoice->setClientName($equisInv->getClientName());
  8847.         $invoice->setClientAddress($equisInv->getClientAddress());
  8848.         $invoice->setClientDocument($equisInv->getClientDocument());
  8849.         $invoice->setClientType($equisInv->getClientType());
  8850.         $em->persist($invoice);
  8851.         $em->flush();
  8852.         // FIN: Generamos la factura de deposito rectificativa
  8853.         // INICIO: Generamos el invoice rec item
  8854.         $invDepositItem = new ReservationInvoiceRecItems();
  8855.         $invDepositItem->setDepControlId($resInvDepItem->getId());
  8856.         $invDepositItem->setDepName($resInvDepItem->getName());
  8857.         $invDepositItem->setDepAmount($resInvDepItem->getAmount() * (-1));              // Esteban ha pedido todos los datos de la rectificativa en negativo
  8858.         $invDepositItem->setDepIva($resInvDepItem->getIva());
  8859.         $invDepositItem->setDepDateAt($resDepControl->getDateAt());
  8860.         $invDepositItem->setReservationId($proformaDeposit->getReservationId());
  8861.         $invDepositItem->setCreatedAt(new DateTime('now'));
  8862.         $invDepositItem->setUpdatedAt(new DateTime('now'));
  8863.         $invDepositItem->setCreatedId($user_id);
  8864.         $invDepositItem->setUpdatedId($user_id);
  8865.         $invDepositItem->setInvoiceId($id);
  8866.         $invDepositItem->setItemType('DEPOSIT');
  8867.         $invDepositItem->setInvoiceRecId($invoice->getId());
  8868.         $em->persist($invDepositItem);
  8869.         $em->flush();
  8870.         // FIN: Generamos el invoice deposit item
  8871.         // INICIO: Buscamos Pagos asociados a la factura de deposito (se crean de forma automatica, se van a eliminar de forma automatica)
  8872.         $payToDelete $em->getRepository(ReservationPaymentsClient::class)->findOneByInvoiceId($id);
  8873.         if (!empty($payToDelete)){
  8874.             $em->remove($payToDelete);
  8875.             $em->flush();
  8876.         }
  8877.         // FIN: Buscamos Pagos asociados a la factura de deposito (se crean de forma automatica, se van a eliminar de forma automatica)
  8878.         $total $totalInvoiceDep;
  8879.         $invoicedeposititems = array();
  8880.         $invoicedeposititems[] = $invDepositItem;
  8881.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  8882.         // Buscamos el cliente
  8883.         $reservation $em->getRepository(Reservation::class)->findOneById($proformaDeposit->getReservationId());
  8884.         $client $em->getRepository(Client::class)->findById($reservation->getClient());
  8885.         if (!empty($client)){
  8886.             $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  8887.             $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  8888.             $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  8889.             $client['city'] = $city$client['region'] = $region$client['country'] = $country;
  8890.         } else {
  8891.             $client[0] = new Client();
  8892.             $client[0]->setName('');
  8893.             $client[0]->setTitle('');
  8894.             $client[0]->setIdDocument('');
  8895.             $client[0]->setPopulation('');
  8896.             $client[0]->setRegion('');
  8897.             $client[0]->setCountry('');
  8898.         }
  8899.         // Buscamos el cliente
  8900.         $allInvoiceDeposit $em->getRepository(ReservationProformaDeposit::class)->findBy(
  8901.             array(
  8902.                 'reservationId' => $id,
  8903.             )
  8904.         );
  8905.         $totales_iva $vat;
  8906. //        $totales = ($invoice->getTotalNet() * (-1)) + $totales_iva;
  8907.         $totales $invoice->getTotalNet() + $totales_iva;
  8908.         // Una factura solo se puede rectificar una vez
  8909. //        $rectf = $em->getRepository(ReservationInvoiceRec::class)->findBy( array('invoiceToRec' => $invoice->getId()));
  8910.         $boolToRec false;
  8911.         $invoicedeposititemsTemp = array(
  8912.             'name' => $invoicedeposititems[0]->getDepName(),
  8913.             'amount' => $invoicedeposititems[0]->getDepAmount(),
  8914.             'iva' => $invoicedeposititems[0]->getDepIva(),
  8915.         );
  8916.         $invoicedeposititems = array();
  8917.         $invoicedeposititems[] = $invoicedeposititemsTemp;
  8918.         return $this->redirectToRoute('reservation_view_new_invoice_deposit_rec',array('id' => $invoice->getId()));
  8919.     }
  8920.     /**
  8921.      * @Route("/reservations/newinvoicedeposit/viewinvoicedepositrec/{id}",  name="reservation_view_new_invoice_deposit_rec")
  8922.      */
  8923.     public function detailsViewNewInvoiceDepositRecAction($idRequest $request){
  8924.         // Visualizar Factura de Deposito Rectificativa
  8925.         $em $this->getDoctrine()->getManager();
  8926.         /* Obtengo usuario logueado */
  8927.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  8928.         $user_id $user_logueado->getId();
  8929.         $newProformaDeposit $em->getRepository(ReservationInvoiceRec::class)->findOneById($id);
  8930.         $total $newProformaDeposit->getTotal();
  8931.         $invoicedeposititems $em->getRepository(ReservationInvoiceRecItems::class)->findBy(
  8932.             array(
  8933.                 'reservationId' => $newProformaDeposit->getReservationId(),
  8934.                 'invoiceRecId' => $id,
  8935.             )
  8936.         );
  8937.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  8938.         // Buscamos el cliente
  8939.         $reservation $em->getRepository(Reservation::class)->findOneById($newProformaDeposit->getReservationId());
  8940.         $client $em->getRepository(Client::class)->findById($reservation->getClient());
  8941.         if (!empty($client)){
  8942.             $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  8943.             $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  8944.             $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  8945.             $client['city'] = $city$client['region'] = $region$client['country'] = $country;
  8946.         } else {
  8947.             $client[0] = new Client();
  8948.             $client[0]->setName('');
  8949.             $client[0]->setTitle('');
  8950.             $client[0]->setIdDocument('');
  8951.             $client[0]->setPopulation('');
  8952.             $client[0]->setRegion('');
  8953.             $client[0]->setCountry('');
  8954.         }
  8955.         // Buscamos el cliente
  8956.         $allInvoiceDeposit $em->getRepository(ReservationProformaDeposit::class)->findBy(
  8957.             array(
  8958.                 'reservationId' => $newProformaDeposit->getReservationId(),
  8959.             )
  8960.         );
  8961.         $totales_iva $newProformaDeposit->getVat();
  8962.         $totales $newProformaDeposit->getTotal();
  8963.         // Una factura solo se puede rectificar una vez
  8964. //        $rectf = $em->getRepository(ReservationInvoiceRec::class)->findBy( array('invoiceToRec' => $newProformaDeposit->getId()));
  8965.         $boolToRec false;
  8966.         $invoicedeposititemsTemp = array(
  8967.             'name' => $invoicedeposititems[0]->getDepName(),
  8968.             'amount' => $invoicedeposititems[0]->getDepAmount(),
  8969.             'iva' => $invoicedeposititems[0]->getDepIva(),
  8970.         );
  8971.         $invoicedeposititems = array();
  8972.         $invoicedeposititems[] = $invoicedeposititemsTemp;
  8973.         $reservaEquis $em->getRepository(Reservation::class)->findOneById($newProformaDeposit->getReservationId());
  8974.         if(empty($newProformaDeposit->getClientName()) and empty($newProformaDeposit->getClientAddress()) and empty($newProformaDeposit->getClientDocument())){
  8975.             $newProformaDeposit $this->clientDataToInvoice($newProformaDeposit'Client'$reservaEquis->getClient(), $newProformaDeposit->getReservationId());
  8976.         }
  8977.         return $this->render('MDS/GreenPatioBundle/reservations/invoice-deposit-invoice.html.twig',
  8978.             array(
  8979.                 'id' => $newProformaDeposit->getReservationId(),
  8980.                 'cid' => '',
  8981.                 'fid' => $newProformaDeposit->getId(),
  8982.                 'invoice' => '',
  8983.                 'numberadmin' => null,
  8984.                 'type' => 'Invoice Deposit Rec',
  8985.                 'number' => $id,
  8986.                 'prefix' => '',
  8987.                 'date' => $newProformaDeposit->getDateAt(),
  8988.                 'token' =>  '',
  8989.                 'company' => $company,
  8990.                 'clients' => $client,
  8991.                 'user' => $user_logueado,
  8992.                 'boolToRec' => $boolToRec,
  8993.                 'invoiceIdToRec' => $newProformaDeposit->getInvoiceToRec(),
  8994.                 'invoicedeposititems' => $invoicedeposititems,
  8995.                 'allProformaDeposit' => $allInvoiceDeposit,
  8996.                 'totales_neto' => $newProformaDeposit->getTotalNet(),
  8997.                 'totales_iva' => $totales_iva,
  8998.                 'totales' => $totales,
  8999.                 'balance' => (-1) * $newProformaDeposit->getBalance(),
  9000.                 'bases_imponibles' => '',
  9001.                 'currency' => '€',
  9002.                 'clientName' => $newProformaDeposit->getClientName(),
  9003.                 'clientAddress' => $newProformaDeposit->getClientAddress(),
  9004.                 'clientDocument' => $newProformaDeposit->getClientDocument(),
  9005.             )
  9006.         );
  9007.     }
  9008.     /**
  9009.      * @Route("/reservations/invoice/invoicedeposit-proforma/print/{type}/{id}",  name="reservations_invoicedepositproforma_print")
  9010.      */
  9011.     public function detailsInvoiceDepositProformaPrintAction($type$idRequest $request)
  9012.     {
  9013.         // Pantalla para imprimir Proformas, Facturas y Facturas Rectificativas de Deposito
  9014.         $data = array();
  9015.         $em $this->getDoctrine()->getManager();
  9016.         // Si el ID de factura viene vacio regresamos a ver facturas
  9017.         if (empty($type)){
  9018.             return $this->redirectToRoute('reservations_viewreservation_invoices',array('id' => $id));
  9019.         }
  9020.         //Acumuladores de datos globales de la factura o proforma
  9021.         $valorTotalNet 0;
  9022.         $valorVat 0;
  9023.         if ($type == 'I'){
  9024.             // El tipo es una factura de deposito
  9025.             $data['type'] = 'Invoice Deposit';
  9026.             $data['number'] = $id;
  9027.             $proDepositNet 0;
  9028.             $proDepositIva 0;
  9029.             $proDepositTotal 0;
  9030.             $ivaPorcentaje 0;
  9031.             $monto 0;
  9032.             $concepto ='';
  9033.             //INICIO: Buscamos los items de la factura
  9034.             $controlInvDep $em->getRepository(ReservationInvoiceDepositControl::class)->findOneByNumber($id);
  9035.             $arrayInvoicedItems $em->getRepository(ReservationInvoiceDepositItems::class)->findByControlId($controlInvDep->getId());
  9036.             if (!empty($arrayInvoicedItems)) {
  9037.                 foreach ($arrayInvoicedItems as $itemInvoice) {
  9038.                     if (is_numeric($itemInvoice->getAmount()) and is_numeric($itemInvoice->getIva())) {
  9039.                         $proDepositNet $itemInvoice->getAmount();
  9040.                         $proDepositIva = ($itemInvoice->getAmount()*$itemInvoice->getIva())/100;
  9041.                         $proDepositTotal $itemInvoice->getAmount() + $proDepositIva;
  9042.                         $ivaPorcentaje $itemInvoice->getIva();
  9043.                         $monto $itemInvoice->getAmount();
  9044.                         $concepto $itemInvoice->getName();
  9045.                         //Acumulamos neto e iva para la factura
  9046.                         $valorTotalNet $valorTotalNet $proDepositNet;
  9047.                         $valorVat $valorVat round($proDepositTotal,2,PHP_ROUND_HALF_UP);
  9048.                     }
  9049.                 }
  9050.             }
  9051.             $valorTotal $valorTotalNet $valorVat;
  9052.             //INICIO: Creamos la factura
  9053.             $newInvoice $em->getRepository(ReservationInvoice::class)->findOneById($id);
  9054.             //FIN: Creamos la factura
  9055.             $allInvoices $em->getRepository(ReservationInvoice::class)->findByReservationId($newInvoice->getReservationId());
  9056.             // Buscamos el cliente
  9057.             $reservation $em->getRepository(Reservation::class)->findOneById($newInvoice->getReservationId());
  9058.             $client $em->getRepository(Client::class)->findById($reservation->getClient());
  9059.             if (!empty($client)){
  9060.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  9061.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  9062.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  9063.                 $client['city'] = $city$client['region'] = $region$client['country'] = $country;
  9064.             } else {
  9065.                 $client[0] = new Client();
  9066.                 $client[0]->setName('');
  9067.                 $client[0]->setTitle('');
  9068.                 $client[0]->setIdDocument('');
  9069.                 $client[0]->setPopulation('');
  9070.                 $client[0]->setRegion('');
  9071.                 $client[0]->setCountry('');
  9072.             }
  9073.             // Buscamos el cliente
  9074.             $invoiceIdToRec null;
  9075.             $data['prefix'] = $newInvoice->getPrefix();
  9076.             $data['date'] = $newInvoice->getDateAt();
  9077.             $data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  9078.             $data['totales_neto'] = $proDepositNet;
  9079.             $data['totales'] = $proDepositTotal;
  9080.             $data['balance'] = $proDepositTotal;
  9081.             $data['currency'] = '€';
  9082.             $data['datasupplier'] = $newInvoice;
  9083.             $data['bases_imponibles'] = array(
  9084.                 'iva' => $ivaPorcentaje,
  9085.                 'ivaAmount' => ($monto $ivaPorcentaje)/100
  9086.             );
  9087.             $data['paymentInvoice'] = $newInvoice;
  9088.             $dataTemp = array(
  9089.                 'balance' => $data['datasupplier']->getBalance(),
  9090.                 'dateAt' => $data['datasupplier']->getDateAt(),
  9091.                 'id' => $data['datasupplier']->getId(),
  9092.                 'reservationId' => $data['datasupplier']->getReservationId(),
  9093.                 'total' => $data['datasupplier']->getTotal(),
  9094.                 'amount' => $data['datasupplier']->getTotalNet(),
  9095.                 'type' => $data['datasupplier']->getType(),
  9096.                 'vat' => $data['datasupplier']->getVat(),
  9097.                 'name' => $concepto
  9098.             );
  9099.             $data['datasupplier'] = $dataTemp;
  9100.             //Es una proforma
  9101.             $proforma $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
  9102.             $invoiceIdToRec null;
  9103.             $reservaEquis $em->getRepository(Reservation::class)->findOneById($newInvoice->getReservationId());
  9104.             if(empty($newInvoice->getClientName()) and empty($newInvoice->getClientAddress()) and empty($newInvoice->getClientDocument())){
  9105.                 $newInvoice $this->clientDataToInvoice($newInvoice'Client'$reservaEquis->getClient(), $newInvoice->getReservationId());
  9106.             }
  9107.         } else {
  9108.             if ($type == 'R'){
  9109.                 //El tipo es una factura rectificativa
  9110.                 //INICIO: Creamos los items de la factura rectficativa
  9111.                 $arrayInvoicedItems $em->getRepository(ReservationInvoiceRecItems::class)->findByInvoiceRecId($id);
  9112.                 $vatItem 0;
  9113.                 $concepto ='';
  9114.                 if (!empty($arrayInvoicedItems)) {
  9115.                     foreach ($arrayInvoicedItems as $itemInvoice) {
  9116.                         if ($itemInvoice->getItemType() == 'DEPOSIT') {
  9117.                             //Acumulamos neto e iva para la factura rectificativa
  9118.                             $valorTotalNet $valorTotalNet $itemInvoice->getDepAmount();
  9119.                             $valorVat $valorVat round((($itemInvoice->getDepAmount() * $itemInvoice->getDepIva())/100),2,PHP_ROUND_HALF_UP);
  9120.                             $vatItem $itemInvoice->getDepIva();
  9121.                             $concepto $itemInvoice->getDepName();
  9122.                         }
  9123.                     }
  9124.                 }
  9125.                 $valorTotal $valorTotalNet $valorVat;
  9126.                 //INICIO: Creamos la factura rectificativa
  9127.                 $newInvoice $em->getRepository(ReservationInvoiceRec::class)->findOneById($id);
  9128.                 //FIN: Creamos la factura rectificativa
  9129.                 $paymentsClient = new ReservationPaymentsClient();
  9130.                 $paymentsClient->setReservationId($id);
  9131.                 $reservaInv = new ReservationInvoice();
  9132.                 $reservaInv->setReservationId($id);
  9133.                 $idLounges = array();
  9134.                 $loungesBoolToInvoice = array();
  9135.                 $idPayments = array();
  9136.                 $paymentsBoolToInvoice = array();
  9137.                 $allInvoices $em->getRepository(ReservationInvoice::class)->findByReservationId($newInvoice->getReservationId());
  9138.                 //Es una proforma
  9139.                 $proforma $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
  9140.                 // Buscamos el cliente
  9141.                 $reservation $em->getRepository(Reservation::class)->findOneById($newInvoice->getReservationId());
  9142.                 $client $em->getRepository(Client::class)->findById($reservation->getClient());
  9143.                 if (!empty($client)){
  9144.                     $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  9145.                     $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  9146.                     $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  9147.                     $client['city'] = $city$client['region'] = $region$client['country'] = $country;
  9148.                 } else {
  9149.                     $client[0] = new Client();
  9150.                     $client[0]->setName('');
  9151.                     $client[0]->setTitle('');
  9152.                     $client[0]->setIdDocument('');
  9153.                     $client[0]->setPopulation('');
  9154.                     $client[0]->setRegion('');
  9155.                     $client[0]->setCountry('');
  9156.                 }
  9157.                 // Buscamos el cliente
  9158.                 $invoiceIdToRec $newInvoice->getInvoiceToRec();
  9159.                 $data['number'] = $id;
  9160.                 $data['balance'] = $newInvoice->getBalance();
  9161.                 $data['type'] = 'Invoice Deposit Rec';
  9162.                 $data['prefix'] = 'R';
  9163.                 $data['date'] = $newInvoice->getDateAt();
  9164.                 $data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  9165.                 $data['totales_neto'] = $newInvoice->getTotalNet();
  9166.                 $data['totales'] = $newInvoice->getTotal();
  9167.                 $data['balance'] = $newInvoice->getBalance();
  9168.                 $data['currency'] = '€';
  9169.                 $data['datasupplier'] = $newInvoice;
  9170.                 $data['bases_imponibles'] = array(
  9171.                     'iva' => $vatItem,
  9172.                     'ivaAmount' => $newInvoice->getVat()
  9173.                 );
  9174.                 $data['paymentInvoice'] = $newInvoice;
  9175.                 $dataTemp = array(
  9176.                     'balance' => $data['datasupplier']->getBalance(),
  9177.                     'dateAt' => $data['datasupplier']->getDateAt(),
  9178.                     'id' => $data['datasupplier']->getId(),
  9179.                     'reservationId' => $data['datasupplier']->getReservationId(),
  9180.                     'total' => $data['datasupplier']->getTotal(),
  9181.                     'amount' => $data['datasupplier']->getTotalNet(),
  9182.                     'type' => $data['datasupplier']->getType(),
  9183.                     'vat' => $data['datasupplier']->getVat(),
  9184.                     'name' => $concepto
  9185.                 );
  9186.                 $data['datasupplier'] = $dataTemp;
  9187.                 //Es una proforma
  9188.                 $proforma $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
  9189.                 $reservaEquis $em->getRepository(Reservation::class)->findOneById($newInvoice->getReservationId());
  9190.                 if(empty($newInvoice->getClientName()) and empty($newInvoice->getClientAddress()) and empty($newInvoice->getClientDocument())){
  9191.                     $newInvoice $this->clientDataToInvoice($newInvoice'Client'$reservaEquis->getClient(), $newInvoice->getReservationId());
  9192.                 }
  9193.             } else {
  9194.                 // El tipo es una proforma de deposito
  9195.                 $data['type'] = 'Proforma Deposit';
  9196.                 $data['number'] = $id;
  9197.                 $proDepositNet 0;
  9198.                 $proDepositIva 0;
  9199.                 $proDepositTotal 0;
  9200.                 //INICIO: Creamos los items de la proforma
  9201.                 $arrayInvoicedItems $em->getRepository(ReservationProformaDeposit::class)->findById($id);
  9202.                 if (!empty($arrayInvoicedItems)) {
  9203.                     foreach ($arrayInvoicedItems as $itemInvoice) {
  9204.                         if (is_numeric($itemInvoice->getAmount()) and is_numeric($itemInvoice->getIva())) {
  9205.                             $proDepositNet $itemInvoice->getAmount();
  9206.                             $proDepositIva = ($itemInvoice->getAmount()*$itemInvoice->getIva())/100;
  9207.                             $proDepositTotal $itemInvoice->getAmount() + (($itemInvoice->getAmount()*$itemInvoice->getIva())/100);
  9208.                             //Acumulamos neto e iva para la factura
  9209.                             $valorTotalNet $valorTotalNet $proDepositNet;
  9210.                             $valorVat $valorVat round($proDepositTotal,2,PHP_ROUND_HALF_UP);
  9211.                         }
  9212.                     }
  9213.                 }
  9214.                 $valorTotal $valorTotalNet $valorVat;
  9215.                 //INICIO: Creamos la factura
  9216.                 $newInvoice $em->getRepository(ReservationProformaDeposit::class)->findOneById($id);
  9217.                 //FIN: Creamos la factura
  9218.                 $allInvoices $em->getRepository(ReservationInvoice::class)->findByReservationId($newInvoice->getReservationId());
  9219.                 // Buscamos el cliente
  9220.                 $reservation $em->getRepository(Reservation::class)->findOneById($newInvoice->getReservationId());
  9221.                 $client $em->getRepository(Client::class)->findById($reservation->getClient());
  9222.                 if (!empty($client)){
  9223.                     $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  9224.                     $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  9225.                     $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  9226.                     $client['city'] = $city$client['region'] = $region$client['country'] = $country;
  9227.                 } else {
  9228.                     $client[0] = new Client();
  9229.                     $client[0]->setName('');
  9230.                     $client[0]->setTitle('');
  9231.                     $client[0]->setIdDocument('');
  9232.                     $client[0]->setPopulation('');
  9233.                     $client[0]->setRegion('');
  9234.                     $client[0]->setCountry('');
  9235.                 }
  9236.                 // Buscamos el cliente
  9237.                 $invoiceIdToRec null;
  9238.                 $data['prefix'] = $newInvoice->getPrefix();
  9239.                 $data['date'] = $newInvoice->getDateAt();
  9240.                 $data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  9241.                 $data['totales_neto'] = $proDepositNet;
  9242.                 $data['totales'] = $proDepositTotal;
  9243.                 $data['balance'] = $proDepositTotal;
  9244.                 $data['currency'] = '€';
  9245.                 $data['datasupplier'] = $newInvoice;
  9246.                 $data['bases_imponibles'] = array(
  9247.                     'iva' => $newInvoice->getIva(),
  9248.                     'ivaAmount' => ($newInvoice->getAmount() * $newInvoice->getIva())/100
  9249.                 );
  9250.                 $data['paymentInvoice'] = $newInvoice;
  9251.                 $reservaEquis $em->getRepository(Reservation::class)->findOneById($newInvoice->getReservationId());
  9252.                 if(true){ $newInvoice $this->clientDataToInvoice(null'Client'$reservaEquis->getClient(), $reservaEquis->getId()); }
  9253.             }
  9254.         }
  9255.         if (!empty($data['bases_imponibles']['iva'])){$bases_imponibles $data['bases_imponibles']['iva'];} else {$bases_imponibles '';}
  9256.         return $this->render('MDS/GreenPatioBundle/reservations/services-proforma-deposit-print-reservation.html.twig',
  9257.             array(
  9258.                 'id' => $id,
  9259.                 'type' => $data['type'],
  9260.                 'number' => $data['number'],
  9261.                 'invoiceIdToRec' => $invoiceIdToRec,
  9262.                 'prefix' => $data['prefix'],
  9263.                 'date' => $data['date'],
  9264.                 'token' => null,
  9265.                 'company' => $data['company'],
  9266.                 'clients' => $client,
  9267.                 'datasupplier' => $data['datasupplier'],
  9268.                 'totales_neto' => $data['totales_neto'],
  9269.                 'bases_imponibles' => $data['bases_imponibles'],
  9270.                 'totales' => $data['totales'],
  9271.                 'balance' => $data['balance'],
  9272.                 'currency' => $data['currency'],
  9273.                 'iva' => $bases_imponibles,
  9274.                 'paymentInvoice' => $data['paymentInvoice'],
  9275.                 'clientName' => $newInvoice->getClientName(),
  9276.                 'clientAddress' => $newInvoice->getClientAddress(),
  9277.                 'clientDocument' => $newInvoice->getClientDocument(),
  9278.             )
  9279.         );
  9280.     }
  9281.     /**
  9282.      * @Route("/instantUpdateInvoice", name="instant_update_invoice")
  9283.      */
  9284.     public function instantUpdateInvoiceAction(Request $request) {
  9285.         $codProfile $_POST['idprofile'];
  9286. //        $codProfile = "1";
  9287. //        $codProfile = $request->request->get('idProfile');
  9288. //        $codProfile = $idProfile;
  9289.         $em $this->getDoctrine()->getManager();
  9290.         $salasPorPerfil $em->getRepository(ReservationLoungeProfile::class)->findBy(
  9291.             array(
  9292.                 'periodId' => $codProfile
  9293.             )
  9294.         );
  9295.         $datos = array();
  9296.         if (!empty($salasPorPerfil)){
  9297.             foreach($salasPorPerfil as $sala){
  9298.                 $datos[] = array(
  9299.                     "id" => $sala->getId(),
  9300.                     "idlounge" => $sala->getLoungeId(),
  9301.                     "nameDescription" => $sala->getDescription(),
  9302.                     "price" => $sala->getPrice(),
  9303.                 );
  9304.             }
  9305.         }
  9306.         $return = array(
  9307.             'salasPerfil' => $datos,
  9308.             'id' => $codProfile,
  9309.         );
  9310.         $response = new JsonResponse($return);
  9311.         return $response;
  9312.     }
  9313.     /**
  9314.      * @Route("/invoicerec/{id}",  name="reservations_invoice_rec")
  9315.      */
  9316.     public function generateReservationInvoiceRecAction($idRequest $request)
  9317.     {
  9318.         $em $this->getDoctrine()->getManager();
  9319.         $invoice $em->getRepository(ReservationInvoice::class)->findOneById($id);
  9320.         if (true){
  9321.             // Verificamos que no exista una factura rectificativa previa sobre la misma factura
  9322.             $previusInvoiceRec $em->getRepository(ReservationInvoiceRec::class)->findOneByInvoiceToRec($id);
  9323.             if (!empty($previusInvoiceRec)){ return $this->redirectToRoute('reservations_viewrec_invoice', array('id' => $previusInvoiceRec->getId())); }
  9324.         }
  9325.         $now = new DateTime();
  9326.         /* Obtengo usuario logueado */
  9327.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  9328.         $user_id $user_logueado->getId();
  9329.         $invoiceRec = new ReservationInvoiceRec();
  9330.         $invoiceRec->setInvoiceToRec($id);
  9331.         $invoiceRec->setCreatedAt($now);
  9332.         $invoiceRec->setUpdatedAt($now);
  9333.         $invoiceRec->setCreatedId($user_id);
  9334.         $invoiceRec->setUpdatedId($user_id);
  9335.         $invoiceRec->setDateAt($now);
  9336.         $invoiceRec->setMaster($invoice->getMaster());
  9337.         $invoiceRec->setNumber('REC-'.$invoice->getNumber());
  9338.         $invoiceRec->setPrefix('R');
  9339.         $invoiceRec->setReservationId($invoice->getReservationId());
  9340.         $invoiceRec->setTotal($invoice->getTotal()*(-1));
  9341.         $invoiceRec->setTotalNet($invoice->getTotalNet()*(-1));
  9342.         $invoiceRec->setType('Invoice Rec');
  9343.         $invoiceRec->setVat($invoice->getVat()*(-1));
  9344.         $invoiceRec->setBalance($invoice->getBalance()*(-1));
  9345.         $invoiceRec->setClientName($invoice->getClientName());
  9346.         $invoiceRec->setClientAddress($invoice->getClientAddress());
  9347.         $invoiceRec->setClientDocument($invoice->getClientDocument());
  9348.         $invoiceRec->setClientType($invoice->getClientType());
  9349.         $em->persist($invoiceRec);
  9350.         $em->flush();
  9351.         $invoiceItems $em->getRepository(ReservationInvoiceItems::class)->findByInvoiceId($id);
  9352.         // Cada elemento se duplica en ItemsRec y se libera asignando ID = 0
  9353.         foreach ($invoiceItems as $item){
  9354.             $itemRec = new ReservationInvoiceRecItems();
  9355.             $itemRec->setReservationId($item->getReservationId());
  9356.             $itemRec->setInvoiceId($item->getInvoiceId());
  9357.             $itemRec->setItemType($item->getItemType());
  9358.             $itemRec->setInvoiceRecId($invoiceRec->getId());
  9359.             $itemRec->setLngControlId($item->getLngControlId());
  9360.             $itemRec->setLngLoungeName($item->getLngLoungeName());
  9361.             $itemRec->setLngIdLounge($item->getLngIdLounge());
  9362.             $itemRec->setLngIdLounge($item->getLngIdLounge());
  9363.             $itemRec->setLngDateStart($item->getLngDateStart());
  9364.             $itemRec->setLngDateEnd($item->getLngDateEnd());
  9365.             $itemRec->setLngServicePrice($item->getLngServicePrice()*(-1));
  9366.             $itemRec->setLngPax($item->getLngPax());
  9367.             $itemRec->setLngType($item->getLngType());
  9368.             $itemRec->setLngHourStart($item->getLngHourStart());
  9369.             $itemRec->setLngMinStart($item->getLngMinStart());
  9370.             $itemRec->setLngHourEnd($item->getLngHourEnd());
  9371.             $itemRec->setLngMinEnd($item->getLngMinEnd());
  9372.             $itemRec->setSrvControlId($item->getSrvControlId());
  9373.             $itemRec->setSrvSupplierId($item->getSrvSupplierId());
  9374.             $itemRec->setSrvServiceId($item->getSrvServiceId());
  9375.             $itemRec->setSrvServiceCatId($item->getSrvServiceCatId());
  9376.             $itemRec->setSrvServiceCatName($item->getSrvServiceCatName());
  9377.             $itemRec->setSrvPrice($item->getSrvPrice()*(-1));
  9378.             $itemRec->setSrvCurrency($item->getSrvCurrency());
  9379.             $itemRec->setSrvUnits($item->getSrvUnits());
  9380.             $itemRec->setSrvOpCommission($item->getSrvOpCommission());
  9381.             $itemRec->setSrvCommission($item->getSrvCommission());
  9382.             $itemRec->setSrvOpOver($item->getSrvOpOver());
  9383.             $itemRec->setSrvOver($item->getSrvOver()*(-1));
  9384.             $itemRec->setSrvOpIva($item->getSrvOpIva());
  9385.             $itemRec->setSrvIva($item->getSrvIva());
  9386.             $itemRec->setSrvPax($item->getSrvPax());
  9387.             $itemRec->setSrvHour($item->getSrvHour());
  9388.             $itemRec->setSrvDateInAt($item->getSrvDateInAt());
  9389.             $itemRec->setSrvDateOutAt($item->getSrvDateOutAt());
  9390.             $itemRec->setSrvContcolor($item->getSrvContcolor());
  9391.             $itemRec->setSrvRank($item->getSrvRank());
  9392.             $itemRec->setSrvAssistantId($item->getSrvAssistantId());
  9393.             $itemRec->setSrvActivityId($item->getSrvActivityId());
  9394.             $itemRec->setSrvPay($item->getSrvPay());
  9395.             $itemRec->setSrvName($item->getSrvName());
  9396.             $itemRec->setPayControlId($item->getPayControlId());
  9397. //            $itemRec->setPayAmount($item->getPayAmount()*(-1));
  9398.             $itemRec->setPayAmount($item->getPayAmount());          // Los pagos han pasado a ser las facturas de deposito, en la tabla su amount se encuentra en positivo, en la rectificativa, este valor lo necesitamos en positivo
  9399.             $itemRec->setPayDatePayAt($item->getPayDatePayAt());
  9400.             $itemRec->setPayWayToPay($item->getPayWayToPay());
  9401. //            $itemRec->setPayAmountTotal($item->getPayAmountTotal()*(-1));
  9402.             $itemRec->setPayAmountTotal($item->getPayAmountTotal());    // Los pagos han pasado a ser las facturas de deposito, en la tabla su amount se encuentra en positivo, en la rectificativa, este valor lo necesitamos en positivo
  9403.             $itemRec->setPayVat($item->getPayVat());
  9404.             $itemRec->setCreatedId($user_id);
  9405.             $itemRec->setCreatedAt(new DateTime('now'));
  9406.             $itemRec->setUpdatedId($user_id);
  9407.             $itemRec->setUpdatedAt(new DateTime('now'));
  9408.             $em->persist($itemRec);
  9409.             $em->flush();
  9410.             // Se libera asignando ID = 0
  9411.             $item->setLngControlId(0);
  9412.             $item->setSrvControlId(0);
  9413.             $item->setPayControlId(0);
  9414.             $em->persist($item);
  9415.             $em->flush();
  9416.         }
  9417.         $allInvoices $em->getRepository(ReservationInvoice::class)->findByReservationId($invoice->getReservationId());
  9418.         $allInvoicesRec $em->getRepository(ReservationInvoiceRec::class)->findByReservationId($invoice->getReservationId());
  9419.         foreach ($allInvoicesRec as $item){ array_push($allInvoices$item); }
  9420.         $reservation $em->getRepository(Reservation::class)->findOneById($invoice->getReservationId());
  9421.         $client $em->getRepository(Client::class)->findOneById($reservation->getClient());
  9422.         $data = array();
  9423.         $data['clients'][0] = $client;
  9424.         $data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  9425.         $data['datasupplier'] = '';
  9426.         $data['totales_neto'] = '';
  9427.         $data['totales'] = '';
  9428.         $data['bases_imponibles'] = '';
  9429.         $data['balance'] = '';
  9430.         $data['paymentInvoice'] = '';
  9431.         $data['currency'] = '';
  9432.         // Una factura solo se puede rectificar una vez
  9433.         $rectf $em->getRepository(ReservationInvoiceRec::class)->findBy( array('number' => 'REC-'.$invoice->getNumber()));
  9434.         $boolToRec = empty($rectf);
  9435.         return $this->redirectToRoute('reservations_viewrec_invoice', array('id' => $invoiceRec->getId()));
  9436.     }
  9437.     /**
  9438.      * @Route("/reservations/invoicedeposit/proforma/{id}",  name="reservation_invoice_deposit_proforma")
  9439.      */
  9440.     public function detailsProformaAction($idRequest $request)
  9441.     {
  9442.         $em $this->getDoctrine()->getManager();
  9443.         $reservation $em->getRepository(Reservation::class)->findOneById($id);
  9444.         $invoicedepositcontrol $em->getRepository(ReservationInvoiceDepositControl::class)->findByReservationId($id);
  9445.         $invoicedeposit = new ReservationInvoiceDepositItems();
  9446.         $invoicedeposit->setReservationId($id);
  9447.         $form $this->createReservationInvoiceDepositItemsForm($invoicedeposit);
  9448.         $controlId null;
  9449.         $type "Proforma";
  9450.         $prefix "PFD-";
  9451.         $date = new \DateTime('now');
  9452.         $data $this->baseInvoiceDepositReservation($id$controlId$type$id$prefix$date$request);
  9453.         return $this->render('MDS/GreenPatioBundle/reservations/invoice-deposit-proforma.html.twig',
  9454.             array(
  9455.                 'id' => $id,
  9456.                 'cid' => $data['cid'],
  9457.                 'numberadmin' => null,
  9458.                 'type' => $data['type'],
  9459.                 'invoice' => $invoicedepositcontrol,
  9460.                 'number' => $data['number'],
  9461.                 'prefix' => $data['prefix'],
  9462.                 'date' => $data['date'],
  9463.                 'token' =>  $data['token'],
  9464.                 'reservation' => $data['reservation'],
  9465.                 'company' => $data['company'],
  9466.                 'clients' => $data['clients'],
  9467.                 'invoicedeposititems' => $data['invoicedeposititems'],
  9468.                 'totales_neto' => $data['totales_neto'],
  9469.                 'totales_iva' => $data['totales_iva'],
  9470.                 'totales' => $data['totales'],
  9471.                 'bases_imponibles' => $data['ivas'],
  9472.                 'currency' => $data['currency'],
  9473.                 'form' => $form->createView(),
  9474. //                'mcp' => $proposal->getMcp(),
  9475.             )
  9476.         );
  9477.     }
  9478.     private function createReservationInvoiceDepositItemsForm(ReservationInvoiceDepositItems $entity)
  9479.     {
  9480.         $form $this->createForm(ReservationInvoiceDepositItemsType::class, $entity, array(
  9481.             'action' => $this->generateUrl('reservation_invoice_Deposit_proforma_add'),
  9482.             'method' => 'POST'
  9483.         ));
  9484.         return $form;
  9485.     }
  9486.     private function baseInvoiceDepositReservation($id$controlId$type$number$prefix$dateRequest $request)
  9487.     {
  9488.         $em $this->getDoctrine()->getManager();
  9489.         $reservation $em->getRepository(Reservation::class)->findOneById($id);
  9490.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  9491.         $parameters = array(
  9492.             'id' => $reservation->getClient(),
  9493.         );
  9494.         $dql 'SELECT cl,  c.country, re.region, p.name, r.city
  9495.                 FROM App:Client cl
  9496.                 INNER JOIN App:Country c WITH c.id = cl.country
  9497.                 INNER JOIN App:Regions re WITH re.id = cl.region
  9498.                 INNER JOIN App:Provinces p WITH p.id = cl.province
  9499.                 INNER JOIN App:Cities r WITH r.id = cl.population
  9500.                 WHERE cl.id = :id';
  9501.         $query $em->createQuery($dql)->setParameters($parameters);
  9502.         $client $query->getResult();
  9503.         if (!is_null($controlId)){
  9504.             $invoicecontrol $em->getRepository(ReservationInvoiceDepositControl::class)->findOneById($controlId);
  9505.             if (!is_null($invoicecontrol->getNumber())){
  9506.                 $numberadmin $invoicecontrol->getNumber();
  9507.             }else{
  9508.                 $numberadmin null;
  9509.             }
  9510.         }else{
  9511.             $numberadmin null;
  9512.         }
  9513.         $invoicedeposititems $em->getRepository(ReservationInvoiceDepositItems::class)->findBy(
  9514.             array(
  9515.                 'reservationId' => $id,
  9516.                 'controlId' => $controlId,
  9517.             )
  9518.         );
  9519.         $totales_neto_all "0";
  9520.         $totales_iva_all "0";
  9521.         $totales_con_iva_all "0";
  9522.         $data_iva = array();
  9523.         $data_deposititems = array();
  9524.         foreach($invoicedeposititems as $deposititems){
  9525.             $amount $deposititems->getAmount();
  9526.             $iva_base $deposititems->getIva();
  9527.             $iva $iva_base 100;
  9528.             if($iva_base !='0'){
  9529.                 $amount_iva $amount $iva;
  9530.             }else{
  9531.                 $amount_iva "0";
  9532.             }
  9533.             $amount_con_iva $amount $amount_iva;
  9534.             $totales_neto_all += $amount;
  9535.             $totales_iva_all += $amount_iva;
  9536.             $totales_con_iva_all += $amount_con_iva;
  9537.             if (empty($totales_ivas_all[$iva_base])){
  9538.                 $totales_ivas_all[$iva_base]= 0;
  9539.             }
  9540.             $totales_ivas_all[$iva_base] += $amount_iva;
  9541.             $data_iva[$iva_base] = array(
  9542.                 'iva' => $iva_base,
  9543.                 'ivas' => $totales_ivas_all[$iva_base],
  9544.             );
  9545.             $data_deposititems[] = array(
  9546.                 'id' => $deposititems->getId(),
  9547.                 'name' => $deposititems->getName(),
  9548.                 'amount' => $amount,
  9549.                 'iva' => $iva_base,
  9550.                 'total' => $amount_con_iva
  9551.             );
  9552.         }
  9553.         $currency ="€";
  9554.         $data = array(
  9555.             'id' => $id,
  9556.             'cid' => $controlId,
  9557.             'type' => $type,
  9558.             'number' => $number,
  9559.             'prefix' => $prefix,
  9560.             'numberadmin' => $numberadmin,
  9561.             'date' => $date,
  9562.             'token' => $reservation->getAccessKey(),
  9563.             'reservation' => $reservation,
  9564.             'company' => $company,
  9565.             'clients' => $client,
  9566.             'invoicedeposititems' => $data_deposititems,
  9567.             'totales_neto' => $totales_neto_all,
  9568.             'totales_iva' => $totales_iva_all,
  9569.             'totales' => $totales_con_iva_all,
  9570.             'ivas' => $data_iva,
  9571.             'currency' => $currency,
  9572.         );
  9573.         return $data;
  9574.     }
  9575.     /**
  9576.      * @Route("/reservations/invoicedeposit/add", name="reservation_invoice_Deposit_proforma_add")
  9577.      */
  9578.     public function createDepositAction(Request $request)
  9579.     {
  9580.         $invoicedeposit = new ReservationInvoiceDepositItems();
  9581.         $form $this->createReservationInvoiceDepositItemsForm($invoicedeposit);
  9582.         $form->handleRequest($request);
  9583.         if($form->isValid())
  9584.         {
  9585.             $em $this->getDoctrine()->getManager();
  9586.             /* Obtengo usuario logueado */
  9587.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  9588.             $user_id $user_logueado->getId();
  9589.             $invoicedeposit->setCreatedId($user_id);
  9590.             $invoicedeposit->setUpdatedId($user_id);
  9591.             /* Gestión de eventos en Log */
  9592.             $user_lastname $user_logueado->getLastname();
  9593.             $user_name $user_logueado->getName();
  9594.             $user_email $user_logueado->getEmail();
  9595.             $user_rol $user_logueado->getRoles();
  9596.             $event_url $request->getPathInfo();
  9597.             $event_complete $user_name.' '.$user_lastname.' - '.$user_email.' - '.$user_rol[0].' | '.$event_url;
  9598.             $em->persist($invoicedeposit);
  9599.             $em->flush();
  9600.             $event 'the Items was registered';
  9601.             $successMessage $this->translator->trans($event);
  9602.             $this->addFlash('mensajeinvoicedepositservices'$successMessage);
  9603.             return $this->redirectToRoute('reservation_invoice_deposit_proforma',
  9604.                 array(
  9605.                     'id' => $invoicedeposit->getReservationId()
  9606.                 ));
  9607.         } else {
  9608.             $errorMessage $this->translator->trans('Error, some fields are empty');
  9609.             $this->addFlash('mensajeinvoicedepositserviceserror'$errorMessage);
  9610.         }
  9611.         return $this->redirectToRoute('reservation_invoice_deposit_proforma', array('id' => $invoicedeposit->getReservationId()));
  9612.     }
  9613.     /**
  9614.      * @Route("/reservations/invoicedeposit/invoice/{id}/{fid}", defaults={"fid" = ""}, name="reservation_invoice_deposit")
  9615.      */
  9616.     public function detailsInvoiceDepositAction($id$fidRequest $request)
  9617.     {
  9618.         $data = array();
  9619.         $em $this->getDoctrine()->getManager();
  9620.         $reservation $em->getRepository(Reservation::class)->findOneById($id);
  9621.         $invoicecontrol $em->getRepository(ReservationInvoiceDepositControl::class)->findByReservationId($id);
  9622. //        $number = $invoicecontrol->getNumber();
  9623.         $prefix "IFD-";
  9624.         if (empty($fid)){
  9625.             $invoicedeposititems $em->getRepository(ReservationInvoiceDepositItems::class)->findBy(
  9626.                 array(
  9627.                     'reservationId' => $id,
  9628.                     'controlId' => null,
  9629.                 )
  9630.             );
  9631.             if (!empty($invoicedeposititems)){
  9632.                 /* Obtengo usuario logueado */
  9633.                 $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  9634.                 $user_id $user_logueado->getId();
  9635.                 $invoicedeposit = new ReservationInvoice();
  9636.                 $invoicedeposit->setDateAt(new \DateTime());
  9637.                 $invoicedeposit->setMaster('0');
  9638.                 $invoicedeposit->setNumber('0');
  9639.                 $invoicedeposit->setType('Invoice Deposit');
  9640.                 $invoicedeposit->setReservationId($id);
  9641.                 $invoicedeposit->setPrefix('');
  9642.                 $invoicedeposit->setTotal('0');
  9643.                 $invoicedeposit->setTotalNet('0');
  9644.                 $invoicedeposit->setVat('0');
  9645.                 $invoicedeposit->setCreatedId($user_id);
  9646.                 $invoicedeposit->setUpdatedId($user_id);
  9647.                 $invoicedeposit->setCreatedAt(new \DateTime());
  9648.                 $invoicedeposit->setUpdatedAt(new \DateTime());
  9649.                 $em->persist($invoicedeposit);
  9650.                 $em->flush();
  9651.                 $number $invoicedeposit->getId();
  9652.                 $invoicedepositcontrol = new ReservationInvoiceDepositControl();
  9653.                 $invoicedepositcontrol->setReservationId($id);
  9654.                 $invoicedepositcontrol->setNumber($invoicedeposit->getId());
  9655.                 $invoicedepositcontrol->setDateAt(new \DateTime("now"));
  9656.                 $invoicedepositcontrol->setPrefix($prefix);
  9657.                 $invoicedepositcontrol->setCreatedId($user_id);
  9658.                 $invoicedepositcontrol->setUpdatedId($user_id);
  9659.                 $em->persist($invoicedepositcontrol);
  9660.                 $em->flush();
  9661.                 $invoiceSQL $em->getRepository(ReservationInvoice::class)->findOneById($invoicedeposit->getId());
  9662.                 $invoiceSQL->setMaster($invoicedepositcontrol->getId());
  9663.                 $invoiceSQL->setNumber($invoicedepositcontrol->getId());
  9664.                 $em->persist($invoiceSQL);
  9665.                 $em->flush();
  9666.                 $controlId $invoicedepositcontrol->getId();
  9667.                 $date $invoicedepositcontrol->getDateAt();
  9668.                 foreach($invoicedeposititems as $invoicedeposit){
  9669.                     $invoicedeposit->setControlId($controlId);
  9670.                     $em->persist($invoicedeposit);
  9671.                 }
  9672.                 $em->flush();
  9673.                 return $this->redirectToRoute('reservation_invoice_deposit',
  9674.                     array(
  9675.                         'id' => $id,
  9676.                         'fid' => $invoicedepositcontrol->getId(),
  9677.                     )
  9678.                 );
  9679.             }else{
  9680.                 return $this->redirectToRoute('reservation_invoice_deposit_proforma',
  9681.                     array(
  9682.                         'id' => $id
  9683.                     )
  9684.                 );
  9685.             }
  9686.         }else{
  9687.             $invoicedepositcontrolconsulta $em->getRepository(ReservationInvoiceDepositControl::class)->findOneBy(
  9688.                 array(
  9689.                     'reservationId' => $id,
  9690.                     'id' => $fid
  9691.                 )
  9692.             );
  9693.             $controlId $invoicedepositcontrolconsulta->getId();
  9694.             $date $invoicedepositcontrolconsulta->getDateAt();
  9695.         }
  9696.         $number $id;
  9697.         $type "Invoice";
  9698.         $data $this->baseInvoiceDepositReservation($id$controlId$type$number$prefix$date$request);
  9699.         /* Obtengo usuario logueado */
  9700.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  9701.         $user_id $user_logueado->getId();
  9702.         if ($reservation->getStatus() != 'Invoiced'){
  9703.             $reservation->setStatus('Confirmed');
  9704.             $em->persist($reservation);
  9705.             $em->flush();
  9706.         }
  9707.         // Una factura solo se puede rectificar una vez
  9708.         $rectf $em->getRepository(ReservationInvoiceRec::class)->findByInvoiceToRec($number);
  9709.         $boolToRec = empty($rectf);
  9710.         $newclient[] = $data['clients'];
  9711.         return $this->render('MDS/GreenPatioBundle/reservations/invoice-deposit-invoice.html.twig',
  9712.             array(
  9713.                 'id' => $id,
  9714.                 'cid' => $data['cid'],
  9715.                 'fid' => $controlId,
  9716.                 'invoice' => $invoicecontrol,
  9717.                 'numberadmin' => $data['numberadmin'],
  9718.                 'type' => $data['type'],
  9719.                 'number' => $data['number'],
  9720.                 'prefix' => $data['prefix'],
  9721.                 'date' => $data['date'],
  9722.                 'token' =>  $data['token'],
  9723.                 'reservation' => $data['reservation'],
  9724.                 'company' => $data['company'],
  9725.                 'clients' => $newclient,
  9726.                 'user' => $user_logueado,
  9727.                 'boolToRec' => $boolToRec,
  9728.                 'invoicedeposititems' => $data['invoicedeposititems'],
  9729.                 'totales_neto' => $data['totales_neto'],
  9730.                 'totales_iva' => $data['totales_iva'],
  9731.                 'totales' => $data['totales'],
  9732.                 'bases_imponibles' => $data['ivas'],
  9733.                 'currency' => $data['currency'],
  9734. //                'mcp' => $proposal->getMcp(),
  9735.             )
  9736.         );
  9737.     }
  9738.     /**
  9739.      * @Route("/reservations/invoicedeposit/number/updated/{cid}/{id}", name="reservation_invoicedeposit_number_update")
  9740.      */
  9741.     public function InvoiceEmptyNumberInvoiceDepositUpdateAction($cid$idRequest $request)
  9742.     {
  9743.         $em $this->getDoctrine()->getManager();
  9744.         $invoice $em->getRepository(ReservationInvoiceDepositControl::class)->findOneById($id);
  9745.         $numberinvoice $request->request->get('invoice')['number'];
  9746.         if(!empty($numberinvoice) and !is_null($invoice))
  9747.         {
  9748.             $invoice->setNumber($numberinvoice);
  9749.             /* Obtengo usuario logueado */
  9750.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  9751.             $user_id $user_logueado->getId();
  9752.             $invoice->setUpdatedId($user_id);
  9753.             $em->persist($invoice);
  9754.             $em->flush();
  9755.             $event 'The Invoice Deposit has been Updated.';
  9756.             $successMessage $this->translator->trans($event);
  9757.             $this->addFlash('mensajeinvoicedepositservices'$successMessage);
  9758.         }else{
  9759.             $errorMessage $this->translator->trans('Error, some fields are empty');
  9760.             $this->addFlash('mensajeinvoicedepositserviceserror'$errorMessage);
  9761.         }
  9762.         return $this->redirectToRoute('reservation_invoice_deposit',
  9763.             array(
  9764.                 'id' => $cid,
  9765.                 'fid' => $id,
  9766.             )
  9767.         );
  9768.     }
  9769.     /**
  9770.      * @Route("/reservations/invoicedepositdelete/invoice/{id}/{fid}", defaults={"fid" = ""}, name="reservation_invoice_deposit_delete")
  9771.      */
  9772.     public function deleteInvoiceDepositAction($id$fidRequest $request)
  9773.     {
  9774.         $em $this->getDoctrine()->getManager();
  9775.         // INICIO: Buscamos en ITEMS los elementos que coincidan
  9776.         $invoicedeposititems $em->getRepository(ReservationInvoiceDepositItems::class)->findBy(
  9777.             array(
  9778.                 'reservationId' => $id,
  9779.                 'controlId' => $fid
  9780.             )
  9781.         );
  9782.         foreach ($invoicedeposititems as $item){
  9783.             $em->remove($item);
  9784.             $em->flush();
  9785.         }
  9786.         // FIN: Buscamos en ITEMS los elementos que coincidan
  9787.         // INICIO: Buscamos en CONTROL los elementos que coincidan
  9788.         $invoicedepositcontrol $em->getRepository(ReservationInvoiceDepositControl::class)->findBy(
  9789.             array(
  9790.                 'reservationId' => $id,
  9791.                 'id' => $fid
  9792.             )
  9793.         );
  9794.         foreach ($invoicedepositcontrol as $item){
  9795.             $numberDeposit $item->getNumber();
  9796.             $em->remove($item);
  9797.             $em->flush();
  9798.         }
  9799.         // FIN: Buscamos en CONTROL los elementos que coincidan
  9800.         /* Obtengo usuario logueado */
  9801.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  9802.         $user_id $user_logueado->getId();
  9803.         $now = new DateTime('now');
  9804.         $tracingDeleteDeposit = new ReservationTracing();
  9805.         $tracingDeleteDeposit->setDateAt($now);
  9806.         $tracingDeleteDeposit->setCreatedAt($now);
  9807.         $tracingDeleteDeposit->setUpdatedAt($now);
  9808.         $tracingDeleteDeposit->setText('Ha eliminado la Factura de deposito No. '.$numberDeposit);
  9809.         $tracingDeleteDeposit->setAgentId($user_id);
  9810.         $tracingDeleteDeposit->setReservationId($id);
  9811.         $tracingDeleteDeposit->setViewed('no');
  9812.         $tracingDeleteDeposit->setCreatedId($user_id);
  9813.         $tracingDeleteDeposit->setUpdatedId($user_id);
  9814.         try{
  9815.             $em->persist($tracingDeleteDeposit);
  9816.             $em->flush();
  9817.             $event 'The item has been deleted.';
  9818.             $successMessage $this->translator->trans($event);
  9819.             $this->addFlash('mensajereservation'$successMessage);
  9820.         } catch (\Exception $e){
  9821.             $event 'An error occurred: '.$e->getMessage();
  9822.             $errorMessage $this->translator->trans($event);
  9823.             $this->addFlash('mensajereservationerror'$errorMessage);
  9824.         }
  9825.         return $this->redirectToRoute('reservation_invoice_deposit_proforma',
  9826.             array('id' => $id));
  9827.     }
  9828.     /**
  9829.      * @Route("/reservations/invoicedeposit/print/invoice/{id}/{fid}",  name="reservation_invoice_deposit_invoice_print_externo")
  9830.      */
  9831.     public function printdetailsInvoicedepositAction($id$fidRequest $request)
  9832.     {
  9833.         $data = array();
  9834.         $em $this->getDoctrine()->getManager();
  9835.         $invoicedepositcontrolconsulta $em->getRepository(ReservationInvoiceDepositControl::class)->findOneBy(
  9836.             array(
  9837.                 'reservationId' => $id,
  9838.                 'id' => $fid
  9839.             )
  9840.         );
  9841.         $type "Invoice";
  9842.         $controlId $invoicedepositcontrolconsulta->getId();
  9843.         $date $invoicedepositcontrolconsulta->getDateAt();
  9844.         $prefix $invoicedepositcontrolconsulta->getPrefix();
  9845.         $data $this->baseInvoiceDepositReservation($id$controlId$type$id$prefix$date$request);
  9846.         return $this->render('MDS/GreenPatioBundle/reservations/print-invoice-deposit-proforma.html.twig',
  9847.             array(
  9848.                 'id' => $id,
  9849.                 'type' => $data['type'],
  9850.                 'number' => $data['number'],
  9851.                 'prefix' => $data['prefix'],
  9852.                 'numberadmin' => $data['numberadmin'],
  9853.                 'date' => $data['date'],
  9854.                 'token' =>  $data['token'],
  9855.                 'reservation' => $data['reservation'],
  9856.                 'company' => $data['company'],
  9857.                 'clients' => $data['clients'],
  9858.                 'invoicedeposititems' => $data['invoicedeposititems'],
  9859.                 'totales_neto' => $data['totales_neto'],
  9860.                 'totales_iva' => $data['totales_iva'],
  9861.                 'totales' => $data['totales'],
  9862.                 'bases_imponibles' => $data['ivas'],
  9863.                 'currency' => $data['currency'],
  9864.             )
  9865.         );
  9866.     }
  9867.     /**
  9868.      * @Route("/reservations/invoicedeposit/deleted/items/{id}", name="reservation_invoice_deposit_invoice_deleted_items")
  9869.      *
  9870.      */
  9871.     public function deleteItemsInvoiceDepositAction($idRequest $request)
  9872.     {
  9873.         $em $this->getDoctrine()->getManager();
  9874.         $delete $em->getRepository(ReservationInvoiceDepositItems::class)->findOneById($id);
  9875.         $em->remove($delete);
  9876.         $em->flush();
  9877.         $event 'The item in the deposit proforma has been removed';
  9878.         $successMessage $this->translator->trans($event);
  9879.         $this->addFlash('mensajeinvoicedepositservices'$successMessage);
  9880.         return $this->redirectToRoute('reservation_invoice_deposit_proforma', array( 'id' => $delete->getReservationId(), ));
  9881.     }
  9882.     /**
  9883.      * @Route("/reservations/invoice/list", name="reservation_invoice_list")
  9884.      */
  9885.     public function indexAction(Request $request) {
  9886.         $em $this->getDoctrine()->getManager();
  9887.         $todayTwoYearAgo = new DateTime('now -2 year');
  9888.         $parameters = array( 'dateStart' => $todayTwoYearAgo, );
  9889.         $dql 'SELECT p
  9890.                 FROM GreenPatioBundle:ReservationInvoice p
  9891.                 WHERE p.dateAt > :dateStart';
  9892.         $query $em->createQuery($dql)->setParameters($parameters);
  9893.         $invoiced $em->getRepository(ReservationInvoice::class)->findAll();
  9894.         $invoiced $query->getResult();
  9895.         $parameters = array( 'dateStart' => $todayTwoYearAgo, );
  9896.         $dql 'SELECT p
  9897.                 FROM GreenPatioBundle:ReservationInvoiceRec p
  9898.                 WHERE p.dateAt > :dateStart';
  9899.         $query $em->createQuery($dql)->setParameters($parameters);
  9900.         $invoicedRec $em->getRepository(ReservationInvoiceRec::class)->findAll();
  9901.         $invoicedRec $query->getResult();
  9902.         // Agregamos las rectificativas al arreglo de facturas con el indice "R(id)"
  9903.         foreach ($invoicedRec as $idRecArray => $item){
  9904.             $invoiced['R'.$item->getId()] = $item;
  9905.         }
  9906.         $sumatoriaTotalNet 0;
  9907.         $sumatoriaTotalVat 0;
  9908.         $sumatoriaTotal 0;
  9909.         foreach ($invoiced as $idArray => $item){
  9910.             $reserva $em->getRepository(Reservation::class)->findOneById($item->getReservationId());
  9911.             $invoiced[$idArray]->setNumber($reserva->getTitle());
  9912.             $client $em->getRepository(Client::class)->findOneById($reserva->getClient());
  9913.             if(!empty($client)){
  9914.                 $invoiced[$idArray]->setPrefix($client->getName());
  9915.             } else {
  9916.                 $invoiced[$idArray]->setPrefix('');
  9917.             }
  9918.             $estaEnFactura false;
  9919.             $estaEnFacturaRectificativa false;
  9920.             if ($item->getType() == 'Invoice Deposit'){
  9921.                 // Si la factura de deposito se encuentra en una factura sumara 0
  9922.                 // INICIO: Verificamos factura de deposito dentro de alguna factura
  9923.                 $payOfInvoiceDeposit $em->getRepository(ReservationPaymentsClient::class)->findOneByInvoiceId($item->getId());
  9924.                 if (!empty($payOfInvoiceDeposit)){
  9925.                     // Verificamos si el deposito esta dentro de una factura
  9926.                     $itemInvoiceOfInvoiceDeposit $em->getRepository(ReservationInvoiceItems::class)->findOneByPayControlId($payOfInvoiceDeposit->getId());
  9927.                 }
  9928.                 if (!empty($itemInvoiceOfInvoiceDeposit)){
  9929.                     $estaEnFactura true;
  9930.                 } else {
  9931.                     // Verificamos que el control Id no haya sido seteado a 0 por rectificar la factura
  9932.                     if (!empty($payOfInvoiceDeposit)) {
  9933.                         $itemInvoiceOfInvoiceDeposit $em->getRepository(ReservationInvoiceRecItems::class)->findOneByPayControlId($payOfInvoiceDeposit->getId());
  9934.                         if (!empty($itemInvoiceOfInvoiceDeposit)) {
  9935.                             $estaEnFactura true;
  9936.                         }
  9937.                     }
  9938.                 }
  9939.                 if (!empty($payOfInvoiceDeposit)){
  9940.                     // Verificamos si el deposito esta dentro de una factura rectificativa
  9941.                     $itemInvoiceOfInvoiceDepositRec $em->getRepository(ReservationInvoiceRecItems::class)->findOneByPayControlId($payOfInvoiceDeposit->getId());
  9942.                 }
  9943.                 if (!empty($itemInvoiceOfInvoiceDepositRec)){
  9944.                     $estaEnFacturaRectificativa true;
  9945.                 }
  9946.                 // FIN: Verificamos factura de deposito dentro de alguna factura
  9947.                 $invoicedDepositItems $em->getRepository(ReservationInvoiceDepositItems::class)->findByControlId($item->getMaster());
  9948.                 foreach ($invoicedDepositItems as $itemDep){
  9949.                         $invoiced[$idArray]->setTotalNet($invoiced[$idArray]->getTotalNet() + $itemDep->getAmount());
  9950.                         $invoiced[$idArray]->setVat($invoiced[$idArray]->getVat() + (($itemDep->getAmount() * $itemDep->getIva())/100));
  9951.                         $invoiced[$idArray]->setTotal($invoiced[$idArray]->getTotal() + ($itemDep->getAmount() + (($itemDep->getAmount() * $itemDep->getIva())/100)));
  9952.                 }
  9953.             }
  9954.             // Sumara cuando ambos esten en false (no esta en factura ni en fact rect) o en true en ambas (fue facturado pero luego rectificado)
  9955.             if ((!$estaEnFactura and !$estaEnFacturaRectificativa) or ($estaEnFactura and $estaEnFacturaRectificativa)) {
  9956.                 $sumatoriaTotalNet $sumatoriaTotalNet $item->getTotalNet();
  9957.                 $sumatoriaTotalVat $sumatoriaTotalVat $item->getVat();
  9958.                 $sumatoriaTotal $sumatoriaTotal $item->getTotal();
  9959.             }
  9960.         }
  9961.         $toXls $request->request->get('boolToXls');
  9962.         if (!empty($toXls)){
  9963.             $id 0;
  9964.             // Solicita el servicio de excel
  9965.             $phpExcelObject $this->get('phpexcel')->createPHPExcelObject();
  9966.             $phpExcelObject->getProperties()->setCreator("InOut Travel & Events")
  9967.                 ->setLastModifiedBy("InOut Travel & Events")
  9968.                 ->setTitle("InOut Travel & Events")
  9969.                 ->setSubject("InOut Travel & Events")
  9970.                 ->setDescription("InOut Travel & Events, generado usando clases de PHP")
  9971.                 ->setKeywords("office 2005 openxml php")
  9972.                 ->setCategory("Archivo de ejemplo");
  9973.             $fill = new Fill();
  9974.             $numberFormat = new NumberFormat();
  9975.             $alignment = new Alignment();
  9976.             $i 6;
  9977.             $indiceInicial 7;
  9978.             $indiceFinal 7;
  9979.             $activesheet $phpExcelObject->getActiveSheet();
  9980.             $drawingobject $this->get('phpexcel')->createPHPExcelWorksheetDrawing();
  9981.             $drawingobject->setName('Image name');
  9982.             $drawingobject->setDescription('Image description');
  9983.             $drawingobject->setPath(getcwd().'/assets/images/logo/logo_green_patio.png');
  9984.             $drawingobject->setHeight(60);
  9985.             $drawingobject->setOffsetY(20);
  9986.             $drawingobject->setCoordinates('Q1');
  9987.             $drawingobject->setWorksheet($activesheet);
  9988.             $phpExcelObject
  9989.                 ->getActiveSheet()
  9990.                 ->getStyle('B3:O3')
  9991.                 ->getFill()
  9992.                 ->setFillType($fill::FILL_SOLID)
  9993.                 ->getStartColor()
  9994.                 ->setRGB('9fc4a6');
  9995.             $phpExcelObject->setActiveSheetIndex(0)
  9996.                 ->setCellValue('C3','LISTADO DE FACTURACION')
  9997.             ;
  9998.             $phpExcelObject->setActiveSheetIndex(0)
  9999.                 ->setCellValue('B'.$i'Fecha')
  10000.                 ->setCellValue('D'.$i'Número')
  10001.                 ->setCellValue('F'.$i'Expediente')
  10002.                 ->setCellValue('H'.$i'Nombre del Evento')
  10003.                 ->setCellValue('L'.$i'Cliente')
  10004.                 ->setCellValue('O'.$i'Tipo')
  10005.                 ->setCellValue('Q'.$i'Neto')
  10006.                 ->setCellValue('S'.$i'Total')
  10007.             ;
  10008.             $data = array();
  10009.             $data $invoiced;
  10010.             foreach ($data as $item) {
  10011.                 $time $item->getDateAt()->format('d/m/Y');
  10012.                 $idExp = ($item->getType() == 'Invoice Rec') ? 'R'.$item->getId() : $item->getId();
  10013.                 $clientTypeText = ($item->getClientType() == 'Client') ? 'Cliente' 'Proveedor';
  10014.                 $phpExcelObject->setActiveSheetIndex(0)
  10015.                     ->setCellValue('B' . ($i 1), $time)
  10016.                     ->setCellValue('D' . ($i 1), $idExp)
  10017.                     ->setCellValue('F' . ($i 1), $item->getReservationId())
  10018.                     ->setCellValue('H' . ($i 1), $item->getNumber())
  10019.                     ->setCellValue('L' . ($i 1), $item->getClientName())
  10020.                     ->setCellValue('O' . ($i 1), $clientTypeText)
  10021.                     ->setCellValue('Q' . ($i 1), $item->getTotalNet())
  10022.                     ->setCellValue('S' . ($i 1), $item->getTotal())
  10023.                 ;
  10024.                 $i++;
  10025.                 $indiceFinal++;
  10026.             }
  10027.             $indiceFinal--;
  10028.             $indicesResta $indiceFinal $indiceInicial 1;
  10029.             $phpExcelObject
  10030.                 ->getActiveSheet()
  10031.                 ->getStyle('Q' . ($indiceFinal 3) . ':' 'S' . ($indiceFinal 3))
  10032.                 ->getFill()
  10033.                 ->setFillType($fill::FILL_SOLID)
  10034.                 ->getStartColor()
  10035.                 ->setRGB('9fc4a6');
  10036.             $phpExcelObject->setActiveSheetIndex(0)
  10037.                 ->setCellValue('Q' . ($indiceFinal 3), 'Total Neto')
  10038.                 ->setCellValue('S' . ($indiceFinal 3), 'Total');
  10039.             $phpExcelObject->setActiveSheetIndex(0)
  10040.                 ->setCellValue('Q' . ($indiceFinal 4), '=SUM(' 'Q' $indiceInicial ' : Q' $indiceFinal ')')
  10041.                 ->setCellValue('S' . ($indiceFinal 4), '=SUM(' 'S' $indiceInicial ' : U' $indiceFinal ')');
  10042.             $phpExcelObject->getActiveSheet()->setTitle('Estadísticas por sala');
  10043.             // Define el indice de página al número 1, para abrir esa página al abrir el archivo
  10044.             $phpExcelObject->setActiveSheetIndex(0);
  10045.             // Creamos pagina de Datos en bruto para Esteban Rincon
  10046.             // Add new sheet
  10047.             $objWorkSheet $phpExcelObject->createSheet(1); //Setting index when creating
  10048.             $phpExcelObject->setActiveSheetIndex(1);
  10049.             $phpExcelObject->getActiveSheet()->setTitle('Datos en bruto');
  10050.             $x 1;
  10051.             $phpExcelObject->setActiveSheetIndex(1)
  10052.                 ->setCellValue('A'.$x'Fecha')
  10053.                 ->setCellValue('B'.$x'Número')
  10054.                 ->setCellValue('C'.$x'Expediente')
  10055.                 ->setCellValue('D'.$x'Nombre del Evento')
  10056.                 ->setCellValue('E'.$x'Cliente')
  10057.                 ->setCellValue('F'.$x'Tipo')
  10058.                 ->setCellValue('G'.$x'Neto')
  10059.                 ->setCellValue('H'.$x'Total')
  10060.             ;
  10061.             foreach ($data as $item) {
  10062.                 $time $item->getDateAt()->format('d/m/Y');
  10063.                 $idExp = ($item->getType() == 'Invoice Rec') ? 'R'.$item->getId() : $item->getId();
  10064.                 $clientTypeText = ($item->getClientType() == 'Client') ? 'Cliente' 'Proveedor';
  10065.                 $phpExcelObject->setActiveSheetIndex(1)
  10066.                     ->setCellValue('A' . ($x 1), $time)
  10067.                     ->setCellValue('B' . ($x 1), $idExp)
  10068.                     ->setCellValue('C' . ($x 1), $item->getReservationId())
  10069.                     ->setCellValue('D' . ($x 1), $item->getNumber())
  10070.                     ->setCellValue('E' . ($x 1), $item->getClientName())
  10071.                     ->setCellValue('F' . ($x 1), $clientTypeText)
  10072.                     ->setCellValue('G' . ($x 1), $item->getTotalNet())
  10073.                     ->setCellValue('H' . ($x 1), $item->getTotal())
  10074.                 ;
  10075.                 $x++;
  10076.             }
  10077.             $phpExcelObject->setActiveSheetIndex(0);
  10078.             // Crea el writer
  10079.             $writer $this->get('phpexcel')->createWriter($phpExcelObject'Excel2007');
  10080.             // Envia la respuesta del controlador
  10081.             $response $this->get('phpexcel')->createStreamedResponse($writer);
  10082.             // Agrega los headers requeridos
  10083.             $dispositionHeader $response->headers->makeDisposition(
  10084.                 ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  10085.                 'Green Patio - Listado Facturas La Imprenta'.'.xlsx'
  10086.             );
  10087.             $response->headers->set('Content-Type''application/vnd.ms-excel; charset=utf-8');
  10088.             $response->headers->set('Pragma''public');
  10089.             $response->headers->set('Cache-Control''maxage=1');
  10090.             $response->headers->set('Content-Disposition'$dispositionHeader);
  10091.             $phpExcelObject->getActiveSheet()->setTitle('Facturación Green Patio');
  10092.             // Define el indice de página al número 1, para abrir esa página al abrir el archivo
  10093.             $phpExcelObject->setActiveSheetIndex(0);
  10094.             // Crea el writer
  10095.             $writer $this->get('phpexcel')->createWriter($phpExcelObject'Excel2007');
  10096.             // Envia la respuesta del controlador
  10097.             $response $this->get('phpexcel')->createStreamedResponse($writer);
  10098.             // Agrega los headers requeridos
  10099.             $dispositionHeader $response->headers->makeDisposition(
  10100.                 ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  10101.                 'Green Patio - Listado Facturacion La Imprenta.xlsx'
  10102.             );
  10103.             $response->headers->set('Content-Type''application/vnd.ms-excel; charset=utf-8');
  10104.             $response->headers->set('Pragma''public');
  10105.             $response->headers->set('Cache-Control''maxage=1');
  10106.             $response->headers->set('Content-Disposition'$dispositionHeader);
  10107.             return $response;
  10108.         }
  10109.         return $this->render('MDS/GreenPatioBundle/reservations/list-reservations-invoice.html.twig',
  10110.             array(
  10111.                 'invocied' => $invoiced,
  10112.                 'sumatoriaTotalNet' => $sumatoriaTotalNet,
  10113.                 'sumatoriaTotalVat' => $sumatoriaTotalVat,
  10114.                 'sumatoriaTotal' => $sumatoriaTotal,
  10115.             )
  10116.         );
  10117.     }
  10118.     /**
  10119.      * @Route("/reservations/updateinvoicedate/", name="reservation_update_invoice_date")
  10120.      * Editar la fecha de una factura
  10121.      */
  10122.     public function updateInvoiceDateActionRequest $request){
  10123.         $em $this->getDoctrine()->getManager();
  10124.         $invoiceId $request->request->get('invoice_id');
  10125.         $invoiceNewDate $request->request->get('new_invoice_date');
  10126.         /* Obtengo usuario logueado */
  10127.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  10128.         $user_id $user_logueado->getId();
  10129.         $invoice $em->getRepository(ReservationInvoice::class)->findOneById($invoiceId);
  10130.         $newDate = new DateTime($invoiceNewDate);
  10131.         $invoice->setDateAt($newDate);
  10132.         // Modificamos el number para que se adapte a la nueva fecha
  10133.         $invoice->setNumber('GPF-' $newDate->format('dmy') . substr($invoice->getNumber(),10));
  10134.         $invoice->setUpdatedId($user_id);
  10135.         $invoice->setUpdatedAt(new DateTime('now'));
  10136.         $em->persist($invoice);
  10137.         $em->flush();
  10138.         return $this->redirectToRoute('reservation_invoice_list');
  10139.     }
  10140.     /**
  10141.      * @Route("/mkbdgt/{token}", name="reservations_greenpatio_make_budget")
  10142.      */
  10143.     public function makeBudgetAction($tokenRequest $request)
  10144.     {
  10145.         $em $this->getDoctrine()->getManager();
  10146.         $budgetControl $em->getRepository(ReservationBudgetControl::class)->findOneByToken($token);
  10147.         $allBudgets $em->getRepository(ReservationBudgetControl::class)->findByReservationId($budgetControl->getReservationId());
  10148.         $id $budgetControl->getReservationId();
  10149. //        $paymentsClient = new ReservationPaymentsClient();
  10150. //        $paymentsClient->setReservationId($id);
  10151. //        $form = $this->createReservationPaymentsClientForm($paymentsClient);
  10152.         $reserva $em->getRepository(Reservation::class)->findOneById($id);
  10153. //        $payments = $em->getRepository(ReservationPaymentsClient::class)->findByReservationId($id);
  10154.         $services $em->getRepository(ReservationService::class)->findByReservationId($id);
  10155.         $proforma $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
  10156. //        $allProformas = $em->getRepository(ReservationProforma::class)->findAll();
  10157. //        if (!empty($allProformas)){
  10158. //            $number = end($allProformas)->getId() + 1;
  10159. //        } else {
  10160.         // Primer registro de proformas
  10161.         $number 1;
  10162. //        }
  10163.         $type 'Proforma';
  10164.         $date = new DateTime('now');
  10165.         $prefix "GP-".$date->format('dmy')."-";
  10166.         $reservaInv = new ReservationInvoice();
  10167.         $reservaInv->setReservationId($id);
  10168. //        $form1 = $this->createReservationInvoiceProformaForm($reservaInv);
  10169.         $data $this->baseInvoiceReservation($id$type$number$prefix$date);
  10170. //        $token = $data['token'];
  10171.         $idLounges = array();
  10172.         if (array_key_exists('lounge',$data['datasupplier'])) {
  10173.             foreach ($data['datasupplier']['lounge'] as $key => $item) {
  10174.                 $existe $em->getRepository(ReservationInvoiceItems::class)->findOneByLngControlId($item['id']);
  10175.                 if (empty($existe)){
  10176.                     $data['datasupplier']['lounge'][$key]['enabledToInvoice'] = true;
  10177.                 } else {
  10178.                     $data['datasupplier']['lounge'][$key]['enabledToInvoice'] = false;
  10179.                 }
  10180.             }
  10181.         }
  10182.         if (array_key_exists('service',$data['datasupplier'])) {
  10183.             foreach ($data['datasupplier']['service'] as $key => $item) {
  10184.                 $existe $em->getRepository(ReservationInvoiceItems::class)->findOneBySrvControlId($item['id']);
  10185.                 if (empty($existe)){
  10186.                     $data['datasupplier']['service'][$key]['enabledToInvoice'] = true;
  10187.                 } else {
  10188.                     $data['datasupplier']['service'][$key]['enabledToInvoice'] = false;
  10189.                 }
  10190.             }
  10191.         }
  10192. //        $idPayments = array();
  10193. //        if (array_key_exists('payment',$data['datasupplier'])) {
  10194. //            foreach ($data['datasupplier']['payment'] as $key => $item) {
  10195. //                $existe = $em->getRepository(ReservationInvoiceItems::class)->findOneByPayControlId($item['id']);
  10196. //
  10197. //                if (empty($existe)){
  10198. //                    $data['datasupplier']['payment'][$key]['enabledToInvoice'] = true;
  10199. //                } else {
  10200. //                    $data['datasupplier']['payment'][$key]['enabledToInvoice'] = false;
  10201. //                }
  10202. //            }
  10203. //        }
  10204.         /* Obtengo usuario logueado */
  10205.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  10206.         $user_id $user_logueado->getId();
  10207.         return $this->render('MDS/GreenPatioBundle/reservations/budget-add-items.html.twig',
  10208.             array(
  10209.                 'id' => $id,
  10210.                 'idLounges' => $idLounges,
  10211.                 'reserva' => $reserva,
  10212.                 'idPayments' => null,
  10213.                 'type' => $data['type'],
  10214.                 'number' => $data['number'],
  10215.                 'prefix' => $data['prefix'],
  10216.                 'date' => $data['date'],
  10217.                 'token' => $token,
  10218.                 'company' => $data['company'],
  10219.                 'clients' => $data['clients'],
  10220.                 'datasupplier' => $data['datasupplier'],
  10221.                 'currency' => $data['currency'],
  10222.                 'totales_neto' => $data['totales_neto'],
  10223.                 'bases_imponibles' => $data['bases_imponibles'],
  10224.                 'totales' => $data['totales'],
  10225.                 'balance' => $data['balance'],
  10226.                 'paymentInvoice' => $data['paymentInvoice'],
  10227.                 'payments' => null,
  10228.                 'user_id' => $user_id,
  10229.                 'allBudgets' => $allBudgets,
  10230.             )
  10231.         );
  10232.     }
  10233.     /**
  10234.      * @Route("/createbdgt/{token}", name="reservations_greenpatio_create_budget")
  10235.      */
  10236.     public function createBudgetAction($tokenRequest $request)
  10237.     {
  10238.         $em $this->getDoctrine()->getManager();
  10239.         $budgetControl $em->getRepository(ReservationBudgetControl::class)->findOneByToken($token);
  10240.         $nameBud $request->request->get('budget_name_hidden');
  10241.         $budgetControl->setName($nameBud);
  10242.         $em->persist($budgetControl);
  10243.         $em->flush();
  10244.         /* Obtengo usuario logueado */
  10245.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  10246.         $user_id $user_logueado->getId();
  10247.         $arrayLounge $request->request->get('lounge_hidden_bool');
  10248.         $arrayService $request->request->get('service_hidden_bool');
  10249.         foreach ($arrayLounge as $key => $item) {
  10250.             if ($item == 'true'){
  10251.                 //Buscamos la sala
  10252.                 $lounge $em->getRepository(ReservationLoungeSimple::class)->findOneById($key);
  10253.                 $budgetItem = new ReservationBudgetItems();
  10254.                 $budgetItem->setReservationId($budgetControl->getReservationId());
  10255.                 $budgetItem->setControlId($budgetControl->getId());
  10256.                 $budgetItem->setItemType('LOUNGE');
  10257.                 $budgetItem->setLngControlId($key);
  10258.                 $budgetItem->setLngLoungeName($lounge->getLoungeName());
  10259.                 $budgetItem->setLngIdLounge($lounge->getIdLounge());
  10260.                 $budgetItem->setLngDateStart($lounge->getDateStart());
  10261.                 $budgetItem->setLngDateEnd($lounge->getDateEnd());
  10262.                 $budgetItem->setLngServicePrice($lounge->getServicePrice());
  10263.                 $budgetItem->setLngPax($lounge->getPax());
  10264.                 $budgetItem->setLngType($lounge->getType());
  10265.                 $budgetItem->setLngHourStart($lounge->getHourStart());
  10266.                 $budgetItem->setLngMinStart($lounge->getMinStart());
  10267.                 $budgetItem->setLngHourEnd($lounge->getHourEnd());
  10268.                 $budgetItem->setLngMinEnd($lounge->getMinEnd());
  10269.                 $budgetItem->setCreatedAt(new DateTime('now'));
  10270.                 $budgetItem->setCreatedId($user_id);
  10271.                 $budgetItem->setUpdatedAt(new DateTime('now'));
  10272.                 $budgetItem->setUpdatedId($user_id);
  10273.                 $em->persist($budgetItem);
  10274.                 $em->flush();
  10275.             }
  10276.         }
  10277.         foreach ($arrayService as $key => $item) {
  10278.             if ($item == 'true'){
  10279.                 //Buscamos el servicio
  10280.                 $service $em->getRepository(ReservationService::class)->findOneById($key);
  10281.                 $budgetItem = new ReservationBudgetItems();
  10282.                 $budgetItem->setReservationId($budgetControl->getReservationId());
  10283.                 $budgetItem->setControlId($budgetControl->getId());
  10284.                 $budgetItem->setItemType('SERVICE');
  10285.                 $budgetItem->setSrvControlId($key);
  10286.                 $budgetItem->setSrvSupplierId($service->getSupplierId());
  10287.                 $budgetItem->setSrvServiceId($service->getServiceId());
  10288.                 $budgetItem->setSrvServiceCatId($service->getServiceCatId());
  10289.                 $budgetItem->setSrvServiceCatName($service->getServiceCatName());
  10290.                 $budgetItem->setSrvName($service->getName());
  10291.                 $budgetItem->setSrvPrice($service->getPrice());
  10292.                 $budgetItem->setSrvCurrency($service->getCurrency());
  10293.                 $budgetItem->setSrvUnits($service->getUnits());
  10294.                 $budgetItem->setSrvOpCommissions($service->getOpCommissions());
  10295.                 $budgetItem->setSrvCommissions($service->getCommissions());
  10296.                 $budgetItem->setSrvOpOver($service->getOpOver());
  10297.                 $budgetItem->setSrvOver($service->getOver());
  10298.                 $budgetItem->setSrvOpIva($service->getOpIva());
  10299.                 $budgetItem->setSrvIva($service->getIva());
  10300.                 $budgetItem->setSrvPax($service->getPax());
  10301.                 $budgetItem->setSrvHour($service->getHour());
  10302.                 $budgetItem->setSrvHour($service->getHour());
  10303.                 $budgetItem->setSrvDateInAt($service->getDateInAt());
  10304.                 $budgetItem->setSrvDateOutAt($service->getDateOutAt());
  10305.                 $budgetItem->setSrvContcolor($service->getContcolor());
  10306.                 $budgetItem->setSrvRank($service->getRank());
  10307.                 $budgetItem->setSrvAssistantId($service->getAssistantId());
  10308.                 $budgetItem->setSrvActivityId($service->getActivityId());
  10309.                 $budgetItem->setSrvPay($service->getPay());
  10310.                 $budgetItem->setCreatedAt(new DateTime('now'));
  10311.                 $budgetItem->setCreatedId($user_id);
  10312.                 $budgetItem->setUpdatedAt(new DateTime('now'));
  10313.                 $budgetItem->setUpdatedId($user_id);
  10314.                 $em->persist($budgetItem);
  10315.                 $em->flush();
  10316.             }
  10317.         }
  10318.         $data = array();
  10319.         $data $this->baseInvoiceDoneReservation($budgetControl->getReservationId(), 0,'P');
  10320. //        $allInvoices = $em->getRepository(ReservationInvoice::class)->findByReservationId($newInvoice->getReservationId());
  10321.         $allInvoices null;
  10322.             //Es una proforma
  10323. //        $proforma = $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
  10324.         $invoiceIdToRec null;
  10325.         return $this->render('MDS/GreenPatioBundle/reservations/budget-print.html.twig', array(
  10326.         'id' => $budgetControl->getReservationId(),
  10327.         'type' => $data['type'],
  10328.         'number' => $data['number'],
  10329.         'invoiceIdToRec' => $invoiceIdToRec,
  10330.         'prefix' => $data['prefix'],
  10331.         'date' => $data['date'],
  10332.         'token' => '',
  10333.         'company' => $data['company'],
  10334.         'clients' => $data['clients'],
  10335.         'datasupplier' => $data['datasupplier'],
  10336.         'totales_neto' => $data['totales_neto'],
  10337.         'bases_imponibles' => $data['bases_imponibles'],
  10338.         'totales' => $data['totales'],
  10339.         'balance' => $data['balance'],
  10340.         'currency' => $data['currency'],
  10341.         'paymentInvoice' => $data['paymentInvoice']
  10342.     ));
  10343.     }
  10344.     /**
  10345.      * @Route("/selinvoicesp/{id}",  name="reservations_select_invoice_special")
  10346.      * Vista previa para selecionar la entidad a la cual se le va a facturar (cliente o proveedor)
  10347.      */
  10348.     public function generateReservationSpecialInvoiceAction($idRequest $request)
  10349.     {
  10350.         $em $this->getDoctrine()->getManager();
  10351.         //Buscamos los clientes
  10352.         $clients $em->getRepository(Client::class)->findAll();
  10353.         //Buscamos los proveedores
  10354.         $suppliers $em->getRepository(Supplier::class)->findAll();
  10355.         //Unimos en un solo arreglo
  10356.         $arrayClients = array();
  10357.         foreach ($clients as $item){
  10358.             $arrayClients[] = array(
  10359.                 'nombre' => $item->getName(),
  10360.                 'id' => $item->getId(),
  10361.                 'tipo' => 'CLIENTE',
  10362.                 'indice' => 'C'.$item->getId(),
  10363.             );
  10364.         }
  10365.         foreach ($suppliers as $item){
  10366.             $arrayClients[] = array(
  10367.                 'nombre' => $item->getCompany(),
  10368.                 'id' => $item->getId(),
  10369.                 'tipo' => 'PROVEEDOR',
  10370.                 'indice' => 'S'.$item->getId(),
  10371.             );
  10372.         }
  10373.         return $this->render('MDS/GreenPatioBundle/reservations/services-invoice-select-client-supplier.html.twig',
  10374.             array(
  10375.                 'id' => $id,
  10376.                 'clients' => $arrayClients,
  10377.             )
  10378.         );
  10379.     }
  10380.     private function clientDataToInvoice($invoice$typeClient$idClient$reservationId){
  10381.         //Recibe una ReservationInvoice y se le agregan los datos del cliente
  10382.         $em $this->getDoctrine()->getManager();
  10383.         $address null;
  10384.         if (empty($invoice)){
  10385.             // Venimos de un selector y vamos a cotizar
  10386.             $reserva $em->getRepository(Reservation::class)->findOneById($reservationId);
  10387.             $typeClient 'Client'$idClient $reserva->getClient();
  10388.             $invoice = new ReservationInvoice();
  10389.         }
  10390.         if ($typeClient == 'Client'){
  10391.             $client $em->getRepository(Client::class)->findOneById($idClient); $typeClient 'Client';
  10392.             if (!empty($client)){ $name $client->getName(); $address $client->getAddress() . ' ' $client->getAddressNumber(); }
  10393.         } else {
  10394.             // Proveedor (Para facturas de comision)
  10395.             $client $em->getRepository(Supplier::class)->findOneById($idClient); $typeClient 'Supplier';
  10396.             if (!empty($client)){ $name $client->getCompany(); $address $client->getAddress(); }
  10397.         }
  10398.         if(empty($client)){
  10399.             // No se encontro el cliente o proveedor, se utilizará por defecto el de la reserva
  10400.             $reserva $em->getRepository(Reservation::class)->findOneById($invoice->getReservationId()); $typeClient 'Client';
  10401.             $client $em->getRepository(Client::class)->findOneById($reserva->getClient());
  10402.             if (!empty($client)){ $name $client->getName(); $address $client->getAddress() . ' ' $client->getAddressNumber(); }
  10403.         }
  10404.         $region $em->getRepository(Regions::class)->findOneById($client->getRegion());
  10405.         $country $em->getRepository(Country::class)->findOneById($client->getCountry());
  10406.         $address = (empty($client->getRegion())) ? $address $address', ' $region->getRegion();
  10407.         $address = (empty($client->getZipCode())) ? $address $address' - ' $client->getZipCode();
  10408.         $address = (empty($client->getCountry())) ? $address $address', ' $country->getCountry();
  10409.         $invoice->setClientAddress($address);
  10410.         $invoice->setClientName($name);
  10411.         $clientDocument null;
  10412.         $clientDocument = (empty($client->getTypeDocument())) ? $clientDocument $client->getTypeDocument();
  10413.         $clientDocument = (empty($client->getIdDocument())) ? ' ' $clientDocument': ' $client->getIdDocument();
  10414.         $invoice->setClientDocument($clientDocument);
  10415.         $invoice->setClientType($typeClient);
  10416.         return $invoice;
  10417.     }
  10418.     private function clientOrSupplierDataSearchToInvoice($index$reservationId){
  10419.         //Recibe un indice C22 o S41 para buscar los datos del cliente 22 o el proveedor 41 y pasar esos datos para la siguiente factura
  10420.         $em $this->getDoctrine()->getManager();
  10421.         $address null$name null$clientDocument null$typeClient null;
  10422.         if (substr($index,0,1) == 'C'){
  10423.             // Cliente
  10424.             $client $em->getRepository(Client::class)->findOneById(substr($index,1,strlen($index))); $typeClient 'Client';
  10425.             if (!empty($client)){ $name $client->getName(); $address $client->getAddress() . ' ' $client->getAddressNumber(); }
  10426.         } else {
  10427.             // Proveedor (Para facturas de comision)
  10428.             $client $em->getRepository(Supplier::class)->findOneById(substr($index,1,strlen($index))); $typeClient 'Supplier';
  10429.             if (!empty($client)){ $name $client->getCompany(); $address $client->getAddress(); }
  10430.         }
  10431.         if(empty($client)){
  10432.             // No se encontro el cliente o proveedor, se utilizará por defecto el de la reserva
  10433.             $reserva $em->getRepository(Reservation::class)->findOneById($reservationId); $typeClient 'Client';
  10434.             $client $em->getRepository(Client::class)->findOneById($reserva->getClient());
  10435.             if (!empty($client)){ $name $client->getName(); $address $client->getAddress() . ' ' $client->getAddressNumber(); }
  10436.         }
  10437.         $region $em->getRepository(Regions::class)->findOneById($client->getRegion());
  10438.         $country $em->getRepository(Country::class)->findOneById($client->getCountry());
  10439.         $address = (empty($client->getRegion())) ? $address $address', ' $region->getRegion();
  10440.         $address = (empty($client->getZipCode())) ? $address $address' - ' $client->getZipCode();
  10441.         $address = (empty($client->getCountry())) ? $address $address', ' $country->getCountry();
  10442.         $clientDocument = (empty($client->getTypeDocument())) ? $clientDocument $client->getTypeDocument();
  10443.         $clientDocument = (empty($client->getIdDocument())) ? ' ' $clientDocument': ' $client->getIdDocument();
  10444.         $dataClient = array(
  10445.                             'clientName' => $name,
  10446.                             'clientAddress' => $address,
  10447.                             'clientDocument' => $clientDocument,
  10448.                             'clientType' => $typeClient);
  10449.         return $dataClient;
  10450.     }
  10451.     private function selectorLineaDeFacturacion($id$lounge$service$payment$clientName$clientAddress$clientDocument$clientType){
  10452.         // Se elige si la factura ha de ir por GreenPatio o Covarrubias, las salas con ID > 21 son de Covarrubias
  10453.         $em $this->getDoctrine()->getManager();
  10454.         $parameters = array( 'id' => $id, );
  10455.         $dql 'SELECT p
  10456.                 FROM GreenPatioBundle:ReservationLoungeSimple p
  10457.                 WHERE p.idReservation = :id AND p.idLounge > 21';
  10458.         $query $em->createQuery($dql)->setParameters($parameters);
  10459.         $loungesSimples $query->getResult();
  10460.         if (!empty($loungesSimples)){
  10461.             // Redirigir a Covarrubias
  10462.             return $this->redirectToRoute('reservations_generatenew_invoice_cvr',
  10463.                 array(
  10464.                     'id' => $id,
  10465.                     'lounge' => $lounge,
  10466.                     'service' => $service,
  10467.                     'payment' => $payment,
  10468.                     'clientName' => $clientName,
  10469.                     'clientAddress' => $clientAddress,
  10470.                     'clientDocument' => $clientDocument,
  10471.                     'clientType' => $clientType
  10472.                 )
  10473.             );
  10474.         }
  10475.         return true;
  10476.     }
  10477. }