<?
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = '../index.php';
		</script>
		<? 
		exit();
		}
$id_empresa =$_SESSION['ss_empresa'];
$id_user = $_SESSION['ss_user'];
?>
<!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>Deuda General Cliente</title>
<?
include("../conex.php");



?>
<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>

<table width="900" border="0">
	<form name="form1" method="post" action="">
      <tr>
        <th width="50%"><div align="right">
            <input name="salir" type="button" class="Estilo1" id="salir" value="Salir" onclick="cerrar()"/>
        </div></th>
  <th width="50%"><div align="left">
			<input name="imprimir" type="button" class="Estilo1" id="imprimir" value="Imprimir" onclick="imprimir()"/>
        </div></th>
         <input name="txt_rut" id="txt_rut" type="text" style="visibility:hidden" >
      </tr>
        </form>
    </table>
    
<table width="670" border="0" >
<tr bgcolor="#CCCCCC" >
	  	<th width="139" scope="col"><div align="center">Rut</div></th>
    <th width="387" scope="col"><div align="center">Nombre</div></th>
    <th width="152" scope="col"><div align="center">Total credito</div></th>
  </tr>
	  <?
		
	
	$total_deuda=0;
	$ttotal_deuda=0;
	
	
	
	 $sqlfs = "SELECT rut_cliente, razon_social, sum(total) as total1 FROM salida, nombres  WHERE (salida.tipo_dcto='2' OR salida.tipo_dcto='6' OR salida.tipo_dcto='7') AND salida.rut_cliente=nombres.rut AND  fecha_emision > '2008-10-31' AND fecha_emision < '2009-11-01' GROUP BY rut_cliente ORDER BY razon_social";
	
	  	  	$resfs = mysql_query($sqlfs,$enlace);	
			$cont=0;
		
	while (mysql_fetch_object ($resfs))
		{
		$total = 3*mysql_result($resfs, $cont, "total1")/12;
		$rut = mysql_result($resfs, $cont, "rut_cliente");
		if ($total>0)
		{
			$sqldcto = "update nombres set monto_credito=$total WHERE monto_credito=0 AND rut='$rut'";
			$resdcto = mysql_query($sqldcto,$enlace);	
		}
				
				$nombre = mysql_result($resfs, $cont, "razon_social");
			
			
				
				$total_deuda=$total;
	
	if ($total_deuda!=0)			
		 { 
				
				
				$ttotal_deuda+=$total_deuda;
	

		  $total_deuda=number_format($total_deuda,0,',','.');
			
	?>			
	
				<tr>
				
		       <td class="Estilo1" style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="left"><strong>
			    <?=$rut?>
			    </strong></div></td>
                
				<td class="Estilo1" style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="left"><strong>
			    <?=$nombre?>
			    </strong></div></td>
 
		       
<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="right"><span class="Estilo2"><strong>
	            <?=$total_deuda;?>
		          </strong></span></div></td>
		        
		        </tr>	
		<?
		}
			$cont = $cont + 1;
       	
	}
		  
		
		  $ttotal_deuda=number_format($ttotal_deuda,0,',','.');
		  
		  
		?>
        
      <tr>
				
		       <td class="Estilo1" style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="left"><strong>
			
			    </strong></div></td>
                
				<td class="Estilo1" style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="left"><strong> Totales	    </strong></div></td>
 
		       
<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-left-width:1px"><div align="right"><span class="Estilo2"><strong>
	            <?=$ttotal_deuda;?>
		          </strong></span></div></td>
		        
</tr>
    </table>
</div>
</body>
</html>

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

var nav4 = window.Event ? true : false;

<!-- Valida el no ingreso de los caracteres < = > | & / " ' [ ]  -->
function validac(evt)
{
var key = nav4 ? evt.which : evt.keyCode;
return (key != 60 && key != 61 && key != 62 && key != 124 && key != 38 && key != 47 && key != 34 && key != 39 && key != 91 && key != 93);
}	  

function cerrar()
{
window.top.open('','_parent','');
window.top.close();
}

function 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>