Improved code organisation
[infodrom.org/service.infodrom.org] / src / InfoCon / account / list.wml
1 #include <infocon.style>
2 #include <phptools.inc>
3 #include "account.inc"
4
5 <page func=InfoCon title="Kontoführung">
6
7 <account_heading>
8 <form_to_yyyymmdd>
9
10 <table class=font width=100% border=0 cellpadding=2 cellspacing=0>
11 <tr bgcolor=#<colh>>
12   <th width=10%><font face="Helvetica,Arial">Datum</font></th>
13   <th width=10%><font face="Helvetica,Arial">Kategorie</font></th>
14   <th width=70%><font face="Helvetica,Arial">Verwendungszweck</font></th>
15   <th width=10%><font face="Helvetica,Arial">Betrag</font></th>
16 </tr>
17 <?
18   pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
19
20   $table = "account";
21   $value = "value_eur";
22   $add = '';
23   if ((strlen ($_POST[currency]) > 0) && ($_POST[currency] == "dm")) {
24     $table = "account_dm";
25     $value = "value_dm";
26     $add = "&cur=dm";
27   }
28
29   $where[] = "blz_kto = '$_POST[blzkto]'";
30   if (strlen($_POST[year])) {
31     $where[] = sprintf ("datum >= '%04d-01-01'", $_POST[year]);
32     $year++;
33     $where[] = sprintf ("datum < '%04d-01-01'", $_POST[year]+1);
34   }
35
36   if (strlen($_POST[deadline])) {
37     $date = form_to_yyyymmdd ($_POST[deadline]);
38     $where[] = sprintf ("datum < '%s'", $date);
39   }
40
41   if (strlen($_POST[statement])) {
42     $where[] = "statement = '$_POST[statement]'";
43   }
44
45   if (strlen($_POST[category])) {
46     $where[] = "category = '$_POST[category]'";
47   }
48
49   if (strlen($_POST[keyword])) {
50     $where[] = "descr ~* '$_POST[keyword]'";
51   }
52
53   if (strlen($_POST[from_to])) {
54     $where[] = "from_to = '$_POST[from_to]'";
55   }
56
57   if ($_POST[input] && !$_POST[output]) {
58     $where[] = "$value > 0.0";
59   } elseif ($_POST[output] && !$_POST[input]) {
60     $where[] = "$value < 0.0";
61   }
62
63   $query = "SELECT datum,oid,category,descr,$value FROM $table WHERE "
64          . implode ($where, " AND ")
65          . " ORDER BY datum,oid";
66   $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
67
68   $sum = 0.0;
69   $sum_in = 0.0;
70   $sum_out = 0.0;
71   $color = "<cold>";
72   for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
73     $row = pg_fetch_array ($sth, $nr);
74     $color = $color=="<cold>"?"<coln>":"<cold>";
75
76     $descr = explode ("
77 ", $row['descr']);
78     $date = explode (" ", $row['datum']);
79     $date = explode ("-", $date[0]);
80     $date = sprintf ("%d.%d.%d", $date[2], $date[1], $date[0]);
81
82     printf ("<tr bgcolor=\"#%s\">", $color);
83     printf ("<td width=\"10%%\" align=\"right\"><font face=\"Helvetica,Arial\">%s</font></td>", $date);
84     printf ("<td width=\"10%%\" align=\"center\"><font face=\"Helvetica,Arial\">%s</font></td>", $row['category']);
85     printf ("<td width=\"70%%\"><font face=\"Helvetica,Arial\"><a href=\"edit.php?oid=%d%s\">%s</a></font></td>",
86             $row['oid'], $add, $descr[0]);
87     printf ("<td width=\"10%%\" align=\"right\"><font face=\"Helvetica,Arial\">%5.2f</font></td>", $row[$value]);
88     $sum += $row[$value];
89     if ($row[$value] > 0) {
90       $sum_in += $row[$value];
91     } else {
92       $sum_out += $row[$value];
93     }
94     echo ("</tr>");
95   }
96     $color = $color=="<cold>"?"<coln>":"<cold>";
97     printf ("<tr bgcolor=\"#%s\">", $color);
98     echo ("<th width=\"90%\" colspan=\"3\"><font face=\"Helvetica,Arial\">Summe</font></th>");
99     printf ("<th width=\"10%%\" align=\"right\"><font face=\"Helvetica,Arial\">%5.2f</font></th>", $sum);
100     echo ("</tr>");
101     if (strlen($statement)) {
102       $color = $color=="<cold>"?"<coln>":"<cold>";
103       printf ("<tr bgcolor=\"#%s\">", $color);
104       echo ("<th width=\"90%\" colspan=\"3\"><font face=\"Helvetica,Arial\">Summe Einnahmen</font></th>");
105       printf ("<th width=\"10%%\" align=\"right\"><font face=\"Helvetica,Arial\">%5.2f</font></th>", $sum_in);
106       echo ("</tr>");
107       $color = $color=="<cold>"?"<coln>":"<cold>";
108       printf ("<tr bgcolor=\"#%s\">", $color);
109       echo ("<th width=\"90%\" colspan=\"3\"><font face=\"Helvetica,Arial\">Summe Ausgaben</font></th>");
110       printf ("<th width=\"10%%\" align=\"right\"><font face=\"Helvetica,Arial\">%5.2f</font></th>", $sum_out*-1);
111       echo ("</tr>");
112     }
113
114 ?>
115 </table><p>
116
117 <? printf ("<a href=\"edit.php?blzkto=%s\"><strong>Neuer Eintrag</strong></a>", $_POST[blzkto]); ?>
118
119 </page>
120
121 # Local variables:
122 # mode: text
123 # mode: auto-fill
124 # end: