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