<?php
 include ("emenux.php"); 
 require ("conecta.php");
 $sw=$_POST['hdsw'];
 $sw2=$_POST['hdsw'];
 $codigo=strtoupper($_POST['codigo']);
 $codigo=sprintf("%03d",$codigo);
 //$codigo="";
 $glosa="";
 $dias1="";
 $dias2="";
 $dias3="";
 $dias4="";
 $cont=0;
 $error2= "0";
 $recomendacion2="0";
 if ($sw=="buscar"){
  $sqlb="select * from m01002 where codconpa = '$codigo' ;";
  $resb=mysql_query($sqlb,$con);
  if (mysql_num_rows($resb)>0){ 
   $sw="encontrado";
   $sw2="encontrado";
   while ($filab = mysql_fetch_row($resb)){
    $glosa=$filab[1];
	$dias1=$filab[2];
	$dias2=$filab[3];
	$dias3=$filab[4];
	$dias4=$filab[5];
    }//while
   }else{
    $error2= "Codigo no encontrado.";
    $recomendacion2="->Agregar.";
   }//fin si   
  }//fin de buscar
  if ($sw=="grabar"){
   $codigo=strtoupper($_POST['codigo']);
   $glosa=$_POST['glosa'];
   $dias1=$_POST['dias1'];
   $dias2=$_POST['dias2'];   
   $dias3=$_POST['dias3'];
   $dias4=$_POST['dias4'];
   $codcpago=$_POST['hdcodpag'];//hdcodpag
   $sqlg="replace into m01002 
   (codconpa,glosa,dias1,dias2,dias3,dias4)
   values ('$codigo','$glosa','$dias1','$dias2','$dias3','$dias4');";
   $resg=mysql_query($sqlg,$con) ; 
   $codigo="";
   $glosa="";
   $dias1="";
   $dias2="";
   $dias3="";
   $dias4="";
   $sw=""; 
  }//fin grabar
 if ($sw=="eliminar"){
  $sqle="delete from m01002 where codconpa='$codigo';";
  mysql_query($sqle,$con);
   	$codigo="";
	$glosa="";
	$dias1="";
	$dias2="";
	$dias3="";
	$dias4="";
  $sw="";
 }//fin si de eliminar
// if (strlen($codcomuna)==0){$codcomuna="5406";}
//if (strlen($codcpago)==0){$codcpago="001";}
?>
<!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>
<TITLE>Maestro Condicion de pago</TITLE>
<script language="javascript" src="fstandar.js"></script>
<script language="javascript">
function valida(){ 
 if (document.form1.codigo.value.length > 0){
  err=0;
  document.form1.hdsw.value="grabar";
  if (document.form1.codigo.value.length > 3 || isNaN(document.form1.codigo.value) ){
   window.alert("El codigo ingresado es incorrecto" );
   err=1;
   document.form1.codigo.style.backgroundColor="#FFFFCC";
   document.form1.codigo.focus();  
   }
  if (err==0){
   document.form1.action="M0101002.php"
   document.form1.method="post";
   document.form1.submit();
   }  
 }//fin si  
}  
function buscaCodigo(){
 if (document.form1.codigo.value.length > 0){
  document.form1.codigo.style.backgroundColor="#FFFFFF";
  document.form1.hdsw.value="buscar";
  document.form1.action="M0101002.php";
  document.form1.method="post";
  document.form1.submit();
 // window.alert("si");
  }else{
   window.alert("El codigo ingresado es incorrecto" );
   document.form1.codigo.style.backgroundColor="#FFFFCC";
   document.form1.codigo.focus();  
  }//si 
 } 
 function limpiar(){
  document.form1.codigo.value="";
  document.form1.glosa.value="";
  document.form1.dias1.value="";  
  document.form1.dias2.value="";
  document.form1.dias3.value="";
  document.form1.dias4.value="";
 }//fin limpiar
 function eliminar(){
 if(window.confirm("Seguro desea eliminar?")==true){
  document.form1.hdsw.value="eliminar";
  document.form1.action="M0101002.php";
  document.form1.method="post";
  document.form1.submit();
  }
 }//fin eliminar 
</script>
<link rel="stylesheet" href="styles.css">
<style type="text/css">
<!--
.Estilo1 {color: #0000FF}
.Estilo2 {color: #FF0000}
-->
</style>
</HEAD>
<BODY <?php
 if ($sw2=="buscar"){
  echo "onload='javascript:(document.form1.glosa.focus())'";
  }
 if ($sw2=="grabar" || $sw2=="eliminar"){
  echo "onload='javascript:(document.form1.codigo.focus())'";
  } 
 if ($sw2=="encontrado" ){
  echo "onload='javascript:(document.form1.cmdgra.focus())'";
  }  
  ?>>
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" align=center 
border=0>
  <TBODY>
  <TR>
    <TD vAlign=center align=middle height="100%">
      <TABLE height=400 cellSpacing=0 cellPadding=0 width=718 border=0>
        <TBODY>
        <TR>
          <TD width="718" height=22>
            <TABLE height=22 cellSpacing=0 cellPadding=0 width="100%" 
              border=0><TBODY>
              <TR>
                <TD vAlign=top align=left width=24><A 
                  href="index.php"><IMG src="images/xc_left.gif" alt="Inicio" width=24 
                  height=22 
                  border=0></A></TD>
                <TD vAlign=top align=left width="100%"><IMG height=22 
                  src="images/xc_center.gif" width="100%" 
                border=0></TD>
              <TD vAlign=top align=right width=24><IMG height=22 
                  src="images/xc_right.gif" width=24 
              border=0></TD></TR></TBODY></TABLE></TD></TR>
        <TR>
          <TD class=BottomTable vAlign=top 
          background=images/xc_stripes.gif height="100%">
            <TABLE class=IconsTable height=33 cellSpacing=0 cellPadding=0 
            width="100%" border=0>
              <TBODY>
              <TR>
                <TD height="32"><div align="right" class="larger">
                  <div align="right">Vemol</div>
                </div></TD>
                </TR></TBODY></TABLE>
            <TABLE cellSpacing=0 cellPadding=0 width="715" 
              border=0>
              <TBODY>
              <TR>
                <TD width=23 height=18>&nbsp;</TD>
                <TD vAlign=top align=left width=180 height=18>&nbsp;</TD>
                <TD width=12 height=18>&nbsp;</TD>
                <TD width="461" height=18 class=MainMenuHead>Condiciones de pago :</TD>
                <TD width=20 height=18>&nbsp;</TD></TR>
              <TR>
                <TD width=23 height="100%">&nbsp;</TD>
                <TD vAlign=top align=left width=180 height="100%">
                  <TABLE cellSpacing=0 cellPadding=0 width="150" border=0>
                    <TBODY>
                      <tr>
                        <td valign="top"><img 
                        src="images/xc_dotgrey.gif" alt="1" width="10" height="12" /></td>
                        <td>&nbsp;</td>
                        <td class="LeftMenu" nowrap="nowrap"><p>Ingreso de Condiciones<br />
                          de pago
                          :<br />
                          -&gt;Agregar.<br />
                          -&gt;Modificar.<br />
                          -&gt;Eliminar.</p></td>
                      </tr>
                      <tr>
                        <td valign="top"><img 
                        src="images/xc_dotgrey.gif" alt="1" width="10" height="12" /></td>
                        <td>&nbsp;</td>
                        <td class="LeftMenu" nowrap="nowrap">Alertas:<span class="Estilo2"><br />
                              <?php echo $error2 ?></span></td>
                      </tr>
                      <tr>
                        <td valign="top"><img 
                        src="images/xc_dotgrey.gif" alt="1" width="10" height="12" /></td>
                        <td>&nbsp;</td>
                        <td class="LeftMenu" nowrap="nowrap">Se recomienda:<span class="Estilo1"><br />
                              <?php echo $recomendacion2 ?></span></td>
                      </tr>
                    </TBODY></TABLE></TD>
                <TD width=12 height="100%">&nbsp;</TD>
                <TD class=contentcell vAlign=top align=middle width=461 
                height="100%">
                  <TABLE width="100%">
                    <TBODY>
                    <TR>
                      <TD>
                        <form name="form1" method="post" action="">
                          <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <th scope="col"><div align="right" class="Emphasize">Codigo:</div></th>
                              <th scope="col"><div align="left">
                                <input name="codigo" type="text" id="codigo" onblur="buscaCodigo()" value="<?php echo $codigo ?>" size="4" maxlength="3" />
                                <input name="hdsw" type="hidden" id="hdsw" value="nada" />
                              </div></th>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right" class="Emphasize">
                                <p>Descripci&oacute;n:</p>
                                </div></th>
                              <td><input name="glosa" type="text" id="glosa"  value="<?php echo $glosa ?>" size="50" maxlength="100"/></td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right" class="Emphasize">Dias 1 :</div></th>
                              <td><input name="dias1" type="text" id="dias1" value="<?php echo $dias1 ?>" size="4" maxlength="3"/> </td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right" class="Emphasize">Dias 2 :</div></th>
                              <td>
							  <div align="left">
							    <label>
							  	<input name="dias2" type="text" id="dias2" value="<?php echo $dias2 ?>" size="4" maxlength="3" />
							  	</label>
							  </div></td>
                            </tr>
                            <tr>
                              <th scope="row"><label>
                                <div align="right" class="Emphasize">Dias 3 :</div>
                                </label></th>
                              <td><input name="dias3" type="text" id="dias3" value="<?php echo $dias3 ?>" size="4" maxlength="3" /></td>
                            </tr>
                            <tr>
                              <th scope="row"><label>
                                <div align="right"><span class="Emphasize">Dias 4 :</span></div>
                                </label></th>
                              <td><input name="dias4" type="text" id="dias4" value="<?php echo $dias4 ?>" size="4" maxlength="3" /></td>
                            </tr>
                            <tr>
                              <th scope="row"><label>
                                <div align="right"></div>
                              </label>                                </th>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <th scope="row"><label>
                                </label></th>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right"></div></th>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right" class="Emphasize"></div></th>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <th scope="row">&nbsp;</th>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <th colspan="2" scope="row"><input name="cmdgra" type="button" id="cmdgra" value="Grabar" onclick="valida()" />
                                <label></label>
                                &nbsp;&nbsp;
                                <label></label>
                                <label></label>                                
                                <label></label>
                                &nbsp;&nbsp;
								<input name="cmdel" type="button" id="cmdel" value="Eliminar" onclick="eliminar()"/>								</th>
                              </tr>
                          </table>
                                </form>						</TD>
                    </TR></TBODY></TABLE></TD>
                <TD width=20 height="100%">&nbsp;</TD></TR>
              <TR>
                <TD width=23 height=8>&nbsp;</TD>
                <TD width=180 height=8>&nbsp;</TD>
                <TD width=12 height=8>&nbsp;</TD>
                <TD width="461" height=8>&nbsp;</TD>
        <TD width=20 
      height=8>&nbsp;</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY>
<!-- /Footer -->
<script language="JavaScript" src="menu.js"></script>
<script language="JavaScript" src="menu_tpl.js"></script>
<script language="JavaScript">
 new menu (MENU_ITEMS, MENU_POS);
</script>
</TABLE>
</BODY>
<?php
 mysql_close($con);
?>
</HTML>