<?
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = '../index.php';
		</script>
		<? 
		exit();
		}
$id_empresa = $_SESSION['ss_empresa'];
$id_user = $_SESSION['ss_user'];
?>
<!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");
if (isset($_GET["id"]))$id=$_GET["id"];
else $id = 0;
$emp=$id;

$f3sql="SELECT razon_social AS nombre FROM nombres WHERE rut='$emp'";
$f3cons = mysql_query($f3sql,$enlace);	
$nombre=mysql_result($f3cons, 0, "nombre");
?>
<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">
<div align="center" class="titulos2">Cuenta Corriente de <?=$nombre?>, Rut: <?=$emp;?> </div>
  <div align="center">
    <table width="640px" border="0">
      <tr>
        <th width="50%"><div align="right">
            <input name="salir" type="button" class="Estilo1" id="salir" value="Salir" onclick="cerrar()"/>
        </div></th>
		<th width="50%"><div align="left">
			<input name="imprimir" type="button" class="Estilo1" id="imprimir" value="Imprimir" onclick="imprimir()"/>
        </div></th>
      </tr>
    </table>
    <table width="60%" border="0">
      <tr bgcolor="#CCCCCC">
	  	<th scope="col"><div align="center">Fecha</div></th>
        <th scope="col"><div align="center">Descripcion</div></th>
        <th scope="col"><div align="center">Cargo</div></th>
        <th scope="col"><div align="center">Abono</div></th>
        <th scope="col"><div align="center">Saldo</div></th>
      </tr>
		<?
			$rut=$emp;
			
			$f2sql="SELECT * FROM pago_cliente WHERE rut='$rut' AND empresa = $id_empresa ORDER BY fecha";
		  	$f2cons = mysql_query($f2sql,$enlace);	
			$cont=0;
			$saldo=0;
			while (mysql_fetch_object ($f2cons))
				{
				$fecha = mysql_result($f2cons, $cont, "fecha");
				$descripcion= mysql_result($f2cons, $cont, "descripcion");
				$valor = mysql_result($f2cons, $cont, "valor");
				$tipo = mysql_result($f2cons, $cont, "tipo");
				$totalf2=number_format($valor,0,',','.');
				$ano = substr ($fecha, 0, 4);
				$mes = substr ($fecha, 5, 2);
				$dia = substr ($fecha, 8, 2); 
				$fecha = "$dia/$mes/$ano";
				if ($tipo=='C')$saldo+=$valor;
				else $saldo-=$valor;
				$saldo2=number_format($saldo,0,',','.');
		  	?>
				<tr>
		        <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong>
	            <?=$fecha?>
		          </strong></span></div></td>
				<td class="Estilo1" style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="center"><strong>
		        <?=$descripcion?>
				</strong></div></td>
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="center"><span class="Estilo2"><strong><? if ($tipo=='C') { echo $totalf2;}?>&nbsp;</strong></span></div></td>
			
				 <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="center"><span class="Estilo2"><strong><? if ($tipo=='A') echo $totalf2;?>&nbsp;</strong></span></div></td>
				 
				  <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="center"><span class="Estilo2"><strong><?=$saldo2;?></strong></span></div></td>

	        </tr>	
			<?
			$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 = '../';
}
</script>
<script language="javascript" type="text/javascript">
function cerrar()
{
window.top.open('','_parent','');
window.top.close();
}
function imprimir(){
document.getElementById('salir').style.display = "none";
document.getElementById('imprimir').style.display = "none";
window.print();
document.getElementById('salir').style.display = "block";
document.getElementById('imprimir').style.display = "block";
};
</script>