EVOLUTION-MANAGER
Edit File: documentoController.php
<?php namespace App\Http\Controllers; use mPDF; use Illuminate\Http\Request; use GuzzleHttp\Client as GuzzleHttpClient; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; use TCPDF; use PDF; use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Support\Facades\Validator; use Redirect; use Log; class documentoController extends Controller { //var $url_principal="http://localhost/wscabildo/public/"; var $url_principal="http://190.95.138.26/wscabildo/public/"; // var $url_principal="http://192.168.50.3/wscabildo/public/"; //var $url_principal="http://190.95.138.26/wscabildo/public/"; // var $url_principal="http://192.168.50.3/wscabildo/public/"; function validar_documento(Request $request){ $valor=$request->valor; try { $client = new \GuzzleHttp\Client(); $url=$this->url_principal."validar_documento/$valor"; $header=[ 'headers' => [ 'Content-Type' => 'application/x-www-form-urlencoded', 'Api-Token' => 'clavedetokenparawebservicesdecabildo' ], 'connect_timeout' => 10 ]; $response = $client->request('GET',$url,$header); $resultado= json_decode($response->getBody()->getContents()); //dd($resultado); return view('documentos.resultado_validacion',compact('resultado')); } catch (RequestException $e) { dd($e->getMessage()); } } function consulta_deudas_post(Request $request){ $tipo_busqueda=$request->tipo_busqueda; $valor=$request->valor; try { $client = new \GuzzleHttp\Client(); $url=$this->url_principal."dato_deuda/$tipo_busqueda/$valor"; //$url="http://localhost/wscabildo/public/dato_deuda/$tipo_busqueda/$valor"; //dd($url); $header=[ 'headers' => [ 'Content-Type' => 'application/x-www-form-urlencoded', 'Api-Token' => 'clavedetokenparawebservicesdecabildo' ], 'connect_timeout' => 10 ]; $response = $client->request('GET',$url,$header); $resultado= json_decode($response->getBody()->getContents()); //dd($resultado); //calculamos el total de deudas ----------------------------------- $total_pagar = $resultado->total; if(count($resultado->titulo)){ foreach($resultado->titulo as $clave){ $detalles=collect($clave->detalles); foreach($detalles as $emisiones){ if($emisiones->tipo_impuesto_id==1||$emisiones->tipo_impuesto_id==2){ $total_pagar = $total_pagar + $emisiones->total; } } } } //----------------------------------------------------------------- return view('documentos.resultado_deuda',compact('resultado', 'total_pagar')); } catch (\Throwable $e) { return '<center> <h1 style="font-size: 30px; margin-bottom: 5px; text-transform: none!important; color: #ff9005 !important;"> No se pudo obtener las deudas, por favor inténtelo de nuevo más tarde</h1> </center>'; } } function consulta_descarga_documento(Request $request){ //dd($request->all()); $tipo_busqueda=$request->tipo_busqueda; try { $dato['tipo_busqueda'] = $request->tipo_busqueda; $dato['valor'] = $request->valor; $dato['codigo'] = $request->codigo; // dd($dato); $header=['form_params' => $dato, 'headers' => [ 'Content-Type' => 'application/x-www-form-urlencoded', 'Api-Token' => 'clavedetokenparawebservicesdecabildo' ], 'connect_timeout' => 10 ]; $client = new \GuzzleHttp\Client(); $url=$this->url_principal."datos_pago_ultimo"; // $url="http://localhost/wscabildo/public/datos_pago_ultimo"; $response = $client->request('POST',$url,$header); $resultado= json_decode($response->getBody()->getContents()); return view('documentos.resultado_validacion_descarga',compact('resultado')); } catch (RequestException $e) { $resultado = []; $error = true; return view('documentos.resultado_validacion_descarga',compact('resultado', 'error')); } } function consulta_descarga_documento_get($tipo_busqueda, $valor, $codigo){ $error = 500; try { #validamos la data si se envian caracteres especiales if($tipo_busqueda==0){ $tipo_busqueda = 'cedula'; }else if($tipo_busqueda==1){ $tipo_busqueda = 'ciu'; }else if($tipo_busqueda==2){ $tipo_busqueda = 'clave'; }else{ $error = 404; abort($error); } $dato['tipo_busqueda'] = $tipo_busqueda; $dato['valor'] = $valor; $dato['codigo'] = $codigo; $reglatexto = 'required|regex:/^[A-Za-z0-9ñÑáéíóúÁÉÍÓÚ\s+\/\-.+]+$/'; $validator = Validator::make($dato, [ "tipo_busqueda" => $reglatexto, "valor" => $reglatexto, "codigo" => $reglatexto ]); if($validator->fails()){ $error = 500; abort($error); } $header=['form_params' => $dato, 'headers' => [ 'Content-Type' => 'application/x-www-form-urlencoded', 'Api-Token' => 'clavedetokenparawebservicesdecabildo' ], 'connect_timeout' => 10 ]; $client = new \GuzzleHttp\Client(); $url=$this->url_principal."datos_pago_ultimo"; $response = $client->request('POST',$url,$header); $resultado= json_decode($response->getBody()->getContents()); if(sizeof($resultado) == 0){ $error = 404; abort($error); } return Redirect::to( url('titulo_credito/'.encrypt($resultado[0]->numero_emision)) ); //return view('documentos.resultado_validacion_descarga',compact('resultado')); } catch (RequestException $e) { abort($error); } } function titulo_credito($id){ try { $id=decrypt($id); } catch (DecryptException $e) { dd('ruta no permitida'); } try { $client = new \GuzzleHttp\Client(); //titulo_credito // $url="http://181.198.62.182/wscabildo/public/dato_titulo/$id"; $url=$this->url_principal."dato_titulo/$id"; $header=[ 'headers' => [ 'Content-Type' => 'application/x-www-form-urlencoded', 'Api-Token' => 'clavedetokenparawebservicesdecabildo' ], 'connect_timeout' => 10 ]; $response = $client->request('GET',$url,$header); $resultado= json_decode($response->getBody()->getContents()); // dd($resultado); ini_set('max_execution_time', 5000); $certificado=file_get_contents('public/certificado/xadesnettest.p12'); if(openssl_pkcs12_read($certificado, $certificado_read, "xadesnet")) { $ckey=$certificado_read['pkey']; $crt=$certificado_read['cert']; } PDF::SetAuthor('Titulo de Credito'); PDF::SetTitle('Titulo de Credito'); PDF::SetSubject('Titulo de Credito'); PDF::SetKeywords('TCPDF, PDF, example, test, guide'); PDF::setHeaderCallback(function($pdf){ $bMargin = $pdf->getBreakMargin(); $auto_page_break= true; $pdf->SetAutoPageBreak(false, 30); $img_file = 'public'.'/Escudo_Canton_Sucre_nuevo.jpg'; $pdf->Image($img_file, 85, 20, 120, 150, '', '', '', false, 200, '', false, false, 0); $pdf->SetAutoPageBreak( $auto_page_break, $bMargin); $pdf->setPageMark(); }); PDF::SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE." 048", PDF_HEADER_STRING); PDF::SetMargins(PDF_MARGIN_LEFT+3, PDF_MARGIN_TOP-15, PDF_MARGIN_RIGHT-80); PDF::setHeaderFont(Array(PDF_FONT_NAME_MAIN, "", PDF_FONT_SIZE_MAIN)); PDF::setFooterFont(Array(PDF_FONT_NAME_DATA, "", PDF_FONT_SIZE_DATA)); PDF::SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); PDF::AddPage('L', 'A4'); PDF::SetAutoPageBreak(true, PDF_MARGIN_BOTTOM-1); PDF::lastPage(); PDF::writeHTML(view('certificados.titulo_credito',['resultado'=>$resultado])->render() ); PDF::setFooterCallback(function($pdf)use ($resultado, $id) { $stylew = array( 'border' => true, 'vpadding' => 'auto', 'hpadding' => 'auto', 'fgcolor' => array(0,0,0), 'bgcolor' => false, 'module_width' => 1, 'module_height' => 1 ); $style = array( 'border' => true, 'padding' => 1, 'fgcolor' => array(0,0,0), 'bgcolor' => false, ); $style2 = array( 'position' => 'C', 'align' => 'C', 'stretch' => false, 'fitwidth' => true, 'cellfitalign' => '', 'border' => false, 'hpadding' => 'auto', 'vpadding' => 'auto', 'fgcolor' => array(0,0,0), 'bgcolor' => false, //array(255,255,255), 'text' => true, 'font' => 'helvetica', 'fontsize' => 10, 'stretchtext' => 4 ); PDF::SetY(-45); PDF::Cell(0, 7, '', 0, 1, 'C', 0, '', 0); PDF::Cell(0, 1,'Código Seguro de Verificación (CVS)', 0, 1, 'C', 0, '', 0); PDF::write1DBarcode($resultado->cabecera->numero_emision, 'CODE11', '', '', 195, 16, 0.4, $style2, 'N'); $txt='Puede verificar la validez de este documento ingresando al portal web www.sucre.gob.ec opción Trámites en Línea - Verificar Documentos Electrónicos o leyendo el código QR'; $ttx=''; //$pdf->Image('public/eee.png', 10, 165, 70, 42, '', '', '', false, 300, '', false, false, 0); //$pdf->Image('public/SucreEsUnidad.jpg', 13, 160, 60, 46, '', '', '', false, 300, '', false, false, 0); $pdf->Image('public/SucreEsUnidad.jpg', 13, 175, 60, 26, '', '', '', false, 300, '', false, false, 0); $pdf->SetY(-8); PDF::SetFont('', '', 15); PDF::MultiCell(0, 1, ' '.$ttx."\n", 0, 'J', false, 13, 130, 165, true, 0, false, true, 108, 'T', false); PDF::SetFont('', '', 9 ); PDF::MultiCell(0, 1, ' '.$txt, 0, 'C', false, 13, 2, 193, true, 0, false, true, 0, 'T', false); PDF::write2DBarcode(url('validar_titulo_credito/'.$id), 'QRCODE,Q', 75, 165, 35, 35, $style, 'N'); }); if (ob_get_contents()) ob_end_clean(); return response( PDF::Output('comprobante_pago.pdf'))->header('Content-Type', 'application/pdf'); } catch (\Throwable $e) { Log::error(__CLASS__." => ".__FUNCTION__." => Mensaje => ".$e->getMessage()." => en la linea: ".$e->getLine()); abort(500); } } public function validar_titulo_credito($id){ return Redirect::to( url('titulo_credito/'.encrypt($id)) ); } }