<?
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = '../index.php';
		</script>
		<? 
		exit();
		}
$id_empresa =$_SESSION['ss_empresa'];      //             ***************  mcc   27-10-10
$id_user = $_SESSION['ss_user'];	
$cntch=$_POST["txtval"];	
$total=$_POST["txttotalfac"];
$rutc=$_POST["txtrutc"];
$comproban=$_POST["comproban"];
$id_vendedor=$_POST["lstvendedor"];
$id_bodega=$_POST["id_bodega"];
$fecha=$_POST["fecha"];
$observacion=$_POST["txtdescripcion"];

?>
<?
include("../conex.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=iso-8859-1" />
<title>Cuenta Corriente</title>
<script type="text/javascript" src="../css/validarut.js"></script>
<script language="javascript" src="../css/cal.js" type="text/javascript"></script>


<style type="text/css">
<!--
.Estilo11 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; }
body {
	background-color: #CCCCCC;
	margin-left: 0px;
	margin-top: 3px;
	margin-right: 0px;
	margin-bottom: 0px;
}
select {
	clear: right;
	float: left;
	height: auto;
	width: 267px;
}
-->
</style></head>

</head>

<body alink="CCCCCC" link="CCCCCC" vlink="CCCCCC">


<form id="form1" name="form1" method="post" action="">
<div align="center">
<table width="90%" border="0" cellspacing="0" cellpadding="0">
     <tr>
		<td width="100%">&nbsp;</td>
	</tr>
	<tr>
		<td width="100%"><div align="center">Ingreso de Cheques </div></td>
	</tr>
    <tr>
		<td width="100%">&nbsp;</td>
	</tr>
</table>
<table width="90%" border="0" cellspacing="0" cellpadding="0">
    <tr>
		<td width="4%">&nbsp;</td>
        <td width="18%">Banco</td>
        <td width="16%">N&uacute;mero&nbsp;</td>
        <td width="16%">Cta. Cte.</td>
        <td width="12%">Emisi&oacute;n</td>
        <td width="4%">&nbsp;</td>
        <td width="12%">Vencimiento</td>
        <td width="4%">&nbsp;</td>
        <td width="10%">Cantidad</td>
        <td width="4%">&nbsp;</td>
	</tr>
<?
$cnt=1;

while ($cnt<=$cntch)
	{
	?>
        <tr>
		<td>&nbsp;</td>
        <td>
	        <select name="lstbanco" id="lstbanco" style="width:98%">
		    <?
			$cons_comuna = mysql_query("SELECT * FROM banco", $enlace);
 			$cont=0;
			while ( mysql_fetch_object ($cons_comuna) ) 
 				{
 				$ides=mysql_result($cons_comuna, $cont, "id");
  				$nombres=mysql_result($cons_comuna, $cont, "descripcion");
  				echo "              <option value=\"".$ides."\">".$nombres."\n";
  				$cont+=1;
 				}
			?>
		    </select>
        </td>
        <td>
        	<input type="text" name="txtnumch[<?=$cnt;?>]" id="txtnumch[<?=$cnt;?>]" style="width:95%">
        </td>
        <td>
        	<input type="text" name="txtctacte[<?=$cnt;?>]" id="txtctacte[<?=$cnt;?>]" style="width:93%">
        </td>
        <td>
        	<input name="fechae<?=$cnt;?>" type="text" class="textboxnormal" id="fechae[<?=$cnt;?>]" readonly="readonly" size="35" maxlength="40" value="<?=date("d/m/Y");?>" style="width:100%">
        </td>
        <td>
        	<a href="javascript:show_calendar('form1.fechae<?=$cnt;?>');"><img src="../Images/CALENDAR.jpg" width="24" height="22" align="absmiddle" style="cursor:pointer" title="Presione aqui y seleccione la fecha"/></a>
        </td>
        <td>
        	<input name="fechav<?=$cnt;?>" type="text" class="textboxnormal" id="fechav[<?=$cnt;?>]" readonly="readonly" size="35" maxlength="40" value="<?=date("d/m/Y");?>" style="width:100%"></td>
        <td width="5%"><a href="javascript:show_calendar('form1.fechav<?=$cnt;?>');"><img src="../Images/CALENDAR.jpg" width="24" height="22" align="absmiddle" style="cursor:pointer" title="Presione aqui y seleccione la fecha"/></a></td>
        <td>
        	<input type="text" name="txtcnt[<?=$cnt;?>]" id="txtcnt[<?=$cnt;?>]" style="width:100%"  onkeypress="return validanum(event);" onBlur="fun_suma_facturas('<?=$cnt;?>');">
        </td>
        <td>&nbsp;</td>
	</tr>
    
	<?
    $cnt+=1;
	}
?>
	<tr>
		<td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td align="left">Contado:&nbsp;</td>
        <td>&nbsp;</td>
        <td><input type="text" name="txtcontado" id="txtcontado" style="width:100%"  onkeypress="return validanum(event);" onBlur="fun_suma_facturas('<?=$cnt;?>');"></td>
        <td width="5%">&nbsp;</td>
	</tr>    
<tr>
		<td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td align="left">Transferencia:&nbsp;</td>
        <td>&nbsp;</td>
        <td><input type="text" name="txttranferencia" id="txttranferencia" style="width:100%"  onkeypress="return validanum(event);" onBlur="fun_suma_facturas('<?=$cnt;?>');"></td>
        <td width="5%">&nbsp;</td>
	</tr>    
	<tr>
	    <td>&nbsp;</td>
		<td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td align="left">Total:&nbsp;</td>
        <td>&nbsp;</td>
        <td><input type="text" name="txttotalch" id="txttotalch" style="width:100%"></td>
        <td>&nbsp;</td>
	</tr>    
</table>


<table width="90%" border="0" cellspacing="0" cellpadding="0">
    <tr>
		<td width="100%" align="center"><input type="button" name="button" id="button" value="Enviar/Grabar" onClick="enviar()" /></td>
	</tr>
</table>
<input type="text" name="rutc" id="rutc" style="width:1px; visibility:hidden" value="<?=$rutc;?>">
<input type="text" name="txtcntch" id="txtcntch" style="width:1px; visibility:hidden">
<input type="text" name="comproban" id="comproban" style="width:1px; visibility:hidden" value="<?=$comproban;?>">
<input type="text" name="id_bodega" id="id_bodega" style="width:1px; visibility:hidden" value="<?=$id_bodega;?>">
<input type="text" name="id_vendedor" id="id_vendedor" style="width:1px; visibility:hidden" value="<?=$id_vendedor;?>">
<input type="text" name="fecha" id="fecha" style="width:1px; visibility:hidden" value="<?=$fecha;?>">
<input type="text" name="txtdescripcion" id="txtdescripcion" style="width:1px; visibility:hidden" value="<?=$observacion;?>">
</div>
</form>
</body>
</html>

<script language="javascript">
<!-- Ingreso solo numeros -->
var nav4 = window.Event ? true : false;
function validanum(evt){
	var key = nav4 ? evt.which : evt.keyCode;
	return (key < 13 || (key >= 48 && key <= 57));
	}
</script>


<script language="javascript" type="text/javascript">
function cerrar()
	{
	window.top.open('','_parent','');
	window.top.close();
	}
function fun_suma_facturas(donde)
	{
	var jscantidad,jsi,jstotal;
	jscantidad=<?=$cnt?>;
	jstotal=0;
	for (jsi=1;jsi<jscantidad;jsi++)
		{
			if (document.getElementById("txtcnt["+jsi+"]").value!='')
				{
				jstotal+=Number(document.getElementById("txtcnt["+jsi+"]").value);
				}
		}
	if (document.form1.txtcontado.value!='')
		{
		jstotal+=Number(document.form1.txtcontado.value);
		}
	if (document.form1.txttranferencia.value!='')
		{
		jstotal+=Number(document.form1.txttranferencia.value);
		}	
		
	document.form1.txttotalch.value=jstotal;
	}
	
function enviar()
	{
	var jstotalc, jstotali, jscantidad,jstotal;
	jstotal=0;
	jstotalc=<?=$total;?>;           //  total facturas
	jscantidad=<?=$cnt?>;            //  cantidad de cheques
	jstotali=document.form1.txttotalch.value;     // total suma
	if (jstotali=='') jstotali=0;
	for (jsi=1;jsi<jscantidad;jsi++)
		{
		if ((document.getElementById("txtcnt["+jsi+"]").value!='' && document.getElementById("txtnumch["+jsi+"]").value!='' &&document.getElementById("txtctacte["+jsi+"]").value!='' )||(document.getElementById("txtcnt["+jsi+"]").value=='' && document.getElementById("txtnumch["+jsi+"]").value=='' && document.getElementById("txtctacte["+jsi+"]").value=='' ))
			{
			jstotal+=Number(document.getElementById("txtcnt["+jsi+"]").value);
			}
		else
			{
			document.getElementById("txtcnt["+jsi+"]").value = '';
			document.getElementById("txtnumch["+jsi+"]").value = '';
			document.getElementById("txtctacte["+jsi+"]").value = '';
			}
		}
	//document.form1.txttotalch.value=jstotal;
	if (jstotalc!=jstotali)
		{
		alert("No coinciden los totales\nTotal Pago: "+jstotalc+", Total Cheques: "+jstotali);
		return false;
		}	
	else 
		{
		//window.opener.enviar(); no envio aca
		document.form1.txtcntch.value=jscantidad;
		document.form1.action = "gcheque.php";
		document.form1.submit();
		}
	}

</script>