<?
include("../../conexion/class-sb-conexion.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=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<div align="center" class="titulos">LIBRO MAYOR<br></div>
<?
$sql = "select numero_eit, fecha, cuenta_contable2, glosa, cargo , abono, DAY(fecha) as dia,MONTH(fecha) as mes,year(fecha) as ano from sb_conta_cta, plan_cuenta "."where cod_empresa = ".$Codigo_Empresa." and (fecha BETWEEN '".$fecha_desde."' and '".$fecha_hasta."') and cuenta_contable2 between  ".$cuentas1." and ".$cuentas2." and nulo = 0 AND id_plan_cuenta=plan_cuenta.id
		group by cuenta_contable2,fecha
		order by  cuenta_contable2 asc;";	

//echo $sql;

?>
<table width="645" align="center" cellpadding="0" cellspacing="0" border="0">
		<tr  style="color:#000000; font-weight:bold" >
<td width="50%"  >
EMPRESA : <?="".$Empresa.""?>
			
       
			
</td>
</tr>
</table>
<table  border="1" align="center"  cellpadding="0" cellspacing="0" >
<?

$db = new sb_mysql();
$consulta = $db->consulta_free($sql);
$cuenta_anterior="";
$total_cargo=0;
$total_abono=0;
$total_saldo=0;
$indice=0;
		
while($comp_detalle = $db->sb_array($consulta)){
if($cuenta_anterior!=$comp_detalle['cuenta_contable2']){
$cuenta_anterior=$comp_detalle['cuenta_contable2'];

$indice++;
if($indice!=1){
?>
<tr bgcolor="#358391" style="color:#FFFFFF; font-weight:bold" align="center">
	<td  colspan="3" align="center">SUB TOTAL</td>
    <td width="80px" align="right"><?=$total_cargo?></td>
    <td width="80px" align="right"><?=$total_abono?></td>
    <td width="80px" align="right"><?=$total_saldo?></td>
</tr>
<tr bgcolor="#358391" style="color:#FFFFFF; font-weight:bold" align="center">
	<td  colspan="3" align="center">SALDOS</td>
    <?
    if($total_saldo<0){
		$cargo=abs($total_saldo);
		$abono=0;
	}else{
		$cargo=0;
		$abono=abs($total_saldo);
	}
	?>
    <td width="80px" align="right"><?=$cargo?></td>
    <td width="80px" align="right"><?=abs($abono)?></td>

    <td width="80px" align="right">&nbsp;</td>
</tr>
<tr bgcolor="#358391" style="color:#FFFFFF; font-weight:bold" align="center">
	<td  colspan="3" align="center">TOTAL</td>
    <td width="80px" align="right"><?=($total_cargo+$cargo)?></td>
    <td width="80px" align="right"><?=($total_abono+abs($abono))?></td>
    <td width="80px" align="right"></td>
</tr>

<?
}
?>
</table>
<table width="645" align="center" cellpadding="0" cellspacing="0" border="0">
		
<tr>
<td>CUENTA : <?=$cuenta_anterior?></td>
</tr>
</table>
<table  border="1" align="center"  cellpadding="0" cellspacing="0" >
<tr bgcolor="#358391" style="color:#FFFFFF; font-weight:bold" align="center">
	<td width="80px">FECHA</td>
    <td width="80px">EIT</td>
    <td width="400px">GLOSA</td>
    <td width="80px">DEBITOS</td>
    <td width="80px">CREDITOS</td>
    <td width="80px">SALDO</td>
</tr>
<?
$total_saldo=0;
$total_cargo=0;
$total_abono=0;
}

?>
        <tr class='detalle_tablas_II' bgcolor="#CCCCCC">
          <?
		  
          $total_cargo=$total_cargo+$comp_detalle['cargo'];
		  $total_abono=$total_abono+$comp_detalle['abono'];
		  $diferencia=$comp_detalle['cargo']-$comp_detalle['abono'];
		  $total_saldo=$total_saldo+($diferencia);
         
		  //echo "---".$total_diferencia."---".$comp_detalle['cargo']."/".$comp_detalle['abono']."..".$diferencia;    
		  ?>
          <td><div align="center">
          <?=$comp_detalle['dia']."/".$comp_detalle['mes']."/".$comp_detalle['ano']?>
          </div></td>
          <td align="center">
                    <a href="#" onclick="ventana_emergente('../comprobante_contable.php?numero_comp=<?=$comp_detalle['numero_eit']?>&ano=<?=$comp_detalle['ano']?>&Codigo_Empresa=<?=$Codigo_Empresa?>')">

		  <?=$comp_detalle['numero_eit']?>	
          </a>         
          </td>
          <td><div align="left">
          <?=$comp_detalle['glosa']?>
          
          </div></td>
          <td><div align="right">
          <?=number_format($comp_detalle['cargo'],0,"",".")?>
          
          </div></td>
          <td><div align="right">
          <?=number_format($comp_detalle['abono'],0,"",".")?> 
          </div></td>
          <td align="right"><?=$total_saldo?></td>
          
          </tr>
        
         <?

}
?>
<tr bgcolor="#358391" style="color:#FFFFFF; font-weight:bold" align="center">
	<td  colspan="3" align="center">SUB TOTAL</td>
    <td width="80px" align="right"><?=$total_cargo?></td>
    <td width="80px" align="right"><?=$total_abono?></td>
    <td width="80px" align="right"><?=$total_saldo?></td>
</tr>
<tr bgcolor="#358391" style="color:#FFFFFF; font-weight:bold" >
	<td  colspan="3" align="center">SALDOS</td>
    <?
	echo $total_saldo;
    if($total_saldo<0){
		$cargo=abs($total_saldo);
		$abono=0;
	}else{
		$cargo=0;
		$abono=abs($total_saldo);
	}
	?>
    <td width="80px" align="right"><?=$cargo?></td>
    <td width="80px" align="right"><?=$abono?></td>

    <td width="80px" align="right">&nbsp;</td>
</tr>
<tr bgcolor="#358391" style="color:#FFFFFF; font-weight:bold" >
	<td  colspan="3" align="center">TOTAL</td>
    <td width="80px" align="right"><?=($total_cargo+$cargo)?></td>
    <td width="80px" align="right"><?=($total_abono+$abono)?></td>
    <td width="80px" align="right">&nbsp;</td>
</tr>

</table>
<div id="botones" style="display:block" align="center" >
<input name="Imprimir" type="button" class="botones" value="Imprimir" onClick="imprimir_formulario();">
<input name="S A L I R" type="button" class="botones" onClick="top.window.close();" value="S A L I R">
</div>
<script>
function imprimir_formulario(){
document.getElementById('botones').style.display = "none";
window.print();
document.getElementById('botones').style.display = "block";
};

function ventana_emergente(vlink){
ventana1 = window.open(vlink,'popupwin1','status,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=950,height=600,left=300,top=200');
ventana1.focus();
window.open('','_parent','');window.close();
};

</script>

