<?
ini_set('error_reporting',1);
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = '../index.php';
		</script>
		<? 
		exit();
		}
$id_empresa = $_SESSION['ss_empresa'];
$id_user = $_SESSION['ss_user'];
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 DIARIO<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" align="center"  cellpadding="0" cellspacing="0" >
        <?
        $sql="select MONTH(fecha) as mes,* from sb_conta_cta where numero_eit='".$numero_comp."'
			AND year(fecha) = '".$ano."' AND cod_empresa='".$Codigo_Empresa."'	";  
			
		$sql="select 
			DAY(fecha) as dia,MONTH(fecha) as mes,year(fecha) as ano,sb_conta_eit.*
		 from sb_conta_eit where cod_empresa='".$Codigo_Empresa."' ";
		
		if($mes=='on'){
		  $sql.=" AND MONTH(fecha) = '".$mes1."' AND year(fecha) = '".$ano1."' order by DAY(fecha)  ";
		}else{
			  $sql.=" AND fecha = '".$fecha_comprobante."' order by DAY(fecha)  ";
		}
	
		// echo $sql;	
		$total_abono=0;
		$total_cargo=0;
		
		$db = new sb_mysql();
		$consulta = $db->consulta_free($sql);
		$dia_anterior="";
		$indice=0;
		
		while($comp_detalle = $db->sb_array($consulta)){
		$indice++;	        
		if($indice==1){
		   //$dia_anterior=$comp_detalle['dia'];
		}
		if($dia_anterior!=$comp_detalle['dia']){
		$dia_anterior=$comp_detalle['dia'];
		if($indice!=1){
		?>
        <tr>
        <td colspan="2" align="right">Total Diario</td>
        <td align="right"><?=$total_abono?></td>
        <td align="right"><?=$total_cargo?></td>
        </tr>
        <?
        }
		?>
        </table>
        <?
		
		
        $total_abono=0;
		$total_cargo=0;
		?>
        <table width="645" align="center" cellpadding="0" cellspacing="0" border="0">
		<tr  style="color:#000000; font-weight:bold" >
<td  align="left">
DIA :<?=$comp_detalle['dia']?>
</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">N&deg;EIT</td>
    <td width="400px">GLOSA</td>
    <td width="80px">CARGO</td>
    <td width="80px">ABONO</td>
</tr>

		<?
		
		}	
		
		
		 
		?>
        <tr class='detalle_tablas_II' bgcolor="#CCCCCC">
          <td><div align="center">
          <!--<a href="#" onclick="ventana_emergente('../comprobante_contable.php?numero_comp=<?//=$comp_detalle['numero']?>&flag=anular&ano=<?//=$comp_detalle['ano']?>&Codigo_Empresa=<?//=$Codigo_Empresa?>')">-->
          <a href="#" onClick="ventana_emergente('../comprobante_contable.php?id_eit=<?=$comp_detalle['id']?>&numero_comp=<?=$comp_detalle['numero']?>&flag=anular')">
          <?=$comp_detalle['numero']?>
          </a>
          </div></td>
          <td align="left">
		  <?=$comp_detalle['glosa']?>	         
          </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>
          
        </tr>
        
         <?
		 
		// $sql="select * from sb_conta_cta INNER JOIN plan_cuenta ON sb_conta_cta.id_plan_cuenta = plan_cuenta.Id
		// where numero_eit='".$numero_comp."'
		//	AND year(fecha) = '".$ano."' AND cod_empresa='".$Codigo_Empresa."'	";   
		//$sql="select * from sb_conta_eit where cod_empresa='".$Codigo_Empresa."' ";
		
		//$sql="select * from sb_conta_cta INNER JOIN plan_cuenta ON sb_conta_cta.id_plan_cuenta = plan_cuenta.Id
		//where numero_eit='".$comp_detalle['numero']."'
		//	 AND cod_empresa='".$Codigo_Empresa."'	";
	    $sql="SELECT * FROM sb_conta_cta INNER JOIN plan_cuenta ON sb_conta_cta.id_plan_cuenta = plan_cuenta.Id
			WHERE id_sb_conta_eit='".$comp_detalle['id']."'
			AND cod_empresa='".$Codigo_Empresa."'	"; 
		
		if($mes=='on'){
		  $sql=$sql." AND MONTH(fecha) = '".$mes1."' AND year(fecha) = '".$ano1."' ";
		}else{
			  $sql=$sql." AND fecha = '".$fecha_comprobante."' ";
		}
		//echo $sql;
		$consulta_eit = $db->consulta_free($sql);
		while($comp_detalle_eit = $db->sb_array($consulta_eit)){	        
		?>
        <tr class='detalle_tablas_II'>
          
          <td align="left" colspan="2">
	    <!--<pre><?php //print_r($comp_detalle_eit)?></pre>-->
		  <?//=$comp_detalle_eit['glosa']?>
		  <?php echo $comp_detalle_eit['descripcion']; ?>
		  (<?php echo $comp_detalle_eit['cuenta_contable2']; ?>)
          </td>
          <td><div align="right">
          <?=number_format($comp_detalle_eit['cargo'],0,"",".")?> 
          </div></td>
          <td><div align="right">
          <?=number_format($comp_detalle_eit['abono'],0,"",".")?> 
          </div></td>
          
        </tr>
		 <?
		 //echo "...".$comp_detalle['cargo']."...";
          $total_abono=$total_abono+$comp_detalle_eit['abono'];
		  $total_cargo=$total_cargo+$comp_detalle_eit['cargo'];
		 }
         }
		 ?>
         <tr>
        <td colspan="2" align="right">Total Diario</td>
        <td align="right"><?=$total_abono?></td>
        <td align="right"><?=$total_cargo?></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>

</body>
</html>
