var Vgrulpdf=""
function consultar_fe(){
	
	
	
	var myHeaders = new Headers();
	myHeaders.append("Content-Type", "application/json");
	myHeaders.append("x-api-key", VGkeyApi); 
	var numero=VGnumero
	if(VGchkfte==1){
		var Api_ruta="https://isv.aliaddo.net/api/v1/public/documents/invoices/"+numero+"/findByConsecutive"
	}
	if(VGchkfte==2){
		var Api_ruta="https://isv.aliaddo.net/api/v1/public/documents/notes-cr/"+numero+"/findByConsecutive"
	}
	fetch(Api_ruta,{
		method: 'GET',
	 headers: myHeaders
      })  
	  .then(response => response.json())
	  .then(ResTex=>{
		   mostrar_resp(ResTex)	  
	  })
	  .catch(err=>console.log(err))
	  
	}
	
	function mostrar_resp(ResTex){ 
		console.log(ResTex)
		var rpdf=""
		var rxml=""
		var rest=""
		var rzip=""
		var rid=""
		var rcufe=""
		var rqr=""
		var rpre=""
		var rfch=""
		var sw=0
		var rnum=VGprefijo+VGnumero
		Detalle="<div>Factura..";
		for (RowArray=0;RowArray<ResTex.length; RowArray++){
			//alert(ResTex[RowArray].prefix+"-"+VGprefijo+"/"+ResTex[RowArray].consecutive+"-"+VGnumero)
			if(ResTex[RowArray].prefix==VGprefijo && ResTex[RowArray].consecutive==VGnumero){ 
				sw=1
				rpdf=ResTex[RowArray].urlPdf
				rid=ResTex[RowArray].id
				rxml=ResTex[RowArray].urlXmlDocument
				rzip=ResTex[RowArray].urlZip
				rcufe=ResTex[RowArray].cufe
				rqr=ResTex[RowArray].qr
				rest=ResTex[RowArray].dianStateReason
				rpre=ResTex[RowArray].prefix
				rfch=ResTex[RowArray].date
				rfch=rfch.substr(0,10);

				Detalle+='<a href="'+ResTex[RowArray].urlPdf+'">Pdf factura</a><br>';
				Vgrulpdf=ResTex[RowArray].urlPdf;
			}
		}
		
		Detalle+="</div>";
		document.getElementById("app").innerHTML=Detalle;
		//Acctualizando e del Doc. E.
		url="&tipo="+"l";
		url+="&documento="+VGdocumento;
		url+="&empresa="+VGempresa;
		url+="&rpdf="+rpdf;
		url+="&rid="+rid;
		url+="&rxml="+rxml;
		url+="&rzip="+rzip;
		url+="&rcufe="+rcufe;
		url+="&rqr="+rqr;
		url+="&rfch="+rfch;
		url+="&rest="+rest;
		//console.log(url);
		if(sw==1){
			doAjax('controllers/updatedes/',url,'resp_updatede','post','0','Ccargar');
		}else{
			return
		}
	}  
	
	function resp_updatede(ResTex) {
	console.log("PROCESADO");
	abrirlink();
	}
  function abrirlink(){
	  console.log(Vgrulpdf);
	  location.href=Vgrulpdf;
	  }