Add ID column as unique identifier
[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="border smallfont" width=100% border=0 cellpadding=0 cellspacing=1>
11 <tr class=head>
12   <th width=10%>Datum</th>
13   <th width=10%>Kategorie</th>
14   <th width=70%>Verwendungszweck</th>
15   <th width=10%>Betrag</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]) && strlen(trim($_POST[deadline]))) {
37     $date = form_to_yyyymmdd ($_POST[deadline]);
38     $where[] = sprintf ("datum < '%s'", $date);
39   }
40
41   if (strlen($_POST[statement]) && strlen(trim($_POST[statement]))) {
42     $where[] = "statement = '$_POST[statement]'";
43   }
44
45   if (strlen($_POST[category]) && strlen(trim($_POST[category]))) {
46     $where[] = "category = '$_POST[category]'";
47   }
48
49   if (strlen($_POST[keyword]) && strlen(trim($_POST[keyword]))) {
50     $where[] = "descr ~* '$_POST[keyword]'";
51   }
52
53   if (strlen($_POST[from_to]) && strlen(trim($_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,id,category,descr,$value FROM $table WHERE "
64          . implode ($where, " AND ")
65          . " ORDER BY datum,id";
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 = 0;
72   for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
73     $row = pg_fetch_array ($sth, $nr);
74
75     $descr = explode ("
76 ", $row['descr']);
77     $date = explode (" ", $row['datum']);
78     $date = explode ("-", $date[0]);
79     $date = sprintf ("%d.%d.%d", $date[2], $date[1], $date[0]);
80
81     printf ("<tr class=\"t%d\">", $color);
82     printf ("<td width=\"10%%\" align=\"right\">%s</td>", $date);
83     printf ("<td width=\"10%%\" align=\"center\">%s</td>", $row['category']);
84     printf ("<td width=\"70%%\"><a href=\"edit.php?id=%d%s\">%s</a></td>",
85             $row['id'], $add, $descr[0]);
86     printf ("<td width=\"10%%\" align=\"right\" class=\"%s\">%5.2f</td>",
87       $row[$value]>0?"in":"out", $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     $color = !$color;
96   }
97     if (strlen($statement)) {
98       printf ("<tr class=\"t%d\">", $color);
99       echo ("<td width=\"90%\" colspan=\"3\"><strong>Summe Einnahmen</strong></td>");
100       printf ("<td width=\"10%%\" align=\"right\" class=\"in\">%5.2f</td>",$sum_in);
101       echo ("</tr>");
102       printf ("<tr class=\"t%d\">", $color);
103       echo ("<td width=\"90%\" colspan=\"3\"><strong>Summe Ausgaben</strong></td>");
104       printf ("<td width=\"10%%\" align=\"right\" class=\"out\">%5.2f</td>", $sum_out*-1);
105       echo ("</tr>");
106     }
107     printf ("<tr class=\"t%d\">", $color);
108     echo ("<td width=\"90%\" colspan=\"3\" align=\"left\"><strong>Summe</strong></td>");
109     printf ("<td width=\"10%%\" align=\"right\" class=\"%s\"><strong>%5.2f</strong></td>",
110       $sum>0?"in":"out", $sum);
111     echo ("</tr>");
112
113 ?>
114 </table><p>
115
116 </page>
117
118 # Local variables:
119 # mode: text
120 # mode: auto-fill
121 # end: