#include <infocon.style>
+<future>
<page func=InfoCon title="Buchhaltung">
+<script type="text/javascript" src="<root_prefix>jquery.editable.js"></script>
-<table width=100% border=0 cellpadding=2 cellspacing=0>
-<tr bgcolor=#<colh>>
- <th width=15%><font face="Helvetica,Arial">Datum</font></th>
- <th width=20%><font face="Helvetica,Arial">Kategorie</font></th>
- <th width=50%><font face="Helvetica,Arial">Verwendungszweck</font></th>
- <th width=15%><font face="Helvetica,Arial">Betrag</font></th>
-</tr>
<?
$dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
or die("Unable to connect to SQL server");
pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
- if ($_POST[currency] == "eur") {
- $table = "sales";
- } elseif ($_POST[currency] == "dm") {
- $table = "sales_dm";
- } else {
- die ("Unknown currency");
- }
+ $table = "sales";
+if ($_POST["submit"] == "List") {
+?>
+<table class="smallfont border" width=100% border=0 cellpadding=1 cellspacing=1>
+<tr class="head">
+ <th width=10%>Datum</th>
+ <th width=10%>Buchung</th>
+ <th width=10%>Kategorie</th>
+ <th width=60%>Verwendungszweck</th>
+ <th width=10%>Betrag</th>
+</tr>
+<?
if (strlen($_POST[year])) {
# $where[] = "date >= '$year-01-01'";
# $year++;
# $where[] = "date < '$year-01-01'";
$where[] = "date ~* '$_POST[year]'";
-
- # Implicit selection of currency
- if ($_POST[year] < 2002) {
- $table = "sales_dm";
- } elseif ($_POST[year] > 2001) {
- $table = "sales";
- }
}
if (strlen($_POST[category])) {
$where[] = "category = '$_POST[category]'";
$where[] = "price < 0.0";
}
- $query = "SELECT date,oid,category,description,price FROM $table ";
+ $query = "SELECT nr,date,billing_date,category,description,price FROM $table ";
if (count($where) > 0) {
$query .= " WHERE " . implode ($where, " AND ");
}
$sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
$sum = 0.0;
- $color = "<cold>";
+ $color = 0;
for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
$row = pg_fetch_array ($sth, $nr);
- $color = $color=="<cold>"?"<coln>":"<cold>";
# $date = explode (" ", $row['date']);
# $date = explode ("-", $date[0]);
# $date = sprintf ("%d.%d.%d", $date[2], $date[1], $date[0]);
$date = substr ($row['date'],6,2) . "." . substr ($row['date'],4,2) . "." . substr ($row['date'],0,4);
-
- printf ("<tr bgcolor=\"#%s\">", $color);
- printf ("<td width=\"15%%\" align=\"right\"><font face=\"Helvetica,Arial\">%s</font></td>", $date);
- printf ("<td width=\"20%%\"><font face=\"Helvetica,Arial\">%s</font></td>", $row['category']);
- printf ("<td width=\"50%%\"><font face=\"Helvetica,Arial\"><a href=\"edit.php?oid=%d&cur=%s\">%s</a></font></td>",
- $row['oid'], $currency, $row['description']);
- printf ("<td width=\"15%%\" align=\"right\"><font face=\"Helvetica,Arial\">%5.2f</font></td>", $row['price']);
+ if ($row['billing_date'])
+ $billing_date = substr ($row['billing_date'],8,2) . "." . substr ($row['billing_date'],5,2) . "." . substr ($row['billing_date'],0,4);
+ else
+ $billing_date = ' ';
+
+ printf ("<tr class=\"t%d\">", $color);
+ printf ("<td width=\"10%%\" align=\"right\">%s</td>", $date);
+ printf ("<td width=\"10%%\" align=\"right\">%s</td>", $billing_date);
+ printf ("<td width=\"10%%\" align=\"center\">%s</td>", $row['category']);
+ printf ("<td width=\"0%%\"><span class=\"edit\" route=\"Sales/EditDescription\" item_id=\"%d\">%s</span></td>",
+ $row['nr'], $row['description']);
+ printf ("<td width=\"10%%\" align=\"right\">%5.2f</td>", $row['price']);
$sum += $row['price'];
echo ("</tr>");
+ $color = !$color;
}
- echo ("<tr>");
- echo ("<td width=\"85%\" colspan=\"3\"><font face=\"Helvetica,Arial\"><b>Summe</b></font></td>");
- printf ("<td width=\"15%%\" align=\"right\"><font face=\"Helvetica,Arial\"><b>%5.2f</b></font></td>", $sum);
+ printf ("<tr class=\"t%d\">", $color);
+ echo ("<td width=\"85%\" colspan=\"4\"><b>Summe</b></td>");
+ printf ("<td width=\"15%%\" align=\"right\"><b>%5.2f</b></td>", $sum);
echo ("</tr>");
- echo ("</table><p>");
+ echo ("</table>");
- 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!");
if (count ($catz) > 0) {
echo ("<h3>Nach Kategorien sortiert</h3>");
- echo ("<div align=\"center\"><table width=\"80%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" summary=\"\">");
- echo ("<tr bgcolor=\"#<colh>\">"
- ."<th width=\"70%\"><font face=\"Helvetica,Arial\">Kategorie</font></th>"
- ."<th width=\"10%\"><font face=\"Helvetica,Arial\">Einnahmen</font></th>"
- ."<th width=\"10%\"><font face=\"Helvetica,Arial\">Ausgaben</font></th>"
- ."<th width=\"10%\"><font face=\"Helvetica,Arial\">Summe</font></th></tr>");
+ echo ("<div align=\"center\"><table class=\"smallfont border\" width=\"60%\" cellpadding=\"1\" cellspacing=\"1\" summary=\"\">");
+ echo ("<tr class=\"head\">"
+ ."<th width=\"40%\">Kategorie</th>"
+ ."<th width=\"20%\">Einnahmen</th>"
+ ."<th width=\"20%\">Ausgaben</th>"
+ ."<th width=\"20%\">Summe</th></tr>");
sort ($catz);
- $color = "<cold>";
+ $color = 0;
$sum_output = 0;
for ($i=0; $i < count ($catz); $i++) {
$query = sprintf ("SELECT SUM (price) FROM $table WHERE category = '%s' AND price > 0.0", $catz[$i]);
- $color = $color=="<cold>"?"<coln>":"<cold>";
if (strlen($_POST[year])) {
$query .= " AND date ~* '$_POST[year]'";
$row = pg_fetch_array ($sth, 0);
$output = -$row[0]; $sum_output += $output;
- printf ("<tr bgcolor=\"#%s\"><td width=\"70%%\"><font face=\"Helvetica,Arial\">%s</font></td>"
- ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\">%.2f</font></td>"
- ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\">%.2f</font></td>"
- ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\">%.2f</font></td></tr>",
- $color, $catz[$i], $input, $output, $input - $output);
+ $sum = $input - $output;
+ printf ("<tr class=\"t%d\"><td width=\"40%%\">%s</td>"
+ ."<td align=\"right\" width=\"20%%\">%.2f</td>"
+ ."<td align=\"right\" width=\"20%%\">%.2f</td>"
+ ."<td align=\"right\" width=\"20%%\" class=\"%s\">%.2f</td></tr>",
+ $color, $catz[$i], $input, $output, $sum>0?'in':'out', $sum);
+ $color = !$color;
}
- printf ("<tr bgcolor=\"#%s\"><td width=\"70%%\"><font face=\"Helvetica,Arial\"><b>Summe</b></font></td>"
- ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\"><b>%.2f</b></font></td>"
- ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\"><b>%.2f</b></font></td>"
- ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\"><b>%.2f</b></font></td></tr>",
- $color, $sum_input, $sum_output, $sum_input - $sum_output);
+ $sum = $sum_input - $sum_output;
+ printf ("<tr class=\"t%d\"><td width=\"40%%\"><b>Summe</b></td>"
+ ."<td align=\"right\" width=\"20%%\"><b>%.2f</b></td>"
+ ."<td align=\"right\" width=\"20%%\"><b>%.2f</b></td>"
+ ."<td align=\"right\" width=\"20%%\" class=\"%s\"><b>%.2f</b></td></tr>",
+ $color, $sum_input, $sum_output, $sum>0?'in':'out', $sum);
+
echo ("</table></div>");
}
+ } elseif ($_POST["submit"] == "Tally") {
+ if (strlen($_POST[year]))
+ $where = "date ~* '$_POST[year]' AND ";
+ else
+ $where = '';
+
+ if (strlen($_POST[year]))
+ printf("<h3>Jahresabrechnung %d</h3>", $_POST[year]);
+ else
+ echo ("<h3>Abrechnung</h3>");
+
+ $input = tally ($dbh, "Einnahmen", $where, 'in');
+ echo '<div style="padding-top: 15px;"></div>';
+ $output = tally ($dbh, "Ausgaben", $where, 'out');
+
+ if (strlen($_POST[year])) {
+ echo '<div style="padding-top: 15px;"></div>';
+ echo('<table class="smallfont border" cellspacing="1" cellpadding="1">');
+ $foo = $input["tax"] - $output["tax"];
+ printf('<tr><td>%s</td><td align="right">%.2f €</td><td>(%s)</td></tr>',
+ 'Summe Steuern', $foo, $foo>0?'Nachzahlung':'Rückzahlung');
+ printf('<tr><td>%s</td><td align="right">%.2f €</td><td> </td></tr>',
+ 'Summe netto', $input["netto"] - $output["netto"]);
+ $foo = $input["brutto"] - $output["brutto"];
+ printf('<tr><td>%s</td><td align="right">%.2f €</td><td>(%s)</td></tr>',
+ 'Summe brutto', $foo, $foo>0?'Gewinn':'Verlust');
+ if (($privat = privat($dbh, $where)))
+ printf('<tr><td>%s</td><td align="right">%.2f €</td><td> </td></tr>',
+ 'Privatentnahme', $privat);
+ echo('</table>');
+ }
}
-?>
+function privat ($dbh, $where)
+{
+ $query = "SELECT sum(price) * -1 AS privat"
+ . " FROM sales WHERE " . $where
+ . " category = 'privat'";
+
+ error_log($query);
+ $sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
+ if (pg_NumRows($sth) != 1)
+ return 0;
+
+ $row = pg_fetch_array ($sth, $nr);
+ return $row['privat'];
+}
+
+function tally ($dbh, $head, $where, $class)
+{
+ echo ("<div align=\"center\"><table class=\"smallfont border\" width=\"60%\" cellpadding=\"1\" cellspacing=\"1\" summary=\"\">");
+ printf ("<tr class=\"head\"><th colspan=\"4\" align=\"left\"><strong>%s</strong></td></tr>", $head);
+ printf ("<tr class=\"head\">"
+ ."<th width=\"10%%\">USt.</th>"
+ ."<th width=\"30%%\">Steuer</th>"
+ ."<th width=\"30%%\">netto</th>"
+ ."<th width=\"30%%\">brutto</th></tr>");
+
+ $query = "SELECT tax_percent,sum(tax_assigned) AS tax,sum(price-tax_assigned) AS netto,sum(price) AS brutto"
+ . " FROM sales WHERE " . $where
+ . ($class=='in'?"price > 0.0":"price < 0.0")
+ . " AND category <> 'privat' "
+ . " GROUP BY tax_percent ORDER BY tax_percent";
+
+ $color = 0;
+ $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);
+
+ if ($row["brutto"] < 0) {
+ $row["tax"] = -$row["tax"];
+ $row["netto"] = -$row["netto"];
+ $row["brutto"] = -$row["brutto"];
+ }
+
+ printf ("<tr class=\"t%d\"><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"];
+ $color = !$color;
+ }
+
+ printf ("<tr class=\"t%d\"><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%%\" class=\"%s\"><b>%.2f</b></td></tr>",
+ $color,
+ $sum["tax"], $sum["netto"], $class, $sum["brutto"]);
+
+ echo ("</table></div>\n");
+
+ return $sum;
+}
+
+?>
+<div style="padding-top: 5px;"></div>
+
+<script type="text/javascript">
+<protect>
+$(function(){
+ make_editable('table.smallfont tr span.edit');
+});
+</protect>
+</script>
</page>
# Local variables:
-# mode: text
-# mode: auto-fill
+# mode: php
# end: