

function login(){
	var form = $('#form_login').serialize();
	var url = '../base/response_api.php';

		$.post(url,form , function(data,status){
			
				let dat  = JSON.parse(data);
			if(dat["id"] > 0){
				let user = $('#user').val();
				
				window.localStorage.setItem("user_mob", user);
				window.localStorage.setItem("id", dat["id"]);
				
				window.location.href = 'index.html';
			}else{
				alert(
					'Falha ao fazer login!',  // message
				);
			}
		});
}
function datacorrig(){
	dayName = new Array ("00","01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12","13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24","25", "26", "27", "28","29", "30", "31"); 
	monName = new Array ("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
	var d = new Date();
	var tp =  dayName[d.getDate()]+"/"+monName[d.getMonth()]+"/"+d.getFullYear();
	
	// hora
	
	var date = new Date();
		var hora = date.getHours() + 1;          // 0-23
		var min = date.getMinutes() + 1;        // 0-59
		var seg = date.getSeconds() + 1;        // 0-59  
		hora = (hora <= 9 ? '0' + hora : hora);
		min = (min <= 9 ? '0' + min : min);
		seg = (seg <= 9 ? '0' + seg : seg);

		var h = hora + ':' + min;
	
	let result = tp+" "+h
	return result;
}
function acaofex(){
		$(".popover").popover("hide");
		console.log("Ok");
}

function consulta_cod(){
	var POST_paramentro = "consulta_externa";
	
	var modo = $("#modo").val();
	var campo = $("#num").val();
	
	if(modo == 1 && campo.length < 3){
		alert("codigo Invalido!!");
	}else{
		
		$.ajax({
			url: "../backend/config/processos/processos2.php",
			type: "POST",
			data: {POST_paramentro,campo,modo},
			dataType: 'json',  
			beforeSend: function(){
				
				$("#verbutt").attr("disabled", true);
				$("#result").html("Aguarde! <img src='../utils/img/gifs.gif' width='15' height='15'/>");
			},   
			error: function(jqXHR, textStatus, errorThrown){
				$("#verbutt").attr("disabled", false);
				console.log('jqXHR: \n'+jqXHR);
				console.log('textStatus: \n'+textStatus);
				console.log('errorThrown: \n'+errorThrown);
			},
			success: function(retorno){
								$("#verbutt").attr("disabled", false);
				if(retorno != false){
						var con = "";
						con += "<div class='card text-left' style='margin: 0;'>";
						con += "  <div class='card-body' style='padding: 0;'>";
							
						con += "	<div class='table-responsive'>";
						con += "	<table class='table table-bordered'>";
						con += "	  <thead class=='thead-dark text-center'>";
						con += "		<tr>";
						con += "		  <th scope='col'>CÓDIGO</th>";
						if(modo == 3){
						con += "		  <th scope='col'>REFERÊNCIA</th>";
						}else{
						con += "		  <th scope='col'>DESCRIÇÃO</th>";
						}
						con += "		</tr>";
						con += "	  </thead>";
						con += "	  <tbody  class='text-center'>";
						
						$.each(retorno, function( p, item ){
							con += "		<tr>";
							con += "		  <td><button type='button' class='btn btn-secondary' onclick='acaofex();' data-container='body' data-toggle='popover' data-placement='left' data-html='true' data-content='<b>DESC:</b>"+item.SQL_IDESCRI+"<br> <b>REF1:</b>"+item.SQL_IREFFAB_1+"<br><b>REF2:</b> "+item.SQL_IREFFAB_2+"<br><b>APL:</b> "+item.SQL_IAPLICA+"<br><b>PV:</b> R$"+item.SQL_IPREVEN+"<br><b>FSA:</b> "+item.LOJA_1STOCK+"<br><b>SAJ:</b> "+item.LOJA_2STOCK+"<br><b>ALG:</b> "+item.LOJA_3STOCK+"<br><b>PNE:</b> "+item.LOJA_4STOCK+"<br><b>CAM:</b> "+item.LOJA_5STOCK+"<br><b>JUA:</b> "+item.LOJA_6STOCK+"<br>'>"+item.SQL_ICODBUS+"</button></td>";
												if(modo == 3){
													con += "		  <td>"+item.SQL_IREFFAB_1+"</td>";
												}else{
													con += "		  <td>"+item.SQL_IDESCRI+"</td>";
												}
							con += "		</tr>";
						});	
						
						con += "	  </tbody>";
						con += "	</table>";
						con += "	</div>";
						
						con += "  </div>";
						con += "</div>	";
				
						
						$("#result").html(con);
						  $('[data-toggle="popover"]').popover();

				}else{
						$("#result").html("Sem resultados!");

				}
				
				
			}
		});
	}
}