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

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