<?
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = '../index.php';
		</script>
		<? 
		exit();
		}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Cuentas Corrientes</title>
<?
include("../conex.php");
$id=$_GET["id"];
if ($id != 0 && $_POST["txtempresa"] != NULL)
{
	$cliente=$_GET["id1"];
	$emp=$_POST["txtempresa"];
}
else
{
	$emp=0;
}
//echo $emp;
?>
<style type="text/css">
<!--
.Estilo1 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;}
.Estilo2 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color:#FF0000}
-->
</style>
</head>
<body LINK="#FFFFFF" VLINK="#FFFFFF" ALINK="#FFFFFF">
<form name="form1" method="post" action="clientes.php?id=1&id1=<?=$cliente;?>" target="_self">
<div align="center" class="titulos2">Cuenta Corriente de Clientes </div>
  <table width="261"  border="1" align="center" cellspacing="0">
    <tr bgcolor="#CCCCCC">
      <td width="45">Buscar:</td>
      <td width="148"><input name="txtempresa" type="text" id="txtempresa"  onKeyPress="return validac(event)"></td>
      <td width="54"><input name="cmdbuscar" type="submit" id="cmdbuscar" value="Buscar"></td>
    </tr>
  </table>
</form>
  <div align="center">
    <table width="30%" border="0">
      <tr>
        <th scope="col"><div align="center">
            <input name="salir" type="button" class="Estilo1" id="salir" value="Salir" onclick="cerrar()"/>
        </div></th>
      </tr>
    </table>
    <table width="40%" border="0">
      <tr bgcolor="#CCCCCC">
        <th scope="col"><div align="center">Número Factura</div></th>
        <th scope="col"><div align="center">Total Factura </div></th>
        <th scope="col"><div align="center">Saldo</div></th>
        <th width="60" scope="col"><div align="center">Mov.</div></th>
      </tr>
	  <?
	  if ($emp == "0")
	  {
		  	$fsql="SELECT * FROM salida AS s WHERE s.rut_cliente='$cliente' AND s.tipo_dcto=2 AND tipo_pago <> 1 ORDER BY s.num_dcto";
			//echo $fsql;
		  	$fcons = mysql_query($fsql,$enlace);
		  	$cont=0;
			$total=0;
		  	while (mysql_fetch_object ($fcons))
		  	{	
				$total=mysql_result($fcons, $cont, "total")-mysql_result($fcons, $cont, "pagada");
			
				$total=$total*(-1);
				//echo $fsql;
		  	?>
				<tr>
		        <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong>
	            <? echo mysql_result($fcons, $cont, "num_dcto");?>
		          </strong></span></div></td>
				<td class="Estilo1" style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="center"><strong>
		        <?=number_format(mysql_result($fcons, $cont, "total"),2,',','.');?>
				</strong></div></td>
				<?  
				  if($total<0)
				  {
				?>  
		        <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="center"><span class="Estilo2"><strong><?=number_format($total,2,',','.');?></strong></span></div></td>
				<?
				}
				else
				{
				?>
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="center"><span class="Estilo1"><strong><?=number_format($total,2,',','.');?></strong></span></div></td>
				<?
				}
				?>
		        <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px; border-left-width:1px"><div align="center"><a href="movimientos.php?id=<?=mysql_result($fcons, $cont, "id");?>&id1=<?=$cliente;?>" target="_blank"><img src="../Images/dir.gif" width="16" height="16" border="0" style="cursor:pointer" title="Click aqui para ver movimientos del Cliente..."></a></div></td>
		        </tr>	
			<?
			
			$cont = $cont + 1;
		  }
		}
		else
	  {
		  $esql="SELECT * FROM salida AS s WHERE s.num_dcto=$emp AND s.tipo_dcto=2 AND tipo_pago <> 1 ORDER BY s.num_dcto";
		  //echo $esql;
		  $fcons = mysql_query($esql,$enlace);
		  $cont=0;
		  	$total=0;
		  	while (mysql_fetch_object ($fcons))
		  	{	
		  		$total=mysql_result($fcons, $cont, "total")-mysql_result($fcons, $cont, "pagada");
				
				$total=$total*(-1);
				//echo $fsql;
			?>
				<tr>
		        <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong>
	            <? echo mysql_result($fcons, $cont, "num_dcto");?>
		          </strong></span></div></td>
				<td class="Estilo1" style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="center"><strong>
				  <?=number_format(mysql_result($fcons, $cont, "total"),2,',','.');?>
				</strong></div></td>
				<?  
				  if($total<0)
				  {
				?>  
		        <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="center"><span class="Estilo2"><strong><?=number_format($total,2,',','.');?></strong></span></div></td>
				<?
				}
				else
				{
				?>
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="center"><span class="Estilo1"><strong><?=number_format($total,2,',','.');?></strong></span></div></td>
				<?
				}
				?>
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px; border-left-width:1px"><div align="center"><a href="movimientos.php?id=<?=mysql_result($fcons, $cont, "id");?>&id1=<?=$cliente;?>" target="_blank"><img src="../Images/dir.gif" width="16" height="16" border="0" style="cursor:pointer" title="Click aqui para ver movimientos del Cliente..."></a></div></td>
		        </tr>	
			<?
			
			$cont = $cont + 1;
		  }
		}
	  ?>
    </table>
  </div>
</body>
</html>

<script language="javascript" type="text/javascript">

var nav4 = window.Event ? true : false;

<!-- Valida el no ingreso de los caracteres < = > | & / " ' [ ]  -->
function validac(evt){
var key = nav4 ? evt.which : evt.keyCode;
return (key != 60 && key != 61 && key != 62 && key != 124 && key != 38 && key != 47 && key != 34 && key != 39 && key != 91 && key != 93);
}	  

function volver(){
parent.location.href = '../index.html';
}
</script>
<script language="javascript" type="text/javascript">
function cerrar()
{
window.top.open('','_parent','');
window.top.close();
}
</script>