Support for PHP > 3
[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 ($currency == "eur") {
19     $table = "sales";
20   } elseif ($currency == "dm") {
21     $table = "sales_dm";
22   } else {
23     die ("Unknown currency");
24   }
25
26   if (strlen($year)) {
27     # $where[] = "date >= '$year-01-01'";
28     # $year++;
29     # $where[] = "date < '$year-01-01'";
30     $where[] = "date ~* '$year'";
31
32     # Implicit selection of currency
33     if ($year < 2002) {
34       $table = "sales_dm";
35     } elseif ($year > 2001) {
36       $table = "sales";
37     }
38   }
39   if (strlen($category)) {
40     $where[] = "category = '$category'";
41   }
42   if ($input && !$output) {
43     $where[] = "price > 0.0";
44   } elseif ($output && !$input) {
45     $where[] = "price < 0.0";
46   }
47
48   $query = "SELECT date,oid,category,description,price FROM $table ";
49   if (count($where) > 0) {
50     $query .= " WHERE " . implode ($where, " AND ");
51   }
52   $query .= " ORDER BY date,oid";
53   $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
54
55   $sum = 0.0;
56   $color = "<cold>";
57   for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
58     $row = pg_fetch_array ($sth, $nr);
59     $color = $color=="<cold>"?"<coln>":"<cold>";
60
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);
65
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'];
73     echo ("</tr>");
74   }
75   echo ("<tr>");
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);
78   echo ("</tr>");
79   echo ("</table><p>");
80
81   if (!strlen($category)) {
82
83     $query = "SELECT DISTINCT category FROM $table ";
84     if (strlen($year)) {
85       $query .= "WHERE date ~* '$year'";
86     }
87
88     $sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
89
90     for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
91       $row = pg_fetch_array ($sth, $nr);
92       $catz[] = $row['category'];
93     }
94
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>");
103       sort ($catz);
104
105       $color = "<cold>";
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>";
109
110         if (strlen($year)) {
111           $query .= " AND date ~* '$year'";
112         }
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]);
117         if (strlen($year)) {
118           $query .= " AND date ~* '$year'";
119         }
120         $sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
121         $row = pg_fetch_array ($sth, 0);
122         $output = -$row[0]; $sum_output += $output;
123
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);
129       }
130
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>");
137
138     }
139   }
140 ?>
141
142 </page>
143
144 # Local variables:
145 # mode: text
146 # mode: auto-fill
147 # end: