<?php
	
	session_start();

		if($_SESSION['tipo_usu']=='a'  or $_SESSION['tipo_usu']=='c' ){

		}else{

			header('location:acceso_denegado.php');

		}
	
		
?>


<html>
<head>
<link href="../estilos/estilos.css" type="text/css" rel="stylesheet">
</head>
<script language="javascript">

function pon_prefijo(cdgcli,dsccli,salact) {
	parent.opener.document.form_busqueda.cdgcli.value=cdgcli;
	parent.opener.document.form_busqueda.dsccli.value=dsccli;

	parent.opener.document.getElementById("salant").focus();
	parent.opener.document.getElementById("salant").select();


	parent.window.close();


}

function limpiar() {
	parent.opener.document.form_busqueda.cdgcli.value="";
	parent.opener.document.form_busqueda.dsccli.value="";

	parent.opener.document.getElementById("cdgcli").focus();
	parent.opener.document.getElementById("cdgcli").select();
	
	parent.window.close();

}

</script>
<?php include('../conexion.php');


$dsccli=strtoupper($_POST["dsccli"]);

?>
<body>
<?php
		
	if ($result = $mysqli->query("SELECT * FROM web_0301  WHERE dsccli like '%$dsccli%' AND cdgcli != 9999" )) {
  $nrs = $result->num_rows;
   $result->close();
}		
	
?>
<div id="tituloForm2" >
<form id="form1" name="form1">
<?php if ($nrs>0) { ?>
		<table class="fuente8" width="98%" cellspacing=0 cellpadding=3 border=0>
		  <tr class="cabeceraTabla" >
			<td width="10%"><div align="center"><span class="cabeceraTabla"><b>CODIGO</b></span></div></td>
			<td width="60%"><div align="center"><span class="cabeceraTabla"><b>CLIENTE</b></span></div></td>
			<td width="20%"><div align="center"><span class="cabeceraTabla"><b>CEDULA</b></span></div></td>
			<td width="10%"><span class="totalResultado"></span></td>
		    <div align="center">
			
		  </tr>
		<?php
		$consulta="SELECT * FROM web_0301  WHERE dsccli like '%$dsccli%' AND cdgcli != 9999";
		 if ($resultado = $mysqli->query($consulta)) 
        $contador=0;
		
		  while ($fila = $resultado->fetch_assoc()) {
		
				$cdgcli = $fila["CDGCLI"];
				$dsccli = substr($fila["DSCCLI"], 0, 50); 
				$cedcli = $fila["CEDCLI"];
			

				 if ($contador % 2) { $fondolinea="itemParTabla"; } else { $fondolinea="itemImparTabla"; }?>
						<tr class="<?php echo $fondolinea?>">
					<td>
        <div align="center"><?php echo $cdgcli;?></div></td>
					<td>
        <div align="left"><?php echo $dsccli;?></div></td>
		
		<?php
		     $query_saldo ="SELECT SUM(salact) AS saldo FROM web_2101 WHERE cdgcli='$cdgcli'"; 
			 
			 $rs_busqueda = $mysqli->query($query_saldo);
			$fila = $rs_busqueda->fetch_array();
			$salact = $fila["saldo"];

		
		if ($salact > 0)  {
		$salact =  $fila["saldo"];
		}else  {
		$salact = "0.00";
		}
				?>
					<td><div align="center"><?php echo $cedcli;?></div></td>
					<td align="center"><div align="center"><a href="javascript:pon_prefijo(<?php echo $cdgcli?>,'<?php echo $dsccli?>','<?php echo $salact?>')"><img src="../img/Redo_32x32-32.png" border="0" title="Seleccionar"></a></div></td>					
				</tr>
                
			<?php }
		?>
  </table>
  
  		<?php } else { ?>
					<table class="fuente8" width="87%" cellspacing=0 cellpadding=3 border=0>
						<tr>
							<td width="100%" class="mensaje"><?php echo "No existe  cliente que cumpla con los criterios de b&uacute;squeda";?></td>
					    </tr>
					</table>					
					<?php } ?>	
  
  
<iframe id="frame_datos" name="frame_datos" width="0%" height="0" frameborder="0">
	<ilayer width="0" height="0" id="frame_datos" name="frame_datos"></ilayer>
</iframe>
<input type="hidden" id="accion" name="accion">
</form>
</div>
</body>
</html>
