$table = "sales";
+if ($_POST["submit"] == "List") {
if (strlen($_POST[year])) {
# $where[] = "date >= '$year-01-01'";
# $year++;
echo ("</tr>");
echo ("</table><p>");
- if (!strlen($_POST[category])) {
+} elseif ($_POST["submit"] == "Overview") {
$query = "SELECT DISTINCT category FROM $table ";
- if (strlen($_POST[year])) {
+ if (strlen($_POST[year]))
$query .= "WHERE date ~* '$_POST[year]'";
- }
$sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
echo ("</table></div>");
}
+ } elseif ($_POST["submit"] == "Tally") {
+ if (strlen($_POST[year]))
+ $where = "date ~* '$_POST[year]' AND ";
+ else
+ $where = '';
+
+ echo ("<h3>Abrechnung</h3>");
+
+ $output = tally ($dbh, "Aus", $where . "price < 0.0");
+ $input = tally ($dbh, "Ein", $where . "price < 0.0");
+
+ printf "<p>Summe Steuern: %.2f", $input["tax"] - $output["tax"];
+ printf "<br>Summe netto: %.2f", $input["netto"] - $output["netto"];
+ printf "<br>Summe btutto: %.2f</p>", $input["brutto"] - $output["brutto"];
}
+
+function tally ($dbh, $head, $where)
+{
+ echo ("<div align=\"center\"><table class=\"font\" width=\"80%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" summary=\"\">");
+ printf ("<tr bgcolor=\"#<colh>\">"
+ ."<th width=\"10%%\">%s</th>"
+ ."<th width=\"30%%\">Steuer</th>"
+ ."<th width=\"30%%\">netto</th>"
+ ."<th width=\"30%%\">brutto</th></tr>",
+ $head);
+
+ $query = "SELECT tax_percent,sum(tax_assigned) AS tax,sum(price-tax_assigned) AS netto,sum(price) AS brutto"
+ . " FROM sales WHERE " . $where
+ . " GROUP BY tax_percent ORDER BY tax_percent";
+
+ $color = "<cold>";
+ $sum = array();
+
+ $sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
+ for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
+ $row = pg_fetch_array ($sth, $nr);
+ $color = $color=="<cold>"?"<coln>":"<cold>";
+
+ $output = -$row[0]; $sum_output += $output;
+
+ printf ("<tr bgcolor=\"#%s\"><td align=\"right\" width=\"10%%\">%d</td>"
+ ."<td align=\"right\" width=\"30%%\">%.2f</td>"
+ ."<td align=\"right\" width=\"30%%\">%.2f</td>"
+ ."<td align=\"right\" width=\"30%%\">%.2f</td></tr>",
+ $color,
+ $row["tax_percent"], $row["tax"], $row["netto"], $row["brutto"]);
+ $sum["tax"] += $row["tax"];
+ $sum["netto"] += $row["netto"];
+ $sum["brutto"] += $row["brutto"];
+ }
+
+ printf ("<tr bgcolor=\"#%s\"><td width=\"10%%\"><b>Sum</b></td>"
+ ."<td align=\"right\" width=\"30%%\"><b>%.2f</b></td>"
+ ."<td align=\"right\" width=\"30%%\"><b>%.2f</b></td>"
+ ."<td align=\"right\" width=\"30%%\"><b>%.2f</b></td></tr>",
+ $color,
+ $sum["tax"], $sum["netto"], $sum["brutto"]);
+
+ echo ("</table></div>\n");
+
+ return $sum;
+}
+
?>
</page>
# Local variables:
-# mode: text
-# mode: auto-fill
+# mode: php
# end: