<?
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">BALANCE SALDOS AL <?=$mes1."-".$ano1?><br></div>
<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" width="90%" align="center" cellspacing="0">
  <tr bgcolor="#358391" style="color:#FFFFFF; font-weight:bold">
			    <th rowspan="2" scope="col">C&oacute;digo<br>contable</th>
			    <th rowspan="2" scope="col">Nombre</th>
			    <th colspan="3" scope="col">Totales del mes </th>
			    <th height="17" colspan="3" scope="col">Totales Acumulados</th>
		      </tr>
 <tr bgcolor="#358391" style="color:#FFFFFF; font-weight:bold">
			    <th scope="col">D&eacute;bitos</th>
			    <th scope="col">Cr&eacute;ditos</th>
			    <th scope="col">Saldo</th>
				<th height="17" scope="col">D&eacute;bitos</th>
			    <th scope="col">Cr&eacute;ditos</th>
			    <th scope="col">Saldo</th>
			  </tr>


<?
$sql = "
	   select codigo_contable, plan_cuenta.descripcion,
	    SUM(cargo) as cargo, SUM(abono) AS abono,
		SUM(suma_cargo) as suma_cargo,SUM(suma_abono) as suma_abono from ( 
	   
	   SELECT * from (    
		   select  codigo_contable,SUM(cargo) as cargo , SUM(abono) as abono,
		   0 as suma_cargo, 0 as suma_abono  
		   from sb_conta_cta "."where cod_empresa = ".$Codigo_Empresa." 
		   and month(fecha) = ".$mes1." and year(fecha) = ".$ano1."
		   GROUP by     MONTH(fecha),codigo_contable
		   order by  codigo_contable asc
	    ) as table1			
		union
		SELECT * from (    
			select  codigo_contable,0 as cargo, 0 as abono,
			SUM(cargo) as suma_cargo , SUM(abono) as suma_abono 
		   from sb_conta_cta "."where cod_empresa = ".$Codigo_Empresa." 
		   and (fecha BETWEEN '".$ano1."-01-01"."' and '".$ano1."-".$mes1."-31')  
			GROUP by     MONTH(fecha),codigo_contable
			order by  codigo_contable asc
		) as table1					
		
		) as tabla1 
                inner join plan_cuenta 
                on tabla1.codigo_contable = plan_cuenta.cuenta_contable2
		GROUP by tabla1.codigo_contable;		
		";
//echo $sql;		
$db = new sb_mysql();
$saldo_mes=0;
$saldo_ano=0;

$consulta = $db->consulta_free($sql);
while($comp_detalle = $db->sb_array($consulta)){

$saldo_mes=$saldo_mes+($comp_detalle['cargo']-$comp_detalle['abono']);
$saldo_ano=$saldo_ano+($comp_detalle['suma_cargo']-$comp_detalle['suma_abono']);

?>
        <tr class='detalle_tablas_II' bgcolor="#CCCCCC">
          <td><div align="center">
          <?=$comp_detalle['codigo_contable']?>
          </div></td>
          <td align="left">
          <?=$comp_detalle['descripcion']?> 
		  </td>
          <td align="right">
          <?=number_format($comp_detalle['cargo'],0,"",".")?> 
          </td>
          <td align="right">
          <?=number_format($comp_detalle['abono'],0,"",".")?> 
          </td>
          <td align="right">
          <?=number_format($saldo_mes,0,"",".")?> 
		  </td>
          <td align="right">
          <?=number_format($comp_detalle['suma_cargo'],0,"",".")?> 
		  </td>
          <td align="right">
          <?=number_format($comp_detalle['suma_abono'],0,"",".")?> 
		  </td>
          <td align="right">
          <?=number_format($saldo_ano,0,"",".")?> 
		  </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";
};


</script>

