<?
include("../fnc.php");
enlinea_a();
?>
<!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 suma_totales(valor, objeto){
  var total = document.form2.txttotalboletas;
  

  if(objeto.checked==true){
   total.value = Math.round(( eval(total.value) + eval(valor) )*100)/100;
  }else{
   total.value = Math.round(( eval(total.value) - eval(valor) )*100)/100;
  }
}

function cambiar_boton(){
  document.form2.Submit2.value="Generar Boleta No. "+document.form2.txtboletai.value;
}

function chequear(objeto){
 //alert(objeto.checked);
 if(objeto.checked==true){
   objeto.checked=0;
 }else{
   objeto.checked=1;
 }
}

function validar(formulario){
 var formulario=document.form2;
 var objeto;
 
 objeto=formulario.txtfechadep;
 if(objeto.value==""){
   alert("Ingrese la fecha máxima a depositar");
   objeto.focus();
   return (false);
 }
 
 objeto=formulario.txtboletai;
 if(objeto.value==""){
   alert("Ingrese el número de boleta inicial");
   objeto.focus();
   return (false);
 }

 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;
    }
  }
}
</script>
<style type="text/css">
<!--
body {
	background-image: url(../images/tema/bg_pagina.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"> Generar boletas por cargos </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 class='selected_option'";
                                }
                                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();" value="<?=$txtcarnet;?>">
                                <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 background="../images/tema/bg_contenido.png"><form action="rpt_cp_boletaxcargo.php" method="post" name="form2" target="_blank" onsubmit="return validar(this.form);">
                                <table width="125%"  border="0" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
                                  <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" class="lbl_formulario">
                                      <?=$ialm[apellido].", ".$ialm[nombre];?>                                    </td>
                                  </tr>
                                </table>
                                <hr size="1">
                                <div align="center">
                                  <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"><div align="left"><span class="titulo_formulario"><strong>Seleccione los cargos a incluir en la boleta de dep&oacute;sito </strong></span></div></td>
                                    </tr>
                                  </table>
                                </div>
                                <table width="100%"  border="0" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
                                  <tr bgcolor="#CFDFEF">
                                    <td width="7%"><div align="center"><strong>TIPO</strong></div></td>
                                    <td width="21%" bgcolor="#CFDFEF"><div align="center"><strong>FECHA DEL CARGO </strong></div></td>
                                    <td width="42%"><div align="center"><strong>DESCRIPCION</strong></div></td>
                                    <td width="10%"><div align="center"><strong>SALDO</strong></div></td>
                                    <td width="11%"><div align="center"><strong>SELECCIONE</strong></div></td>
                                    </tr>
                                  <?
                                  $qcargo=mysql_query("select * from cp_cargos where carnet='$p_alumno' and saldo > 0 order by mes");
                                  $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" onclick="chequear(document.form2.txtcargo<?=$i;?>)">
                                        <?=($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="suma_totales('<?=($icargo[saldo]);?>',this)"></div></td>
                                    </tr>
                                  <?
                                  }
                                  ?>
                                  <tr bgcolor="#CFDFEF">
                                    <td><div align="center">&nbsp;</div></td>
                                    <td align="center" valign="bottom"><div align="left"><strong>TOTALES</strong></div></td>
                                    <td align="center" valign="bottom"><input name="imax" type="hidden" id="imax" value="<?=$i;?>"><input type="hidden" name="txtalumno" value="<?=$p_alumno;?>"></td>
                                    <td align="center" valign="bottom"><div align="right"><strong>
                                        <?=moneda(sprintf("%.2f",$suma_saldo),"Q");?>
                                    </strong></div></td>
                                    <td align="center" valign="bottom"><div align="center">
                                    </div></td>
                                    </tr>
                                </table>
                                <div align="center"><span class="lbl_formulario">Total de las boletas: 
                                  </span>
                                  <input name="txttotalboletas" type="text" class="lbl_formulario" id="txttotalboletas" dir="rtl" value="0">
                                  <br>
                                  Fecha m&aacute;xima de dep&oacute;sito: 
                                  <input name="txtfechadep" type="text" class="textbox" id="txtfechadep" size="10" maxlength="10" <?=fmascara();?>>
                                  <br>
                                  N&uacute;mero de boleta: 
                                  <input name="txtboletai" type="text" class="textbox" id="txtboletai" size="25" maxlength="25" value="<?=get_numboletadp()+1;?>" onkeyup="cambiar_boton();">
                                  <br>
                                  <input name="Submit2" type="submit" class="boton_guardar" value="Generar Boleta No. <?=get_numboletadp()+1;?>">
                                  <input name="idalumno" type="hidden" id="idalumno" value="<?=$p_alumno;?>">
                                  <input name="maxi" type="hidden" id="maxi" value="<?=$i;?>">
                                </div>
                              </form>                                </td>
                            </tr>
                            <tr>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <td>&nbsp;</td>
                            </tr>
                          </table></td>
                      </tr>
                    </table></td>
                    </tr>
                </table>
                </div></td>
              </tr>
          </table></td>
        </tr>
    </table>    </td>
  </tr>
</table>
</body>
</html>
