Use new object-oriented backend
[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   $table = "account";
19   $value = "value_eur";
20   $add = '';
21   if ((strlen ($_POST['currency']) > 0) && ($_POST['currency'] == "dm")) {
22     $table = "account_dm";
23     $value = "value_dm";
24     $add = "&cur=dm";
25   }
26
27   $where[] = sprintf("blz_kto = '%s'", $_POST['blzkto']);
28   if (strlen($_POST['year'])) {
29     $where[] = sprintf ("datum >= '%04d-01-01'", $_POST['year']);
30     $year++;
31     $where[] = sprintf ("datum < '%04d-01-01'", $_POST['year']+1);
32   }
33
34   if (strlen($_POST[deadline]) && strlen(trim($_POST['deadline']))) {
35     $date = form_to_yyyymmdd ($_POST['deadline']);
36     $where[] = sprintf ("datum < '%s'", $date);
37   }
38
39   if (strlen($_POST['statement']) && strlen(trim($_POST['statement']))) {
40     $where[] = sprintf("statement = '%s'", $_POST['statement']);
41   }
42
43   if (strlen($_POST['category']) && strlen(trim($_POST['category']))) {
44     $where[] = sprintf("category = '%s'", $_POST['category']);
45   }
46
47   if (strlen($_POST['keyword']) && strlen(trim($_POST['keyword']))) {
48     $where[] = sprintf("descr ~* '%s'", $_POST['keyword']);
49   }
50
51   if (strlen($_POST['from_to']) && strlen(trim($_POST['from_to']))) {
52     $where[] = sprintf("from_to = '%s'", $_POST['from_to']);
53   }
54
55   if ($_POST['input'] && !$_POST['output']) {
56     $where[] = "$value > 0.0";
57   } elseif ($_POST['output'] && !$_POST['input']) {
58     $where[] = "$value < 0.0";
59   }
60
61   $query = "SELECT datum,id,category,descr,$value FROM $table WHERE "
62          . implode ($where, " AND ")
63          . " ORDER BY datum,id";
64
65   $sum = 0.0;
66   $sum_in = 0.0;
67   $sum_out = 0.0;
68   $color = 0;
69   foreach ($db->fetchAssocList($query) as $row) {
70     $descr = explode ("
71 ", $row['descr']);
72     $date = explode (" ", $row['datum']);
73     $date = explode ("-", $date[0]);
74     $date = sprintf ("%d.%d.%d", $date[2], $date[1], $date[0]);
75
76     printf ("<tr class=\"t%d\">", $color);
77     printf ("<td width=\"10%%\" align=\"right\">%s</td>", $date);
78     printf ("<td width=\"10%%\" align=\"center\">%s</td>", $row['category']);
79     printf ("<td width=\"70%%\"><a href=\"edit.php?id=%d%s\">%s</a></td>",
80             $row['id'], $add, $descr[0]);
81     printf ("<td width=\"10%%\" align=\"right\" class=\"%s\">%5.2f</td>",
82       $row[$value]>0?"in":"out", $row[$value]);
83     $sum += $row[$value];
84     if ($row[$value] > 0) {
85       $sum_in += $row[$value];
86     } else {
87       $sum_out += $row[$value];
88     }
89     echo ("</tr>");
90     $color = !$color;
91   }
92     if (strlen($statement)) {
93       printf ("<tr class=\"t%d\">", $color);
94       echo ("<td width=\"90%\" colspan=\"3\"><strong>Summe Einnahmen</strong></td>");
95       printf ("<td width=\"10%%\" align=\"right\" class=\"in\">%5.2f</td>",$sum_in);
96       echo ("</tr>");
97       printf ("<tr class=\"t%d\">", $color);
98       echo ("<td width=\"90%\" colspan=\"3\"><strong>Summe Ausgaben</strong></td>");
99       printf ("<td width=\"10%%\" align=\"right\" class=\"out\">%5.2f</td>", $sum_out*-1);
100       echo ("</tr>");
101     }
102     printf ("<tr class=\"t%d\">", $color);
103     echo ("<td width=\"90%\" colspan=\"3\" align=\"left\"><strong>Summe</strong></td>");
104     printf ("<td width=\"10%%\" align=\"right\" class=\"%s\"><strong>%5.2f</strong></td>",
105       $sum>0?"in":"out", $sum);
106     echo ("</tr>");
107
108 ?>
109 </table><p>
110
111 </page>
112
113 # Local variables:
114 # mode: text
115 # mode: auto-fill
116 # end: