<?
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = '../index.php';
		</script>
		<? 
		exit();
		}
$id_empresa = $_SESSION['ss_empresa']; // ********  02/08/09  **************
$id_user = $_SESSION['ss_user'];
include("../conex.php");
?>
<!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>Informe de Pagos</title>
<?

$caja =$_POST["caja"];


?>
<style type="text/css">
<!--
.Estilo1 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;}
.Estilo4 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; }
-->
</style>
</head>
<body>
<div align="center" class="titulos2"> COMPROBANTES DE CAJA </div>


<table width="23%"border="0"  align="center">
  <tr bgcolor="#CCCCCC">
  	<th scope="col"><div align="left">Pagos </div></th>
</table>		
 <table width="77%"border="0"  align="center">
<tr bgcolor="#CCCCCC">
	  	<th scope="col"><div align="center">Fecha</div></th>
		<th scope="col"><div align="center">Comprobante</div></th>
        <th scope="col"><div align="center">Cliente</div></th>
        <th scope="col"><div align="center">Contado</div></th>
        <th scope="col"><div align="center">Transferencia</div></th>
        <th scope="col"><div align="center">Documentos</div></th>
        <th scope="col"><div align="center">Total</div></th>
      </tr>

<?	
		$t_contado=0;
		$t_tranferencia=0;
        $t_documento=0;
		$t_total=0;
		$sql_cpc = "SELECT * FROM cabeza_pago_cliente, nombres WHERE comprobante=$caja and cabeza_pago_cliente.rut=nombres.rut ORDER BY comprobante";
  		$res_cpc = mysql_query($sql_cpc,$enlace);
     	$cont=0;
			while (mysql_fetch_object ($res_cpc))
			{
			$id_numero = mysql_result($res_cpc, $cont, "id");
			$numero = mysql_result($res_cpc, $cont, "comprobante");
			$contado = mysql_result($res_cpc, $cont, "contado");	
			$tranferencia = mysql_result($res_cpc, $cont, "tranferencia");	
			$documento = mysql_result($res_cpc, $cont, "documento");
			$total=$contado+$tranferencia+$documento;
			$fecha = mysql_result($res_cpc,$cont, "fecha");
				$dia = substr ($fecha, 8, 2);
				$ano = substr ($fecha, 0, 4);
				$mes = substr ($fecha, 5, 2);
				$fecha = "$dia/$mes/$ano";
			$nombre = mysql_result($res_cpc, $cont, "razon_social");
			
			$t_contado+=$contado;
			$t_tranferencia+=$tranferencia;
			$t_documento+=$documento;
			$t_total+=$total;
		  $contado=number_format($contado,0,',','.');	
		  $tranferencia=number_format($tranferencia,0,',','.');	
		  $documento=number_format($documento,0,',','.');
		   $total=number_format($total,0,',','.');
?>
<tr>
<td width="6%" 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 width="10%" style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong>
   	<a  href="javascript:fun_fact('<?=$id_numero;?>');" > <?=$numero?> </a></strong></span></div></td>
                
<td width="29%" style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong><?=$nombre?></strong></span></div></td>
<td width="13%" style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong><?=$contado?></strong></span></div></td>
<td width="14%" style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong><strong>
  <?=$tranferencia?>
</strong></strong></span></div></td>
<td width="12%" style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong><?=$documento?></strong></span></div></td>
<td width="13%" style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong><?=$total?></strong></span></div></td>
</tr>			


<?
			
			$cont+=1;
			}
		
		  $t_contado=number_format($t_contado,0,',','.');	
		  $t_tranferencia=number_format($t_tranferencia,0,',','.');
		  $t_documento=number_format($t_documento,0,',','.');	
		  $t_total=number_format($t_total,0,',','.');	
?>

<tr>
<td width="6%" style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>
				
<td width="13%" style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong>Totales</strong></span></div></td>
<td width="29%" style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong></strong></span></div></td>

<td width="13%" style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong> <?=$t_contado?> </strong></span></div></td>

<td width="14%" style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong> <?=$t_tranferencia?> </strong></span></div></td>
<td width="12%" style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong> <?=$t_documento?> </strong></span></div></td>
<td width="13%" style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong> <?=$t_total?> </strong></span></div></td>
</tr>
</table>
		
<form name="form1" method="post" action="">
	<table width="150" border="0" align="center">
	<tr>
		<td width="30%" align="rigth">
			<input type="submit" name="salir" value="Salir" onClick="fun_salir();"/>
		</td>
		<td width="70%" align="right">
			<input type="button" name="imprimir" id="imprimir" value="Imprimir" onClick="fun_imprimir();">
		</td>
	</tr>
</table>
		<input name="idsalidaant" type="text" id="idsalidaant" style="visibility:hidden" size="1">
    </form>


  </div>
</body>
</html>

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


function fun_salir()
	{
	window.top.open('','_parent','');window.top.close();
	}
	
function fun_fact(cual)
	{
	var donde;
	donde = "comprobante.php";
	document.form1.idsalidaant.value=cual;
	document.form1.action=donde;
	document.form1.target="_blank";
	document.form1.submit();
	}
	
function fun_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>