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

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