src/Noahtech/Sistemas/InterjamaBundle/Handler/McPrecargaHandler.php line 609

Open in your IDE?
  1. <?php
  2. namespace Noahtech\Sistemas\InterjamaBundle\Handler;
  3. use Noahtech\Sistemas\InterjamaBundle\Entity\McPrecarga;
  4. use Noahtech\Sistemas\InterjamaBundle\Utils\Constants;
  5. use Noahtech\Sistemas\InterjamaBundle\Utils\EmailsMessages;
  6. use Noahtech\Sistemas\InterjamaBundle\Utils\Encrypt;
  7. use DateInterval;
  8. use DateTime;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Component\DependencyInjection\ContainerInterface;
  11. use Symfony\Component\HttpKernel\Exception\HttpException;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Noahtech\Sistemas\InterjamaBundle\Utils\PDF;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Afip;
  16. use UltraMsg;
  17. use Exception;
  18. date_default_timezone_set('America/Argentina/Buenos_Aires');
  19. class McPrecargaHandler extends BaseHandler {
  20.     public function __construct(ContainerInterface $containerEntityManagerInterface $entityManager) {
  21.         $this->container $container;
  22.         $this->entityManager $entityManager;
  23.         $this->repository $entityManager->getRepository(McPrecarga::class);
  24.     }
  25.     public function search($offset$limit$sortField$sortDirection$searchParam) {
  26.         $lp $this->repository->search($offset$limit$sortField$sortDirection$searchParam);
  27.         $precargas $this->toarray($lp->getListado(), 'precarga');
  28.         $lp->setListado($precargas);
  29.         return $lp;
  30.     }
  31.     public function searchPrecargasFinalizadas($offset$limit$sortField$sortDirection$searchParam) {
  32.         $lp $this->repository->searchPrecargasFinalizadas($offset$limit$sortField$sortDirection$searchParam);
  33.         $montoAduana $this->repository->getTotalMontoAduana($searchParam);
  34.         // Estructura base con todos los valores en 0
  35.         $montoAduanaDefault = [
  36.             'argentinos' => 0,
  37.             'bolivianos' => 0,
  38.             'chilenos' => 0,
  39.             'paraguayos' => 0,
  40.             'dolares' => 0,
  41.             'reales' => 0,
  42.             'soles' => 0
  43.         ];
  44.         // Si hay resultados, los combinamos con los valores por defecto
  45.         if (!empty($montoAduana) && isset($montoAduana[0])) {
  46.             $montoAduanaFinal array_merge($montoAduanaDefault$montoAduana[0]);
  47.         } else {
  48.             $montoAduanaFinal $montoAduanaDefault;
  49.         }
  50.         $precargas $this->toarray($lp->getListado(), 'precarga');
  51.         if (count($precargas) > 0) {
  52.             // Solo el primer registro incluirá el monto total
  53.             $precargas[0]['montoAduana'] = $montoAduanaFinal;
  54.         }
  55.         // Inicializamos variables para el cálculo de totales
  56.         $totalesPagos = [];
  57.         // Definimos los ids las monedas que nos interesan
  58.         $divisas = [1234567];
  59.         foreach ($precargas as &$precarga) {
  60.             $precarga['tiposTramites'] = $this->container
  61.                 ->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")
  62.                 ->getByPrecarga((int)$precarga['id']);
  63.             $precarga["hoja_ruta"] = false;
  64.             // Verificar si el trámite es 'Entrada'
  65.             if ($precarga['tramite'] === 'Entrada') {
  66.                 foreach ($precarga['tiposTramites'] as &$tipo) {
  67.                     if (stripos($tipo["tipos_tramite"]["nombre"], 'cargado') !== false) {
  68.                         $precarga["hoja_ruta"] = true;
  69.                         break;
  70.                     }
  71.                 }
  72.             }
  73.             // Tipo de pago
  74.             $tipoPago $precarga['tipo_pago'];
  75.             // Inicializamos el array para este tipo de pago si no existe
  76.             if (!isset($totalesPagos[$tipoPago])) {
  77.                 $totalesPagos[$tipoPago] = [];
  78.             }
  79.             // ID y nombre de la moneda
  80.             $monedaId $precarga['moneda']['id'];
  81.             $monedaNombre $precarga['moneda']['nombre'];
  82.             // Inicializamos la moneda si no existe
  83.             if (!isset($totalesPagos[$tipoPago][$monedaId])) {
  84.                 $totalesPagos[$tipoPago][$monedaId] = [
  85.                     'nombre' => $monedaNombre,
  86.                     'total' => 0
  87.                 ];
  88.             }
  89.             // Sumamos total + aduana para esa moneda
  90.             $montoAAgregar = (float)$precarga['total'] + (float)$precarga['aduana'];
  91.             $totalesPagos[$tipoPago][$monedaId]['total'] += $montoAAgregar;
  92.         }
  93.         // Asignamos los totales calculados al primer registro
  94.         if (count($precargas) > 0) {
  95.             $precargas[0]['totalesPagos'] = $totalesPagos;
  96.         }
  97.         $lp->setListado($precargas);
  98.         return $lp;
  99.     }
  100.     public function searchPrecargasFinalizadasConDeudas($offset$limit$sortField$sortDirection$searchParam) {
  101.         $lp $this->repository->searchPrecargasFinalizadasConDeudas($offset$limit$sortField$sortDirection$searchParam);
  102.         $precargas $this->toarray($lp->getListado(), 'precarga');
  103.         $lp->setListado($precargas);
  104.         return $lp;
  105.     }
  106.     public function searchPrecargasFumigadas($offset$limit$sortField$sortDirection$searchParam) {
  107.         $lp $this->repository->searchPrecargasFumigadas($offset$limit$sortField$sortDirection$searchParam);
  108.         $precargas $this->toarray($lp->getListado(), 'precarga');
  109.         $lp->setListado($precargas);
  110.         return $lp;
  111.     }
  112.     public function searchPrecargasByCliente($offset$limit$sortField$sortDirection$searchParam) {
  113.         $lp $this->repository->searchPrecargasByCliente($offset$limit$sortField$sortDirection$searchParam);
  114.         $precargas $this->toarray($lp->getListado(), 'precarga');
  115.         $lp->setListado($precargas);
  116.         return $lp;
  117.     }
  118.     public function searchPrecargasByChofer($offset$limit$sortField$sortDirection$searchParam) {
  119.         $lp $this->repository->searchPrecargasByChofer($offset$limit$sortField$sortDirection$searchParam);
  120.         $precargas $this->toarray($lp->getListado(), 'precarga');
  121.         $lp->setListado($precargas);
  122.         return $lp;
  123.     }
  124.     public function searchAtenciones($offset$limit$sortField$sortDirection$searchParam) {
  125.         $lp $this->repository->searchPrecargasAtendidas($offset$limit$sortField$sortDirection$searchParam);
  126.         $precargas $this->toarray($lp->getListado(), 'precarga');
  127.         foreach ($precargas as &$precarga) {
  128.             $precarga['tiposTramites'] = $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")->getByPrecarga((int)$precarga['id']);
  129.             $precarga["hoja_ruta"] = false;
  130.             foreach ($precarga['tiposTramites'] as &$tipo) {
  131.                 if ($tipo["tipos_tramite"]["nombre"] == 'Entrada cargado') {
  132.                     $precarga["hoja_ruta"] = true;
  133.                 }
  134.             }
  135.         }
  136.         $lp->setListado($precargas);
  137.         return $lp;
  138.     }
  139.     public function searchPrecargasParaFinalizar($offset$limit$sortField$sortDirection$searchParam) {
  140.         $lp $this->repository->searchPrecargasParaFinalizar($offset$limit$sortField$sortDirection$searchParam);
  141.         $precargas $this->toarray($lp->getListado(), 'precarga');
  142.         foreach ($precargas as &$precarga) {
  143.             $precarga['tiposTramites'] = $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")->getByPrecarga((int)$precarga['id']);
  144.             $precarga["hoja_ruta"] = false;
  145.             foreach ($precarga['tiposTramites'] as &$tipo) {
  146.                 if ($tipo["tipos_tramite"]["nombre"] == 'Entrada cargado') {
  147.                     $precarga["hoja_ruta"] = true;
  148.                 }
  149.             }
  150.         }
  151.         $lp->setListado($precargas);
  152.         return $lp;
  153.     }
  154.     public function getPrecargaSinFinalizarByDominio($dominio) {
  155.         $aux null;
  156.         $precarga $this->repository->findBy(array('dominio1' => $dominio'estado' => [0,1,2]));
  157.         if (COUNT($precarga) > 0) {
  158.             $aux $this->toarray($precarga'precarga');
  159.         }
  160.         return $aux;
  161.     }
  162.     public function getVehiculoByDominio($dominio1) {
  163.         $aux null;
  164.         $vehiculo $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McVehiculoHandler")->getVehiculoByDominio($dominio1);
  165.         if (!is_null($vehiculo)) {
  166.             $precarga $this->getPrecargaSinFinalizarByDominio($dominio1);
  167.             if (is_null($precarga)) {
  168.                 $aux $this->toarray($vehiculo"vehiculo");
  169.             } else {
  170.                 throw new HttpException(409"El dominio ingresado " $dominio1" tiene una precarga no Finalizada."); 
  171.             }
  172.         };
  173.         return $aux;
  174.     }
  175.     public function getVehiculoByDominioByCliente($dominio1$clienteId) {
  176.         $aux null;
  177.         $vehiculo =  $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McVehiculoHandler")->getVehiculoByDominioByCliente($dominio1,$clienteId);
  178.         if (!is_null($vehiculo)) {
  179.             $precarga $this->getPrecargaByDominioByCliente($dominio1$clienteId);
  180.             if (is_null($precarga)) {
  181.                 $aux $this->toarray($vehiculo"vehiculo");
  182.             } else {
  183.                 throw new HttpException(409"El dominio ingresado " $dominio1" tiene una precarga no Finalizada."); 
  184.             }
  185.         };
  186.         return $aux
  187.     }
  188.     public function base64ToImage($val_pic) {
  189.         $path $this->getPathFiles();
  190.         //Crea la carpeta si no existe
  191.         if (!file_exists($path)) {
  192.             mkdir($path0777true);
  193.         }
  194.         $fname 'foto';
  195.         $fextension 'png';
  196.         $nameMd5 md5($fname.time());
  197.         $nameFileMd5 "$nameMd5.$fextension";
  198.         $nameFileMd5File "$nameMd5.$fextension";
  199.         $pathFile $path.$nameFileMd5;
  200.         $img str_replace('data:image/png;base64,'''$val_pic);
  201.         $img str_replace(' ''+'$img);
  202.         $img base64_decode($img);
  203.         file_put_contents($pathFile$img);
  204.         return $nameFileMd5File;
  205.     }
  206.     public function comprobarArchivo($archivo$foto) {
  207.         //Sección que almadena el archivo relacionado                
  208.         if (!is_null($archivo) && $archivo['name'] !== '') {
  209.             $pathFile $this->saveImageFile($archivo);           
  210.             if ($archivo['result']) {            
  211.                 $archivo $archivo['name_file_Md5'];            
  212.             } else {
  213.                 $this->deleteFile($pathFile);            
  214.             }
  215.         } else if (isset($foto)) {
  216.             $fotoFile $this->base64ToImage($foto);
  217.             $archivo $fotoFile;               
  218.         } else {
  219.             $archivo null;
  220.         }
  221.         return $archivo;  
  222.         // fin carga de archivo
  223.     }
  224.     public function getPrecargaFromRequest(Request $request$usuarioint $id null): McPrecarga {
  225.         $dominio1 $request->request->get('dominio1');
  226.         $dominio2 $request->request->get('dominio2');
  227.         if (is_null($dominio2) || empty($dominio2) || $dominio2 == 'null') {
  228.             $dominio2 null;
  229.         }
  230.         $chofer $request->request->get('chofer');
  231.         $tramite str_replace('string:'''$request->request->get('tramite'));
  232.         $clienteId = (int)$request->request->get('cliente_id');
  233.         $cliente $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McClienteHandler")
  234.         ->getClienteById($clienteId);
  235.         $registro $request->request->get('registro');
  236.         $tras $request->request->get('tras');
  237.         $rg $request->request->get('rg');
  238.         $tlmd $request->request->get('tlmd');
  239.         $mani $request->request->get('mani');
  240.         $aduana $request->request->get('aduana');
  241.         $aduana_nombre str_replace('string:'''$request->request->get('aduana_nombre'));
  242.         $plazo $request->request->get('plazo');
  243.         $tipoOperacion $request->request->get('tipo_operacion');
  244.         $paisOrigen $request->request->get('pais_origen');
  245.         $mercaderia $request->request->get('mercaderia');
  246.         $expImp $request->request->get('exp_imp');
  247.         $tipoPago str_replace('string:'''$request->request->get('tipo_pago'));
  248.         $monedaId = (int)$request->request->get('moneda');
  249.         $moneda $this->container
  250.         ->get("Noahtech\Sistemas\InterjamaBundle\Handler\McMonedaHandler")
  251.         ->getMonedaById((int)$monedaId);
  252.         $total $request->request->get('total');
  253.         $mercaderia1 $request->request->get('mercaderia_1');
  254.         if (is_null($id)) {
  255.             $precarga = new McPrecarga();
  256.             $precarga->setFechaCreacion(new DateTime());
  257.             $precarga->setEstado(3);
  258.             $precarga->setLeido('Leido');
  259.         } else {
  260.             $precarga $this->repository->findOneById($id);
  261.             $precarga->setFechaActualizacion(new DateTime());
  262.             $precarga->setLeido('Leido');
  263.         }
  264.         // Validar duplicado de registro
  265.         if (!is_null($registro)) {
  266.             $registroExistente $this->repository->buscarNumRegistro(trim($registro), null);
  267.             if (COUNT($registroExistente) > 0) {
  268.                 throw new HttpException(409"El N° de Registro " $registro " ya se encuentra almacenado en el sistema."); 
  269.             }
  270.         }
  271.         // Seteo de campos
  272.         $precarga->setTramite($tramite);
  273.         $precarga->setTipoPago($tipoPago);
  274.         $precarga->setMoneda($moneda);
  275.         $precarga->setTotal($total);
  276.         $precarga->setRegistro($registro);
  277.         $precarga->setTras(!is_null($tras) ? json_encode($tras) : null);
  278.         $precarga->setRg($rg);
  279.         $precarga->setTlmd($tlmd);
  280.         $precarga->setMani($mani);
  281.         $precarga->setAduana($aduana);
  282.         $precarga->setAduanaNombre($aduana_nombre);
  283.         $precarga->setPlazo($plazo);
  284.         $precarga->setTipoOperacion($tipoOperacion);
  285.         $precarga->setPaisOrigen($paisOrigen);
  286.         $precarga->setMercaderia($mercaderia);
  287.         $precarga->setExpImp($expImp);
  288.         $precarga->setDominio1($dominio1);
  289.         $precarga->setDominio2($dominio2);
  290.         $precarga->setChofer($chofer);
  291.         $precarga->setUsuario($usuario);
  292.         $precarga->setCliente($cliente);
  293.         $precarga->setMercaderia1($mercaderia1);
  294.         return $precarga;
  295.     }
  296.     public function saveImageFile(&$archivo){
  297.         $data['result'] = false;
  298.         $path $this->getPathFiles();
  299.         //Crea la carpeta si no existe
  300.         if (!file_exists($path)) {
  301.             mkdir($path0777true);
  302.         }
  303.         $info pathinfo($archivo['name']);
  304.         $ext $info['extension']; // get the extension of the file
  305.         $name $info['filename'];
  306.         
  307.         $nameMd5 md5($name.time());
  308.         $nameFileMd5 "$nameMd5.$ext";
  309.         $nameFileMd5File "$nameMd5.$ext";
  310.         $pathFile $path.$nameFileMd5;
  311.         
  312.         $archivo['result'] = true;
  313.         move_uploaded_file($archivo['tmp_name'], $pathFile);
  314.         $archivo['name_md5']=$nameMd5;
  315.         $archivo['name_file_Md5'] = $nameFileMd5;
  316.         $archivo['path_file']=$pathFile;
  317.         $archivo['path_only']=$path;
  318.         return $pathFile;
  319.     }
  320.     private function getPathFiles(){
  321.         $basePath $this->container->getParameter('kernel.root_dir');
  322.         $basePath str_replace('/app''/web'$basePath);        
  323.         
  324.         $basePath $basePath $this->container->getParameter('path_files_precargas');
  325.         $path "$basePath/";
  326.         return $path;
  327.     }
  328.     private function deleteFile($pathFile) {
  329.         try {
  330.             unlink($pathFile);
  331.         } catch (Exception $e) {
  332.         }
  333.         return $pathFile;
  334.     }
  335.     public function validarPrecargaSinFinalizar($precarga) {
  336.         $precargaSinFinalizar $this->repository->getPrecargasSinfinalizar($precarga->getId(), $precarga->getDominio1());
  337.         if (!is_null($precargaSinFinalizar)) {
  338.             throw new HttpException(409"El dominio ingresado " $precarga->getDominio1(). " cuenta con una precarga sin finalizar."); 
  339.         }
  340.     }
  341.     public function validarPrecargaAndCrt ($crt) {
  342.         if (!is_null($crt->request->get('crt'))) {
  343.             $crtId = (int)$crt->request->get('crt');
  344.             $crtCantidad = (int)$crt->request->get('cantidad');
  345.             $crtDB $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McCrtHandler")->getCrtById($crtId);
  346.             $cantidadBd $crtDB->getCantidad();
  347.             $precargasCrt $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaCrtHandler")->getCantidadPrecargaCrtByCrt($crtId);
  348.             if (COUNT($precargasCrt) > 0) {
  349.                 $cantidadAux 0;
  350.                 //Realizar el calculo
  351.                 foreach ($precargasCrt as $crt) {
  352.                     $cantidadAux $cantidadAux $crt->getCantidad();
  353.                 }
  354.                 $cantidadAux $cantidadAux $crtCantidad;
  355.                 if ($cantidadAux $cantidadBd) {
  356.                     throw new HttpException(409"La Cantidad ingresada es mayor a la cantidad registrada para el CRT ingresado."); 
  357.                 }
  358.             } else {
  359.                 if ($crtCantidad $cantidadBd) {
  360.                     throw new HttpException(409"La Cantidad ingresada es mayor a la cantidad registrada para el CRT ingresado."); 
  361.                 }
  362.             }
  363.         }
  364.     }
  365.     public function save(McPrecarga $precargaRequest $request) {
  366.         //$this->validarPrecargaSinFinalizar($precarga);
  367.         $this->validarPrecargaAndCrt($request);
  368.         // Guardar la precarga
  369.         $precarga $this->repository->save($precarga);
  370.         // Registro de movimiento en caja
  371.         $monedaId str_replace('number:'''$request->request->get('moneda'));
  372.         $cajaId $request->request->get('caja');
  373.         $tipoPago str_replace('string:'''$request->request->get('tipo_pago'));
  374.         $total $request->request->get('total');
  375.         if (!is_numeric((int)$monedaId) || !is_numeric((int)$cajaId) || !is_numeric((float)$total)) {
  376.             throw new HttpException(400"Datos numéricos inválidos para el movimiento de caja.");
  377.         }
  378.         $moneda $this->container
  379.         ->get("Noahtech\Sistemas\InterjamaBundle\Handler\McMonedaHandler")
  380.         ->getMonedaById((int)$monedaId);
  381.         $this->container
  382.         ->get("Noahtech\Sistemas\InterjamaBundle\Handler\McMovimientoHandler")
  383.         ->saveFromAtencionPrecarga((int)$monedaId, (int)$cajaId$tipoPago, (float)$total$precarga->getUsuario(), $precarga);
  384.         // Guardar tipos de trámite
  385.         $tiposTramites $request->request->get('tipoTramite');
  386.         $importes $request->request->get('importe');
  387.         if (!is_array($tiposTramites)) {
  388.             throw new HttpException(400"Los tipos de trámite deben ser enviados como un arreglo.");
  389.         }
  390.         foreach ($tiposTramites as $key => $value) {
  391.             $tipoId str_replace('number:'''$value);
  392.             $this->container
  393.             ->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")
  394.             ->saveNew($precarga, (int)$tipoId$importes[$key]);
  395.         }
  396.         // Guardar precarga_crt si viene en request
  397.         $this->container
  398.         ->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaCrtHandler")
  399.         ->savePrecargaCrt($precarga$request);
  400.         // Actualizo el turno como atendido = 1
  401.         $this->container
  402.         ->get("Noahtech\Sistemas\InterjamaBundle\Handler\McTurnoHandler")
  403.         ->update((int)$request->request->get('turno'));
  404.         $precarga $this->toarray($precarga"precarga");
  405.         $precarga['tiposTramites'] = $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")->getByPrecarga((int)$precarga['id']);
  406.         return $precarga;
  407.     }
  408.     public function update(McPrecarga $precarga$archivosRequest $requestint $id) {
  409.         $this->validarPrecargaSinFinalizar($precarga);
  410.         $precarga $this->repository->update($precarga);
  411.         //Compruebo si hay que eliminar archivos
  412.         $removeArchivosIds $request->request->get('removeIdArchivo'); // Array;
  413.         $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaArchivoHandler")->removeArchivo($precarga->getId(), $removeArchivosIds);
  414.         //Se editan o eliminan las imagenes/fotos en la edición de la precarga
  415.         $fotos $request->request->get('fotos'); // Array
  416.         $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaArchivoHandler")->save($precarga$fotostrue);
  417.         $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaArchivoHandler")->save($precarga$archivosfalse);
  418.         $precarga $this->toarray($precarga"precarga");
  419.         return $precarga;
  420.     }
  421.     public function getById($id) {
  422.         $precarga $this->repository->findOneById($id);
  423.         $precarga $this->toarray($precarga"precarga");
  424.         $precarga['archivos'] = $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaArchivoHandler")->findAllByPrecarga((int)$id);
  425.         return $precarga;
  426.     }
  427.     public function getPrecargaById($id) {
  428.         return $this->repository->findOneById($id);        
  429.     }
  430.     public function getPrecargaByCliente($id$clienteId) {
  431.         return $this->repository->findBy(array('id' => $id'cliente' => $clienteId));        
  432.     }
  433.     public function getPrecargaByChofer($id$choferId) {
  434.         return $this->repository->findBy(array('id' => $id'choferId' => $choferId));        
  435.     }
  436.     public function updateFacturado(McPrecarga $precarga) {
  437.         $precarga->setFacturado(true);
  438.         return $this->update($precarga$precarga->getId());
  439.     }
  440.     public function getPrecargaByDominio($dominio) {
  441.         $precarga $this->repository->findBy(array('dominio1' =>$dominio));
  442.         if (COUNT($precarga) > 0) {
  443.             $band false;
  444.             foreach ($precarga as &$pre) {
  445.                 if ($pre->getEstado() != 1) {
  446.                     $band true;
  447.                 }
  448.                 if ($band) {
  449.                     $pre $this->toarray($pre"precarga");
  450.                     //Obtengo los datos del tipo de tramites que se registraron
  451.                     $pre['tiposTramites'] = $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")->getByPrecarga((int)$pre['id']);
  452.                     return $pre;
  453.                 }               
  454.             }
  455.             if (!$band) {
  456.                 throw new HttpException(409"El dominio ingresado " $dominio " tiene una precarga en estado Finalizada. Registre una nueva precarga para realizar esta acción."); 
  457.             }
  458.         } else {
  459.             throw new HttpException(409"El dominio ingresado " $dominio" no esta registrado en una precarga en nuestra base de datos. Registre el dominio en el sistema dentro de Precargas para realizar esta acción."); 
  460.         }
  461.     }
  462.     public function getPrecargaByDominioByCliente($dominio$clienteId) {
  463.         $aux null;
  464.         $precarga $this->repository->findBy(array('dominio1' => $dominio'estado' => [0,1,2], 'cliente' => $clienteId));
  465.         if (COUNT($precarga) > 0) {
  466.             $aux $this->toarray($precarga"precarga");
  467.         }
  468.         return $aux;
  469.     }
  470.     public function getAtencionPrecargaFromRequest(Request $requestint $id$usuario):McPrecarga {
  471.         $chofer $request->request->get('chofer');
  472.         $dominio1 $request->request->get('dominio1');
  473.         $dominio2 $request->request->get('dominio2');
  474.         if (is_null($dominio2) || empty($dominio2) || $dominio2 == 'null') {
  475.             $dominio2 null;
  476.         }
  477.         $tramite $request->request->get('tramite');
  478.         $tipoPago $request->request->get('tipo_pago');
  479.         $total $request->request->get('total');
  480.         $registro $request->request->get('registro');
  481.         $tras $request->request->get('tras');
  482.         $rg $request->request->get('rg');
  483.         $tlmd $request->request->get('tlmd');
  484.         $mani $request->request->get('mani');
  485.         $tiposTramites $request->request->get('tiposTramite');
  486.         $aduana $request->request->get('aduana');
  487.         $aduana_nombre $request->request->get('aduana_nombre');
  488.         $plazo $request->request->get('plazo');
  489.         //Campos de intervención SENESA
  490.         $tipoOperacion $request->request->get('tipo_operacion');
  491.         $paisOrigen $request->request->get('pais_origen');
  492.         $mercaderia $request->request->get('mercaderia');
  493.         $expImp $request->request->get('exp_imp');
  494.         $mercaderia1 $request->request->get('mercaderia_1');
  495.         $detalle_cambio $request->request->get('detalle_cambio');
  496.         $clienteId = (int)$request->request->get('cliente');
  497.         $cliente $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McClienteHandler")->getClienteById($clienteId);
  498.         $precarga $this->repository->findOneById($id);
  499.         //Seccion donde guardo el movimiento en la caja
  500.         $monedaId $request->request->get('moneda');
  501.         $moneda $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McMonedaHandler")->getMonedaById((int)$monedaId);
  502.         $cajaId $request->request->get('caja');
  503.         $movimiento =  $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McMovimientoHandler")->saveFromAtencionPrecarga((int)$monedaId, (int)$cajaId$tipoPago, (float)$total$usuario,  $precarga);
  504.         // Fin del registro del movimiento
  505.         // Elimino todos los tipos y agrego los que vienen
  506.         $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")->removeAllTiposByPrecarga((int)$id);
  507.         // Corroboramos que no exista el mismo N° de Registro
  508.         if (!is_null($registro)) {
  509.             $registroExistente $this->repository->buscarNumRegistro(trim($registro), $id);
  510.             $registroExistente $this->toarray($registroExistente'precarga');
  511.             if (COUNT($registroExistente) > 0) {
  512.                 throw new HttpException(409"El N° de Registro " $registro" ya se encuentra almacenado en el sistema."); 
  513.             }
  514.         }
  515.         
  516.         foreach ($tiposTramites as &$tipo) {
  517.             $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")->save($id$tipo);
  518.         };
  519.         $precarga->setChofer($chofer);
  520.         $precarga->setDominio1($dominio1);
  521.         $precarga->setDominio2($dominio2);
  522.         $precarga->setCliente($cliente);
  523.         $precarga->setTramite($tramite);
  524.         $precarga->setTipoPago($tipoPago);
  525.         $precarga->setMoneda($moneda);
  526.         $precarga->setTotal($total);
  527.         $precarga->setRegistro($registro);
  528.         $precarga->setTras($tras);
  529.         $precarga->setRg($rg);
  530.         $precarga->setTlmd($tlmd);
  531.         $precarga->setMani($mani);
  532.         $precarga->setAduana($aduana);
  533.         $precarga->setAduanaNombre($aduana_nombre);
  534.         $precarga->setPlazo($plazo);
  535.         $precarga->setTipoOperacion($tipoOperacion);
  536.         $precarga->setPaisOrigen($paisOrigen);
  537.         $precarga->setMercaderia($mercaderia);
  538.         $precarga->setExpImp($expImp);
  539.         $precarga->setMercaderia1($mercaderia1);
  540.         $precarga->setDetalleCambio($detalle_cambio);
  541.         return $precarga;
  542.     }
  543.     public function updateAtencion(McPrecarga $precargaint $id) {
  544.         // Corroboramos que no exista el mismo N° de Registro
  545.         if (!is_null($precarga->getRegistro())) {
  546.             $registroExistente $this->repository->buscarNumRegistro($precarga->getRegistro(), $id);
  547.             $registroExistente $this->toarray($registroExistente'precarga');
  548.             if (COUNT($registroExistente) > 0) {
  549.                 throw new HttpException(409"El N° de Registro " $precarga->getRegistro(). " ya se encuentra almacenado en el sistema."); 
  550.             }
  551.         }
  552.         $precarga $this->repository->update($precarga);
  553.         $precarga $this->toarray($precarga"precarga");
  554.         $precarga['tiposTramites'] = $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")->getByPrecarga((int)$precarga['id']);
  555.         return $precarga;
  556.     }
  557.     public function searchPrecargasAtendidas($offset$limit$sortField$sortDirection$searchParam) {
  558.         $lp $this->repository->searchPrecargasAtendidas($offset$limit$sortField$sortDirection$searchParam);
  559.         $precargas $this->toarray($lp->getListado(), 'precarga');
  560.         $lp->setListado($precargas);
  561.         return $lp;
  562.     }
  563.     public function getPrecargaAtencionById ($id) {
  564.         $precarga $this->repository->findOneById($id);
  565.         $precarga $this->toarray($precarga"precarga");
  566.         $precarga['tiposTramites'] = $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")->getByPrecarga((int)$precarga['id']);
  567.         return $precarga;
  568.     }
  569.     public function getAtencionPrecargaFinalizarFromRequest(Request $request$archivo$usuarioint $id null):McPrecarga {
  570.         $foto $request->request->get('foto');
  571.         $precarga $this->repository->findOneById($id);
  572.         $precarga->setFechaActualizacion(new DateTime());
  573.         $archivoBD $precarga->getArchivo();
  574.         $archivoReverso $this->comprobarArchivo($archivo,$foto);
  575.         $precarga->setUsuario($usuario);
  576.         $precarga->setEstado(3); //Estado de finalización de la atención
  577.         $precarga->setArchivoReverso($archivoReverso);
  578.         //Envio mensaje de WhatsApp al chofer con la finaliazaion del trámite
  579.         //$this->sendMessaggeWhatsApp($precarga);  
  580.         return $precarga;
  581.     }
  582.     public function descargaManifiestoPdf($id) {
  583.         $precarga $this->getById((int)$id);
  584.         $trastlmd ' - ';
  585.         $trastlmdNumero ' - ';
  586.         if (!is_null($precarga['tras']) && trim($precarga['tras']) != '') {
  587.             $trastlmd 'TRAS';
  588.             $trastlmdNumero $precarga['tras'];
  589.         } else if (!is_null($precarga['tlmd']) && trim($precarga['tlmd']) != '') {
  590.             $trastlmd 'TLMD';
  591.             $trastlmdNumero $precarga['tlmd'];
  592.         }
  593.         $fechaHoy date('d/m/Y');
  594.         $anio date('Y');
  595.         $basePath $this->container->getParameter('kernel.root_dir');
  596.         $urlLogo strstr($basePath'app_dev.php'true);
  597.         $urlLogo .= "app/images/afip-logo.jpeg";
  598.         // create new PDF document
  599.         $pdf = new PDF();       
  600.         $pdf->SetTitle("Panilla - Afip");
  601.         $pdf->SetSubject("Panilla - Afip");
  602.         $pdf->setFontSubsetting(true);
  603.         // set default header data
  604.         $pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTHPDF_HEADER_TITLEPDF_HEADER_STRING);
  605.         $pdf->SetFont('helvetica'''11''true);
  606.         $pdf->SetMargins(PDF_MARGIN_LEFTPDF_MARGIN_TOPPDF_MARGIN_RIGHT);
  607.         $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  608.         $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  609.         $pdf->setPrintFooter(false);
  610.         // set auto page breaks
  611.         $pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);
  612.         // set image scale factor
  613.         $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  614.         $pdf->AddPage('P''A4');
  615.         $pdf->Image($urlLogo1543525'JPEG'''''false150''falsefalse0falsefalsefalse);
  616.         $html = <<<EOD
  617.         <br/>
  618.         <div style="text-align: center;">
  619.         <span style="font-size: 30px; font-weight: bold;">MANIFIESTO DE CARGA</span>
  620.         </div>
  621.         <div style="text-align: left;">
  622.         <h2> ADUANA DE: <u>JUJUY - ACI - PASO DE JAMA</u></h2>
  623.         </div>
  624.         <div style="float:left; clear:none;">
  625.         <strong style="text-align: left;font-size: 17px;"> AÑO: </strong><span style="font-size: 17px;">{$anio}</span> &nbsp;&nbsp;&nbsp;<strong style="text-align: left;font-size: 17px;">ADUANA: </strong><span style="font-size: 17px;">031</span>&nbsp;&nbsp;&nbsp;<strong style="text-align: left;font-size: 17px;">MANI: </strong><span style="font-size: 17px;">{$precarga['mani']}</span><br>
  626.         EOD;
  627.         if ($trastlmd == 'TLMD') {
  628.             $html .= <<<EOD
  629.             <strong style="text-align: left; font-size: 17px;"> AÑO: </strong><span style="font-size: 17px;">{$anio}</span> &nbsp;&nbsp;&nbsp;<strong style="text-align: right; font-size: 17px;">ADUANA: </strong><span style="font-size: 17px;">031</span>&nbsp;&nbsp;&nbsp;<strong style="text-align: left; font-size: 17px;">{$trastlmd}: </strong><span style="font-size: 17px;">{$trastlmdNumero}</span><br>
  630.             </div>
  631.             <br/>
  632.             <div style="text-align: center;">
  633.             <span style="font-size: 20px;">/__/__/__/__/__/</span>
  634.             </div>
  635.             <div style="text-align: center;">
  636.             <span style="font-size: 20px;">/__/__/__/__/__/</span>
  637.             </div>
  638.             <div style="text-align: center;">
  639.             <span style="font-size: 20px;">/__/__/__/__/__/</span>
  640.             </div>
  641.             EOD;
  642.         } else {
  643.             $trastlmdNumero json_decode($trastlmdNumero);
  644.             if (!is_array($trastlmdNumero)) {
  645.                 $html .= <<<EOD
  646.                 <strong style="text-align: left; font-size: 17px;"> AÑO: </strong><span style="font-size: 17px;">{$anio}</span> &nbsp;&nbsp;&nbsp;<strong style="text-align: right; font-size: 17px;">ADUANA: </strong><span style="font-size: 17px;">031</span>&nbsp;&nbsp;&nbsp;<strong style="text-align: left; font-size: 17px;">{$trastlmd}: </strong><span style="font-size: 17px;">{$trastlmdNumero}</span><br>
  647.                 </div>
  648.                 <br/>
  649.                 EOD;
  650.             } else {
  651.                 if (COUNT($trastlmdNumero) == 0) {
  652.                     $html .= <<<EOD
  653.                     <strong style="text-align: left; font-size: 17px;"> AÑO: </strong><span style="font-size: 17px;">{$anio}</span> &nbsp;&nbsp;&nbsp;<strong style="text-align: right; font-size: 17px;">ADUANA: </strong><span style="font-size: 17px;">031</span>&nbsp;&nbsp;&nbsp;<strong style="text-align: left; font-size: 17px;">{$trastlmd}: </strong> - <br>
  654.                     </div>
  655.                     <br/>
  656.                     <div style="text-align: center;">
  657.                     <span style="font-size: 20px;">/__/__/__/__/__/</span>
  658.                     </div>
  659.                     <div style="text-align: center;">
  660.                     <span style="font-size: 20px;">/__/__/__/__/__/</span>
  661.                     </div>
  662.                     <div style="text-align: center;">
  663.                     <span style="font-size: 20px;">/__/__/__/__/__/</span>
  664.                     </div>
  665.                     EOD;
  666.                 } else {
  667.                     if (COUNT($trastlmdNumero) > 1) {
  668.                         foreach ($trastlmdNumero as $key => $value ) {
  669.                             $html .= <<<EOD
  670.                             <strong style="text-align: left;"> AÑO: </strong>{$anio} &nbsp;&nbsp;&nbsp;<strong style="text-align: right;">ADUANA: </strong>031&nbsp;&nbsp;&nbsp;<strong style="text-align: left;">{$trastlmd}: </strong>{$value}<br>
  671.                             EOD;
  672.                         }
  673.                         $html .= <<<EOD
  674.                         </div>
  675.                         EOD;
  676.                     } else {
  677.                         $html .= <<<EOD
  678.                         <div style="text-align: center;">
  679.                         <span style="font-size: 20px;">/__/__/__/__/__/</span>
  680.                         </div>
  681.                         <div style="text-align: center;">
  682.                         <span style="font-size: 20px;">/__/__/__/__/__/</span>
  683.                         </div>
  684.                         <div style="text-align: center;">
  685.                         <span style="font-size: 20px;">/__/__/__/__/__/</span>
  686.                         </div>
  687.                         EOD;
  688.                     }
  689.                 }
  690.             }
  691.         }
  692.         $html .= <<<EOD
  693.         <div style="text-align: center;">
  694.         <span style="font-size: 30px; font-weight: bold;">SISTEMA INFORMÁTICO</span>
  695.         </div>
  696.         <div style="text-align: center;">
  697.         <span style="font-size: 50px; font-weight: bold;">MALVINAS</span>
  698.         </div>
  699.         <div style="text-align: center;">
  700.         <span style="font-size: 30px; font-weight: bold;">(S.I.M)</span>
  701.         </div>
  702.         <br/>
  703.         <div style="text-align: left;">
  704.         <span style="font-size: 30px;">PAD Nº 2503140001&nbsp;_______________&nbsp;{$anio}</span>
  705.         </div>
  706.         <span style="font-size: 15px;">          OM-2017JU</span>
  707.         <br><br>
  708.         <div style="text-align: center;">
  709.         <span style="font-size: 50px; font-weight: bold;">INTERJAMA S.R.L.</span>
  710.         </div>
  711.         EOD;
  712.         $pdf->writeHTML($htmltruefalsefalsefalse'');
  713.         return new Response($pdf->Output("Panilla de Afip""S"), 200, array(
  714.             'Content-Type' => 'application/pdf',
  715.             'Content-Disposition' => 'attachment; filename="Panilla-Afip.pdf"'
  716.         )
  717.     );
  718.     }
  719.     public function getNombreAduana($nombre_aduana) {
  720.         $aux explode('-'$nombre_aduana);
  721.         $nombre trim(strtolower($aux[1]));
  722.         $sin_acentos iconv('UTF-8''ASCII//TRANSLIT'$nombre);
  723.         return $sin_acentos '.png';
  724.     }
  725.     public function descargaHojaRutaPdf($id) {
  726.         $imagenHojaRuta false;
  727.         $basePath $this->container->getParameter('kernel.root_dir');
  728.         $urlLogo strstr($basePath'app_dev.php'true);
  729.         $urlLogo .= "app/images/afip-logo.jpeg";
  730.         $precarga $this->getById((int)$id);
  731.         $precarga['plazo'] = (!is_null($precarga['plazo']) && $precarga['plazo'] != 'No disponible') ? $precarga['plazo'] . " (dias)" 'No disponible';
  732.         // Se arma la imagen de la hoja de ruta
  733.         $imagen $this->getNombreAduana($precarga['aduana_nombre']);
  734.         $urlHojaRutaAduana strstr($basePath'app_dev.php'true);
  735.         $urlHojaRutaAduana .= 'app/images/'.$imagen;
  736.         if (file_exists($urlHojaRutaAduana)) {
  737.             $imagenHojaRuta true;
  738.         }
  739.         $anio date('Y');
  740.         $fechaHoy date('d-m-Y');
  741.         $horaHoy =  date('H:m:s');
  742.         // create new PDF document
  743.         $pdf = new PDF();       
  744.         $pdf->SetTitle("Hoja de ruta");
  745.         $pdf->SetSubject("Hoja de ruta");
  746.         $pdf->setFontSubsetting(true);
  747.         // set default header data
  748.         $pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTHPDF_HEADER_TITLEPDF_HEADER_STRING);
  749.         $pdf->SetFont('helvetica'''10''true);
  750.         $pdf->SetMargins(PDF_MARGIN_LEFTPDF_MARGIN_TOPPDF_MARGIN_RIGHT);
  751.         $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  752.         $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  753.         $pdf->setPrintFooter(false);
  754.         // set auto page breaks
  755.         $pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);
  756.         // set image scale factor
  757.         $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  758.         $pdf->AddPage('P''A4');
  759.         $pdf->Image($urlLogo1543525'JPEG'''''false150''falsefalse0falsefalsefalse);
  760.         $html = <<<EOD
  761.         <div style="text-align:right;">
  762.         <h5>INSTRUCCION GENERAL Nº 32/2001 (DGA)<br>
  763.         ACTUACION 0432/2001 AD JUJUY<br>
  764.         MEMORANDO 27-29/2007 (ADJUJU)
  765.         </h5>
  766.         </div>
  767.         <div style="text-align: center;">
  768.         <h2><u>HOJA DE RUTA</u></h2>
  769.         </div>
  770.         <div>
  771.         <strong style="text-align: left;"> FECHA: </strong> {$fechaHoy} &nbsp;&nbsp;&nbsp;<strong style="text-align: left;">HORA: </strong> {$horaHoy}&nbsp;&nbsp;&nbsp;<strong style="text-align: left;">PLAZO: </strong> {$precarga['plazo']}<br>
  772.         </div>
  773.         <div>
  774.         EOD;
  775.         if ($imagenHojaRuta) {
  776.             $html .= <<<EOD
  777.             <img src="{$urlHojaRutaAduana}" alt="{$precarga['aduana_nombre']}" width="300" heigth="300" />
  778.             EOD;
  779.         } else {
  780.             $html .= <<<EOD
  781.             <span style="font-size: 12px; font-weight: bold;"> Sin recorrido cargado.</span><br>
  782.             EOD;
  783.         }
  784.         
  785.         $html .=<<<EOD
  786.         </div>
  787.         <div>
  788.         EOD;
  789.         if ($precarga['aduana_nombre'] == '061 - SANTA CRUZ') {
  790.             $html .= <<<EOD
  791.             <span style="font-size: 12px; font-weight: bold;"> POR LA PRESENTE SE NOTIFICA AL CONDUCTOR QUE DEBE INGRESAR DE MANERA OBLIGATORIA A ZONA PRIMARIA ADUANERA PALPALA (Z.P.A.P.).</span><br>
  792.             EOD;
  793.         }
  794.         $html .= <<<EOD
  795.         <span style="font-size: 12px; font-weight: bold;"> CERTIFICO EL COMPROMIDO DE CUMPLIR CON EL INTINERARIO DETALLADO.</span>
  796.         </div>
  797.         <div style="float:left; clear:none;">
  798.         <br>
  799.         <strong style="text-align: left;"> CONDUCTOR: </strong>&nbsp;&nbsp;_ _ _ _ _ _ _ _ _ _ _ _&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Agente de Transporte ADUANERO</strong>&nbsp;&nbsp;_ _ _ _ _ _ _ _ _ _ _ _<br>
  800.         <br/>
  801.         <br/>
  802.         <br/>
  803.         <strong style="text-align: left;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Servicio ADUANERO: </strong> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_ _ _ _ _ _ _ _ _ _ _ _<br>
  804.         </div>
  805.         <div>
  806.         <p> Cuando un hecho impida la prosecución del medio de transporte, el conductor dará aviso inmediato a la autoridad policial más cercana, bajo cuya vigilancia quedaran el camión y la carga, hasta que tome intervención el servicio ADUANERO.-</p>
  807.         </div>
  808.         EOD;
  809.         $pdf->writeHTML($htmltruefalsefalsefalse'');
  810.         return new Response($pdf->Output("Hoja de ruta""S"), 200, array(
  811.             'Content-Type' => 'application/pdf',
  812.             'Content-Disposition' => 'attachment; filename="Hoja-Ruta.pdf"'
  813.         )
  814.     );
  815.     }
  816.     public function descargaMcdtaPdf($id) {
  817.         $precarga $this->getById((int)$id);
  818.         $anio substr($precarga['fecha_creacion'], 04);
  819.         $fechaHoy date('d-m-Y');
  820.         $horaHoy =  date('h:m:s');
  821.         // create new PDF document
  822.         $pdf = new PDF();       
  823.         $pdf->SetTitle("MCDTA");
  824.         $pdf->SetSubject("MCDTA");
  825.         $pdf->setFontSubsetting(true);
  826.         // set default header data
  827.         $pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTHPDF_HEADER_TITLEPDF_HEADER_STRING);
  828.         $pdf->SetFont('helvetica'''11''true);
  829.         $pdf->SetMargins(PDF_MARGIN_LEFTPDF_MARGIN_TOPPDF_MARGIN_RIGHT);
  830.         $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  831.         $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  832.         $pdf->setPrintFooter(false);
  833.         // set auto page breaks
  834.         $pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);
  835.         // set image scale factor
  836.         $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  837.         $pdf->AddPage('P''A4');
  838.         $html = <<<EOD
  839.         <div style="width: 100%;height: 100%;display: table;text-align: center;">
  840.         <span style="font-size: 15px; font-weight: bold;display: table-cell;vertical-align: middle;">{$anio}031MANI{$precarga['mani']}</span><br>
  841.         <span style="font-size: 15px; font-weight: bold;display: table-cell;vertical-align: middle;">{$anio}031TLMD{$precarga['tlmd']}</span>
  842.         </div>
  843.         EOD;
  844.         $pdf->writeHTML($htmltruefalsefalsefalse'');
  845.         return new Response($pdf->Output("Hoja de ruta""S"), 200, array(
  846.             'Content-Type' => 'application/pdf',
  847.             'Content-Disposition' => 'attachment; filename="MCDTA.pdf"'
  848.         )
  849.     );
  850.     }
  851.     public function saveFromFumigacion ($certificado) {
  852.         $precarga = new McPrecarga();
  853.         $precarga->setFechaCreacion(new DateTime());
  854.         $precarga->setEstado(0);
  855.         $precarga->setDominio1($certificado->getVehiculo()->getDominio1());
  856.         $precarga->setDominio2($certificado->getVehiculo()->getDominio2());
  857.         $precarga->setChofer($certificado->getChofer());
  858.         $precarga->setUsuario($certificado->getUsuario());
  859.         $precarga->setCliente($certificado->getCliente());
  860.         $precarga->setOrigen("Fumigación");
  861.         $precargaBD $this->repository->save($precarga);
  862.         $precargaBD $this->toarray($precargaBD"precarga");
  863.         return $precargaBD;
  864.     }
  865.     public function updatePrecargaAsignarNumero($request$id) {
  866.         $precarga $this->repository->findOneById((int)$id);
  867.         $registro $request->request->get('registro');
  868.         // Corroboramos que no exista el mismo N° de Registro
  869.         if (!is_null($registro) && str_replace(' '''$registro) != '') {
  870.             $registroExistente $this->repository->buscarNumRegistro($registro$id);
  871.             $registroExistente $this->toarray($registroExistente'precarga');
  872.             if (COUNT($registroExistente) > 0) {
  873.                 throw new HttpException(409"El N° de Registro " $precarga->getRegistro(). " ya se encuentra almacenado en el sistema."); 
  874.             }
  875.             $precarga->setRegistro($registro);
  876.             $precarga->setEstado(2); // Atendido
  877.         }
  878.         $precarga $this->updateAtencion($precarga$id);
  879.         return $precarga;
  880.         
  881.     }
  882.     private function obtenerAbreviaturaDivisa($nombreDivisa) {
  883.     // Convertir a minúsculas respetando acentos
  884.     $nombreDivisa mb_strtolower($nombreDivisa'UTF-8');
  885.     // Lista de divisas y sus abreviaturas ISO
  886.     $divisas = [
  887.         'pesos argentinos'   => 'ARS',
  888.         'pesos chilenos'     => 'CLP',
  889.         'pesos paraguayos'   => 'PYG',
  890.         'soles'              => 'PEN',
  891.         'reales'             => 'BRL',
  892.         'dólares'            => 'USD',
  893.         'pesos bolivianos'   => 'BOB',
  894.     ];
  895.     // Retornar la abreviatura si existe
  896.     return $divisas[$nombreDivisa] ?? 'Desconocida';
  897. }
  898.     public function descargaReciboPdf($id) {
  899.         $precarga $this->getById((int)$id);
  900.         $precarga['tiposTramites'] = $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")->getByPrecarga((int)$id);
  901.         $precarga['aduana'] = (!is_null($precarga['aduana']) && !empty($precarga['aduana'])) ? $precarga['aduana'] : 0;
  902.         $fechaHoy date('d-m-Y');
  903.         $anio substr($precarga['fecha_creacion'], 04);
  904.         $fechaHoy date('d-m-Y');
  905.         $chofer $precarga['chofer'];
  906.         //Se obtiene la abreviatura de la moneda
  907.         $monedaReferencia $this->obtenerAbreviaturaDivisa($precarga['moneda']['nombre']);
  908.         // create new PDF document
  909.         $pdf = new PDF();       
  910.         $pdf->SetTitle("Recibo Atención");
  911.         $pdf->SetSubject("Recibo Atención");
  912.         $pdf->setFontSubsetting(true);
  913.         // set default header data
  914.         $pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTHPDF_HEADER_TITLEPDF_HEADER_STRING);
  915.         $pdf->SetFont('helvetica'''9''true);
  916.         $pdf->SetMargins(555);
  917.         $pdf->SetHeaderMargin(0);
  918.         $pdf->SetFooterMargin(0);
  919.         $pdf->setPrintFooter(false);
  920.         // set auto page breaks
  921.         $pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);
  922.         // set image scale factor
  923.         $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  924.         $pdf->AddPage('P''A4');
  925.         $html = <<<EOD
  926.         <table style="width: 100%; border-top: 1px solid black;border-left: 1px solid black;border-right: 1px solid black;">
  927.         <tr>
  928.         <th style="text-align: left">
  929.         <span></span><br>
  930.         <img src="app/images/interjama-logo.jpeg" alt="Interjama" width="300" height="100" />
  931.         </th>
  932.         <th style="text-align: center">
  933.         <span style="font-size: 30px; font-weight: bold;">RECIBO</span><br>
  934.         <span style="font-size: 10px;">Original</span>
  935.         </th>
  936.         <th style="text-align: center">
  937.         <span></span><br>
  938.         <span style="font-size: 12px; font-weight: bold;">Recibo</span><br>
  939.         <span style="font-size: 12px; font-weight: bold;">Nº {$id}</span><br>
  940.         <span style="font-size: 12px; font-weight: bold;">{$fechaHoy}</span>
  941.         </th>
  942.         </tr>
  943.         </table>
  944.         <table style="width: 100%; border-bottom: 1px solid black;border-left: 1px solid black;border-right: 1px solid black;">
  945.         <tr>
  946.         <th style="text-align: left; border-right: 1px solid black">
  947.         <strong style="text-align: left;">Raz&oacute;n Social: </strong>INTERJAMA S.R.L.<br>
  948.         <strong style="text-align: left;">Fecha de Emisi&oacute;n: {$fechaHoy}</strong><br>
  949.         <strong style="text-align: left;">Domicilio comercial: </strong>Alvear 495 Piso:2 Dpto:C - San Salvador de Jujuy - Jujuy<br>
  950.         <strong style="text-align: left;">Sitio web: </strong>www.interjama.com.ar<br>
  951.         </th>
  952.         <th style="text-align: left">
  953.         <strong style="text-align: left;">Condici&oacute;n frente al IVA: IVA Responsable Inscripto</strong><br>
  954.         <strong style="text-align: left;">CUIT: </strong>30714865044<br>
  955.         <strong style="text-align: left;">Ingresos Brutos: </strong>A-1-55049<br>
  956.         <strong style="text-align: left;">Fecha de Inicio de Actividad: </strong>01/07/2015
  957.         </th>
  958.         </tr>
  959.         </table>
  960.         <br/>
  961.         <div style="width: 100%; border: 0.5px solid black; margin-top: 1px;">
  962.         <strong style="margin-left: 10px;">Preriodo Facturado Desde:</strong> {$fechaHoy} <strong style="margin-left: 90px;">Hasta:</strong> {$fechaHoy} <strong style="margin-left: 200px;">Fecha de Vto. para el pago:</strong> {$fechaHoy}
  963.         </div>
  964.         <div style="width: 100%; border: 0.5px solid black; margin-top: 1px;">
  965.         <strong style="text-align: left;">CUIT:</strong> {$precarga['cliente']['cuit']}<br>
  966.         <strong style="text-align: left;">Apellido y Nombre / Raz&oacute;n Social</strong> {$precarga['cliente']['razon_social']}<br>
  967.         <strong style="text-align: left;">Condici&oacute;n frente al IVA:</strong> {$precarga['cliente']['condicion_iva']}<br>
  968.         <strong style="text-align: left;">Condici&oacute;n de venta:</strong> {$precarga['tipo_pago']}<br>
  969.         <strong style="text-align: left;">Chofer:</strong> {$chofer}<br>
  970.         <strong style="text-align: left;">Dominio:</strong> {$precarga['dominio1']}<br>
  971.         <strong style="text-align: left;">Dominio Trailer:</strong> {$precarga['dominio2']}
  972.         </div>
  973.         <br/>
  974.         <table border="0.5">
  975.         <tr style="background-color: grey;">
  976.         <th>Cantidad</th>
  977.         <th>Trámite</th>
  978.         <th>Tipo trámite</th>
  979.         <th>Importe</th>
  980.         <th>Subtotal</th>
  981.         </tr>
  982.         EOD;
  983.         foreach ($precarga['tiposTramites'] as $tipo) {
  984.             $html .= <<<EOD
  985.             <tr>
  986.             <td>1,00</td>
  987.             <td>{$tipo['tipos_tramite']['tipo']}</td>
  988.             <td>{$tipo['tipos_tramite']['nombre']}</td>
  989.             <td>{$tipo['importe']}</td>
  990.             <td>{$tipo['importe']}</td>
  991.             </tr>
  992.             EOD;
  993.         }
  994.         $html .= <<<EOD
  995.         </table>
  996.         <br/>
  997.         <br/>
  998.         <table border="0.5">
  999.         <tr>
  1000.         <th><strong style="margin-left: 0%;"> Imp. Aduana: $:</strong> {$precarga['aduana']}</th>
  1001.         <th><strong style="margin-left: 30%;"> Subtotal: $</strong> {$precarga['total']}</th>
  1002.         <th><strong style="margin-left: 60%;"> Importe Total: $</strong> {$precarga['total']} <strong>({$monedaReferencia})</strong></th>
  1003.         </tr>
  1004.         </table>
  1005.         EOD;
  1006.         $pdf->writeHTML($htmltruefalsefalsefalse'');
  1007.         return new Response($pdf->Output("Recibo""S"), 200, array(
  1008.             'Content-Type' => 'application/pdf',
  1009.             'Content-Disposition' => 'attachment; filename="Panilla-Afip.pdf"'
  1010.             )
  1011.         );
  1012.     }
  1013.     public function  numeroAddZero($nro) {
  1014.         $numero "";
  1015.         $nro1 strlen((string)$nro);      
  1016.         switch($nro1) {
  1017.             case 1:
  1018.             $numero "000000" $nro;
  1019.             break;
  1020.             case 2:
  1021.             $numero "00000" $nro;                
  1022.             break;
  1023.             case 3:
  1024.             $numero "0000" $nro;                
  1025.             break;
  1026.             case 4:
  1027.             $numero "000" $nro;                
  1028.             break;
  1029.             case 5:
  1030.             $numero "00" $nro;                
  1031.             break;
  1032.             case 6:
  1033.             $numero "0" $nro;                
  1034.             break;
  1035.             case 7:
  1036.             $numero $nro;                
  1037.             break;
  1038.         }
  1039.         return $numero;
  1040.     }
  1041.     public function descargaFacturaAfipPdf($id$factura) {
  1042.         $precarga $this->getById((int)$id);
  1043.         if (is_null($precarga['facturado']) || !$precarga['facturado']) {
  1044.             $precargaObj $this->getPrecargaById((int)$id);
  1045.             $precarga['tiposTramites'] = $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")->getByPrecarga((int)$id);
  1046.             $precarga['aduana'] = (!is_null($precarga['aduana']) && !empty($precarga['aduana'])) ? $precarga['aduana'] : 0;
  1047.             $monedaReferencia $this->obtenerAbreviaturaDivisa($precarga['moneda']['nombre']);
  1048.             $fechaHoy date('d/m/Y');
  1049.             $tipoFactura "A";
  1050.             /*
  1051.             $afip = new Afip(array(
  1052.                 'CUIT' => 27332574049,
  1053.                 'cert' => 'tramite/cert',
  1054.                 'key' => 'tramite/key'
  1055.             ));
  1056.             */
  1057.             if ($factura == 'A') {
  1058.                 try {
  1059.                     $last_voucher 1;
  1060.                     //$last_voucher = $afip->ElectronicBilling->GetLastVoucher(1,1);
  1061.                 } catch (Exception $e) {
  1062.                     return $e->getMessage();
  1063.                 }              
  1064.             } elseif ($factura == 'B') {
  1065.                 try {
  1066.                     $last_voucher 1;
  1067.                     //$last_voucher = $afip->ElectronicBilling->GetLastVoucher(1,6);
  1068.                 } catch (Exception $e) {
  1069.                     return $e->getMessage();
  1070.                 }
  1071.             }        
  1072.             $valfac $last_voucher 1;
  1073.             $nroComprobante $this->numeroAddZero($valfac);
  1074.             $ptoVta "0001";    
  1075.             $neto round($precarga['total'] / 1.212);
  1076.             $iva =  round($neto 0.212);
  1077.             //Se arma factura A
  1078.             $data = array(
  1079.                 'CantReg'     => 1,  // Cantidad de comprobantes a registrar
  1080.                 'PtoVta'     => 1,  // Punto de venta            
  1081.                 'Concepto'     => 1,  // Concepto del Comprobante: (1)Productos, (2)Servicios, (3)Productos y Servicios
  1082.                 'DocTipo'     => 80// Tipo de documento del comprador (99 consumidor final, ver tipos disponibles)
  1083.                 'DocNro'     => $precarga['cliente']['cuit'],  // Número de documento del comprador (0 consumidor final)
  1084.                 'CbteDesde' => $valfac,  // Número de comprobante o numero del primer comprobante en caso de ser mas de uno
  1085.                 'CbteHasta' => $valfac,  // Número de comprobante o numero del último comprobante en caso de ser mas de uno
  1086.                 'CbteFch'     => intval(date('Ymd')), // (Opcional) Fecha del comprobante (yyyymmdd) o fecha actual si es nulo
  1087.                 'ImpTotal'     => $precarga['total'], // Importe total del comprobante
  1088.                 'ImpTotConc' => 0,   // Importe neto no gravado
  1089.                 'ImpNeto'     => $neto// Importe neto gravado
  1090.                 'ImpOpEx'     => 0,   // Importe exento de IVA
  1091.                 'ImpIVA'     => $iva,  //Importe total de IVA
  1092.                 'ImpTrib'     => 0,   //Importe total de tributos
  1093.                 'MonId'     => 'PES'//Tipo de moneda usada en el comprobante (ver tipos disponibles)('PES' para pesos argentinos) 
  1094.                 'MonCotiz'     => 1,     // Cotización de la moneda usada (1 para pesos argentinos)
  1095.                 'Iva'         => array( // (Opcional) Alícuotas asociadas al comprobante
  1096.                     array(
  1097.                     'Id'         => 5// Id del tipo de IVA (5 para 21%)(ver tipos disponibles) 
  1098.                     'BaseImp'     => $neto// Base imponible
  1099.                     'Importe'     => $iva // Importe 
  1100.                 )
  1101.                 ),
  1102.             );
  1103.             
  1104.             if ($factura == 'A') {
  1105.                 $data['CbteTipo'] = 1;
  1106.                 $codigo 'Código 01';
  1107.             } elseif ($factura == 'B') {
  1108.                 $data['CbteTipo'] = 6;
  1109.                 $tipoFactura "B";
  1110.                 $codigo 'Código 06';
  1111.             } else {
  1112.                 //Se arma factura E de exportación
  1113.             }
  1114.             try {
  1115.                 /*
  1116.                 $res = $afip->ElectronicBilling->CreateVoucher($data);
  1117.                 $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McFacturaHandler")->saveFacturaPrecarga($precargaObj, $tipoFactura, $res, $nroComprobante);
  1118.                 $this->updateFacturado($precargaObj);
  1119.                 */
  1120.                 $res['CAE'] = '987654321';
  1121.                 $res['CAEFchVto'] = '2023-12-31';
  1122.             } catch (Exception $e) {
  1123.                 return $e->getMessage();
  1124.             }          
  1125.             $res['CAE']; //CAE asignado el comprobante
  1126.             $res['CAEFchVto']; //Fecha de vencimiento del CAE (yyyy-mm-dd)
  1127.             // Fin de sección de factura de AFIP
  1128.             //Creacion del PDF
  1129.             // create new PDF document
  1130.             $pdf = new PDF();    
  1131.             $pdf->SetTitle("Precargas atendidas");
  1132.             $pdf->SetSubject("Precargas atendidas");
  1133.             $pdf->setFontSubsetting(true);
  1134.             // set default header data
  1135.             $pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTHPDF_HEADER_TITLEPDF_HEADER_STRING);
  1136.             $pdf->SetFont('helvetica'''9''true);
  1137.             $pdf->SetMargins(5,5,5);
  1138.             $pdf->SetHeaderMargin(0);
  1139.             $pdf->SetFooterMargin(0);
  1140.             $pdf->SetPrintFooter(false);
  1141.             // set auto page breaks
  1142.             $pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);
  1143.             // set image scale factor
  1144.             $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  1145.             $pdf->AddPage('P''A4');
  1146.             // Datos de la empresa emisora de la factura
  1147.             $html = <<<EOD
  1148.             <table style="width: 100%; border-top: 1px solid black;border-left: 1px solid black;border-right: 1px solid black;">
  1149.             <tr>
  1150.             <th style="text-align: left">
  1151.             <span></span><br>
  1152.             <img src="app/images/interjama-logo.jpeg" alt="Interjama" width="300" height="100" />
  1153.             </th>
  1154.             <th style="text-align: center">
  1155.             <span style="font-size: 30px; font-weight: bold;">{$tipoFactura}</span><br>
  1156.             <span style="font-size: 10px;">{$codigo}</span>
  1157.             </th>
  1158.             <th style="text-align: center">
  1159.             <span></span><br>
  1160.             <span style="font-size: 12px; font-weight: bold;">Factura</span><br>
  1161.             <span style="font-size: 12px; font-weight: bold;">Nº {$nroComprobante}</span><br>
  1162.             <span style="font-size: 12px; font-weight: bold;">{$fechaHoy}</span>
  1163.             </th>
  1164.             </tr>
  1165.             </table>
  1166.             <table style="width: 100%; border-bottom: 1px solid black;border-left: 1px solid black;border-right: 1px solid black;">
  1167.             <tr>
  1168.             <th style="text-align: left; border-right: 1px solid black">
  1169.             <strong style="text-align: left;">Raz&oacute;n Social: </strong>INTERJAMA S.R.L.<br>
  1170.             <strong style="text-align: left;">Punto de venta: {$ptoVta}  Comp. Nro: {$nroComprobante}</strong><br>
  1171.             <strong style="text-align: left;">Domicilio comercial: </strong>Alvear 495 Piso:2 Dpto:C - San Salvador de Jujuy - Jujuy<br>
  1172.             <strong style="text-align: left;">Sitio web: </strong>www.interjama.com.ar<br>
  1173.             </th>
  1174.             <th style="text-align: left">
  1175.             <strong style="text-align: left;">Condici&oacute;n frente al IVA: IVA Responsable Inscripto</strong><br>
  1176.             <strong style="text-align: left;">CUIT: </strong>30714865044<br>
  1177.             <strong style="text-align: left;">Ingresos Brutos: </strong>A-1-55049<br>
  1178.             <strong style="text-align: left;">Fecha de Inicio de Actividad: </strong>01/07/2015
  1179.             </th>
  1180.             </tr>
  1181.             </table>
  1182.             <br/>
  1183.             <div style="width: 100%; border: 0.5px solid black; margin-top: 2px;">
  1184.             <strong style="margin-left: 10px;">Preriodo Facturado Desde:</strong> {$fechaHoy} <strong style="margin-left: 90px;">Hasta:</strong> {$fechaHoy} <strong style="margin-left: 200px;">Fecha de Vto. para el pago:</strong> {$fechaHoy}
  1185.             </div>
  1186.             <div style="width: 100%; border: 0.5px solid black; margin-top: 2px;">
  1187.             <strong style="text-align: left;">CUIT:</strong> {$precarga['cliente']['cuit']}<br>
  1188.             <strong style="text-align: left;">Appelidoy Nombre / Raz&oacute;n Social</strong> {$precarga['cliente']['razon_social']}<br>
  1189.             <strong style="text-align: left;">Condici&oacute;n frente al IVA:</strong> {$precarga['cliente']['condicion_iva']}<br>                
  1190.             <strong style="text-align: left;">Condici&oacute;n de venta:</strong> {$precarga['tipo_pago']}
  1191.             </div>
  1192.             <br/>
  1193.             <table border="0.5">
  1194.             <tr style="background-color: grey;">
  1195.             <th>Cantidad</th>
  1196.             <th>Trámite</th>
  1197.             <th>Tipo trámite</th>
  1198.             <th>Importe</th>
  1199.             <th>Subtotal</th>
  1200.             </tr>
  1201.             EOD;
  1202.             foreach ($precarga['tiposTramites'] as $tipo) {
  1203.                 $html .= <<<EOD
  1204.                 <tr>
  1205.                 <td>1,00</td>
  1206.                 <td>{$tipo['tipos_tramite']['tipo']}</td>
  1207.                 <td>{$tipo['tipos_tramite']['nombre']}</td>
  1208.                 <td>{$tipo['importe']}</td>
  1209.                 <td>{$tipo['importe']}</td>
  1210.                 </tr>
  1211.                 EOD;
  1212.             }
  1213.             $html .= <<<EOD
  1214.             </table>
  1215.             <br/>
  1216.             <br/>
  1217.             <table border="0.5">
  1218.             <tr>
  1219.             <th><strong style="margin-left: 0%;"> Imp. Aduana: $:</strong> {$precarga['aduana']}</th>
  1220.             <th><strong style="margin-left: 30%;"> Subtotal: $</strong> {$precarga['total']}</th>
  1221.             <th><strong style="margin-left: 60%;"> Importe Total: $</strong> {$precarga['total']} <strong>({$monedaReferencia})</strong></th>
  1222.             </tr>
  1223.             </table>
  1224.             <div style="float:right; margin-top: 2px; text-align: right;">
  1225.             <strong>CAE Nº:</strong> {$res['CAE']}<br>
  1226.             <strong>Fecha Vto. de CAE:</strong> {$res['CAEFchVto']}
  1227.             </div>
  1228.             <br/>
  1229.             <table style="width: 100%;">
  1230.             <tr>
  1231.             <th>
  1232.             <img src="app/images/qr.png" alt="Código QR" width="50" height="50"/>
  1233.             </th>
  1234.             <th>
  1235.             <img src="app/images/afip-logo.png" alt="Código QR" width="50" height="15"/><br>
  1236.             <span><b>Comprobante Autorizado</b></span>
  1237.             </th>
  1238.             <th>
  1239.             </th>
  1240.             <th>
  1241.             </th>
  1242.             </tr>
  1243.             </table>
  1244.             EOD;
  1245.             $pdf->writeHTML($htmltruefalsefalsefalse'');
  1246.             return new Response($pdf->Output("Precarga-Factura""S"), 200, array(
  1247.                 'Content-Type' => 'application/pdf',
  1248.                 'Content-Disposition' => 'attachment; filename="Precarga-Factura.pdf"'
  1249.             )
  1250.         );
  1251.         } else {
  1252.             throw new HttpException(409"La precarga ya se encuentra facturado.");  
  1253.         }
  1254.     }
  1255.     public function downloadSenasa($data$id) {
  1256.         $precarga $this->getById((int)$id);
  1257.         $dominios '('$precarga['dominio1'] .' - '$precarga['dominio2'] . ')';
  1258.         $fechaHoy date('d/m/Y');
  1259.         $horaHoy =  date('H:i:s');
  1260.         $tipoExportacion '';
  1261.         $tipoImportacion '';
  1262.         $tipoTransito '';
  1263.         $tipoRetorno '';
  1264.         $tipoOtro '';
  1265.         if ($data['tipo'] == 'exportacion') {
  1266.             $tipoExportacion 'X';
  1267.         } else if ($data['tipo'] == 'importacion') {
  1268.             $tipoImportacion 'X';
  1269.         } else if ($data['tipo'] == 'transito') {
  1270.             $tipoTransito 'X';
  1271.         } else if ($data['tipo'] == 'retorno de exportacion') {
  1272.             $tipoRetorno 'X';
  1273.         } else {
  1274.             $tipoOtro 'X';
  1275.         }
  1276.         $pais strtoupper($data['pais']);
  1277.         $mercaderia strtoupper($data['mercaderia']);
  1278.         $nombre strtoupper($data['nombre']);
  1279.         $basePath $this->container->getParameter('kernel.root_dir');
  1280.         $urlLogo strstr($basePath'app_dev.php'true);
  1281.         $urlLogo .= "app/images/senasa.png";
  1282.         // create new PDF document
  1283.         $pdf = new PDF();       
  1284.         $pdf->SetTitle("Panilla - Senasa");
  1285.         $pdf->SetSubject("Panilla - Senasa");
  1286.         $pdf->setFontSubsetting(true);
  1287.         // set default header data
  1288.         $pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTHPDF_HEADER_TITLEPDF_HEADER_STRING);
  1289.         $pdf->SetFont('times'''11''true);
  1290.         $pdf->SetMargins(PDF_MARGIN_LEFT15PDF_MARGIN_RIGHT);
  1291.         $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  1292.         $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  1293.         $pdf->setPrintFooter(false);
  1294.         // set auto page breaks
  1295.         $pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);
  1296.         // set image scale factor
  1297.         $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  1298.         $pdf->AddPage('P''A4');
  1299.         $pdf->Image($urlLogo17203320'PNG'''''false150''falsefalse0falsefalsefalse);
  1300.         $html = <<<EOD
  1301.         <table style="border-top: 2px solid black ; border-left: 2px solid black; border-right: 2px solid black; border-bottom: 2px solid black; width: 100%; border-collapse: collapse;">
  1302.         <tr>
  1303.         <th style="width: 20%;"></th>
  1304.         <th style="background-color: #b5b5b5; width: 60%; border-bottom: 2px solid black; border-top: 2px solid black; border-left: 2px solid black; border-right: 2px solid black; text-align: center;">
  1305.         <br>
  1306.         <strong>SERVICIO NACIONAL DE <br> Y CALIDAD AGROALIMENTARIA</strong>
  1307.         <br>
  1308.         </th>
  1309.         <th style="width: 20%;">
  1310.         <p style="font-size: 8px; text-align: left;">FOR N° 1 POE N° 1<br>Emisión: 08/11/00</p>
  1311.         </th>
  1312.         </tr>
  1313.         <tr>
  1314.         <th style="width: 20%;"></th>
  1315.         <th style="width: 60%; border-left: 2px solid black; border-right: 2px solid black; text-align: center">
  1316.         <br>
  1317.         Manual de procedimientos a desarrollar en los<br> Puestos de Fronteras Habilitados
  1318.         <br>
  1319.         </th>
  1320.         <th style="width: 20%;">
  1321.         <p style="font-size: 8px; text-align: left;">Vigencia:19/11/11<br>Hoja:1</p>
  1322.         </th>
  1323.         </tr>
  1324.         </table>
  1325.         <br/>
  1326.         <br/>
  1327.         <table style="border-collapse: collapse; width: 100%;">
  1328.         <tr>
  1329.         <th style="width: 20%;"></th>
  1330.         <th style="text-align: center; width: 60%;">
  1331.         <br>
  1332.         SOLICITUD DE INTERVENCIÓN: {$precarga['id']}/2023
  1333.         </th>
  1334.         <th style="width: 20%;">
  1335.         </th>
  1336.         </tr>
  1337.         <tr>
  1338.         <th style="width: 20%;"></th>
  1339.         <th style="width: 60%; text-align: center">
  1340.         No se encuentran entradas de índice.
  1341.         </th>
  1342.         <th style="width: 20%;"></th>
  1343.         </tr>
  1344.         <tr>
  1345.         <th style="width: 20%;"></th>
  1346.         <th style="width: 60%; text-align: center">
  1347.         N° ......................(Asignado por SENASA)
  1348.         </th>
  1349.         <th style="width: 20%;"></th>
  1350.         </tr>
  1351.         </table>
  1352.         <br/>
  1353.         <table style="border-collapse: collapse; width: 100%;">
  1354.         <tr>
  1355.         <th style="width: 50%; text-align: left;">
  1356.         <p>Lugar, Paso de Jama, {$fechaHoy}</p>
  1357.         </th>
  1358.         <th style="width: 50%; text-align: left;">
  1359.         <p>Hora: </p>
  1360.         </th>
  1361.         </tr>
  1362.         </table>
  1363.         <table style="border-collapse: collapse; width: 100%;">
  1364.         <tr>
  1365.         <th style="width: 100%; text-align: left;">
  1366.         Sr. Jefe del Puesto de Frontera:
  1367.         </th>
  1368.         </tr>
  1369.         </table>
  1370.         <br/>
  1371.         <table style="border-collapse: collapse;">
  1372.         <tr>
  1373.         <th style="width: 100%; text-align: left;">
  1374.         <p style="font-size: 11px;">Me dirijo a Ud. a fin solicitar la presencia de personal de esa Unidad Operativa, a efectos de
  1375.         intervenir, en la operación cuyos datos se detallan a continuación:</p>
  1376.         </th>
  1377.         </tr>
  1378.         </table>
  1379.         <br/>
  1380.         <br/>
  1381.         <table style="border-collapse: collapse;">
  1382.         <tr>
  1383.         <th style="width: 100%; text-align: left;">
  1384.         TIPO DE OPERACIÓN (marcar a la derecha de la operación que corresponda)
  1385.         </th>
  1386.         </tr>
  1387.         </table>
  1388.         <br/>
  1389.         <br/>
  1390.         <table border="1" style="border-collapse: collapse; width: 100%;">
  1391.         <tr>
  1392.         <th style="width: 20%; background-color: #b5b5b5;">EXPORTACIÓN</th>
  1393.         <th style="width: 5%;"> {$tipoExportacion}</th>
  1394.         <th style="width: 20%;">TRANSITO</th>
  1395.         <th style="width: 5%;">{$tipoTransito}</th>
  1396.         <th style="width: 45%; background-color: #b5b5b5;">RETORNO DE EXPORTACIÓN</th>
  1397.         <th style="width: 5%;">{$tipoRetorno}</th>
  1398.         </tr>
  1399.         <tr>
  1400.         <th style="width: 20%;">IMPORTACIÓN</th>
  1401.         <th style="width: 5%;"> {$tipoImportacion}</th>
  1402.         <th style="width: 20%; background-color: #b5b5b5;">OTRO</th>
  1403.         <th style="width: 55%;">{$tipoOtro}</th>
  1404.         </tr>
  1405.         </table>
  1406.         <table style="border-collapse: collapse; width: 100%;">
  1407.         <tr>
  1408.         <th style="width: 30%;"><strong>PAÍS DE ORIGEN:</strong></th>
  1409.         <th style="width: 70%;"> {$pais}</th>
  1410.         </tr>
  1411.         <tr>
  1412.         <th style="width: 30%;"><strong>MERCADERÍA:</strong></th>
  1413.         <th style="width: 70%;"> {$mercaderia}</th>
  1414.         </tr>
  1415.         <tr>
  1416.         <th style="width: 30%;"><strong>TRANSPORTE de ARRIBO:</strong></th>
  1417.         <th style="width: 70%;"> {$precarga['cliente']['razon_social']} {$dominios}</th>
  1418.         </tr>
  1419.         <tr>
  1420.         <th style="width: 70%;"><strong>LUGAR PREVISTO DE LA INTERVENCIÓN:</strong></th>
  1421.         <th style="width: 30%;"> Paso de Jama</th>
  1422.         </tr>
  1423.         </table>
  1424.         <table style="border-collapse: collapse; width: 100%;">
  1425.         <tr style="background-color: #b5b5b5;">
  1426.         <th style="width: 70%; text-align: left;">
  1427.         SOLICITO PRESENCIA DE PERSONAL DEL SENASA PARA: 
  1428.         </th>
  1429.         <th style="width: 30%;"></th>
  1430.         </tr>
  1431.         </table>
  1432.         <table style="border-collapse: collapse; width: 100%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black;">
  1433.         <tr>
  1434.         <th style="width: 20%;"><br/>Fecha:</th>
  1435.         <th style="width: 30%;"> {$fechaHoy}</th>
  1436.         <th style="width: 20%;"><br/>Hora:</th>
  1437.         <th style="width: 30%;"></th>
  1438.         </tr>
  1439.         </table>
  1440.         <table style="border-collapse: collapse; width: 100%;">
  1441.         <tr>
  1442.         <th style="width: 30%;"><strong>NOMBRE DE EXP E IMP:</strong></th>
  1443.         <th style="width: 70%;"> {$nombre}</th>
  1444.         </tr>
  1445.         <tr>
  1446.         <th style="width: 30%;"><strong>PRESENTANTE:</strong></th>
  1447.         <th style="width: 70%;"> ATA...INTERJAMA SRL 30-71486504-4</th>
  1448.         </tr>
  1449.         <tr>
  1450.         <th style="width: 30%;"><strong>DOMICILIO:</strong></th>
  1451.         <th style="width: 70%;"> RUTA 52 KM 236 PASO DE JAMA</th>
  1452.         </tr>
  1453.         <tr>
  1454.         <th style="width: 30%;"><strong>TELEFONO</strong> (urgencias):</th>
  1455.         <th style="width: 70%;"> 0388 -154580629</th>
  1456.         </tr>
  1457.         </table>
  1458.         <table style="border-collapse: collapse; width: 100%;">
  1459.         <tr style="background-color: #b5b5b5;">
  1460.         <th style="width: 100%; text-align: left;">
  1461.         <p>Por la presente declaro conocer la normativa vigente de aplicación del SENASA y de otros Organismos que
  1462.         pudieran estar involucrados en esta operatoria, así como las pautas operativas actuales.</p> 
  1463.         </th>
  1464.         </tr>
  1465.         </table>
  1466.         <br/>
  1467.         <br/>
  1468.         <table style="border-collapse: collapse; 
  1469.         border-top: 1px solid black; 
  1470.         border-bottom: 1px solid black;
  1471.         border-left: 1px solid black;
  1472.         border-right: 1px solid black;
  1473.         ">
  1474.         <tr>
  1475.         <th style="width: 50%; text-align: left; border-right: 1px solid black;">
  1476.         N° de recepción otorgado (correlativo):................
  1477.         </th>
  1478.         <th style="width: 50%; text-align: left;">
  1479.         Firma y sello aclaratorio del Interesado
  1480.         </th>
  1481.         </tr>
  1482.         <tr>
  1483.         <th style="width: 50%; text-align: left; border-right: 1px solid black;">
  1484.         Recibido en SENASA el....../......./.....hora............
  1485.         </th>
  1486.         <th style="width: 50%; text-align: left;">
  1487.         </th>
  1488.         </tr>
  1489.         <tr>
  1490.         <th style="width: 50%; text-align: left; border-right: 1px solid black;">
  1491.         <br/>
  1492.         <br/>
  1493.         <br/>
  1494.         <p>Firma y aclaración</p>
  1495.         </th>
  1496.         <th style="width: 50%; text-align: left;">
  1497.         </th>
  1498.         </tr>
  1499.         </table>
  1500.         <br/>
  1501.         <br/>
  1502.         <br/>
  1503.         <table style="border-top: 2px solid black ; border-left: 2px solid black; border-right: 2px solid black; border-bottom: 2px solid black; width: 100%; border-collapse: collapse;">
  1504.         <tr>
  1505.         <th style="width: 50%; border-right: 2px solid black; text-align: center;">Elaboraron:</th>
  1506.         <th style="width: 50%; text-align: center;">
  1507.         Aprobó
  1508.         </th>
  1509.         </tr>
  1510.         <tr>
  1511.         <th style="width: 50%; border-right: 2px solid black; text-align: center;">Dr. E. Saint Jean, Dr. H. Castellini, Dra. T. Bianchi</th>
  1512.         <th style="width: 50%; text-align: center;">
  1513.         Dr. L. Mascitelli
  1514.         </th>
  1515.         </tr>
  1516.         </table>
  1517.         EOD;
  1518.         $pdf->writeHTML($htmltruefalsefalsefalse'');
  1519.         return new Response($pdf->Output("Formulario SENASA""S"), 200, array(
  1520.             'Content-Type' => 'application/pdf',
  1521.             'Content-Disposition' => 'attachment; filename="Formulario-Senasa.pdf"'
  1522.         )
  1523.     );
  1524.     }
  1525.     private function FechaCastellano(){
  1526.         $date date('Y-m-d');
  1527.         $mes_ date('F'strtotime($date));
  1528.         $_ES = array("Enero""Febrero""Marzo""Abril""Mayo""Junio""Julio""Agosto""Septiembre""Octubre""Noviembre""Diciembre");
  1529.         $_EN = array("January""February""March""April""May""June""July""August""September""October""November""December");
  1530.         $nombreMes str_replace($_EN$_ES$mes_);
  1531.         return $nombreMes;
  1532.     }
  1533.     public function downloadAnmac($data$id) {
  1534.         $renar $data['renar'];
  1535.         $precarga $this->getById((int)$id);
  1536.         $chofer = (!is_null($precarga['chofer'])) ? $precarga['chofer'] : $precarga['chofer_id']['nombre']." ".$precarga['choferId']['apellido'];
  1537.         $tipo = (!is_null($precarga['chofer_id'])) ? $precarga['chofer_id']['tipo'] : null;
  1538.         $numero = (!is_null($precarga['chofer_id'])) ? $precarga['chofer_id']['numero'] : null;
  1539.         $fecha_nacimiento 
  1540.         $fechaHoy date('d/m/Y');
  1541.         $mesActual $this->FechaCastellano();
  1542.         $diaActual date('d'strtotime(date('Y-m-d')));
  1543.         $anioActual date('Y'strtotime(date('Y-m-d')));
  1544.         $horaActual date('H'strtotime(date('H:i:s')));
  1545.         $minutoActual date('i'strtotime(date('H:i:s')));
  1546.         $horaHoy =  date('H:i:s');
  1547.         // create new PDF document
  1548.         $pdf = new PDF();       
  1549.         $pdf->SetTitle("Panilla - Anmac");
  1550.         $pdf->SetSubject("Panilla - Anmac");
  1551.         $pdf->setFontSubsetting(true);
  1552.         // set default header data
  1553.         $pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTHPDF_HEADER_TITLEPDF_HEADER_STRING);
  1554.         $pdf->SetFont('helvetica'''11''true);
  1555.         $pdf->SetMargins(30155);
  1556.         $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  1557.         $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  1558.         $pdf->setPrintFooter(false);
  1559.         // set auto page breaks
  1560.         $pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);
  1561.         // set image scale factor
  1562.         $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  1563.         $pdf->AddPage('P''CO_OFICIO');
  1564.         $html = <<<EOD
  1565.         <table style="width: 100%; border-collapse: collapse;">
  1566.         <tr>
  1567.         <th style="width: 30%;">
  1568.         REPUBLICA ARGENTINA<br>GENDARMERIA NACIONAL
  1569.         </th>
  1570.         <th style="width: 70%; text-align: left;">
  1571.         “Gral. Martin Miguel de Güemes Héroe de la Nación Argentina”
  1572.         </th>
  1573.         </tr>
  1574.         <tr>
  1575.         <th style="width: 50%;">
  1576.         </th>
  1577.         <th style="width: 50%;">
  1578.         “1983/2023 40 AÑOS DE DEMOCRACIA”
  1579.         </th>
  1580.         </tr>
  1581.         </table>
  1582.         <br/>
  1583.         <br/>
  1584.         <br/>
  1585.         <table style="width: 100%; border-collapse: collapse;">
  1586.         <tr>
  1587.         <th>
  1588.         &nbsp;&nbsp;&nbsp;&nbsp;<strong><u>ACTA DE INSPECCION LEY 20.429, DECRETOS 302/83, 37/01 Y 306/07</u></strong>
  1589.         </th>
  1590.         </tr>
  1591.         </table>
  1592.         <br/>
  1593.         <br/>
  1594.         <table style="width: 100%; border-collapse: collapse;">
  1595.         <tr>
  1596.         <th style="width: 15%;">
  1597.         <i><u>Referencias:</u></i>
  1598.         </th>
  1599.         <th style="width: 85%;">
  1600.         <strong>TRÁMITE RENAR Nº {$data['renar']} ACTA DE INSPECCIÓN NRO {$data["inspeccion"]} <br> CAMIÓN {$data["camion"]}</strong>
  1601.         </th>
  1602.         </tr>
  1603.         </table>
  1604.         <table style="width: 100%; border-collapse: collapse; text-align: justify; text-justify: inter-word; line-height: 1.6;">
  1605.         <p>En Paso Internacional Jama, Departamento de Susques, Provincia de Jujuy, República
  1606.         Argentina, a los {$diaActual} días del mes de {$mesActual} del año {$anioActual}, siendo las {$horaActual}
  1607.         horas con {$minutoActual} minutos, de conformidad a lo determinado en los Art.(s) 4 y 8 de la Ley
  1608.         20.429 (Armas y Explosivos) Art. 599 del Decreto 302/83 (Reglamentación Parcial
  1609.         inherente a Pólvoras, Explosivos y Afines), Decreto 306/07 y convenio preestablecido
  1610.         entre el ANMaC y la Institución, la que suscribe {$data['jefe']} , en su
  1611.         carácter de Jefe del Grupo Paso Internacional “JAMA”, de Gendarmería Nacional
  1612.         Argentina, procede a labrar la presente acta a los fines de dejar expresa constancia de
  1613.         la verificación realizada por el suscripto, acompañado por el Sargento {$data['responsable']}
  1614.         de la unidad de transporte de carga de explosivos en importación al país, el
  1615.         estado de dicho material, las condiciones de transporte y seguridad, como así también la
  1616.         documentación respectiva, en concomitancia con el cuerpo legal citado, en lo que hace
  1617.         a pólvoras, explosivos y afines Acto seguido con la presencia del Sr. {$data['agente_nombre']}
  1618.         DNI {$data['agente_dni']}, con número de Registro {$data['agente_registro']}, de {$data['agente_edad']} años de edad,
  1619.         con domicilio en {$data['agente_domicilio']}, Provincia de Jujuy, en
  1620.         calidad de Apoderado General de Agente de Transporte Aduanero, de INTERJAMA
  1621.         S.R.L. CUIT Nro. 30-71486504-4, con domicilio en Ruta Nacional 52 Km 252, Paso de
  1622.         Jama, provincia de Jujuy, Agente de Transporte Aduanero, representando a la empresa
  1623.         de transporte “{$precarga['cliente']['razon_social']}” y por AFIP DGA Sector Cargas del ACI Paso de
  1624.         Jama, dependiente de la Aduana de Jujuy, en carácter de verificador, {$data['verificador_nombre']}
  1625.         legajo {$data['verificador_legajo']} Nro. {$data['verificador_numero']}, DNI Nro. {$data['verificador_dni']}, se procede a la
  1626.         inspección del transporte de carga tipo camión {$data['marca']}, Modelo {$data['modelo']} dominio
  1627.         colocado “{$precarga['dominio1']}” Año {$data['anio']}, chasis {$data['chasis']}, Motor {$data['motor']},
  1628.         semirremolque marca {$data['semirremolque_marca']} dominio colocado “{$precarga['dominio2']}”, Chasis
  1629.         {$data['semirremolque_chasis']}, conducido por el Sr. {$chofer}, de nacionalidad
  1630.         {$data['nacionalidad']}{$tipo} Nro. {$numero}, fecha de nacimiento {$data['fecha_nacimiento']}, estado
  1631.         civil {$data['estado_civil']}, con Licencia Nacional Habilitante, categoría Mercancías Peligrosas, con
  1632.         fecha de vencimiento el {$data['fecha_vencimiento']}, quien transporta en la oportunidad: {$data['transporta']},
  1633.         conforme detalle en MIC/DTA Nro. {$data['mic_dta']} hoja uno de uno, factura
  1634.         comercial de exportación Nro. {$data['factura_exportacion']}, CRT {$data['crt']} , amparada con
  1635.         autorización de Importación Permiso Nro. 009694 emitida por el R.E.N.A.R., a favor de
  1636.         “{$data['razon_social']}” Se deja expresa constancia que el Despacho Aduanero
  1637.         Provisorio: {$data['provisorio']} y definitivo {$data['definitivo']}, será entregado una
  1638.         vez conformado por la Autoridad Interviniente, en el – Paso de Jama, Provincia de
  1639.         Jujuy. Posteriormente se procedió a inspeccionar el estado general del vehículo
  1640.         mencionado, identificación del mismo, con relación al material transportado, estado de la
  1641.         carga y estiba de la misma, matafuegos y guía de reacción ante circunstancia de
  1642.         siniestro, no detectándose anomalía alguna. Consecuentemente se puso en
  1643.         conocimiento a los nombrados, los Artículos de los Decretos 302/83 y 306/07, que
  1644.         guardan relación con las medidas de seguridad y consideraciones que debe tener
  1645.         presentes en el transporte de explosivos - vía carretera, mediante vehículo de carga.
  1646.         Asimismo, se deja constancia de la apertura del precinto de origen sello aduana
  1647.         {$data['precinto']}-----------------------------------------------------------------------<br>
  1648.         Seguidamente se da por terminado el acto, previa lectura que de por sí realizaron todos
  1649.         los interesados de la presente, se ratifica de todo su contenido, firmando al pié, en
  1650.         prueba de conformidad y para constancia, de SEIS (6) ejemplares de un mismo tenor,
  1651.         por ante mi Oficial Actuante que CERTIFICO. -----------------------------------------------------</p>
  1652.         </table>
  1653.         <br/>
  1654.         <br/>
  1655.         <br/>
  1656.         <br/>
  1657.         <br/>
  1658.         <br/>
  1659.         <table style="width: 100%; border-collapse: collapse; text-align: center;">
  1660.         <tr>
  1661.         <th style="width: 50%;">
  1662.         <p>NOMBRE DEL CHOFER<br>CONDUCTOR</p>
  1663.         </th>
  1664.         <th style="width: 50%;">
  1665.         <p>ORLANDO SEBASTIAN CRUZ<br>APO – ATA</p>
  1666.         </th>
  1667.         </tr>
  1668.         </table>
  1669.         <br/>
  1670.         <br/>
  1671.         <br/>
  1672.         <table style="width: 100%; border-collapse: collapse; text-align: center;">
  1673.         <tr>
  1674.         <th style="width: 50%;">
  1675.         <p>SILVIA ELIANA MAMANI<br>AFIP-DGA</p>
  1676.         </th>
  1677.         <th style="width: 50%;">
  1678.         <p>PABLO GERMAN MIGNONE<br>SARGENTO – GNA</p>
  1679.         </th>
  1680.         </tr>
  1681.         </table>
  1682.         <br/>
  1683.         <br/>
  1684.         <br/>
  1685.         <table style="width: 100%; border-collapse: collapse; text-align: center;">
  1686.         <tr>
  1687.         <th style="width: 100%;">
  1688.         <p>LAURA JOSE IRALA<br>ALFEREZ<br>OFICIAL ACTUANTE-GNA</p>
  1689.         </th>
  1690.         </tr>
  1691.         </table>
  1692.         EOD;
  1693.         $pdf->writeHTML($htmltruefalsefalsefalse'');
  1694.         return new Response($pdf->Output("Formulario Anmac""S"), 200, array(
  1695.             'Content-Type' => 'application/pdf',
  1696.             'Content-Disposition' => 'attachment; filename="Formulario-Anmac.pdf"'
  1697.         )
  1698.     );
  1699.     }
  1700.     /*    
  1701.     public function sendMessaggeWhatsApp($precarga) {
  1702.         $chofer = $precarga->getChoferId()->getTelefono();
  1703.         $ultramsg_token="uzc4beb9g5y20x6j"; // Ultramsg.com token
  1704.         $instance_id="instance59052"; // Ultramsg.com instance id
  1705.         $client = new UltraMsg\WhatsAppApi($ultramsg_token,$instance_id);
  1706.         $to="+549".$chofer; 
  1707.         $body="Interjama informa: Hola " . $precarga->getChoferId()->getNombre();
  1708.         $api=$client->sendChatMessage($to,$body);
  1709.     }
  1710.     */
  1711.     public function getAtencionesConPedidoAsignacionNumero() {
  1712.         $precargas $this->repository->getAtencionesConPedidoAsignacionNumero();
  1713.         return $this->toarray($precargas'precarga');
  1714.     }
  1715.     public function putPrecargaNotificacion($request$id) {
  1716.         $precarga $this->repository->findOneById((int)$id);
  1717.         $precarga->setNotificacion(1);
  1718.         $precarga->setRegistro(null);
  1719.         $precarga $this->updateAtencion($precarga$id);
  1720.         return $precarga;
  1721.     }
  1722.     private function obtenerExtencion($path) {
  1723.         $aux null;
  1724.         $ext explode('.',$path);
  1725.         if ($ext[1] == 'png') {
  1726.             $aux 'PNG';
  1727.         } elseif ($ext[1] == 'jpeg') {
  1728.             $aux 'JPEG';
  1729.         } elseif ($ext[1] == 'jpg') {
  1730.             $aux 'JPG';
  1731.         }
  1732.         return $aux;
  1733.     }
  1734.     public function downloadArchivosFinalizado($precargaId) {
  1735.         $path $this->getPathFiles();
  1736.         $precarga $this->getById((int)$precargaId);
  1737.         // PDF
  1738.         $pdf = new PDF();
  1739.         $pdf->SetTitle("trámite_".$precargaId."_finalizado");
  1740.         $pdf->SetSubject("Archivos de un trámite");
  1741.         $pdf->setFontSubsetting(true);
  1742.         // set default header data
  1743.         $pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTHPDF_HEADER_TITLEPDF_HEADER_STRING);
  1744.         $pdf->SetFont('helvetica'''11''true);
  1745.         $pdf->SetMargins(30155);
  1746.         $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  1747.         $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  1748.         $pdf->setPrintFooter(false);
  1749.         // set auto page breaks
  1750.         $pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);
  1751.         // set image scale factor
  1752.         $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  1753.         // Mic-Data
  1754.         if (COUNT($precarga['archivos']) > 0) {
  1755.             foreach ($precarga['archivos'] as $archivo) {
  1756.                 $ext $this->obtenerExtencion($archivo['ruta']);
  1757.                 $pathAux $path $precargaId '/' $archivo['ruta'];
  1758.                 $pdf->AddPage();
  1759.                 $pdf->Image($pathAux00200200$ext''''false150''falsefalse0falsefalsefalse);
  1760.             }
  1761.         }
  1762.         // Reverso
  1763.         $pdf->AddPage();
  1764.         $pathReverso $path $precarga['archivo_reverso'];
  1765.         $ext $this->obtenerExtencion($precarga['archivo_reverso']);
  1766.         $pdf->Image($pathReverso00200200$ext''''false150''falsefalse0falsefalsefalse);
  1767.         return new Response($pdf->Output("Formulario Anmac""S"), 200, array(
  1768.             'Content-Type' => 'application/pdf',
  1769.             'Content-Disposition' => 'attachment; filename="Archivos-tramite.pdf"'
  1770.         )
  1771.     );
  1772.     }
  1773.     public function getPrecargasByChoferSinFinalizar(int $choferId) {
  1774.         $precargas $this->repository->precargasSinFinalizarPorChofer($choferId);
  1775.         return $this->toarray($precargas,'precarga');
  1776.     }
  1777.     public function searchPrecargasFinalizadasConDeudasByCliente($offset$limit$sortField$sortDirection$searchParam) {
  1778.         $lp $this->repository->searchPrecargasFinalizadasConDeudasByCliente($offset$limit$sortField$sortDirection$searchParam);
  1779.         $precargas $this->toarray($lp->getListado(), 'precarga');
  1780.         foreach ($precargas as &$precarga) {
  1781.             $precarga['tiposTramites'] = $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")->getByPrecarga((int)$precarga['id']);
  1782.             $precarga['monedaReferencia'] = $this->obtenerAbreviaturaDivisa($precarga['moneda']['nombre']);
  1783.         }
  1784.         $lp->setListado($precargas);
  1785.         return $lp;
  1786.     }
  1787.     public function descargaReciboMultiplePdf($tramitesIds) {
  1788.         $fechaHoy date('d-m-Y');
  1789.         $pdf = new PDF();       
  1790.         $pdf->SetTitle("Recibo Atención");
  1791.         $pdf->SetSubject("Recibo Atención");
  1792.         $pdf->setFontSubsetting(true);
  1793.         // set default header data
  1794.         $pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTHPDF_HEADER_TITLEPDF_HEADER_STRING);
  1795.         $pdf->SetFont('helvetica'''9''true);
  1796.         $pdf->SetMargins(555);
  1797.         $pdf->SetHeaderMargin(0);
  1798.         $pdf->SetFooterMargin(0);
  1799.         $pdf->setPrintFooter(false);
  1800.         $precarga1 $this->getById($tramitesIds[0]);
  1801.         // set auto page breaks
  1802.         $pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);
  1803.         // set image scale factor
  1804.         $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  1805.         // Add a page
  1806.         $pdf->AddPage('P''A4');
  1807.         // Encabezado común para todas las precargas
  1808.         $html = <<<EOD
  1809.         <table style="width: 100%; border-top: 1px solid black;border-left: 1px solid black;border-right: 1px solid black;">
  1810.             <tr>
  1811.                 <th style="text-align: left">
  1812.                     <span></span><br>
  1813.                     <img src="app/images/interjama-logo.jpeg" alt="Interjama" width="300" height="100" />
  1814.                 </th>
  1815.                 <th style="text-align: center">
  1816.                     <span style="font-size: 30px; font-weight: bold;">RECIBO</span><br>
  1817.                     <span style="font-size: 10px;">Original</span>
  1818.                 </th>
  1819.         <th style="text-align: center">
  1820.         <span></span><br>
  1821.         <span style="font-size: 12px; font-weight: bold;">Recibo</span><br>
  1822.         <span style="font-size: 12px; font-weight: bold;">Nº MULTIPLE</span><br>
  1823.         <span style="font-size: 12px; font-weight: bold;">{$fechaHoy}</span>
  1824.         </th>
  1825.         </tr>
  1826.         </table>
  1827.         <br/>
  1828.         <table style="width: 100%; border-bottom: 1px solid black;border-left: 1px solid black;border-right: 1px solid black;">
  1829.         <tr>
  1830.         <th style="text-align: left; border-right: 1px solid black">
  1831.         <strong style="text-align: left;">Razón Social: </strong>INTERJAMA S.R.L.<br>
  1832.         <strong style="text-align: left;">Fecha de Emisión: {$fechaHoy}</strong><br>
  1833.         <strong style="text-align: left;">Domicilio comercial: </strong>Alvear 495 Piso:2 Dpto:C - San Salvador de Jujuy - Jujuy<br>
  1834.         <strong style="text-align: left;">Sitio web: </strong>www.interjama.com.ar<br>
  1835.         </th>
  1836.         <th style="text-align: left">
  1837.         <strong style="text-align: left;">Condición frente al IVA: IVA Responsable Inscripto</strong><br>
  1838.         <strong style="text-align: left;">CUIT: </strong>30714865044<br>
  1839.         <strong style="text-align: left;">Ingresos Brutos: </strong>A-1-55049<br>
  1840.         <strong style="text-align: left;">Fecha de Inicio de Actividad: </strong>01/07/2015
  1841.         </th>
  1842.         </tr>
  1843.         </table>
  1844.         <br/>
  1845.         <div style="width: 100%; border: 0.5px solid black; margin-top: 1px;">
  1846.         <strong style="margin-left: 10px;">Periodo Facturado Desde:</strong> {$fechaHoy} <strong style="margin-left: 90px;">Hasta:</strong> {$fechaHoy} <strong style="margin-left: 200px;">Fecha de Vto. para el pago:</strong> {$fechaHoy}
  1847.         </div>
  1848.         <div style="width: 100%; border: 0.5px solid black; margin-top: 1px;">
  1849.         <strong style="text-align: left;">CUIT:</strong> {$precarga1['cliente']['cuit']}<br>
  1850.         <strong style="text-align: left;">Apellido y Nombre / Raz&oacute;n Social</strong> {$precarga1['cliente']['razon_social']}<br>
  1851.         <strong style="text-align: left;">Condici&oacute;n frente al IVA:</strong> {$precarga1['cliente']['condicion_iva']}<br>
  1852.         <strong style="text-align: left;">Condici&oacute;n de venta:</strong> Contado/Efectivo
  1853.         </div>
  1854.         <br/>
  1855.         <!-- Empezamos a mostrar los tiposTramites de todas las precargas -->
  1856.         <table border="0.5">
  1857.         <tr style="background-color: grey;">
  1858.         <th>Cantidad</th>
  1859.         <th>Trámite</th>
  1860.         <th>Tipo trámite</th>
  1861.         <th>Importe</th>
  1862.         <th>Subtotal</th>
  1863.         </tr>
  1864.         EOD;
  1865.         // Iteramos sobre todos los IDs de precarga
  1866.         $totalAduana 0;
  1867.         $subTotal 0;
  1868.         $total 0;
  1869.         $monedaReferencia null;
  1870.         foreach ($tramitesIds as $id) {
  1871.             $precarga $this->getById((int)$id);
  1872.             if (is_null($precarga['comprobante'])) {
  1873.                 $totalAduana $totalAduana + (float)$precarga['aduana'];
  1874.                 $subTotal $subTotal + (float)$precarga['total'];
  1875.                 $total $total + (float)$precarga['total'];
  1876.                 $precarga['tiposTramites'] = $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")->getByPrecarga((int)$id);
  1877.                 $precarga['aduana'] = (!is_null($precarga['aduana']) && !empty($precarga['aduana'])) ? $precarga['aduana'] : 0;
  1878.                 $chofer $precarga['chofer'];
  1879.                 if (is_null($monedaIdReferencia)) {
  1880.                     $monedaReferencia $this->obtenerAbreviaturaDivisa($precarga['moneda']['nombre']);
  1881.                 }
  1882.                 // Aquí, recorremos los tiposTramites de cada precarga y los agregamos a la tabla
  1883.                 foreach ($precarga['tiposTramites'] as $tipo) {
  1884.                     $html .= <<<EOD
  1885.                     <tr>
  1886.                     <td>1,00</td>
  1887.                     <td>{$tipo['tipos_tramite']['tipo']}</td>
  1888.                     <td>{$tipo['tipos_tramite']['nombre']}</td>
  1889.                     <td>{$tipo['importe']}</td>
  1890.                     <td>{$tipo['importe']}</td>
  1891.                     </tr>
  1892.                     EOD;
  1893.                 }
  1894.             }
  1895.         }
  1896.         // Cerrar la tabla de los tipos de trámites
  1897.         $html .= <<<EOD
  1898.         </table>
  1899.         <br/>
  1900.         <!-- Detalle del total por cada precarga -->
  1901.         <table border="0.5">
  1902.         <tr>
  1903.         <th><strong style="margin-left: 0%;"> Imp. Aduana: $:</strong> {$totalAduana}</th>
  1904.         <th><strong style="margin-left: 30%;"> Subtotal: $</strong> {$subTotal}</th>
  1905.         <th><strong style="margin-left: 60%;"> Importe Total: $</strong> {$total} <strong>({$monedaReferencia})</strong></th>
  1906.         </tr>
  1907.         </table>
  1908.         <br/>
  1909.         EOD;
  1910.         // Escribir el HTML al PDF
  1911.         $pdf->writeHTML($htmltruefalsefalsefalse'');
  1912.         // Generar el nombre único del archivo PDF
  1913.         $pdfFileName 'recibo_multiple_' uniqid() . '.pdf';  // Nombre único para el archivo PDF
  1914.         // Generar la ruta completa para guardar el archivo
  1915.         $basePath $this->container->getParameter('kernel.root_dir');
  1916.         $basePath str_replace('/app''/web'$basePath);
  1917.         $basePath $basePath $this->container->getParameter('path_files_comprobantes_deudas');
  1918.         // Verificamos si el directorio existe, y si no, lo creamos
  1919.         if (!file_exists($basePath)) {
  1920.             mkdir($basePath0777true);  // Crear la carpeta si no existe
  1921.         }
  1922.         // Ruta completa del archivo PDF
  1923.         $pdfPath $basePath '/' $pdfFileName;
  1924.         // Guardar el archivo PDF en el servidor
  1925.         $pdf->Output($pdfPath'F');  // 'F' significa guardar el archivo en el sistema
  1926.         // Guardar la URL en la base de datos (relative URL para acceder desde el frontend)
  1927.         $comprobanteUrl '/uploads/files/comprobantes/deudas/' $pdfFileName;
  1928.         // Iteramos sobre todos los trámites y actualizamos cada registro de Precarga
  1929.         foreach ($tramitesIds as $id) {
  1930.             $precarga $this->getPrecargaById($id);
  1931.             $precarga->setComprobante($comprobanteUrl);
  1932.             $this->repository->update($precarga);
  1933.         }
  1934.         // Finalmente, devolver el PDF como respuesta
  1935.         return new Response($pdf->Output("Recibo_Multiple""S"), 200, array(
  1936.             'Content-Type' => 'application/pdf',
  1937.             'Content-Disposition' => 'attachment; filename="Recibo-Multiple.pdf"'
  1938.         ));
  1939.     }
  1940.    public function updateDeuda(Request $request)
  1941.     {
  1942.         $tramitesIds $request->request->get('tramites');
  1943.         $comprobante $request->request->get('comprobante');
  1944.         if (!is_array($tramitesIds) || empty($tramitesIds)) {
  1945.             throw new HttpException(409"No se proporcionaron trámites válidos.");
  1946.         }
  1947.         foreach ($tramitesIds as $id) {
  1948.             if (!is_int($id) && !ctype_digit($id)) { // Asegura que también funcionen strings numéricos
  1949.                 throw new HttpException(409"El ID del trámite debe ser un valor numérico."); 
  1950.             }
  1951.         }
  1952.         if (empty($comprobante)) {
  1953.             throw new HttpException(409"El comporbante es obligatorio."); 
  1954.         }
  1955.         // Validación de moneda unificada
  1956.         $monedaIdReferencia null;
  1957.         // Array para guardar las entidades antes de modificarlas
  1958.         $precargas = [];
  1959.         foreach ($tramitesIds as $tramiteId) {
  1960.             $precarga $this->repository->findOneById($tramiteId);
  1961.             if (!$precarga) {
  1962.                 throw new HttpException(409"Trámite con ID {$tramiteId} no encontrado."); 
  1963.             }
  1964.             // Validar que no tenga fecha de pago aún
  1965.             if (!is_null($precarga->getFechaPago())) {
  1966.                 throw new HttpException(409"El trámite con ID {$tramiteId} ya no tiene deuda."); 
  1967.             }
  1968.             // Obtener el ID de moneda
  1969.             $monedaId $precarga->getMoneda()->getId();
  1970.             if (is_null($monedaIdReferencia)) {
  1971.                 $monedaIdReferencia $monedaId// Guardar la primera moneda como referencia
  1972.             } elseif ($monedaId !== $monedaIdReferencia) {
  1973.                 throw new HttpException(409"Los trámites deben ser de la misma moneda."); 
  1974.             }
  1975.             $precargas[] = $precarga;
  1976.         }
  1977.         // Iniciar transacción
  1978.         $this->entityManager->beginTransaction();
  1979.         try {
  1980.             foreach ($precargas as $precarga) {
  1981.                 $precarga->setFechaPago(new \DateTime());
  1982.                 $this->repository->update($precarga);
  1983.             }
  1984.             $this->entityManager->commit();
  1985.             return 'Las deudas de los trámites han sido actualizadas correctamente.';
  1986.         } catch (\Exception $e) {
  1987.             $this->entityManager->rollback();
  1988.             throw new \Exception('Error al actualizar las deudas: ' $e->getMessage());
  1989.         }
  1990.     }
  1991.     public function descargaFacturaAfipMultiplePdf($tramitesIds$factura) {
  1992.         $precarga1 $this->getById($tramitesIds[0]);
  1993.         if (is_null($precarga1['facturado']) || !$precarga1['facturado']) {
  1994.             // Iteramos sobre todos los IDs de precarga
  1995.             $totalAduana 0;
  1996.             $subTotal 0;
  1997.             $total 0;
  1998.             $monedaReferencia null;
  1999.             foreach ($tramitesIds as $id) {
  2000.                 $precarga $this->getById((int)$id);
  2001.                 $totalAduana $totalAduana + (float)$precarga['aduana'];
  2002.                 $subTotal $subTotal + (float)$precarga['total'];
  2003.                 $total $total + (float)$precarga['total'];
  2004.                 $precarga['tiposTramites'] = $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")->getByPrecarga((int)$id);
  2005.                 if (is_null($monedaIdReferencia)) {
  2006.                     $monedaReferencia $this->obtenerAbreviaturaDivisa($precarga['moneda']['nombre']);
  2007.                 }
  2008.             }
  2009.             $fechaHoy date('d/m/Y');
  2010.             $tipoFactura "A";
  2011.             /*
  2012.             $afip = new Afip(array(
  2013.                 'CUIT' => 27332574049,
  2014.                 'cert' => 'tramite/cert',
  2015.                 'key' => 'tramite/key'
  2016.             ));
  2017.             */
  2018.             if ($factura == 'A') {
  2019.                 try {
  2020.                     $last_voucher 1;
  2021.                     //$last_voucher = $afip->ElectronicBilling->GetLastVoucher(1,1);
  2022.                 } catch (Exception $e) {
  2023.                     return $e->getMessage();
  2024.                 }              
  2025.             } elseif ($factura == 'B') {
  2026.                 try {
  2027.                     $last_voucher 1;
  2028.                     //$last_voucher = $afip->ElectronicBilling->GetLastVoucher(1,6);
  2029.                 } catch (Exception $e) {
  2030.                     return $e->getMessage();
  2031.                 }
  2032.             }        
  2033.             $valfac $last_voucher 1;
  2034.             $nroComprobante $this->numeroAddZero($valfac);
  2035.             $ptoVta "0001";    
  2036.             $neto round($precarga['total'] / 1.212);
  2037.             $iva =  round($neto 0.212);
  2038.             //Se arma factura A
  2039.             $data = array(
  2040.                 'CantReg'   => 1,  // Cantidad de comprobantes a registrar
  2041.                 'PtoVta'    => 1,  // Punto de venta            
  2042.                 'Concepto'  => 1,  // Concepto del Comprobante: (1)Productos, (2)Servicios, (3)Productos y Servicios
  2043.                 'DocTipo'   => 80// Tipo de documento del comprador (99 consumidor final, ver tipos disponibles)
  2044.                 'DocNro'    => $precarga1['cliente']['cuit'],  // Número de documento del comprador (0 consumidor final)
  2045.                 'CbteDesde' => $valfac,  // Número de comprobante o numero del primer comprobante en caso de ser mas de uno
  2046.                 'CbteHasta' => $valfac,  // Número de comprobante o numero del último comprobante en caso de ser mas de uno
  2047.                 'CbteFch'   => intval(date('Ymd')), // (Opcional) Fecha del comprobante (yyyymmdd) o fecha actual si es nulo
  2048.                 'ImpTotal'  => $total// Importe total del comprobante
  2049.                 'ImpTotConc' => 0,   // Importe neto no gravado
  2050.                 'ImpNeto'   => $neto// Importe neto gravado
  2051.                 'ImpOpEx'   => 0,   // Importe exento de IVA
  2052.                 'ImpIVA'    => $iva,  //Importe total de IVA
  2053.                 'ImpTrib'   => 0,   //Importe total de tributos
  2054.                 'MonId'     => 'PES'//Tipo de moneda usada en el comprobante (ver tipos disponibles)('PES' para pesos argentinos) 
  2055.                 'MonCotiz'  => 1,     // Cotización de la moneda usada (1 para pesos argentinos)
  2056.                 'Iva'       => array( // (Opcional) Alícuotas asociadas al comprobante
  2057.                     array(
  2058.                     'Id'        => 5// Id del tipo de IVA (5 para 21%)(ver tipos disponibles) 
  2059.                     'BaseImp'   => $neto// Base imponible
  2060.                     'Importe'   => $iva // Importe 
  2061.                 )
  2062.                 ),
  2063.             );
  2064.             
  2065.             if ($factura == 'A') {
  2066.                 $data['CbteTipo'] = 1;
  2067.                 $codigo 'Código 01';
  2068.             } elseif ($factura == 'B') {
  2069.                 $data['CbteTipo'] = 6;
  2070.                 $tipoFactura "B";
  2071.                 $codigo 'Código 06';
  2072.             } else {
  2073.                 //Se arma factura E de exportación
  2074.             }
  2075.             try {
  2076.                 /*
  2077.                 $res = $afip->ElectronicBilling->CreateVoucher($data);
  2078.                 $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McFacturaHandler")->saveFacturaPrecarga($precargaObj, $tipoFactura, $res, $nroComprobante);
  2079.                 $this->updateFacturado($precargaObj);
  2080.                 */
  2081.                 $res['CAE'] = '987654321';
  2082.                 $res['CAEFchVto'] = '2023-12-31';
  2083.             } catch (Exception $e) {
  2084.                 return $e->getMessage();
  2085.             }          
  2086.             $res['CAE']; //CAE asignado el comprobante
  2087.             $res['CAEFchVto']; //Fecha de vencimiento del CAE (yyyy-mm-dd)
  2088.             // Fin de sección de factura de AFIP
  2089.             //Creacion del PDF
  2090.             // create new PDF document
  2091.             $pdf = new PDF();    
  2092.             $pdf->SetTitle("Precargas atendidas");
  2093.             $pdf->SetSubject("Precargas atendidas");
  2094.             $pdf->setFontSubsetting(true);
  2095.             // set default header data
  2096.             $pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTHPDF_HEADER_TITLEPDF_HEADER_STRING);
  2097.             $pdf->SetFont('helvetica'''9''true);
  2098.             $pdf->SetMargins(5,5,5);
  2099.             $pdf->SetHeaderMargin(0);
  2100.             $pdf->SetFooterMargin(0);
  2101.             $pdf->SetPrintFooter(false);
  2102.             // set auto page breaks
  2103.             $pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);
  2104.             // set image scale factor
  2105.             $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  2106.             $pdf->AddPage('P''A4');
  2107.             // Datos de la empresa emisora de la factura
  2108.             $html = <<<EOD
  2109.             <table style="width: 100%; border-top: 1px solid black;border-left: 1px solid black;border-right: 1px solid black;">
  2110.             <tr>
  2111.             <th style="text-align: left">
  2112.             <span></span><br>
  2113.             <img src="app/images/interjama-logo.jpeg" alt="Interjama" width="300" height="100" />
  2114.             </th>
  2115.             <th style="text-align: center">
  2116.             <span style="font-size: 30px; font-weight: bold;">{$tipoFactura}</span><br>
  2117.             <span style="font-size: 10px;">{$codigo}</span>
  2118.             </th>
  2119.             <th style="text-align: center">
  2120.             <span></span><br>
  2121.             <span style="font-size: 12px; font-weight: bold;">Factura</span><br>
  2122.             <span style="font-size: 12px; font-weight: bold;">Nº {$nroComprobante}</span><br>
  2123.             <span style="font-size: 12px; font-weight: bold;">{$fechaHoy}</span>
  2124.             </th>
  2125.             </tr>
  2126.             </table>
  2127.             <table style="width: 100%; border-bottom: 1px solid black;border-left: 1px solid black;border-right: 1px solid black;">
  2128.             <tr>
  2129.             <th style="text-align: left; border-right: 1px solid black">
  2130.             <strong style="text-align: left;">Raz&oacute;n Social: </strong>INTERJAMA S.R.L.<br>
  2131.             <strong style="text-align: left;">Punto de venta: {$ptoVta}  Comp. Nro: {$nroComprobante}</strong><br>
  2132.             <strong style="text-align: left;">Domicilio comercial: </strong>Alvear 495 Piso:2 Dpto:C - San Salvador de Jujuy - Jujuy<br>
  2133.             <strong style="text-align: left;">Sitio web: </strong>www.interjama.com.ar<br>
  2134.             </th>
  2135.             <th style="text-align: left">
  2136.             <strong style="text-align: left;">Condici&oacute;n frente al IVA: IVA Responsable Inscripto</strong><br>
  2137.             <strong style="text-align: left;">CUIT: </strong>30714865044<br>
  2138.             <strong style="text-align: left;">Ingresos Brutos: </strong>A-1-55049<br>
  2139.             <strong style="text-align: left;">Fecha de Inicio de Actividad: </strong>01/07/2015
  2140.             </th>
  2141.             </tr>
  2142.             </table>
  2143.             <br/>
  2144.             <div style="width: 100%; border: 0.5px solid black; margin-top: 2px;">
  2145.             <strong style="margin-left: 10px;">Preriodo Facturado Desde:</strong> {$fechaHoy} <strong style="margin-left: 90px;">Hasta:</strong> {$fechaHoy} <strong style="margin-left: 200px;">Fecha de Vto. para el pago:</strong> {$fechaHoy}
  2146.             </div>
  2147.             <div style="width: 100%; border: 0.5px solid black; margin-top: 2px;">
  2148.             <strong style="text-align: left;">CUIT:</strong> {$precarga1['cliente']['cuit']}<br>
  2149.             <strong style="text-align: left;">Appelidoy Nombre / Raz&oacute;n Social</strong> {$precarga1['cliente']['razon_social']}<br>
  2150.             <strong style="text-align: left;">Condici&oacute;n frente al IVA:</strong> {$precarga1['cliente']['condicion_iva']}<br>                
  2151.             <strong style="text-align: left;">Condici&oacute;n de venta:</strong> Contado/Efectivo
  2152.             </div>
  2153.             <br/>
  2154.             <table border="0.5">
  2155.             <tr style="background-color: grey;">
  2156.             <th>Cantidad</th>
  2157.             <th>Trámite</th>
  2158.             <th>Tipo trámite</th>
  2159.             <th>Importe</th>
  2160.             <th>Subtotal</th>
  2161.             </tr>
  2162.             EOD;
  2163.             foreach ($tramitesIds as $id) {
  2164.                 $precargaAux $this->getById((int)$id);
  2165.                 if (is_null($precargaAux['comprobante'])) {
  2166.                     $precargaAux['tiposTramites'] = $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaTipoTramitesHandler")->getByPrecarga((int)$id);
  2167.                     // Aquí, recorremos los tiposTramites de cada precarga y los agregamos a la tabla
  2168.                     foreach ($precargaAux['tiposTramites'] as $tipo) {
  2169.                         $html .= <<<EOD
  2170.                         <tr>
  2171.                         <td>1,00</td>
  2172.                         <td>{$tipo['tipos_tramite']['tipo']}</td>
  2173.                         <td>{$tipo['tipos_tramite']['nombre']}</td>
  2174.                         <td>{$tipo['importe']}</td>
  2175.                         <td>{$tipo['importe']}</td>
  2176.                         </tr>
  2177.                         EOD;
  2178.                     }
  2179.                 }
  2180.             }
  2181.             $html .= <<<EOD
  2182.             </table>
  2183.             <br/>
  2184.             <br/>
  2185.             <table border="0.5">
  2186.             <tr>
  2187.             <th><strong style="margin-left: 0%;"> Imp. Aduana: $:</strong> {$totalAduana}</th>
  2188.             <th><strong style="margin-left: 30%;"> Subtotal: $</strong> {$subTotal}</th>
  2189.             <th><strong style="margin-left: 60%;"> Importe Total: $</strong> {$total} <strong>({$monedaReferencia})</strong></th>
  2190.             </tr>
  2191.             </table>
  2192.             <div style="float:right; margin-top: 2px; text-align: right;">
  2193.             <strong>CAE Nº:</strong> {$res['CAE']}<br>
  2194.             <strong>Fecha Vto. de CAE:</strong> {$res['CAEFchVto']}
  2195.             </div>
  2196.             <br/>
  2197.             <table style="width: 100%;">
  2198.             <tr>
  2199.             <th>
  2200.             <img src="app/images/qr.png" alt="Código QR" width="50" height="50"/>
  2201.             </th>
  2202.             <th>
  2203.             <img src="app/images/afip-logo.png" alt="Código QR" width="50" height="15"/><br>
  2204.             <span><b>Comprobante Autorizado</b></span>
  2205.             </th>
  2206.             <th>
  2207.             </th>
  2208.             <th>
  2209.             </th>
  2210.             </tr>
  2211.             </table>
  2212.             EOD;
  2213.             $pdf->writeHTML($htmltruefalsefalsefalse'');
  2214.             
  2215.             // Generar el nombre único del archivo PDF
  2216.             $pdfFileName 'factura_multiple_' uniqid() . '.pdf';  // Nombre único para el archivo PDF
  2217.             // Generar la ruta completa para guardar el archivo
  2218.             $basePath $this->container->getParameter('kernel.root_dir');
  2219.             $basePath str_replace('/app''/web'$basePath);
  2220.             $basePath $basePath $this->container->getParameter('path_files_comprobantes_deudas');
  2221.             // Verificamos si el directorio existe, y si no, lo creamos
  2222.             if (!file_exists($basePath)) {
  2223.                 mkdir($basePath0777true);  // Crear la carpeta si no existe
  2224.             }
  2225.             // Ruta completa del archivo PDF
  2226.             $pdfPath $basePath '/' $pdfFileName;
  2227.             // Guardar el archivo PDF en el servidor
  2228.             $pdf->Output($pdfPath'F');  // 'F' significa guardar el archivo en el sistema
  2229.             // Guardar la URL en la base de datos (relative URL para acceder desde el frontend)
  2230.             $comprobanteUrl '/uploads/files/comprobantes/deudas/' $pdfFileName;
  2231.             // Iteramos sobre todos los trámites y actualizamos cada registro de Precarga
  2232.             foreach ($tramitesIds as $id) {
  2233.                 $precarga $this->getPrecargaById($id);
  2234.                 $precarga->setComprobante($comprobanteUrl);
  2235.                 $this->repository->update($precarga);
  2236.             }
  2237.             return new Response($pdf->Output("Precarga-Factura""S"), 200, array(
  2238.                 'Content-Type' => 'application/pdf',
  2239.                 'Content-Disposition' => 'attachment; filename="Precarga-Factura.pdf"'
  2240.             ));
  2241.         } else {
  2242.             throw new HttpException(409"La precarga ya se encuentra facturado.");  
  2243.         }
  2244.     }
  2245. }