<?php

session_start();
include("DMMYSQLG.php");
//include("DSA1000.php");
include("DMMYSQLG.php");

include("DFJQUERY.inc");
include("DFSELMAN.inc");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Busqueda Producto</title>

</head>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<script language="javascript">
$(document).ready(function(){
	setActions();
	setDefaults();
});

function setActions(){
	$('#divClabp').click(function(){
		var tipBus=document.getElementById('tipBusbp');
		tipBus.value='cla';
		$('#divClabp').removeClass('divUnselected');
		$('#divDesbp').removeClass('divSelected');
		$('#divClabp').addClass('divSelected');
		$('#divDesbp').addClass('divUnselected');
	});
	
	$('#divDesbp').click(function(){
		var tipBus=document.getElementById('tipBusbp');
		tipBus.value='des';
		$('#divClabp').removeClass('divSelected');
		$('#divDesbp').removeClass('divUnselected');		
		$('#divClabp').addClass('divUnselected');
		$('#divDesbp').addClass('divSelected');
	});
		
}

function setDefaults(){
	document.getElementById('te_bus').focus();
}

function sendValPV(idProdFil){
	var sIdProd;
	var documento=window.opener.document;
	documento.getElementById('producto').value=idProdFil;
	window.close();
}

function scapeChar(texto){
	var auxString='';
	for(i=0;i<texto.length;i++){
		if(texto.charAt(i)=="/") 
			auxString +="\\"+texto.charAt(i);
		else
			auxString +=texto.charAt(i);
	}
	return auxString;
}

function resFila(idFila){
	$('#'+idFila).removeClass('divUnselected');
	$('#'+idFila).addClass('divSelected');
}

function noResFila(idFila){
	$('#'+idFila).removeClass('divSelected');
	$('#'+idFila).addClass('divUnselected');
}
</script>
<body>
<form id="frm1" name="frm1" method="post" action="zBusProd.php">
<input type="hidden" name="tipBusbp" id="tipBusbp" value="des">
<div align="center">
  <table border="0">
    <tr class="tabladev" on>
      <td colspan="2" scope="col"><div align="center" class="Estilo2">Buscar Producto<span id="tipVenbp">&nbsp;</span> </div></td>
      </tr>
    <tr >
      <td width="95" style="#FF9900" ><div id="divClabp" align="center" class="divUnselected">&nbsp;&nbsp;&nbsp;Clave&nbsp;&nbsp;&nbsp;</div></td>
      <td width="96" style="#FF9900" ><div id="divDesbp" align="center" class="divSelected">&nbsp;&nbsp;&nbsp;Descripcion&nbsp;&nbsp;&nbsp;</div></td>
      </tr>
    <tr style="#FFFFFF">
      <td colspan="2"><div align="center">
        <input name="te_bus" type="text" id="te_bus" />
      </div></td>
      </tr>
  </table>
  <br>
  <table border="0" >
    <tr class="tabladev">
      <td scope="col"><div align="center" class="style2 Estilo12"><span class="Estilo10">Clave</span></div></td>
      <td scope="col"><div align="center" class="style2 Estilo12"><span class="Estilo10">Descripcion</span></div></td>
      <td scope="col"><div align="center" class="style2 Estilo12"><span class="Estilo10">Almacen</span></div></td>
      <td scope="col"><div align="center" class="style2 Estilo12"><span class="Estilo10">Existencia</span></div></td>
      </tr>
<?php

if((isset($_POST['te_bus']) && $_POST['te_bus']!='') || (isset($_GET['producto']) && $_GET['producto']!='')){
	$tipVen=$_SESSION['tipven'];
	@$dt_tipven=mysqli_fetch_array(mysqli_query($con ,"select * from dgtipven where tip_ven = '$tipVen'"));
	$almacen=$dt_tipven['almacen'];
	$tipBus=$_REQUEST['tipBusbp'];
	if(isset($_POST['te_bus']))
		$teBus=$_POST['te_bus'];
	else
		$teBus=$_GET['producto'];
		
	$sqBus="SELECT 	dginvalm.nparte1 as idProd,
					dginvent.np_desc1 as desProd,
					dgtipven.des_tipven as desAlmacen,
					dginvalm.can_dis_alm as exiFis 
			FROM dginvalm 
				LEFT JOIN dginvent ON(dginvent.nparte1=dginvalm.nparte1) 
				LEFT JOIN dgtipven ON(dgtipven.almacen=dginvalm.almacen) ";
				
	switch($tipBus){
		case 'cla': $sqBus.=" WHERE dginvalm.nparte1='$teBus' AND dginvalm.almacen = '$almacen'";
		case 'des': $sqBus.=" WHERE dginvent.np_desc1 like '%$teBus%' AND dginvalm.almacen = '$almacen'";
	}
	//echo $sqBus.'<br>';
	@$sq_invalm = mysqli_query($con ,$sqBus);
	while(@$dt_invalm=mysqli_fetch_array($sq_invalm)){
	echo '<tr id="'.$dt_invalm['idProd'].'" onmouseover="resFila(this.id)"  onmouseout="noResFila(this.id)" class="divUnselected" onclick="sendValPV(this.id)">
			  <td><div align="center">'.$dt_invalm['idProd'].'&nbsp;</div></td>
			  <td><div align="center">'.$dt_invalm['desProd'].'&nbsp;</div></td>
			  <td><div align="center">'.$dt_invalm['desAlmacen'].'&nbsp;</div></td>
			  <td><div align="center">'.$dt_invalm['exiFis'].'&nbsp;</div></td>
		</tr>';
	}
}
?>	  
 </table>
  <p>&nbsp;</p>
</div>
</form>
</body>
</html>
