6e2294e914d21154a9395c44a2770c2b1bafc9d0
[infodrom.org/service.infodrom.org] / src / InfoCon / buch / list.wml
1 #include <infocon.style>
2
3 <page func=InfoCon title="Buchhaltung">
4
5 <table width=100% border=0 cellpadding=2 cellspacing=0>
6 <tr bgcolor=#<colh>>
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>
11 </tr>
12 <?
13   $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
14                or die("Unable to connect to SQL server");
15
16   pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
17
18   if (strlen($year)) {
19     # $where[] = "date >= '$year-01-01'";
20     # $year++;
21     # $where[] = "date < '$year-01-01'";
22     $where[] = "date ~* '$year'";
23   }
24   if (strlen($category)) {
25     $where[] = "category = '$category'";
26   }
27   if ($input && !$output) {
28     $where[] = "price > 0.0";
29   } elseif ($output && !$input) {
30     $where[] = "price < 0.0";
31   }
32
33   $query = "SELECT date,oid,category,description,price FROM sales ";
34   if (count($where) > 0) {
35     $query .= " WHERE " . implode ($where, " AND ");
36   }
37   $query .= " ORDER BY date,oid";
38   $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
39
40   $sum = 0.0;
41   $color = "<cold>";
42   for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
43     $row = pg_fetch_array ($sth, $nr);
44     $color = $color=="<cold>"?"<coln>":"<cold>";
45
46     # $date = explode (" ", $row['date']);
47     # $date = explode ("-", $date[0]);
48     # $date = sprintf ("%d.%d.%d", $date[2], $date[1], $date[0]);
49     $date = substr ($row['date'],6,2) . "." . substr ($row['date'],4,2) . "." . substr ($row['date'],0,4);
50
51     printf ("<tr bgcolor=\"#%s\">", $color);
52     printf ("<td width=\"15%%\" align=\"right\"><font face=\"Helvetica,Arial\">%s</font></td>", $date);
53     printf ("<td width=\"20%%\"><font face=\"Helvetica,Arial\">%s</font></td>", $row['category']);
54     printf ("<td width=\"50%%\"><font face=\"Helvetica,Arial\"><a href=\"edit.php3?oid=%d\">%s</a></font></td>",
55       $row['oid'], $row['description']);
56     printf ("<td width=\"15%%\" align=\"right\"><font face=\"Helvetica,Arial\">%5.2f</font></td>", $row['price']);
57     $sum += $row['price'];
58     echo ("</tr>");
59   }
60   echo ("<tr>");
61   echo ("<td width=\"85%\" colspan=\"3\"><font face=\"Helvetica,Arial\"><b>Summe</b></font></td>");
62   printf ("<td width=\"15%%\" align=\"right\"><font face=\"Helvetica,Arial\"><b>%5.2f</b></font></td>", $sum);
63   echo ("</tr>");
64   echo ("</table><p>");
65
66   if (!strlen($category)) {
67
68     $query = "SELECT DISTINCT category FROM sales ";
69     if (strlen($year)) {
70       $query .= "WHERE date ~* '$year'";
71     }
72
73     $sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
74
75     for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
76       $row = pg_fetch_array ($sth, $nr);
77       $catz[] = $row['category'];
78     }
79
80     if (count ($catz) > 0) {
81       echo ("<h3>Nach Kategorien sortiert</h3>");
82       echo ("<div align=\"center\"><table width=\"80%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" summary=\"\">");
83       echo ("<tr bgcolor=\"#<colh>\">"
84            ."<th width=\"70%\"><font face=\"Helvetica,Arial\">Kategorie</font></th>"
85            ."<th width=\"10%\"><font face=\"Helvetica,Arial\">Einnahmen</font></th>"
86            ."<th width=\"10%\"><font face=\"Helvetica,Arial\">Ausgaben</font></th>"
87            ."<th width=\"10%\"><font face=\"Helvetica,Arial\">Summe</font></th></tr>");
88       sort ($catz);
89
90       $color = "<cold>";
91       for ($i=0; $i < count ($catz); $i++) {
92         $query = sprintf ("SELECT SUM (price) FROM sales WHERE category = '%s' AND price > 0.0", $catz[$i]);
93         $color = $color=="<cold>"?"<coln>":"<cold>";
94
95         if (strlen($year)) {
96           $query .= " AND date ~* '$year'";
97         }
98         $sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
99         $row = pg_fetch_array ($sth, 0);
100         $input = $row[0]; $sum_input += $input;
101         $query = sprintf ("SELECT SUM (price) FROM sales WHERE category = '%s' AND price < 0.0", $catz[$i]);
102         if (strlen($year)) {
103           $query .= " AND date ~* '$year'";
104         }
105         $sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
106         $row = pg_fetch_array ($sth, 0);
107         $output = -$row[0]; $sum_output += $output;
108
109         printf ("<tr bgcolor=\"#%s\"><td width=\"70%%\"><font face=\"Helvetica,Arial\">%s</font></td>"
110                ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\">%.2f</font></td>"
111                ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\">%.2f</font></td>"
112                ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\">%.2f</font></td></tr>",
113                $color, $catz[$i], $input, $output, $input - $output);
114       }
115
116       printf ("<tr bgcolor=\"#%s\"><td width=\"70%%\"><font face=\"Helvetica,Arial\"><b>Summe</b></font></td>"
117              ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\"><b>%.2f</b></font></td>"
118              ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\"><b>%.2f</b></font></td>"
119              ."<td align=\"right\" width=\"10%%\"><font face=\"Helvetica,Arial\"><b>%.2f</b></font></td></tr>",
120              $color, $sum_input, $sum_output, $sum_input - $sum_output);
121       echo ("</table></div>");
122
123     }
124   }
125 ?>
126
127 </page>
128
129 # Local variables:
130 # mode: text
131 # mode: auto-fill
132 # mode: iso-accents
133 # end: