Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Leo Barreto

Carregando página com e/ou sem itens do pedido

Recommended Posts

Bem Amigos,

Estou com certa dificuldade.

Estou desenvolvendo um sistema de pedidos, que caso o pedido possua itens deverá montar uma tabela com os mesmos.

O problema é que quando o pedido possui itens às vezes a página mostra a tabela e às vezes não.

Tipo, clico para abrir e carrega, se eu fecho e abro de novo não carrega. Se volto a abrir carrega e some a tabela.

 

Segue as funções:

 

botão que chama a janela

$("#itens").on("click", function(){
	var valped;
	valped = $("#valpedido").val();
	if(valped > "0,00"){
	  buscaItem();
	}
	else{
	  buscaProduto('itens.php?tabpreco='+$('select#tabpreco option:selected').val()+'&nrped='+$('#nrpedido').val());
	}
  });

função buscaProduto

function buscaProduto(page){
  var cliente = $("#clien_cod").val(), tabpreco= $("select#tabpreco option:selected").val(),
		nrped = $("#nrpedido").val(), dtmax = $("#dtmax").val(),
		dtmin = $("#dtmin").val(), cond = $("#cond1").val(),
		tippag= $("select#tppagto option:selected").val();
		
	if(cond === ""){
	  $("#alerta").html(
		  "<h4>Informe uma Condição de Pagamento.</h4>"+
		  "<button type='button' class='alerta'>OK</button>");
	  $("#alerta").show();
	  $("#alerta").click(function(){
		$(this).hide();
		$("#cond1").focus();
	  });
	}
	if(tippag === ""){
	  $("#alerta").html(
		"<h4>Selecione um Tipo de Pagamento</h4>"+
		"<button type='button' class='alerta'>OK</button>");
	  $("#alerta").show();
	  $("#alerta").click(function(){
		$(this).hide();
	  });
	}
	if(tabpreco === ""){
	  $("#alerta").html(
		  "<h4>Selecione uma Tabela de Preço.</h4>"+
		  "<button type='button' class='alerta'>OK</button>");
	  $("#alerta").show();
	  $("#alerta").click(function(){
		$(this).hide();
		$("#tabpreco").focus();
	  });
	}
	if(dtmax === ""){
	  $("#alerta").html(
		  "<h4>A Data Máxima de Entrega é inválida.</h4>"+
		  "<button type='button' class='alerta'>OK</button>");
	  $("#alerta").show();
	  $("#alerta").click(function(){
		$(this).hide();
		$("#dtmax").focus();
	  });
	}
	if(dtmin === ""){
	  $("#alerta").html(
		  "<h4>A Data Mínima de Entrega é inválida.</h4>"+
		  "<button type='button' class='alerta'>OK</button>");
	  $("#alerta").show();
	  $("#alerta").click(function(){
		$(this).hide();
		$("#dtmin").focus();
	  });
	}
	if(cliente === ""){
	  $("#alerta").html(
		  "<h4>Selecione um Cliente.</h4>"+
		  "<button type='button' class='alerta'>OK</button>");
	  $("#alerta").show();
	  $("#alerta").click(function(){
		$(this).hide();
	  });
	}
	if(nrped === ""){
	  $("#alerta").html(
		  "<h4>Pedido inválido.</h4>"+
		  "<button type='button' class='alerta'>OK</button>");
	  $("#alerta").show();
	  $("#alerta").click(function(){
		$(this).hide();
	  });
	}
	if ((nrped > '') && (cliente > '') && (tabpreco > '') && (dtmin > '') 
	    && (dtmax > '') && (dtmax > '') && (cond > '')){
		
		$("#busca_prod").load(page);
		$("#busca_prod").show();
	}
}

função buscaItem

function buscaItem(){
  var nrpedido;
  
  nrpedido = $("#nrpedido").val();
  
  buscaProduto('itens.php?tabpreco='+$('select#tabpreco option:selected').val()+'&nrped='+$('#nrpedido').val());
  
  $.ajax({
	type: "POST",
	url: "_application/_itens/itens.php",
	data: {action: "buscaItem", nrpedido: nrpedido},
	dataType: "JSON",
	success: function(data){
	  var totals = 0;
	  totals++;
	  tbl = document.getElementById("tabitem");

	  var novaLinha = tbl.insertRow(2);
	  var novaCelula;

	  if(totals%2===0) cl = "#F5E9EC";
	  else cl = "#FBF6F7";

	  novaCelula = novaLinha.insertCell(0);
	  novaCelula.innerHTML = "<input type='text' class='itrefprod' value='"+data.ref+"' size='20' readonly='readonly' >";

	  novaCelula = novaLinha.insertCell(1);
	  novaCelula.align = "left";
	  novaCelula.style.backgroundColor = cl;
	  novaCelula.innerHTML = "<input type='text' class='ittotref' value='"+data.qtdpecas+"' size='10' readonly='readonly' >";

	  novaCelula = novaLinha.insertCell(2);
	  novaCelula.align = "left";
	  novaCelula.style.backgroundColor = cl;
	  novaCelula.innerHTML = "<input type='text' class='itvalunit' value='"+data.valuni+"' size='10' readonly='readonly' >";

	  novaCelula = novaLinha.insertCell(3);
	  novaCelula.align = "left";
	  novaCelula.style.backgroundColor =cl;
	  novaCelula.innerHTML = "<input type='text' class='ittotgeral' value='"+data.valtot+"' size='10' >";

	  $("#totalpecas").val(data.qtdpecas);
	  $("#valortotal").val(data.valtot);
	}
  });
}

Não estou conseguindo enxergar o erro.

Se alguém puder me dar uma força, uma luz...

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.