<?
  if (basename(__FILE__) == basename($PHP_SELF))
    die("Darf nur als include benutzt werden\n");

function tab_inventur($von,$bis)
{
  $res=send_sql("SELECT a.Name as Artikelname, Sum(u.anz) AS Anzahl_Verkauf, space(1) AS Anzahl_Einkauf FROM umsatz as u, artikel as a where u.artnr=a.artnr and u.datum>\"$von\" and u.datum<\"$bis\" GROUP BY u.artnr");
  $anz=mysql_num_fields($res);
  echo "<table border=1 cellpadding='1' cellspacing='1' align='center'>";
    echo "<tr>";
    for ($i=0;$i<$anz;$i++)
    {
      echo "<th>";
      echo mysql_field_name($res,$i);
      echo "</th>";
    }
    echo "</tr>";
    echo "<tr>";
    while ($row  =  mysql_fetch_array($res,MYSQL_NUM))
    {
      foreach ($row as $elem)
      {
        echo "<td>&nbsp;&nbsp;$elem &nbsp;</td>";
      }
    echo "</tr>";
    }
  echo "</table>";
}


     echo "<br>";
     echo "<table border=1 cellpadding='1' cellspacing='1' align=center bgcolor=white>";
      echo "<tr>";
        echo "<th align=center colspan=2>Bitte Abfragezeitraum eingeben</th>";
      echo "</tr>";
      echo "<tr>";
        echo "<td align=left>Inventur von (JJJJ-MM-TT):</td>";
        echo "<td><input type='Text' name='von' size='10' maxlength=10></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<td align=left>Inventur bis &nbsp;(JJJJ-MM-TT):</td>";
        echo "<td><input type='Text' name='bis' size='10'></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<th><input type=\"hidden\" name=todo value=\"anzeigen\">&nbsp;</th>";
        echo "<td><input type=\"submit\" value=\"Anzeigen\">&nbsp;&nbsp;&nbsp;&nbsp;</td>";
      echo "</tr>";
    echo "</table>";


 if($_POST['todo']=='anzeigen')
 {
   $von=$_POST['von'];
   $bis=$_POST['bis'];

   echo "<h3 align=center>Inventur vom $von bis $bis</h3>";

   $von=$von.' 00:00:00';
   $bis=$bis.' 24:00:00';

   tab_inventur($von,$bis);
 }
?>