<?
  if (basename(__FILE__) == basename($PHP_SELF))
    die("Darf nur als include benutzt werden\n");
?>
<?
     $sum_mwst1='0';
     $sum_mwst2='0';
     $ums_mwst1='0';
     $ums_mwst1='0';
     $sum='0';
     $res=send_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.kasse_id=$kasse_id GROUP BY u.artnr");
     while ($row  =  mysql_fetch_array($res,MYSQL_NUM))
     {
      $sum=$sum+$row[3];
      if($row[2]==1)
      {
        $sum_mwst1=$sum_mwst1+($row[3]/100*$mwst1);
        $ums_mwst1=$ums_mwst1+$row[3];
      }
      if($row[2]==2)
      {
        $sum_mwst2=$sum_mwst2+($row[3]/100*$mwst2);
        $ums_mwst2=$ums_mwst2+$row[3];
      }
     }

     tab_mwst($kasse_id);

  if($_POST['todo']!='logout')
  {
    $res1=send_sql("select kasse_bestand_eingang as 'Kassenbestand bei Geschäftsbeginn' from user as u, kasse as k where u.kasse_id = k.kasse_id");
    $res1=mysql_result($res1,0,0);
    echo "<br>";
    echo "<table border=1 cellpadding='1' cellspacing='1' align=center bgcolor=white>";
      echo "<tr>";
        echo "<th align=left>Kasseneingangsbestand:</th>";
        echo "<td><input type='Text' name='kasse_bestand_eingang' value=$res1 size='40' disabled></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<th align=left>Tagesumsatz Gesamt:</th>";
        echo "<td><input type='Text' name='$name' value='$sum' size='9' disabled>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Davon Mwst: <input type='Text' name='$name' value='".($sum_mwst1+$sum_mwst2)."' size='9' disabled></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<th align=left>Tagesumsatz $mwst1% Mwst:</th>";
        echo "<td><input type='Text' name='$name' value='$ums_mwst1' size='9' disabled>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Davon Mwst: <input type='Text' name='$name' value='$sum_mwst1' size='9' disabled></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<th align=left>Tagesumsatz $mwst2% Mwst:</th>";
        echo "<td><input type='Text' name='$name' value='$ums_mwst2' size='9' disabled>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Davon Mwst: <input type='Text' name='$name' value='$sum_mwst2' size='9' disabled></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<th align=left>Kasse Entname (in Hauptkasse):</th>";
        echo "<td><input type='Text' name='kasse_entname' value='0.00' size='40'></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<th align=left>Kassenbestand bei Geschäftsschluss:</th>";
        echo "<td><input type='Text' name='kasse_bestand_abschluss' value=$wechselgeld size='40'></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<th><input type=\"hidden\" name=todo value=\"logout\">&nbsp;</th>";
        echo "<td><input type=\"submit\" value=\"Bestätigen und Logout\">&nbsp;&nbsp;&nbsp;&nbsp;</td>";
      echo "</tr>";
    echo "</table>";
  }
  else
  {
   $res=send_sql("update user as u, kasse as k SET kasse_entname='".$_POST['kasse_entname']."',kasse_bestand_abschluss='".$_POST['kasse_bestand_abschluss']."', k.Umsatz_mwst_1='".$ums_mwst1."', k.Umsatz_mwst_2='".$ums_mwst2."' where u.kasse_id = k.kasse_id");
   if (destroy_Session_ID($session_id,$status))
   {
    $res1=send_sql("select kasse_bestand_eingang from user as u, kasse as k where u.kasse_id = k.kasse_id");
    $res1=mysql_result($res1,0,0);
    echo "<br>";
    echo "<table border=1 cellpadding='1' cellspacing='1' align=center bgcolor=white>";
      echo "<tr>";
        echo "<th align=left>Kasseneingangsbestand:</th>";
        echo "<td><input type='Text' name='kasse_bestand_eingang' value=$res1 size='40' readonly></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<th align=left>Tagesumsatz Gesamt:</th>";
        echo "<td><input type='Text' name='$name' value='$sum' size='9' readonly>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Davon Mwst: <input type='Text' name='$name' value='".($sum_mwst1+$sum_mwst2)."' size='9' readonly></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<th align=left>Tagesumsatz $mwst1% Mwst:</th>";
        echo "<td><input type='Text' name='$name' value='$ums_mwst1' size='9' readonly>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Davon Mwst: <input type='Text' name='$name' value='$sum_mwst1' size='9' readonly></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<th align=left>Tagesumsatz $mwst2% Mwst:</th>";
        echo "<td><input type='Text' name='$name' value='$ums_mwst2' size='9' readonly>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Davon Mwst: <input type='Text' name='$name' value='$sum_mwst2' size='9' readonly></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<th align=left>Kasse Entname (in Hauptkasse):</th>";
        echo "<td><input type='Text' name='kasse_entname' value='".$_POST['kasse_entname']."' size='40' readonly></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<th align=left>Kassenbestand bei Geschäftsschluss:</th>";
        echo "<td><input type='Text' name='kasse_bestand_abschluss' value=".$_POST['kasse_bestand_abschluss']." size='40' readonly></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<th align=left>Kassendifferenz:</th>";
        $dif=(($_POST['kasse_bestand_abschluss']*100+$_POST['kasse_entname']*100)-($res1*100+$sum*100))/100;
        echo "<td><input type='Text' name='differenz' value=$dif size='40' readonly></td>";
      echo "</tr>";
    echo "</table>";
     echo "<script language='JavaScript'>window.print()</script>";
     echo "<div align='center'><br><br>Logout erfolgreich.</div>";
     echo "<div align='center'><a href=\"index.php\">Zum Login</a></div>";
   }
   else echo "<div align='center'>Logout fehlgeschlagen.<br>Bitte beim Administrator melden.<br><br></div>";
  }
?>