<?
include("../fnc.php");
enlinea_a();

$qver=mysql_query("select * from cp_recibos where numero = '$txtndoc' and tipo='$txtiddoc'");
if(mysql_num_rows($qver)>0){
  alert("El documento ingresado ya existe","$goback");
}
unset($qver);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>e-Ducativo - Bienvenido</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../estilo1.css" rel="stylesheet" type="text/css">
<?=mascara();?>
<script language="javascript">
function fnc_vale(){
/*  if (document.form2.txtvale.value=="" && document.form2.txtvvale.value != "0"){
    document.form2.txtvale.value="VALE ";
  }
*/
}

function validar_abono(objeto, max_abono){
  if(eval(objeto.value) > eval(max_abono)){
    alert("No puede abonar más de "+max_abono);
    objeto.value="";
    objeto.focus();
    return (false);
  }
}

function validar(formulario){
 var total_fp;

 if(parseFloat(document.form2.txttotalp.value)<=0){
  alert('Seleccione un cargo a pagar para continuar');
  return (false);
 }

 total_fp=parseFloat(document.form2.txtvef.value)+parseFloat(document.form2.txtvchq.value)+parseFloat(document.form2.txtvdep.value)+parseFloat(document.form2.txtvtc.value)+parseFloat(document.form2.txtvvale.value);

 if(parseFloat(document.form2.txttotalp.value) != total_fp){
  alert('Los totales no coinciden\n\nPor favor verifique la forma de pago');
  return (false);
 }
 
 if(parseFloat(document.form2.txtvchq.value)>0){
   if(document.form2.txtchq.value==""){
     alert("Ingrese el número de cheque");
     document.form2.txtchq.focus();
     return(false);
   }
 }

 <?
 if($f=="sin_impresion"){
 ?>
 if(document.form2.txtdep.value==""){
   alert("Por favor ingrese el número de boleta de depósito");
   document.form2.txtdep.focus();
   return (false);
 }

 if(document.form2.txtfechadep.value==""){
   alert("Por favor ingrese la fecha de la boleta de depósito");
   document.form2.txtfechadep.focus();
   return (false);

 }
 <?
 }
 ?>

document.form2.submit();
return (true);
}

function mostrar_carnet(){
  document.form1.txtcarnet.value = document.form1.txtalumno.value;
}

function seleccionar_alumno(){
  var combo = document.form1.txtalumno;
  var mcarnet = document.form1.txtcarnet.value;
  var respuesta;

  for(i=0;i<combo.length;i++){
    if(combo.options[i].value==mcarnet){
         combo.selectedIndex = i;
    }
  }
}

function total(formulario, numero){

 var total_pago, cargos;
 total_pago=parseFloat(document.form2.txttotalp.value);
<?
if($txtalumno or $txtcarnet){

                          if($txtalumno<>'SV'){
                           $p_alumno=$txtalumno;
                          }else{
                           $p_alumno=$txtcarnet;
                          }

$qcargo=mysql_query("select * from cp_cargos where carnet='$p_alumno' and saldo > 0 order by mes");
$max=mysql_num_rows($qcargo);
for($i=1;$i<=$max;$i++){
?>
if(numero == <?=$i;?>){
 if(document.form2.txtcargo<?=$i;?>.checked){
  total_pago=total_pago+parseFloat(document.form2.txtvalor<?=$i;?>.value);
  document.form2.txtvabono<?=$i;?>.value=document.form2.txtvalor<?=$i;?>.value;
 }else{
  total_pago=total_pago-parseFloat(document.form2.txtvalor<?=$i;?>.value);
  document.form2.txtvabono<?=$i;?>.value=0;
 }
}
<?
 }
}
?>
 document.form2.txttotalp.value=total_pago;
}


function total_rec(formulario){
var total_pago, cargos;
total_pago=0.00;
<?
if($txtalumno or $txtcarnet){

                          if($txtalumno<>'SV'){
                           $p_alumno=$txtalumno;
                          }else{
                           $p_alumno=$txtcarnet;
                          }

$qcargo=mysql_query("select * from cp_cargos where carnet='$p_alumno' and saldo > 0 order by mes");
$max=mysql_num_rows($qcargo);
for($i=1;$i<=$max;$i++){
?>
total_pago=total_pago+parseFloat(document.form2.txtvabono<?=$i;?>.value);
<?
 }
}
?>
//total_pago=parseFloat(document.form2.txttotalp.value);
document.form2.txttotalp.value=total_pago;
}
</script>
<style type="text/css">
<!--
body {
	background-image: url(../images/tema/bg_frm_etiquetas.png);
}
-->
</style></head>

<body>
<table width="750" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#333333">
  <tr>
    <td bgcolor="#336699">    <table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#E5E5E5">
      <tr bgcolor="#FFFFFF">
        <td width="40%"><img src="../images/logo_5.gif" width="300" height="50"></td>
        <td width="60%" background="../images/back_header_admin.gif" bgcolor="#FFFFFF"><div align="right" class="usuario_nombre_enc"><strong><?echo "$unombre $uapellido";?><br>
          </strong>Tiene <?=mensajes($uuser);?> mensaje(s) sin leer</div></td>
      </tr>
      <tr bgcolor="#FFFFFF">
        <td height="15" colspan="2" background="../images/barra_encabezado.gif">&nbsp;</td>
        </tr>
    </table>
      <table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFCC">
        <tr>
          <td width="20%" valign="top" background="../images/tema/bg_contenido.png" bgcolor="#FFFFCC"><?php include("menu.php"); ?>&nbsp;</td>
          <td width="80%" valign="top" background="../images/tema/bg_contenido.png" bgcolor="#FFFFCC"><table width="100%"  border="0" cellpadding="0" cellspacing="0" bgcolor="#333333">
            <tr align="center" valign="middle" bgcolor="#FFFFCC">
              <td height="20" bgcolor="#FFFFCC" class="titulo_pagina"><div align="center" class="titulo_seccion">
                <div align="left">
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td background="../images/tema/bg_contenido.png"><div align="center" class="titulo_pagina">
                        <div align="left" class="parrafo">CONTROL DE PAGOS <img src="../images/flecha_3.jpg" width="9" height="9"> Ingreso de pagos de alumnos </div>
                      </div></td>
                      <td width="65" background="../images/tema/bg_contenido.png"><div align="right"><a href="inicio.php" class="link_parrafo">Inicio<img src="../images/ic_home.png" width="21" height="21" border="0"></a></div></td>
                    </tr>
                  </table>
                </div>
              </div></td>
            </tr>
            <tr>
              <td align="left" valign="top" background="../images/tema/bg_contenido.png" bgcolor="#FFFFCC"><div align="left" class="parrafo">
                <table width="100%"  border="0" cellspacing="0" cellpadding="1">
                  <tr>
                    <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td>
                         <?if($f=="sin_impresion"){?>
                         <form name="form1" method="post" action="<?=$PHP_SELF;?>">
                          <table width="100%"  border="0" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
                            <tr>
                              <td width="27%" background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><strong>Seleccione un alumno </strong></td>
                              <td width="61%" background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9">
                               <select name="txtalumno" class="textbox" id="txtalumno" onchange="mostrar_carnet();">
                                <option value="SV" selected>Seleccione uno...</option>
                               <?
                               $qalum=mysql_query("select carnet, apellido, nombre
                                                   from alumnos
                                                   where year_estudio>0
                                                   order by apellido, nombre");
                               while($ialum=mysql_fetch_array($qalum)){
                                $sel="";
                                if($txtalumno==$ialum[carnet]){
                                 $sel="selected";
                                }
                                echo "<option value='{$ialum[carnet]}' $sel>{$ialum[apellido]}, {$ialum[nombre]}</option>";
                               }
                               ?>
                               </select>
                              </td>
                              <td width="12%" rowspan="2" background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9"><input name="Submit" type="submit" class="boton_guardar" value="Ver cargos..."></td>
                            </tr>
                            <tr>
                              <td background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><strong>o ingrese n&uacute;mero de carn&eacute;:</strong></td>
                              <td background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9"><input name="txtcarnet" type="text" class="textbox" id="txtcarnet" size="15" maxlength="15" onkeyup="seleccionar_alumno();">
                                <input name="f" type="hidden" id="f" value="<?=$f;?>">
                                <input name="txtiddoc" type="hidden" id="txtiddoc" value="<?=$txtiddoc;?>"></td>
                              </tr>
                          </table>
                          </form>
                         <?
                         }//fin del if

                          if(!$txtalumno and !$txtcarnet){
                           exit();
                          }
                          if($txtalumno<>'SV'){
                           $p_alumno=$txtalumno;
                          }else{
                           $p_alumno=$txtcarnet;
                          }

                          $qalm=mysql_query("select * from alumnos where carnet = '$p_alumno'");
                          if(mysql_num_rows($qalm)==0){
                            alert("El alumno no existe","javascript:history.go(-1)");
                          }
                          $ialm=mysql_fetch_array($qalm);
                          $qvam=mysql_query("select * from grados where id = {$ialm[grado_estudio]}");
                          if(mysql_num_rows($qvam)==0){
                           alert("ERROR:\\nEl alumno no está inscrito en ningun grado","javascript:history.go(-1)");
                          }
                          $ivam=mysql_fetch_array($qvam);

                          $qdoc=mysql_query("select * from cp_talonarios where id = $txtiddoc");
                          $idoc=mysql_fetch_array($qdoc);
                          ?>
                          <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td><form name="form2" method="post" action="mnt_pagov2.php" onsubmit="return validar(this.form);">
                                <table width="125%"  border="0" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
                                  <?
                                  if($f!="sin_impresion"){
                                  ?>
                                  <tr>
                                    <td background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><strong>Documento:</strong></td>
                                    <td background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9" class="lbl_roja"><?=$idoc[nombre];?>                                      , No.                                      <?=$txtndoc;?> </td>
                                  </tr>
                                  <?
                                  }
                                  ?>
                                  <tr>
                                    <td width="20%" background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><strong># Carn&eacute;:</strong></td>
                                    <td width="80%" background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9" class="lbl_formulario"><?=$ialm[carnet];?>                                      </td>
                                  </tr>
                                  <tr>
                                    <td background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><strong>Alumno:</strong></td>
                                    <td background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9"><span class="lbl_formulario">
                                      <?=$ialm[apellido].", ".$ialm[nombre];?>
                                    </span></td>
                                  </tr>
                                </table>
                                <hr size="1">
                                <table width="100%"  border="0" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
                                  <tr bgcolor="#CFDFEF">
                                    <td colspan="6" background="../images/tema/bg_frm_campos.png"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                      <tr>
                                        <td width="6%" background="../images/tema/bg_titulo_frm.png"><img src="../images/tema/ic_formularios.png" width="35" height="32"></td>
                                        <td width="94%" background="../images/tema/bg_titulo_frm.png" class="titulo_formulario"><div align="left">Seleccione los cargos a pagar </div></td>
                                      </tr>
                                    </table></td>
                                    </tr>
                                  <tr bgcolor="#CFDFEF">
                                    <td width="7%" background="../images/tema/bg_frm_campos.png"><div align="center"><strong>TIPO</strong></div></td>
                                    <td width="21%" background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><div align="center"><strong>FECHA DEL CARGO </strong></div></td>
                                    <td width="42%" background="../images/tema/bg_frm_campos.png"><div align="center"><strong>DESCRIPCION</strong></div></td>
                                    <td width="10%" background="../images/tema/bg_frm_campos.png"><div align="center"><strong>SALDO</strong></div></td>
                                    <td width="11%" background="../images/tema/bg_frm_campos.png"><div align="center"><strong>SELECCIONE</strong></div></td>
                                    <td width="9%" background="../images/tema/bg_frm_campos.png"><div align="center"><strong>VALOR</strong></div></td>
                                 </tr>
                                  <?
                                  $qcargo=mysql_query("select * from cp_cargos where carnet='$p_alumno' and saldo > 0 order by fecha_cargo, descripcion");
                                  $i=0;
                                  $suma_cargo=0;
                                  $suma_saldo=0;
                                  while($icargo=mysql_fetch_array($qcargo)){
                                  $i++;
                                  $suma_cargo+=$icargo[valor];
                                  $suma_saldo+=$icargo[saldo];
                                  ?>
                                  <tr bgcolor="<?=color_fila($i);?>">
                                    <td height="21"><div align="center">
                                        <?=$icargo[tipo];?>
                                    </div></td>
                                    <td><div align="center">
                                        <?=fecha($icargo[fecha_cargo]);?>
                                    </div></td>
                                    <td><div align="left">
                                        <?=($icargo[descripcion]);?>
                                        <input type="hidden" name="txtidc[<?=$i;?>]" value="<?=$icargo[id];?>">
                                    </div></td>
                                    <td><div align="right">
                                        <input name="txtvalor<?=$i;?>" type="hidden" id="txtvalor<?=$i;?>" value="<?=$icargo[saldo];?>">
                                        <input name="txtvalor[<?=$i;?>]" type="hidden" id="txtvalor[<?=$i;?>]" value="<?=$icargo[saldo];?>">
                                        <?=moneda(sprintf("%.2f",$icargo[saldo]),"Q");?>
                                    </div></td>
                                    <td><div align="center"><input name="txtcargo<?=$i;?>" type="checkbox" id="txt1" value="S" onClick="total(document.form2, <?=$i;?>); total_rec(this.form2);"></div></td>
                                    <td><div align="center">
                                      <input name="txtvabono<?=$i;?>" type="text" id="txtvabono<?=$i;?>" dir="rtl" onChange="total_rec(this.form);" value="0" size="8" maxlength="8" onkeyup="validar_abono(this,'<?=$icargo[saldo];?>');">
                                    </div></td>
                                  </tr>
                                  <?
                                  }
                                  ?>
                                  <tr bgcolor="#CFDFEF">
                                    <td background="../images/tema/bg_frm_campos.png"><div align="center">&nbsp;</div></td>
                                    <td align="center" valign="bottom" background="../images/tema/bg_frm_campos.png"><div align="left"><strong>TOTALES</strong></div></td>
                                    <td align="center" valign="bottom" background="../images/tema/bg_frm_campos.png"><input name="imax" type="hidden" id="imax" value="<?=$i;?>"><input type="hidden" name="txtalumno" value="<?=$p_alumno;?>"></td>
                                    <td align="center" valign="bottom" background="../images/tema/bg_frm_campos.png"><div align="right"><strong>
                                        <?=moneda(sprintf("%.2f",$suma_saldo),"Q");?>
                                    </strong></div></td>
                                    <td align="center" valign="bottom" background="../images/tema/bg_frm_campos.png"><div align="center">
                                    </div></td>
                                    <td align="center" valign="bottom" background="../images/tema/bg_frm_campos.png"><input name="txttotalp" type="text" id="txttotalp" dir="rtl" value="0.00" size="8" maxlength="8"></td>
                                  </tr>
                                </table>
                                <br>
                                <table width="100%"  border="0" cellpadding="1" cellspacing="1" background="../images/tema/bg_contenido.png" bgcolor="#FFFFFF">
                                  <tr bgcolor="#CFDFEF">
                                    <td colspan="5" class="titulo_seccion"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                      <tr>
                                        <td width="6%" background="../images/tema/bg_titulo_frm.png"><img src="../images/tema/ic_pagos.png" width="35" height="32"></td>
                                        <td width="94%" background="../images/tema/bg_titulo_frm.png"><span class="titulo_formulario">INGRESE LA  FORMA DE PAGO</span>
                                          <input name="txtcarnet" type="hidden" id="txtcarnet" value="<?=$p_alumno;?>">
                                          <input name="f" type="hidden" id="f3" value="<?=$f;?>">
                                          <input name="txttalonario" type="hidden" id="txttalonario" value="<?=$txtiddoc;?>">
                                          <input name="txtndoc" type="hidden" id="txtndoc" value="<?=$txtndoc;?>">
                                          <input name="txtfechadoc" type="hidden" id="txtfechadoc" value="<?=$txtfechadoc;?>">
                                          <input name="txtobs" type="hidden" id="txtobs" value="<?=$txtobs;?>"></td>
                                      </tr>
                                    </table></td>
                                    </tr>
                                  <tr>
                                    <td width="17%" background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><strong>Efectivo</strong></td>
                                    <td colspan="4" background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9"><strong>
                                      <input name="txtvef" type="text" class="textbox" id="txtvef" dir="rtl" value="0" size="11" maxlength="11" ondblclick="this.value=document.form2.txttotalp.value;">
                                    </strong></td>
                                  </tr>
                                  <tr bgcolor="#FFFFFF">
                                    <td colspan="5" background="../images/tema/bg_frm_campos.png"><hr size="1"></td>
                                    </tr>
                                  <tr>
                                    <td background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><strong>Valor del Cheque</strong></td>
                                    <td width="13%" background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9"><strong>
                                      <input name="txtvchq" type="text" class="textbox" id="txtvchq" dir="rtl" value="0" size="11" maxlength="11" ondblclick="this.value=document.form2.txttotalp.value;">
                                    </strong></td>
                                    <td width="19%" background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><div align="right"><strong># Cheque </strong></div></td>
                                    <td width="51%" colspan="2" background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9"><strong>
                                      <input name="txtchq" type="text" class="textbox" id="txtchq" size="10" maxlength="10">
                                    </strong></td>
                                    </tr>
                                  <tr bgcolor="#FFFFFF">
                                    <td colspan="5" background="../images/tema/bg_frm_campos.png"><hr size="1"></td>
                                    </tr>
                                  <tr>
                                    <td background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><strong>Valor  dep&oacute;sito </strong></td>
                                    <td background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9"><strong>
                                      <input name="txtvdep" type="text" class="textbox" id="txtvdep" dir="rtl" value="0" size="11" maxlength="11">
                                    </strong></td>
                                    <td background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><div align="right"><strong># Boleta dep&oacute;sito</strong></div></td>
                                    <td colspan="2" background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><strong>
                                      <input name="txtdep" type="text" class="textbox" id="txtdep" size="10" maxlength="10">
Fecha Deposito:
<input name="txtfechadep" type="text" class="textbox" id="txtfechadep" size="10" maxlength="10" onkeyup="mascara(this,'/',patron,true)">
</strong></td>
                                  </tr>
                                  <tr bgcolor="#FFFFFF">
                                    <td colspan="5" background="../images/tema/bg_frm_campos.png"><hr size="1"></td>
                                    </tr>
                                  <tr>
                                    <td background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><strong>Valor del Vale </strong></td>
                                    <td background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9"><strong>
                                      <input name="txtvvale" type="text" class="textbox" id="txtvvale" dir="rtl" onKeyUp="fnc_vale()" value="0" size="11" maxlength="11">
                                    </strong></td>
                                    <td colspan="3" background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><strong># Vale: </strong> <strong>
                                      <input name="txtvale" type="text" class="textbox" id="txtvale" size="20" maxlength="15">
                                    </strong></td>
                                    </tr>
                                  <tr>
                                    <td colspan="5" background="../images/tema/bg_frm_campos.png"><hr size="1"></td>
                                    </tr>
                                  <tr>
                                    <td background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><strong>Valor <br>
                                      Tarjeta Cr&eacute;dito</strong></td>
                                    <td background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9"><strong>
                                    <input name="txtvtc" type="text" class="textbox" id="txtvtc" dir="rtl" value="0" size="11" maxlength="11"></strong></td>
                                    <td background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF"><div align="right"><strong># Tarjtea de cr&eacute;dito</strong></div></td>
                                    <td background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9"><strong>
                                      <input name="txttc" type="text" class="textbox" id="txttc2" size="16" maxlength="16">
                                    </strong></td>
                                    <td background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9"><div align="right">
                                      <input name="Submit2" type="button" class="boton_guardar" onClick="validar(this.form)" value="Continuar &raquo;">
                                    </div></td>
                                  </tr>
                                </table>
                              </form>
                                </td>
                            </tr>
                          </table></td>
                      </tr>
                    </table></td>
                    </tr>
                </table>
                </div></td>
              </tr>
          </table></td>
        </tr>
    </table>    </td>
  </tr>
</table>
</body>
</html>
