<?php
 session_start(); 
 include ("emenux.php");
 include "conecta.php"; 
 $numr=sprintf("%07d",$_POST['numero']);
 $_SESSION['numr']=$numr;
 $factor=$_POST['factor'];
 //****************primero vemos que la recepcion no este actualizada***
 //*********************************************************************
 $sqla="select * from adae02 where  numero='$numr';"; 
 $resa=mysql_query($sqla,$con) or die(mysql_error());
 $cuentar=0;
 $dtno="actualizar.php";
 while ($filaa=mysql_fetch_row($resa)){
  $estadoa=$filaa[6];
  $d1=$filaa[8]; 
  $f1=1;
  $f2=1;
  $f3=1;  
  $d2=$filaa[9];    
  $d3=$filaa[10];  
  $cuentar++;
 }
 
 if ($estadoa=='1'){
  if ($_SERVER['HTTP_HOST']=="localhost"){
  header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . "ractualizada.php" );
  }else{
   $dtno="ractualizada.php";
  }
 } 
 
 //*********************************************************************
?>
<!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>Actualizando Recepciones</TITLE>
<script language="javascript" src="fstandar.js"></script>
<script language="javascript">
function actualiza(){
 document.form1.action="<?php echo $dtno ?>";
 document.form1.method="post";
 document.form1.submit();
}  
</script>
<link rel="stylesheet" href="styles.css">
<style type="text/css">
<!--
.Estilo1 {
	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=1076 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<br />
                  </div>
                </div></TD>
                </TR></TBODY></TABLE>
            <div align="center" class="Estilo1">Recepci&oacute;n de Mercader&iacute;as N&ordm; <?php echo $numr ?> - Factor:<?php echo $factor ?> </div>
            <form id="form1" name="form1" method="post" action="">
			
              <table width="1057" border="1">
                <tr>
                  <td width="51"><div align="center"><strong>cantidad</strong></div></td>
                  <td width="107"><div align="center"><strong>codigo</strong></div></td>
                  <td width="366"><div align="center"><strong>Glosa</strong></div></td>
                  <td width="52"><div align="center"><strong>Stock Actual </strong></div></td>
                  <td width="57"><div align="center"><strong>Stock Final </strong></div></td>
                  <td width="54"><div align="center"><strong>costo actual </strong></div></td>
                  <td width="55"><div align="center"><strong>costo MP </strong></div></td>
                  <td width="61"><strong>costo Recepci&oacute;n </strong></td>
                  <td width="63"><div align="center"><strong>Precio Actual </strong></div></td>
                  <td width="53"><div align="center"><strong>Precio Nuevo </strong></div></td>
                  <td width="68"><strong>Precio Final </strong></td>
                </tr>
				<?php
				 $sql="select adai02.cantidad,adai02.cod_interno,adai02.glosa,adai02.precio,m07005.stock,m07005.costo_contable from adai02 inner join m07005 on adai02.cod_interno=m07005.cod_interno   where adai02.llave like '$numr%' ;";
				 $res=mysql_query($sql,$con) or die(mysql_error());
				 //echo $sql;
				 $cuenta=0;
				 while ($fila=mysql_fetch_row($res)){
				  $cuenta++;
				  echo "<tr>";
				  $cant=$fila[0];
				  $interno=$fila[1];
				  $glosa=$fila[2];
				  $stocka=$fila[4];
				  $costor=$fila[3];
				  $cr1=$costor-($costor * $d1 /100);
				  $cr2=$cr1-($cr1 * $d2 /100);
				  $cr3=$cr2-($cr2 * $d3 /100);
				  $costor=round($cr3);
				  $stockf=$stocka + $cant;
				  $costoa=$fila[5];
				  $costomp=round((($costoa * $stocka) + ($costor * $cant))/$stockf);
				  $sqlpre="select precio from m07001 where cod_interno='$interno';";
				  $respre=mysql_query($sqlpre,$con) or die(mysql_error());
				  while ($filapre=mysql_fetch_row($respre)){
				   $precio=$filapre[0];
				  }//wend
				  $preciof=round($costor * $factor);
				  $namepre="pre" . $cuenta; 
				  $namestock="stock" . $cuenta;
				  $namecosto="costo" . $cuenta;
				  $namecod="cod" . $cuenta;
				  echo "<td>$cant</td>";
				  echo "<td>$interno<input type='hidden' name='$namecod' value='$interno'></td>";
				  echo "<td>$glosa</a>";
				  echo "<td align='right'>$stocka</a>";
				  echo "<td align='right'>$stockf<input type='hidden' name='$namestock' value='$stockf'></td>";
				  echo "<td align='right'>$costoa</td>";
				  echo "<td align='right'>$costomp <input type='hidden' name='$namecosto' value='$costomp'></td>";
				  echo "<td align='right'>$costor</td>";
				  echo "<td align='right'>$precio</td>";
				  echo "<td align='right'>$preciof</td>";
				  echo "<td><input type='text' name='$namepre' value='$preciof' size='5'/></td>";
				  echo "</tr>";
				 }//wend
				 
				?>
              </table>
              <p align="center">
                <input name="hdnumr" type="hidden" id="hdnumr" value="<?php echo $numr ?>" />
                <input name="hdfactor" type="hidden" id="hdfactor"  value="<?php echo $factor ?>"/>
                <input name="hdlineas" type="hidden" id="hdlineas" value="<?php echo $cuenta ?>"/>
              </p>
              <div align="center">
                <table width="215" border="0">
                    <tr>
                      <td width="102"><label>
                        <div align="center">
                          <input name="act" type="button" id="act" value="Actualizar" onclick="actualiza()"/>
                          </div>
                      </label></td>
                      <td width="103"><?PHP echo $dtno ?></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                              </table>
                </div>
            </form>          </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>