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


if($idga){
 $id_ga=dec($idga);
 $qver=mysql_query("select * from pr_gastos where id = '$id_ga'");
 if(mysql_num_rows($qver)==0){
  $tipo="Add";
 }else{
  $info=mysql_fetch_array($qver);
  $tipo="Update";
 }
}else{
 $tipo="Add";
}
?>

<!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">
<script type="text/javascript" src="../jsincludes/overlib.js"></script>
<?=mascara();?>
<script language="javascript">
function foco(){
  document.form1.txttipogasto.focus();
}

function confirmar_eliminar(url){
  var respuesta;
  
  respuesta = confirm("Está seguro de eliminar este gasto?");
  if(respuesta){
    self.location='mnt_pr_gastos.php?tipo_trn=Delete&'+url;
  }
}
</script>
<style type="text/css">
<!--
body {
	background-image: url(../images/tema/bg_pagina.png);
}
-->
</style></head>



<body onload="foco();">
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<table width="750" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#333333">
  <tr>
    <td>    <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" class="titulo_pagina"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="65" background="../images/tema/bg_contenido.png">&nbsp;</td>
                  <td background="../images/tema/bg_contenido.png"><div align="center" class="titulo_pagina"><strong>ADMINISTRACI&Oacute;N DE TIPOS DE GASTOS </strong></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></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="0">
                  <tr>
                    <td background="../images/tema/bg_contenido.png"><form name="form1" method="post" action="mnt_pr_gastos.php" autocomplete="OFF">
                      <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td colspan="2"><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">Ingrese la informaci&oacute;n del gasto </div></td>
                            </tr>
                          </table></td>
                          </tr>
                        <tr>
                          <td background="../images/tema/bg_frm_campos.png" class="lbl_campo">Fecha:</td>
                          <td background="../images/tema/bg_frm_campos.png"><div align="left">
                            <input name="txtfecha" type="text" class="textbox" id="txtfecha" size="10" maxlength="10" <?=fmascara();?> value="<?if($tipo=="Add"){echo date("d/m/Y");}else{echo fecha($info[fecha],"/");}?>"> 
                            <span class="font_red_11"><em>d&iacute;a/mes/a&ntilde;o</em></span> </div></td>
                        </tr>
                        <tr>
                          <td background="../images/tema/bg_frm_campos.png" class="lbl_campo">Descripci&oacute;n:</td>
                          <td background="../images/tema/bg_frm_campos.png"><div align="left">
                            <textarea name="txtdescripcion" cols="60" rows="3" class="textbox" id="txtdescripcion"><?=$info[descripcion];?></textarea>
                          </div></td>
                        </tr>
                        <tr>
                          <td background="../images/tema/bg_frm_campos.png" class="lbl_campo">Valor:</td>
                          <td background="../images/tema/bg_frm_campos.png"><div align="left">
                            <input name="txtvalor" type="text" class="textbox" id="txtvalor" size="11" maxlength="11" value="<?=$info[valor];?>">
                          </div></td>
                        </tr>
                        <tr>
                          <td width="13%" background="../images/tema/bg_frm_campos.png" class="lbl_campo"><div align="left">Tipo de gasto: </div></td>
                          <td width="87%" background="../images/tema/bg_frm_campos.png">
                            <div align="left">
                              <select name="txttipogasto" class="textbox" id="txttipogasto">
                               <?
                                llenar_combo("pr_tiposgastos","","tipo","id","tipo","{$info[tipo_gasto]}");
                               ?>
                              </select>
                              <input name="tipo_trn" type="hidden" id="tipo_trn" value="<?=$tipo;?>">
                              <input name="idga" type="hidden" id="idga" value="<?=$idga;?>">
                              </div></td></tr>
                        <tr>
                          <td background="../images/tema/bg_frm_campos.png">&nbsp;</td>
                          <td background="../images/tema/bg_frm_campos.png"><input name="Submit" type="submit" class="boton_guardar" value="Guardar Gasto"></td>
                        </tr>
                      </table>
                      </form></td>
                  </tr>
                </table>
                <br>
                <br>
              </div></td>
              </tr>
            <tr>
              <td align="left" valign="top" background="../images/tema/bg_contenido.png" bgcolor="#FFFFCC"><form name="form2" method="post" action="frm_pr_gastos.php?op=det_gastos">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="6%" background="../images/tema/bg_titulo_frm.png"><div align="left"><img src="../images/tema/ic_editar.png" width="35" height="32"></div></td>
                    <td width="94%" background="../images/tema/bg_titulo_frm.png"><div align="left" class="titulo_formulario">Detalle de gastos operados por fecha </div></td>
                  </tr>
                  <tr>
                    <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="15%" background="../images/tema/bg_frm_campos.png" class="lbl_campo">Fecha Inicial: </td>
                        <td width="85%" background="../images/tema/bg_frm_campos.png"><input name="txtfechai" type="text" class="textbox" id="txtfechai" value="<?=fecha($fecha,"/");?>" size="10" maxlength="10" <?=fmascara();?>>
                          <em class="font_red_11">d&iacute;a/mes/a&ntilde;o</em></td>
                      </tr>
                      <tr>
                        <td background="../images/tema/bg_frm_campos.png" class="lbl_campo">Fecha Final: </td>
                        <td background="../images/tema/bg_frm_campos.png"><input name="txtfechaf" type="text" class="textbox" id="txtfechaf" value="<?=fecha($fecha,"/");?>" size="10" maxlength="10" <?=fmascara();?>>
                          <em class="font_red_11">d&iacute;a/mes/a&ntilde;o</em></td>
                      </tr>
                      <tr>
                        <td background="../images/tema/bg_frm_campos.png">&nbsp;</td>
                        <td background="../images/tema/bg_frm_campos.png"><input name="Submit2" type="submit" class="boton_guardar" value="Ver gastos operados"></td>
                      </tr>
                    </table></td>
                    </tr>
                </table>
                            </form>
                            
              <?
              if($op!="det_gastos" || empty($op)){
                exit();
              }
              ?>              
              <table width="100%" border="0" cellspacing="1" cellpadding="1">

                  <tr>
                    <td width="11%" background="../images/tema/bg_frm_campos.png" class="lbl_campo"><div align="center">Fecha</div></td>
                    <td width="43%" background="../images/tema/bg_frm_campos.png" class="lbl_campo"><div align="center">Descripci&oacute;n del gasto </div></td>
                    <td width="10%" background="../images/tema/bg_frm_campos.png" class="lbl_campo"><div align="center">Valor</div></td>
                    <td width="19%" background="../images/tema/bg_frm_campos.png" class="lbl_campo"><div align="center">Tipo de Gasto </div></td>
                    <td width="17%" background="../images/tema/bg_frm_campos.png" class="lbl_campo"><div align="center">Acciones</div></td>
                  </tr>
                  <?
                  $tmpf=explode("/",$txtfechai);
                  $fi="{$tmpf[2]}-{$tmpf[1]}-{$tmpf[0]}";
                  $tmpf=explode("/",$txtfechaf);
                  $ff="{$tmpf[2]}-{$tmpf[1]}-{$tmpf[0]}";
                  //echo "select * from pr_gastos where fecha between '$fi and $ff";
                  $qgst=mysql_query("select pr_gastos.*, tg.tipo 
                                     from pr_gastos inner join pr_tiposgastos tg ON tg.id = pr_gastos.tipo_gasto 
                                     where fecha between '$fi' and '$ff' 
                                     order by fecha, descripcion") or die(mysql_error());
                  $i=$total=0;                   
                  while($igst=mysql_fetch_array($qgst)){
                  $i++;
                  $total+=$igst[valor];
                  ?>
                  <tr bgcolor="<?=color_fila($i);?>">
                    <td class="parrafo"><div align="center"><?=fecha($igst[fecha]);?></div></td>
                    <td align="left" class="parrafo"><?=$igst[descripcion];?></td>
                    <td align="right" class="parrafo"><?=moneda($igst[valor]);?></td>
                    <td align="left" class="parrafo"><?=$igst[tipo];?></td>
                    <td align="center" class="parrafo"><a href="frm_pr_gastos.php?idga=<?=enc($igst[id]);?>" class="link_parrafo">Modificar</a> | <a href="#" onclick="confirmar_eliminar('<?="idga=".enc($igst[id]);?>')" class="link_parrafo">Eliminar</a></td>
                  </tr>
                  <?
                  }
                  ?>
                  <tr>
                    <td background="../images/tema/bg_frm_campos.png" class="lbl_campo"><strong>TOTALES</strong></td>
                    <td background="../images/tema/bg_frm_campos.png" class="lbl_campo">&nbsp;</td>
                    <td align="right" background="../images/tema/bg_frm_campos.png" class="lbl_campo"><strong>
                      <?=moneda($total);?>
                    </strong></td>
                    <td background="../images/tema/bg_frm_campos.png" class="lbl_campo">&nbsp;</td>
                    <td background="../images/tema/bg_frm_campos.png" class="lbl_campo">&nbsp;</td>
                  </tr>
                </table></td>
            </tr>
          </table></td>
        </tr>
    </table>    </td>
  </tr>
</table>
</body>
</html>
