<?
include("../../conexion/class-sb-conexion.php");
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=utf-8" />
<title>Libro mayor analitico</title>
</head>

<body>
<div align="center" class="titulos">LIBRO MAYOR ANALITICO<br></div>
<?
$fecha_desde = $_POST["fecha_desde"]; 
$fecha_hasta = $_POST["fecha_hasta"];
$cuentas1 = $_POST["cuentas1"];


  $wsql = "SELECT cuenta_contable, descripcion FROM plan_cuenta WHERE id_empresa=$Codigo_Empresa AND cuenta_contable= $cuentas1;";
  $db = new sb_mysql();
       $jc_consulta = $db->consulta_free($wsql);
	   while($jc_cuentas = $db->sb_array($jc_consulta))
	   { $nom_cuenta=$jc_cuentas[1];
	
      };

$sql = "select numero_eit, fecha, codigo_contable, glosa, cargo , abono,DAY(fecha) as dia,MONTH(fecha) as mes,year(fecha) as ano, id_sb_conta_eit FROM sb_conta_cta where cod_empresa = $Codigo_Empresa AND (fecha BETWEEN '$fecha_desde' AND '$fecha_hasta') AND codigo_contable = $cuentas1  AND nulo = 0  order by  fecha;";	

 //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.""?>  
<tr>
<td>CUENTA : <?=$cuentas1?>  <?=$nom_cuenta?></td>
</tr>
			
</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>

<?

$db = new sb_mysql();
$consulta = $db->consulta_free($sql);

$total_cargo=0;
$total_abono=0;
$total_saldo=0;
$indice=0;
		
while($comp_detalle = $db->sb_array($consulta))

{

$indice++;

?>
        <tr class='detalle_tablas_II' bgcolor="#CCCCCC">
          <?
		  $id_sb_conta_eit=$comp_detalle['id_sb_conta_eit'];
		  
		  if ($id_sb_conta_eit!='')
		       {
					$sqlx = "SELECT glosa FROM sb_conta_eit WHERE id=$id_sb_conta_eit";
					$resx = mysql_query($sqlx,$enlace);
					$glosa = mysql_result($resx, 0, "glosa");
				}
		  
		  
		  
          $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?id_eit=<?=$comp_detalle['id_sb_conta_eit']?>&numero_comp==<?=$comp_detalle['numero_eit']?>&Codigo_Empresa=<?=$Codigo_Empresa?>')">
		  <?=$comp_detalle['numero_eit']?>
          </a>	         
          </td>
          <td><div align="left">
          <?=$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"><?=number_format($total_saldo,0,"",".")?></td>
          
          </tr>
        
         <?

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

    <td width="80px" align="right"></td>
</tr>
<tr bgcolor="#358391" style="color:#FFFFFF; font-weight:bold" align="center">
	<td  colspan="3">TOTAL</td>
    <td width="80px" align="right"><?=number_format(($total_cargo+$cargo),0,"",".")?></td>
    <td width="80px" align="right"><?=number_format(($total_abono+$abono),0,"",".")?></td>
    <td width="80px" align="right"></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>
