<?
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'];
$id_autoriza=7;
/*Sesiones*/
include("../conex.php");
include("../autoriza.php");
?>
<!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>Facturas Pendientes de Pago</title>
<?
include("../conex.php");
$txtfecha=isset($_POST['txtfecha']) ? $_GET['txtfecha'] : '';			//$_POST["txtfecha"];
$dia = substr ($txtfecha, 0, 2);
$mes = substr ($txtfecha, 3, 2);
$mes2=$mes;
$aņo = substr ($txtfecha, 6, 4);
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="#FFFFFF" VLINK="#FFFFFF" ALINK="#FFFFFF"><br>
<div align="center" class="titulos2">FACTURAS PENDIENTES DE PAGO</div>
  <div align="center">
    <table width="80%" border="0">
      <tr bgcolor="#CCCCCC">
	  	<th scope="col"><div align="center">Fecha</div></th>
		<th scope="col"><div align="center">Vencimiento</div></th>
        <th scope="col"><div align="center">RUT</div></th>
        <th scope="col"><div align="center">Proveedor</div></th>
        <th scope="col"><div align="center">Nro</div></th>
        <th scope="col"><div align="center">Total</div></th>
		<th scope="col"><div align="center">Pagado</div></th>
		<th scope="col"><div align="center">Saldo</div></th>
      </tr>
		<?	
		$total_pagado=0;
		$total_total=0;
		$total_saldo=0;
		$sqlfs = "SELECT * FROM entrada, tipo_pago, tipo_dcto, nombres WHERE nombres.rut=entrada.rut_proveedor AND (tipo_dcto.descripcion = 'FACTURA'  OR entrada.tipo_dcto='33' OR entrada.tipo_dcto='56' OR entrada.tipo_dcto='61') AND tipo_dcto.id=entrada.tipo_dcto AND entrada.pagada<>entrada.total AND tipo_pago.descripcion='CREDITO' AND tipo_pago.id=entrada.tipo_pago AND entrada.empresa = $id_empresa  ORDER BY nombres.razon_social";
		  	$resfs = mysql_query($sqlfs,$enlace);	
			$cont=0;
			while (mysql_fetch_object ($resfs))
				{
				$fecha = mysql_result($resfs, $cont, "entrada.fecha_emision");
				$dia = substr ($fecha, 8, 2);
				$ano = substr ($fecha, 0, 4);
				$mes = substr ($fecha, 5, 2);
				$fecha = "$dia/$mes/$ano";

				$fechav = mysql_result($resfs, $cont, "fecha_pago");
				$dia = substr ($fechav, 8, 2);
				$ano = substr ($fechav, 0, 4);
				$mes = substr ($fechav, 5, 2);
				$fechav = "$dia/$mes/$ano";

				$iddcto = mysql_result($resfs, $cont, "tipo_dcto");
				if($iddcto==1)$dcto='B';
				if($iddcto==2)$dcto='F';
				if($iddcto==3)$dcto='NV';
				if($iddcto==4)$dcto='C';
				if($iddcto==5)$dcto='G';
				if($iddcto==6)$dcto='NC';
				if($iddcto==7)$dcto='ND';
				if($iddcto==33)$dcto='FE';
				if($iddcto==56)$dcto='ND E';
				if($iddcto==61)$dcto='NC E';
				$pagado = mysql_result($resfs, $cont, "pagada");
				$total_pagado+=$pagado;
				$rut = mysql_result($resfs, $cont, "rut_proveedor");
				if ($rut!=''){
				$sqlc = "SELECT * FROM nombres WHERE rut='$rut'";
		  		$resc = mysql_query($sqlc,$enlace);
				
				$nombre = mysql_result($resc, 0, "razon_social");
				}
				else 
					{
					$nombre = "Boleta";
					$rut="&nbsp;";
					
					}
				$idasal = mysql_result($resfs, $cont, "id");	
				$iva = mysql_result($resfs, $cont, "iva");
				$nro = mysql_result($resfs, $cont, "num_dcto");
				$iva=number_format($iva,0,',','.');
				$neto= mysql_result($resfs, $cont, "neto");
				$neto=number_format($neto,0,',','.');
				$total = mysql_result($resfs, $cont, "total");
				$total_total+=$total;
				$saldo=$total-$pagado;
				$total_saldo+=$saldo;
				$pagado=number_format($pagado,0,',','.');
				$saldo=number_format($saldo,0,',','.');
				$total=number_format($total,0,',','.');

		  	?>
			<tr>
		        <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong>
	            	<?=$fecha?>
				</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>
	            	<?=$fechav?>
				</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>
	            	<?=$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="left"><span class="Estilo1"><strong>
	            	<?=$nro?>
				</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="left"><span class="Estilo1"><strong>
					<?=$pagado;?>
				</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>
					<?=$saldo;?>
				</strong></span></div></td>
	        </tr>	
			<?
			
			$cont+=1;
			}
			
			$total_pagado=number_format($total_pagado,0,',','.');;
			$total_total=number_format($total_total,0,',','.');;
			$total_saldo=number_format($total_saldo,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="left"><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>
					<?=$total_pagado;?>
				</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_saldo;?>
				</strong></span></div></td>
	        </tr>
    </table>
	
	
	<form name="form1" method="post" action="">
	<table width="150" border="0" align="center">
	<tr>
		<td width="30%" align="rigth">
			<input type="submit" name="salir" value="Salir" onClick="fun_salir();"/>
		</td>
		<td width="70%" align="left">
			<input type="button" name="imprimir" id="imprimir" value="Imprimir" onClick="fun_imprimir();">
		</td>
	</tr>
</table>
		<input name="idsalidaant" type="text" id="idsalidaant" style="visibility:hidden" size="1">
    </form>
  </div>
</body>
</html>

<script language="javascript" type="text/javascript">
function cerrar()
{
window.top.open('','_parent','');
window.top.close();
}
function fun_eliminar(cual)
	{
	document.form1.idsalidaant.value=cual;
	document.form1.action="anular.php";
	document.form1.target="_self";
	document.form1.submit();
	}
function fun_salir()
	{
	window.top.open('','_parent','');window.top.close();
	}
function fun_imprimir()
	{
	document.getElementById('salir').style.display = "none";
	document.getElementById('imprimir').style.display = "none";
	window.print();
	document.getElementById('salir').style.display = "block"
	document.getElementById('imprimir').style.display = "block";
	};
</script>