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

     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>Umsatz 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>Umsatz 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>Umsatz vom $von bis $bis</h3>";

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

   tab_umsatz($von,$bis);
}

function tab_umsatz($von,$bis)
{
  global $mwst1,$mwst2;
  $sum_mwst1=0;
  $sum_mwst2=0;
  $sum=0;
  $sql="SELECT a.Name as Artikelname, Sum(u.anz) AS Anzahl, a.mwst as Mehrwertsteuersatz, Sum(u.akt_preis) FROM umsatz as u, artikel as a where u.artnr=a.artnr and u.datum>\"$von\" and u.datum<\"$bis\" GROUP BY u.artnr";
  $res=send_sql($sql);
  $anz=mysql_num_fields($res);

  echo "<table border=0 cellpadding='0' cellspacing='0' align=center bgcolor=white>";
    echo "<tr>";
       echo "<th>Artikelname</th>";
       echo "<th>Anzahl</th>";
       echo "<th>Summe</th>";
       echo "<th><font size=-1>Davon Mwst $mwst1%</font></th>";
       echo "<th><font size=-1>Davon Mwst $mwst2%</font></th>";
    echo "</tr>";

    while ($row  =  mysql_fetch_array($res,MYSQL_NUM))
    {
      $sum=$sum+$row[3];
      echo "<tr>";
        echo "<td width='130'><font size=-1>$row[0]</font></td>";
        echo "<td width='80' align='center'><font size=-1>$row[1]</font></td>";
        echo "<td width='80' align='center'><font size=-1>$row[3] &euro;</font></td>";
        if($row[2]==1)
        {
          $sum_mwst1=$sum_mwst1+($row[3]/100*$mwst1);
          echo "<td width='110' align='right'><font size=-1>".($row[3]/100*$mwst1)." &euro;</font></td>";
        }
        else
          echo "<td width='110' align='right'><font size=-1>-</font></td>";
        if($row[2]==2)
        {
          $sum_mwst2=$sum_mwst2+($row[3]/100*$mwst2);
          echo "<td width='110' align='right'><font size=-1>".($row[3]/100*$mwst2)." &euro;</font></td>";
        }
        else
          echo "<td width='110' align='right'><font size=-1>-</font></td>";
      echo "</tr>";
    }
    echo "<tr colspan=5>";
      echo "<td>&nbsp;</td>";
    echo "</tr>";
    echo "<tr>";
      echo "<td>&nbsp;</td>";
      echo "<td align='center'>Gesamtsumme:</td>";
      echo "<td align='center'>$sum &euro;</td>";
      echo "<td align='right'>$sum_mwst1 &euro;</td>";
      echo "<td align='right'>$sum_mwst2 &euro;</td>";
    echo "</tr>";
  echo "</table>";
}
?>