<?
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = '../index.php';
		</script>
		<? 
		exit();
		}
$id_empresa = $_SESSION['ss_empresa'];
$id_user = $_SESSION['ss_user'];
$id_autoriza=25;
?>
<?
/*Sesiones*/
include("../conex.php");
include("../autoriza.php");
if ($editar==0)  
{
?>
		<script>
	alert ("No Autorizado");
		parent.location.href = 'index.php';
		</script>
	<? 
	exit();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Libro de Compra</title>
<?
$cuenta=$_POST["lstcuenta"];
$txtfecha=$_POST["txtfecha"];
$dia = substr ($txtfecha, 0, 2);
$mes = substr ($txtfecha, 3, 2);
$mes2=$mes;
$año = substr ($txtfecha, 6, 4);
$ano2=$año;
if ($mes=='01') $mes = "ENERO";
if ($mes=='02') $mes = "FEBRERO";
if ($mes=='03') $mes = "MARZO";
if ($mes=='04') $mes = "ABRIL";
if ($mes=='05') $mes = "MAYO";
if ($mes=='06') $mes = "JUNIO";
if ($mes=='07') $mes = "JULIO";
if ($mes=='08') $mes = "AGOSTO";
if ($mes=='09') $mes = "SEPTIEMBRE";
if ($mes=='10') $mes = "OCTUBRE";
if ($mes=='11') $mes = "NOVIEMBRE";
if ($mes=='12') $mes = "DICIEMBRE";
?>
<style type="text/css">
<!--
.Estilo1 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;}
.Estilo2 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color:#FF0000}
-->
</style>
</head>
<body LINK="#000000" VLINK="#000000" ALINK="#000000">

<div align="center" class="titulos2">LIBRO DE BANCO GIRO MES DE  <?=$mes?> DEL <?=$año?></div>
  <div align="center">
 
 <table width="77%" border="0">
  <tr bgcolor="#CCCCCC">
	  	<th width="5%" scope="col"><div align="center">Día</div></th>
         <th width="7%" scope="col"><div align="center">Vence</div></th>
         <th width="9%" scope="col"><div align="center">NroCheque</div></th>
          <th width="9%" scope="col"><div align="center">NombreCuenta</div></th>
         <th width="9%" scope="col"><div align="center">NroCuenta</div></th>
          <th width="9%" scope="col"><div align="center">Monto</div></th>
           <th width="9%" scope="col"><div align="center">Comprobante</div></th>
      <th width="9%" scope="col"><div align="center">Girado a</div></th>
      <th width="16%" scope="col"><div align="center">Proveedor</div></th>
	  <th width="11%" scope="col"><div align="center">Cobrado</div></th>
    </tr>
		<?	
		
		$total_exento=0;
		$total_neto=0;
		$total_iva=0;
		$total_total=0;
		$total_ivar=0;
		
			if ($cuenta==0) { $sqlfs = "SELECT * FROM banco_cuentas, documentos_proveedores WHERE extract(month from fecha_em)='$mes2' AND extract(year from fecha_em)='$ano2' AND banco_cuentas.id = id_banco_cuentas AND id_empresa = $id_empresa  ORDER BY numero_cheque";
			}
			else  {
			$sqlfs = "SELECT * FROM banco_cuentas, documentos_proveedores WHERE extract(month from fecha_em)='$mes2' AND extract(year from fecha_em)='$ano2' AND banco_cuentas.id = id_banco_cuentas AND id_empresa = $id_empresa AND id_banco_cuentas = $cuenta ORDER BY numero_cheque";
			}

		  	$resfs = mysql_query($sqlfs,$enlace);	
			$cont=0;
		while (mysql_fetch_object ($resfs))
				{
				$fecha = mysql_result($resfs, $cont, "fecha_em");
				$dia = substr ($fecha, 8, 2);
				$fecha = mysql_result($resfs, $cont, "fecha_ven");
				$vence = substr ($fecha, 8, 2)."/".substr ($fecha, 5, 2)."/".substr ($fecha, 0, 4);
				$nombrectacte= mysql_result($resfs, $cont, "descripcion");
				$cheque = mysql_result($resfs, $cont, "cheque");
				$comprobante = mysql_result($resfs, $cont, "comprobante");
				$cobrado = mysql_result($resfs, $cont, "cobrado");
				$ctacte = mysql_result($resfs, $cont, "ctacte");
				$rut = mysql_result($resfs, $cont, "rut");
				
				if ($rut!=''){
				$sqlc = "SELECT * FROM nombres WHERE rut='$rut'";
		  		$resc = mysql_query($sqlc,$enlace);
				$nombre = mysql_result($resc, 0, "razon_social");
				}
								
				$monto = mysql_result($resfs, $cont, "monto");
				
				$total_total+=$monto;
				
                $monto=number_format($monto,0,',','.');
		  	?>
			<tr>
		<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong><?=$dia?></strong></span></div></td>
		<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong><?=$vence?></strong></span></div></td>
                
	    <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong><?=$cheque?></strong></span></div></td>
	    <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong><?=$nombrectacte?></strong></span></div></td>
        <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong><?=$ctacte?></strong></span></div></td>
        <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong><?=$monto?></strong></span></div></td>
    <td 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('<?=$comprobante;?>');">
          <?=$comprobante?>
          </a> </strong></span></div></td>
          
	
    <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong><?=$rut?></strong></span></div></td>
	<td 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 style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="center"><span class="Estilo1"><strong><?=$cobrado?></strong></span></div></td>
    </tr>	
			<?
			$cont+=1;
			
			}
			
			$total_total=number_format($total_total,0,',','.');
			
			?>
			<tr>
		        <td 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 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 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 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 style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong>	Total:	</strong></span></div></td>
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong> <?=$total_total?> </strong></span></div></td>
                <td 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 style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong> </strong></span></div></td> 
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong> </strong></span></div></td>
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong>  </strong></span></div></td>
	        </tr>
    </table>
    
<form name="form1" method="post" action="">
  <p>
    <input type="button" name="imprimir" id="imprimir" value="Imprimir" onClick="fun_imprimir();">
    </p>
  <p>
    <input name="txt_nv" id="txt_nv" type="text" style="visibility:hidden" size="1">
    </p>
</form>
  </div>
</body>
</html>

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

function cerrar()
{
window.top.open('','_parent','');
window.top.close();
}
function fun_imprimir()
	{
	document.getElementById('imprimir').style.display = "none";
	window.print();
	document.getElementById('imprimir').style.display = "block";
	}

function fun_fact(cual)
	{
	var donde;
	donde = "comprobante.php";
	document.form1.txt_nv.value=cual;
	document.form1.action=donde;
	document.form1.target="_blank";
	document.form1.submit();
	}

</script>