<?php
 require "conecta.php";
 $usu=$_GET['usuario'];
 $sqlmay="select max(numero) from m02008";
 $resmay=mysql_query($sqlmay,$con) or die(mysql_error());
 $filamay=mysql_fetch_row($resmay);
 $may=($filamay[0]*1)+1;
 $may=sprintf("%07d",$may);
 $sql="select cod_interno,cantidad,precio,glosa from m02004 where llave = '$usu';";
 $res=mysql_query($sql,$con) or die(mysql_error());
 $fecha=date("Ymd");
 $sqlgec="insert into m02008 values('$may','$fecha','0');";
 $resgec=mysql_query($sqlgec,$con) or die(mysql_error());
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.Estilo1 {font-size: 24px}
-->
</style>
<script language="javascript">
 function imprime(){
  window.print();
  window.close();
 }
</script>
</head>

<body>
<form name="form1" method="post" action="">
  <table width="661" border="1">
    <tr>
      <td colspan="5"><div align="right" class="Estilo1">Vemol</div></td>
    </tr>
    <tr>
      <td width="55">&nbsp;</td>
      <td colspan="3"><div align="center">Cotizaci&oacute;n de Repuestos Nš <?php echo $may  ?></div></td>
      <td width="58">&nbsp;</td>
    </tr>
    <tr>
      <td><div align="center">Cantidad</div></td>
      <td width="94"><div align="center">C&oacute;digo</div></td>
      <td width="336"><div align="center">Glosa</div></td>
      <td width="84"><div align="center">Precio</div></td>
      <td><div align="center">Total</div></td>
    </tr>
	<?php
	 while ($fila=mysql_fetch_row($res)){
	  $cant=$fila[1];
	  $cod=$fila[0];
	  $pre=$fila[2];
	  $gl=$fila[3];
	  $tot=$cant * $pre;
	  $suma=$suma + $tot;
	  $sqlgdc="insert into m02009 values('$may','$cod','$gl','$pre','$cant','$tot','$may');";
	  $resgdc=mysql_query($sqlgdc,$con) or die(mysql_error()); 
	  echo "<tr>";
	  echo "<td>$cant</td>";
	  echo "<td>$cod</td>";
	  echo "<td>$gl</td>";
	  echo "<td align='right'>" . number_format($pre,0,".",",") . "</td>";
	  echo "<td align='right'>" . number_format($tot,0,".",",") . "</td>";
	  echo "</tr>";
	  

	 }
	 echo "<tr>";
	  echo "<td></td>";
	  echo "<td></td>";
	  echo "<td></td>";
	  echo "<td align='right'>TOTAL</td>";
	  echo "<td align='right'>" . number_format($suma,0,".",",") . "</td>";
	  echo "</tr>";
	?>
  </table>
  <p align="center"><a href="javascript:imprime();">Imprimir</a></p>
</form>
<?php
 mysql_close($con);
?>
</body>
</html>
