292cbca4d9b42715435c89b0a64a18001b5d1d51
[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     if (!empty($_POST['ajax'])) $_POST['category'] = utf8_decode($_POST['category']);
37     $where[] = sprintf("category = '%s'", $_POST['category']);
38   }
39
40   if (strlen($_POST['keyword']) && strlen(trim($_POST['keyword']))) {
41     if (!empty($_POST['ajax'])) $_POST['keyword'] = utf8_decode($_POST['keyword']);
42     $where[] = sprintf("descr ~* '%s'", $_POST['keyword']);
43   }
44
45   if (strlen($_POST['from_to']) && strlen(trim($_POST['from_to']))) {
46     if (!empty($_POST['ajax'])) $_POST['from_to'] = utf8_decode($_POST['from_to']);
47     $where[] = sprintf("from_to = '%s'", $_POST['from_to']);
48   }
49
50   if ($_POST['input'] && !$_POST['output']) {
51     $where[] = "$value > 0.0";
52   } elseif ($_POST['output'] && !$_POST['input']) {
53     $where[] = "$value < 0.0";
54   }
55
56   $query = "SELECT datum,id,category,descr,$value FROM $table WHERE "
57          . implode ($where, " AND ")
58          . " ORDER BY datum,id";
59
60   $sum = 0.0;
61   $sum_in = 0.0;
62   $sum_out = 0.0;
63   $color = 0;
64   foreach ($db->fetchAssocList($query) as $row) {
65     $descr = explode ("\n", $row['descr']);
66     $date = explode (" ", $row['datum']);
67     $date = explode ("-", $date[0]);
68     $date = sprintf ("%d.%d.%d", $date[2], $date[1], $date[0]);
69
70     $out .= sprintf ("<tr class=\"t%d\">", $color);
71     $out .= sprintf ("<td width=\"10%%\" align=\"right\">%s</td>", $date);
72     $out .= sprintf ("<td width=\"10%%\" align=\"center\">%s</td>", $row['category']);
73     if (strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/') === false)
74       $out .= sprintf ("<td width=\"70%%\"><a href=\"edit.php?id=%d%s\" target=\"_new\">%s</a></td>",
75                        $row['id'], $add, $descr[0]);
76     else
77       $out .= sprintf ("<td width=\"70%%\"><span route=\"Accounting/EditDescr\" item_id=\"%d\" text=\"%s\">%s</span></td>",
78                        $row['id'], $add, $descr[0]);
79     $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"%s\">%5.2f</td>",
80       $row[$value]>0?"in":"out", $row[$value]);
81     $sum += $row[$value];
82     if ($row[$value] > 0) {
83       $sum_in += $row[$value];
84     } else {
85       $sum_out += $row[$value];
86     }
87     $out .= "</tr>";
88     $color = !$color;
89   }
90   if (strlen($_POST['statement'])) {
91     $out .= sprintf ("<tr class=\"t%d\">", $color);
92     $out .= "<td width=\"90%\" colspan=\"3\"><strong>Summe Einnahmen</strong></td>";
93     $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"in\">%5.2f</td>",$sum_in);
94     $out .= "</tr>";
95     $out .= sprintf ("<tr class=\"t%d\">", $color);
96     $out .= "<td width=\"90%\" colspan=\"3\"><strong>Summe Ausgaben</strong></td>";
97     $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"out\">%5.2f</td>", $sum_out*-1);
98     $out .= "</tr>";
99   }
100   $out .= sprintf ("<tr class=\"t%d\">", $color);
101   $out .= "<td width=\"90%\" colspan=\"3\" align=\"left\"><strong>Summe</strong></td>";
102   $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"%s\"><strong>%5.2f</strong></td>",
103     $sum>0?"in":"out", $sum);
104   $out .= "</tr>";
105
106   return $out;
107 }
108
109 if (!empty($_POST['ajax']) && $_POST['ajax'] == 1) {
110     echo utf8_encode(filter_account());
111     exit;
112 }
113
114 ?>
115
116 <page func=InfoCon title="Kontoführung">
117
118 <calendar_init -5>
119 <account_heading>
120 <form_to_yyyymmdd>
121
122 <style type="text/css">
123 div#filter_popup {
124     background: white;
125     border: 1px solid #CCC;
126     height:auto;
127     width:340px;
128     position:absolute;
129 }
130 div#filter_title {
131     width: 100%;
132     cursor: move;
133     background: #EEE;
134     margin-bottom: 5px;
135     font-weight: bold;
136 }
137 </style>
138 <table class="border smallfont" width=100% border=0 cellpadding=0 cellspacing=1>
139 <thead>
140 <tr class=head>
141   <th width=10%>Datum</th>
142   <th width=10%>Kategorie</th>
143   <th width=70%>Verwendungszweck</th>
144   <th width=10%>Betrag</th>
145 </tr>
146 </thead>
147 <tbody>
148 <?=(count($_GET)?'':filter_account())?>
149 </tbody>
150 </table><p>
151
152 <protect><script type="text/javascript">
153 $(function(){
154     $('table.border tr').not('.head').click(function(){
155         $(this).toggleClass('highlight');
156         if ($(this).hasClass('highlight'))
157             $(this).css('backgroundColor','#add8e6');
158         else
159             $(this).css('backgroundColor','');
160     });
161     $('body').append('<script type="text/javascript" src="../../jquery.udraggable.js"><\/script>');
162     $('body').append('<script type="text/javascript" src="../../jquery.event.ue.js"><\/script>');
163     $('body').append('<script type="text/javascript" src="../../jquery.editable.js"><\/script>');
164 });
165
166 //+ Jonas Raoni Soares Silva
167 //@ http://jsfromhell.com/geral/utf-8 [rev. #1]
168
169 UTF8 = {
170         encode: function(s){
171                 for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
172                         s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
173                 );
174                 return s.join("");
175         },
176         decode: function(s){
177                 for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
178                         ((a = s[i][c](0)) & 0x80) &&
179                         (s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
180                         o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
181                 );
182                 return s.join("");
183         }
184 };
185
186 function filter_popup()
187 {
188     if (!$('#filter_popup form input').length) {
189         $.get('query.php',
190               window.location.search.substr(1)+'&ajax=1',
191               function(data) {
192                   var text = '<style type="text/css">';
193                   text += '#fc { z-index: 10; }';
194                   $(data).find('style').each(function(i,e){
195                       text += $(this).html();
196                   });
197                   text += '</style>';
198                   text += $(data).find('form').html();
199                   $('#filter_popup form').html(text);
200
201                   $('#filter_popup').udraggable({
202                       'handle': 'div#filter_title'
203                   }).css('top', '70px').css('left', '103px');
204
205                   $('#filter_popup form input,#filter_popup form select').not('input.button').change(function(e){
206                       $.post('list.php',
207                              'ajax=1&'+$('#filter_popup form').serialize(),
208                              function(data){
209                                  $('table.border tbody').html(UTF8.decode(data));
210                                  make_editable('table.smallfont tr span');
211                              });
212                       return false;
213                   });
214
215                   $('#filter_popup form input.button[type="submit"]').click(function(e){
216                       $.post('list.php',
217                              'ajax=1&'+$('#filter_popup form').serialize(),
218                              function(data){
219                                  $('table.border tbody').html(UTF8.decode(data));
220                                  $('#filter_popup').hide();
221                                  make_editable('table.smallfont tr span');
222                              });
223                       return false;
224                   });
225           });
226     }
227
228     if ($('#filter_popup:visible').length)
229         $('#filter_popup').hide();
230     else
231         $('#filter_popup').show();
232
233     return false;
234 }
235
236 </script></protect>
237 <div id="filter_popup" style="display:none;">
238 <div id="filter_title">Filter setzen</div>
239 <div style="padding:5px;">
240 <form id="filter_form"></form>
241 </div>
242 </div>
243 </page>
244
245 # Local variables:
246 # mode: text
247 # mode: auto-fill
248 # end: