1 #include <infocon.style>
3 <page func=InfoCon title="Buchhaltung">
5 <table width=100% border=0 cellpadding=2 cellspacing=0>
7 <th width=15%><font face="Helvetica,Arial">Datum</font></th>
8 <th width=20%><font face="Helvetica,Arial">Kategorie</font></th>
9 <th width=50%><font face="Helvetica,Arial">Verwendungszweck</font></th>
10 <th width=15%><font face="Helvetica,Arial">Betrag</font></th>
13 $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
14 or die("Unable to connect to SQL server");
16 pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
18 if ($currency == "eur") {
20 } elseif ($currency == "dm") {
23 die ("Unknown currency");
27 # $where[] = "date >= '$year-01-01'";
29 # $where[] = "date < '$year-01-01'";
30 $where[] = "date ~* '$year'";
32 # Implicit selection of currency
35 } elseif ($year > 2001) {
39 if (strlen($category)) {
40 $where[] = "category = '$category'";
42 if ($input && !$output) {
43 $where[] = "price > 0.0";
44 } elseif ($output && !$input) {
45 $where[] = "price < 0.0";
48 $query = "SELECT date,oid,category,description,price FROM $table ";
49 if (count($where) > 0) {
50 $query .= " WHERE " . implode ($where, " AND ");
52 $query .= " ORDER BY date,oid";
53 $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
57 for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
58 $row = pg_fetch_array ($sth, $nr);
59 $color = $color=="<cold>"?"<coln>":"<cold>";
61 # $date = explode (" ", $row['date']);
62 # $date = explode ("-", $date[0]);
63 # $date = sprintf ("%d.%d.%d", $date[2], $date[1], $date[0]);
64 $date = substr ($row['date'],6,2) . "." . substr ($row['date'],4,2) . "." . substr ($row['date'],0,4);
66 printf ("<tr bgcolor=\"#%s\">", $color);
67 printf ("<td width=\"15%%\" align=\"right\"><font face=\"Helvetica,Arial\">%s</font></td>", $date);
68 printf ("<td width=\"20%%\"><font face=\"Helvetica,Arial\">%s</font></td>", $row['category']);
69 printf ("<td width=\"50%%\"><font face=\"Helvetica,Arial\"><a href=\"edit.php?oid=%d&cur=%s\">%s</a></font></td>",
70 $row['oid'], $currency, $row['description']);
71 printf ("<td width=\"15%%\" align=\"right\"><font face=\"Helvetica,Arial\">%5.2f</font></td>", $row['price']);
72 $sum += $row['price'];
76 echo ("<td width=\"85%\" colspan=\"3\"><font face=\"Helvetica,Arial\"><b>Summe</b></font></td>");
77 printf ("<td width=\"15%%\" align=\"right\"><font face=\"Helvetica,Arial\"><b>%5.2f</b></font></td>", $sum);
81 if (!strlen($category)) {
83 $query = "SELECT DISTINCT category FROM $table ";
85 $query .= "WHERE date ~* '$year'";
88 $sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
90 for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
91 $row = pg_fetch_array ($sth, $nr);
92 $catz[] = $row['category'];
95 if (count ($catz) > 0) {
96 echo ("<h3>Nach Kategorien sortiert</h3>");
97 echo ("<div align=\"center\"><table width=\"80%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" summary=\"\">");
98 echo ("<tr bgcolor=\"#<colh>\">"
99 ."<th width=\"70%\"><font face=\"Helvetica,Arial\">Kategorie</font></th>"
100 ."<th width=\"10%\"><font face=\"Helvetica,Arial\">Einnahmen</font></th>"
101 ."<th width=\"10%\"><font face=\"Helvetica,Arial\">Ausgaben</font></th>"
102 ."<th width=\"10%\"><font face=\"Helvetica,Arial\">Summe</font></th></tr>");
106 for ($i=0; $i < count ($catz); $i++) {
107 $query = sprintf ("SELECT SUM (price) FROM $table WHERE category = '%s' AND price > 0.0", $catz[$i]);
108 $color = $color=="<cold>"?"<coln>":"<cold>";
111 $query .= " AND date ~* '$year'";
113 $sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
114 $row = pg_fetch_array ($sth, 0);
115 $input = $row[0]; $sum_input += $input;
116 $query = sprintf ("SELECT SUM (price) FROM $table WHERE category = '%s' AND price < 0.0", $catz[$i]);
118 $query .= " AND date ~* '$year'";
120 $sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
121 $row = pg_fetch_array ($sth, 0);
122 $output = -$row[0]; $sum_output += $output;
124 printf ("<tr bgcolor=\"#%s\"><td width=\"70%%\"><font face=\"Helvetica,Arial\">%s</font></td>"
125 ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\">%.2f</font></td>"
126 ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\">%.2f</font></td>"
127 ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\">%.2f</font></td></tr>",
128 $color, $catz[$i], $input, $output, $input - $output);
131 printf ("<tr bgcolor=\"#%s\"><td width=\"70%%\"><font face=\"Helvetica,Arial\"><b>Summe</b></font></td>"
132 ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\"><b>%.2f</b></font></td>"
133 ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\"><b>%.2f</b></font></td>"
134 ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\"><b>%.2f</b></font></td></tr>",
135 $color, $sum_input, $sum_output, $sum_input - $sum_output);
136 echo ("</table></div>");