<?php
 session_start(); 
 include ("emenux.php");
 require "conecta.php"; 
 require "funciones.php";
 $sw=$_POST['hdsw'];
 $numr=sprintf("%07d",$_POST['numeror']);
 if (strlen($_POST['numerop'])>0){
  $nump=sprintf("%07d",$_POST['numerop']);; 
  }
 if ($sw=="grabae"){ 
  $sqlbr="select * from adae01 where numero='$nump'; " ;
  $resbr=mysql_query($sqlbr,$con) or die(mysql_error());
  $fecha=date("Y-m-d");
  while ($filabr=mysql_fetch_row($resbr)){      
   $fecha=$filabr[1];
   $rut=$filabr[2]; 
   $nombre=$filabr[3];
   $estado=$filabr[6];
   $st1=$filabr[7];
   $d1=$filabr[8]; 
   $d2=$filabr[9];
   $d3=$filabr[10];
   $neto=$filabr[11];
   $iva=$filabr[12];
   $total=$filabr[13];   
  }//wend
  $factura=$_POST['factura'];
  $fechafac=editafechag($_POST['fechafac']);
  if ($estado != "1"){//si *
    $sqlgra="replace into adae02 (numero,fecha,rut,nombre,pedido,estado,st1,d1,d2,d3,neto,iva,total,fact,fefact)
	values ('$numr','$fecha','$rut','$nombre','$nump','$estado','$st1','$d1','$d2','$d3','$neto','$iva','$total','$factura','$fechafac');";
	$resgra=mysql_query($sqlgra,$con) or die(mysql_error());
	$sw="verecepcion";	
   }//fin *   
 }//fin grabae 
 if ($sw=="verecepcion"){
  $sqlbr="select * from adae02 where numero='$numr'; " ;
  $resbr=mysql_query($sqlbr,$con) or die(mysql_error());  
  while ($filabr=mysql_fetch_row($resbr)){
   $nump=$filabr[5];
   $prov=$filabr[3];
   $fecha=$filabr[1];
   $estado=$filabr[6];
   $fechaf=editafecha($filabr[15]);
   $numf=$filabr[14];
  }//wend
 } //fin verecepcion
 if ($sw=="vepedido"){
  $sqlbp="select * from adae01 where numero='$nump';";
  $resbp=mysql_query($sqlbp,$con) or die(mysql_error());
  while ($filabp=mysql_fetch_row($resbp)){
   $prov=$filabp[3];
  }//wend
 }//fin verecepcion
 
?>
<!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>Login</TITLE>
<script language="javascript" src="fstandar.js"></script>
<script language="javascript">
function verecepcion(){
 if (event.keyCode==13){ 
  document.form1.hdsw.value="verecepcion";
  document.form1.action="M0105002.php";
  document.form1.method="post";
  document.form1.submit();
  }
}
function vepedido(){
 if (event.keyCode==13){ 
  document.form1.hdsw.value="vepedido";
  document.form1.action="M0105002.php";
  document.form1.method="post";
  document.form1.submit();
  }
}
function grabae(){ 
 document.form1.hdsw.value="grabae";
 document.form1.action="M0105002.php";
 document.form1.method="post";
 document.form1.submit(); 
}
function recupera(){
 document.form1.hdsw.value="";
 document.form1.action="recepcion.php";
 document.form1.method="post";
 document.form1.submit(); 
}
</script>
<link rel="stylesheet" href="styles.css">
<style type="text/css">
<!--
.Estilo1 {
	font-size: 12px;
	font-weight: bold;
}
.Estilo2 {font-size: 14px; font-weight: bold; }
-->
</style>
</HEAD>
<BODY>
<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>
			<form id="form1" name="form1" method="post" action="">	
            <table width="713" height="163" border="1">
              <tr>
                <td colspan="4"><div align="center" class="Estilo2">Recepci&oacute;n de mercader&iacute;a </div></td>
                </tr>
              <tr>
                <td width="179"><span class="Estilo1">N&uacute;mero de Recepci&oacute;n </span></td>
                <td width="166"><input name="numeror" type="text" id="numeror" onkeydown="verecepcion()" value="<?php echo $numr ?>" /></td>
                <td width="172"><span class="Estilo1">N&uacute;mero de pedido</span></td>
                <td width="168"><input name="numerop" type="text" id="numerop" value="<?php echo $nump ?>" onkeydown="vepedido()" /></td>
              </tr>
              <tr>
                <td><span class="Estilo1">Proveedor</span></td>
                <td colspan="3"><input name="prov" type="text" id="prov" size="80" value="<?php echo $prov ?>" /></td>
                </tr>
              <tr>
                <td><div align="left"><span class="Estilo1">N&uacute;mero de Factura </span></div></td>
                <td>
                  <div align="left">
                    <input name="factura" type="text" id="factura" value="<?php echo $numf ?>" />
                  </div></td>
                <td><div align="left"><span class="Estilo1">fecha de Factura </span></div></td>
                <td><input name="fechafac" type="text" id="fechafac"  value="<?php echo $fechaf ?>"/></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td><div align="center">
                  <input name="graba" type="button" id="graba" value="Grabar Encabezado" onclick="grabae()" />
</div></td>
                <td><div align="center">
                  <input name="enviar" type="button" id="enviar" value="Recuperar informaci&oacute;n" onclick="recupera()" />
                </div></td>
                <td><input name="hdsw" type="hidden" id="hdsw" value=" " />                  <input type="text" name="textfield" value="<?php echo $sqlgra ?>" /></td>
              </tr>
            </table>
            
            </form>
            <p>&nbsp;</p></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>