f0fc1e8dad19ea9698e245272c30580d5e1deb89
[infodrom.org/service.infodrom.org] / src / InfoCon / account / list.wml
1 #include <infocon.style>
2 #include <phptools.inc>
3 #include "account.inc"
4
5 <?php
6 function filter_account()
7 {
8   global $db;
9   $out = '';
10   $table = "account";
11   $value = "value_eur";
12   $add = '';
13   if ((strlen ($_POST['currency']) > 0) && ($_POST['currency'] == "dm")) {
14     $table = "account_dm";
15     $value = "value_dm";
16     $add = "&cur=dm";
17   }
18
19   $where[] = sprintf("blz_kto = '%s'", $_POST['blzkto']);
20   if (strlen($_POST['year'])) {
21     $where[] = sprintf ("datum >= '%04d-01-01'", $_POST['year']);
22     $year++;
23     $where[] = sprintf ("datum < '%04d-01-01'", $_POST['year']+1);
24   }
25
26   if (strlen($_POST[deadline]) && strlen(trim($_POST['deadline']))) {
27     $date = form_to_yyyymmdd ($_POST['deadline']);
28     $where[] = sprintf ("datum < '%s'", $date);
29   }
30
31   if (strlen($_POST['statement']) && strlen(trim($_POST['statement']))) {
32     $where[] = sprintf("statement = '%s'", $_POST['statement']);
33   }
34
35   if (strlen($_POST['category']) && strlen(trim($_POST['category']))) {
36     $where[] = sprintf("category = '%s'", $_POST['category']);
37   }
38
39   if (strlen($_POST['keyword']) && strlen(trim($_POST['keyword']))) {
40     $where[] = sprintf("descr ~* '%s'", $_POST['keyword']);
41   }
42
43   if (strlen($_POST['from_to']) && strlen(trim($_POST['from_to']))) {
44     $where[] = sprintf("from_to = '%s'", $_POST['from_to']);
45   }
46
47   if ($_POST['input'] && !$_POST['output']) {
48     $where[] = "$value > 0.0";
49   } elseif ($_POST['output'] && !$_POST['input']) {
50     $where[] = "$value < 0.0";
51   }
52
53   $query = "SELECT datum,id,category,descr,$value FROM $table WHERE "
54          . implode ($where, " AND ")
55          . " ORDER BY datum,id";
56
57   $sum = 0.0;
58   $sum_in = 0.0;
59   $sum_out = 0.0;
60   $color = 0;
61   foreach ($db->fetchAssocList($query) as $row) {
62     $descr = explode ("
63 ", $row['descr']);
64     $date = explode (" ", $row['datum']);
65     $date = explode ("-", $date[0]);
66     $date = sprintf ("%d.%d.%d", $date[2], $date[1], $date[0]);
67
68     $out .= sprintf ("<tr class=\"t%d\">", $color);
69     $out .= sprintf ("<td width=\"10%%\" align=\"right\">%s</td>", $date);
70     $out .= sprintf ("<td width=\"10%%\" align=\"center\">%s</td>", $row['category']);
71     $out .= sprintf ("<td width=\"70%%\"><a href=\"edit.php?id=%d%s\">%s</a></td>",
72             $row['id'], $add, $descr[0]);
73     $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"%s\">%5.2f</td>",
74       $row[$value]>0?"in":"out", $row[$value]);
75     $sum += $row[$value];
76     if ($row[$value] > 0) {
77       $sum_in += $row[$value];
78     } else {
79       $sum_out += $row[$value];
80     }
81     $out .= "</tr>";
82     $color = !$color;
83   }
84   if (strlen($statement)) {
85     $out .= sprintf ("<tr class=\"t%d\">", $color);
86     $out .= "<td width=\"90%\" colspan=\"3\"><strong>Summe Einnahmen</strong></td>";
87     $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"in\">%5.2f</td>",$sum_in);
88     $out .= "</tr>";
89     $out .= sprintf ("<tr class=\"t%d\">", $color);
90     $out .= "<td width=\"90%\" colspan=\"3\"><strong>Summe Ausgaben</strong></td>";
91     $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"out\">%5.2f</td>", $sum_out*-1);
92     $out .= "</tr>";
93   }
94   $out .= sprintf ("<tr class=\"t%d\">", $color);
95   $out .= "<td width=\"90%\" colspan=\"3\" align=\"left\"><strong>Summe</strong></td>";
96   $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"%s\"><strong>%5.2f</strong></td>",
97     $sum>0?"in":"out", $sum);
98   $out .= "</tr>";
99
100   return $out;
101 }
102
103 if (!empty($_POST['ajax']) && $_POST['ajax'] == 1) {
104     echo utf8_encode(filter_account());
105     exit;
106 }
107
108 ?>
109
110 <page func=InfoCon title="Kontoführung">
111
112 <calendar_init -5>
113 <account_heading>
114 <form_to_yyyymmdd>
115
116 <style type="text/css">
117 div#filter_popup {
118     background: white;
119     border: 1px solid #CCC;
120     height:auto;
121     width:340px;
122     position:absolute;
123 }
124 div#filter_title {
125     width: 100%;
126     cursor: move;
127     background: #EEE;
128     margin-bottom: 5px;
129     font-weight: bold;
130 }
131 </style>
132 <table class="border smallfont" width=100% border=0 cellpadding=0 cellspacing=1>
133 <thead>
134 <tr class=head>
135   <th width=10%>Datum</th>
136   <th width=10%>Kategorie</th>
137   <th width=70%>Verwendungszweck</th>
138   <th width=10%>Betrag</th>
139 </tr>
140 </thead>
141 <tbody>
142 <?=(count($_GET)?'':filter_account())?>
143 </tbody>
144 </table><p>
145
146 <protect><script type="text/javascript">
147 $(function(){
148     $('table.border tr').not('.head').click(function(){
149         $(this).toggleClass('highlight');
150         if ($(this).hasClass('highlight'))
151             $(this).css('backgroundColor','#add8e6');
152         else
153             $(this).css('backgroundColor','');
154     });
155     $('body').append('<script type="text/javascript" src="../../jquery.udraggable.js"><\/script>');
156     $('body').append('<script type="text/javascript" src="../../jquery.event.ue.js"><\/script>');
157 });
158
159 function filter_popup()
160 {
161     if (!$('#filter_popup form input').length) {
162         $.get('query.php',
163               window.location.search.substr(1)+'&ajax=1',
164               function(data) {
165                   var text = '<style type="text/css">';
166                   text += '#fc { z-index: 10; }';
167                   $(data).find('style').each(function(i,e){
168                       text += $(this).html();
169                   });
170                   text += '</style>';
171                   text += $(data).find('form').html();
172                   $('#filter_popup form').html(text);
173
174                   $('#filter_popup').udraggable({
175                       'handle': 'div#filter_title'
176                   }).css('top', '70px').css('left', '103px');
177
178                   $('#filter_popup form input.button[type="submit"]').click(function(e){
179                       $.post('list.php',
180                              'ajax=1&'+$('#filter_popup form').serialize(),
181                              function(data){
182                                  $('table.border tbody').html(data);
183                                  $('#filter_popup').hide();
184                              });
185                       return false;
186                   });
187           });
188     }
189
190     if ($('#filter_popup:visible').length)
191         $('#filter_popup').hide();
192     else
193         $('#filter_popup').show();
194
195     return false;
196 }
197
198 </script></protect>
199 <div id="filter_popup" style="display:none;">
200 <div id="filter_title">Filter setzen</div>
201 <div style="padding:5px;">
202 <form id="filter_form"></form>
203 </div>
204 </div>
205 </page>
206
207 # Local variables:
208 # mode: text
209 # mode: auto-fill
210 # end: