<?php
 session_start(); 
 include ("emenux.php");
 require "conecta.php";  
 include "funciones.php";
 if(isset($_POST['numeror'])){ 
  $numr=$_POST['numeror'];
 }else{
  $numr=$_SESSION['numr'];
 }
 if (isset($_POST['numerop'])){
  $nump=$_POST['numerop'];
  }else{
   $nump=$_SESSION['nump'];
  } 
 if (isset($_POST['hdsw'])){
 $sw=$_POST['hdsw'];
 }
 if ($sw=="modifica"){
  $codm=$_POST['hdcod'];
  $cantm=$_POST['hdcant'];
  $prem=$_POST['hdpre'];
  $st=$cantm * $prem; 
  if ($cantm > 0){   
   $sqlm="update adai02 set cantidad='$cantm',precio='$prem',stotal='$st' where llave like '$numr%' and cod_interno='$codm';";
  }else{
   $sqlm="delete from adai02 where llave like '$numr%' and cod_interno='$codm';";
  }
  $resm=mysql_query($sqlm,$con) or die(mysql_error());
  echo $sqlm;
 }
 if ($sw=="grabae"){
  $de1=$_POST['hdd1'];
  $de2=$_POST['hdd2'];
  $de3=$_POST['hdd3'];
  $neto=$_POST['hdneto'];
  $iva=$_POST['hdiva'];
  $total=$_POST['hdtotal'];
  $sqlge="update adae02 set d1='$de1',d2='$de2',d3='$de3',neto='$neto',iva='$iva',total='$total' where numero='$numr';";
  $resge=mysql_query($sqlge,$con);  
 }//fin grabae
 if ($sw != "modifica"){ //si @
 $sqlbd="select * from adai02 where llave like '$numr%';";
 $resbd=mysql_query($sqlbd,$con) or die(mysql_error());
 if (mysql_num_rows($resbd)>0){
 }else{  
  $sqldp="select * from adai01 where llave like '$nump%';";
  $resdp=mysql_query($sqldp,$con) or die(mysql_error());
  while ($filadp=mysql_fetch_row($resdp)){
   $llave=$filadp[0];
   $cantidad=$filadp[1];
   $cod_interno=$filadp[2];
   $glosa=$filadp[4];
   $precio=$filadp[5];
   $stotal=$filadp[6];
   $sqltr="insert into adai02 (llave,cantidad,cod_interno,glosa,precio,stotal)
   values ('$llave','$cantidad','$cod_interno','$glosa','$precio','$stotal');";
   $restr=mysql_query($sqltr,$con) or die(mysql_error());   
  }//wend
 }
 }//si @
?>
<!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 termina(){
 window.open("finrecepcion.php?numero=" + document.form1.hdnumr.value + "&numerop=" + document.form1.hdnump.value );
}//fin termina
function grabae(){
 document.form1.hdsw.value="grabae";
 document.form1.action="recepcion.php";
 document.form1.method="post";
 document.form1.submit(); 
}
function salir(){ 
 document.form1.action="M0205001.php";
 document.form1.method="post";
 document.form1.submit();
}
function modifica(cant,pre,cod){
 if (event.keyCode==13){
  document.form1.hdcod.value=cod;
  document.form1.hdcant.value=cant;
  document.form1.hdpre.value=pre;
  document.form1.hdsw.value="modifica";
  document.form1.action="recepcion.php";
  document.form1.method="post";
  document.form1.submit();
  }
}
</script>
<link rel="stylesheet" href="styles.css">
<style type="text/css">
<!--
.Estilo2 {font-size: 12; font-weight: bold; }
.Estilo3 {
	font-size: 16px;
	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=1119 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="">
            <div align="center"><br />
              <span class="Estilo3">Detalle de Recepci&oacute;n</span> 
              <input name="hdnumr" type="hidden" id="hdnumr"  value="<?php echo $numr ?>"/>
              <input name="hdd1" type="hidden" id="hdd1" />
              <input name="hdd2" type="hidden" id="hdd2" />
              <input name="hdd3" type="hidden" id="hdd13" />
              <input name="hdneto" type="hidden" id="hdd14" />
              <input name="hdiva" type="hidden" id="hdd15" />
              <input name="hdtotal" type="hidden" id="hdd16" />
              <input name="hdsw" type="hidden" id="hdd17" value="<?php echo $sw ?>" />
              <input name="hdnump" type="hidden" id="hdnump" value="<?php echo $nump ?>" />
              <input name="numeror" type="hidden" id="numeror"  value="<?php echo $numr ?>"/>
</div>
            <table width="1105" border="1">
              <tr>
                <td colspan="2"><div align="center"><strong>Cantidad</strong></div>                  <div align="center" class="Estilo2"></div></td>
                <td width="103">&nbsp;</td>
                <td width="404">&nbsp;</td>
                <td colspan="2"><div align="center" class="Estilo2">
                  <div align="center">Precio</div>
                </div>                  <div align="center" class="Estilo2"></div></td>
                <td width="200"><div align="center" class="Estilo2">
                  <div align="center">total</div>
                </div></td>
              </tr>
              <tr>
                <td width="108"><div align="center" class="Estilo2">pedida</div></td>
                <td width="100"><div align="center" class="Estilo2">facturada</div></td>
                <td><div align="center" class="Estilo2">Interno</div></td>
                <td><div align="center" class="Estilo2">Glosa</div></td>
                <td width="67"><div align="center" class="Estilo2">pedido</div></td>
                <td width="77"><div align="center" class="Estilo2">factura</div></td>
                <td><div align="center" class="Estilo2">Total</div></td>
              </tr>
			  <?php
			   $sqlped="select * from adai02 where llave like '$numr%';";
			   $resped=mysql_query($sqlped,$con);
			   $cont=0;
			   while ($filaped=mysql_fetch_row($resped)){
			    $cont++;
				$namecant="cant" . $cont;
				$namecantr="cantr" . $cont;
				$namecod="cod" .  $cont;
				$namegl="gl" . $cont;
				$namepr="pr" . $cont;
				$nameprr="pr" . $cont;//precio de la recepcion
				$nametot="tot" . $cont;
				$cantp=$filaped[1];								
				$int=$filaped[2];				
				$gl=strtoupper($filaped[4]);
				$pr=$filaped[5];
				$prr=$filaped[5]; // despues cambiar
				$tot=$pr * $cantp;				
				$objcant="document.form1." . $namecantr  . ".value";
				echo "<tr>";
				echo "<td><input type='text' name='$namecant' value='$cantp' size='5' disabled onkeydown='modifica(\"$cantp\",\"$pr\",\"$int\")' /></td>";
				echo "<td><input type='text' name='$namecantr' value='$cantp' size='5' onkeydown='modifica($objcant,\"$pr\",\"$int\")'/></td>";
				echo "<td><input type='text' name='$namecod' value='$int' size='14' disabled/></td>";
				echo "<td><input type='text' name='$namgl' value='$gl' size='70' disabled /></td>";
				echo "<td><input type='text' name='$namepr' value='$pr' size='5' disabled /></td>";
				echo "<td><input type='text' name='$nameprr' value='$prr' size='5' /></td>";
				echo "<td><center><input type='text' name='$nametot' value='$tot' size='7' /></center></td>";
				echo "</tr>";
			   }//wend
			  ?>
            </table>
             <table width="1108" border="0">
  <tr>
    <td width="221"><div align="center"></div></td>
    <td width="221">
      <div align="center">
        <input name="terminar" type="button" id="terminar" value="Terminar" onclick="termina();" />
      </div></td>
    <td width="323"><div align="center">
      <input name="sale" type="button" id="sale" value="   salir   " onclick="salir()" />
      <input name="hdcod" type="hidden" id="hdcod" />
      <input name="hdpre" type="hidden" id="hdpre" />
      <input name="hdcant" type="hidden" id="HDCOD3" />
    </div></td>
    <td width="323">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td colspan="2">&nbsp;</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>