return $this->db->fetchObjectList($sql);
}
-}
+ public function filterTable(Array $data)
+ {
+ error_log('filter Table');
+ $out = '';
+
+ $where[] = sprintf("blz_kto = '%s'", $data['blzkto']);
+ if (strlen($data['year'])) {
+ $where[] = sprintf ("datum >= '%04d-01-01'", $data['year']);
+ $year++;
+ $where[] = sprintf ("datum < '%04d-01-01'", $data['year']+1);
+ }
+
+ if (strlen($data['deadline']) && strlen(trim($data['deadline']))) {
+ $date = Utils::assertIsoDate(trim($data['deadline']));
+ $where[] = sprintf ("datum < '%s'", $date);
+ }
+
+ if (strlen($data['statement']) && strlen(trim($data['statement']))) {
+ $where[] = sprintf("statement = '%s'", $data['statement']);
+ }
+
+ if (strlen($data['category']) && strlen(trim($data['category']))) {
+ if (Utils::isAJAX()) $data['category'] = utf8_decode($data['category']);
+ $where[] = sprintf("category = '%s'", $data['category']);
+ }
+
+ if (strlen($data['keyword']) && strlen(trim($data['keyword']))) {
+ if (Utils::isAJAX()) $data['keyword'] = utf8_decode($data['keyword']);
+ $where[] = sprintf("descr ~* '%s'", $data['keyword']);
+ }
+
+ if (strlen($data['from_to']) && strlen(trim($data['from_to']))) {
+ if (Utils::isAJAX()) $data['from_to'] = utf8_decode($data['from_to']);
+ $where[] = sprintf("from_to = '%s'", $data['from_to']);
+ }
+
+ if ($data['input'] && !$data['output']) {
+ $where[] = "{$this->valuecolumn} > 0.0";
+ } elseif ($data['output'] && !$data['input']) {
+ $where[] = "{$this->valuecolumn} < 0.0";
+ }
-?>
+ $sql = sprintf("SELECT datum,id,category,descr,%s FROM %s WHERE %s ORDER BY datum,id",
+ $this->valuecolumn,
+ $this->table,
+ implode (" AND ", $where));
+
+ $sum = 0.0;
+ $sum_in = 0.0;
+ $sum_out = 0.0;
+ $color = 0;
+ foreach ($this->db->fetchAssocList($sql) as $row) {
+ $descr = explode ("\n", $row['descr']);
+ $date = Utils::assertGermanDate($row['datum']);
+
+ $out .= sprintf ("<tr class=\"t%d\">", $color);
+ $out .= sprintf ("<td width=\"10%%\" align=\"right\">%s</td>", $date);
+ $out .= sprintf ("<td width=\"10%%\" align=\"center\">%s</td>", $row['category']);
+ if (strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/') === false)
+ $out .= sprintf ("<td width=\"70%%\"><a href=\"edit.php?id=%d%s\" target=\"_new\">%s</a></td>",
+ $row['id'], $add, $descr[0]);
+ else
+ $out .= sprintf ("<td width=\"70%%\"><span route=\"%s/EditDescr\" item_id=\"%d\" text=\"%s\">%s</span></td>",
+ get_class($this),
+ $row['id'], $add, $descr[0]);
+ $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"%s\">%5.2f</td>",
+ $row[$this->valuecolumn]>0?"in":"out", $row[$this->valuecolumn]);
+ $sum += $row[$this->valuecolumn];
+ if ($row[$this->valuecolumn] > 0) {
+ $sum_in += $row[$this->valuecolumn];
+ } else {
+ $sum_out += $row[$this->valuecolumn];
+ }
+ $out .= "</tr>";
+ $color = !$color;
+ }
+ if (strlen($data['statement'])) {
+ $out .= sprintf ("<tr class=\"t%d\">", $color);
+ $out .= "<td width=\"90%\" colspan=\"3\"><strong>Summe Einnahmen</strong></td>";
+ $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"in\">%5.2f</td>",$sum_in);
+ $out .= "</tr>";
+ $out .= sprintf ("<tr class=\"t%d\">", $color);
+ $out .= "<td width=\"90%\" colspan=\"3\"><strong>Summe Ausgaben</strong></td>";
+ $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"out\">%5.2f</td>", $sum_out*-1);
+ $out .= "</tr>";
+ }
+ $out .= sprintf ("<tr class=\"t%d\">", $color);
+ $out .= "<td width=\"90%\" colspan=\"3\" align=\"left\"><strong>Summe</strong></td>";
+ $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"%s\"><strong>%5.2f</strong></td>",
+ $sum>0?"in":"out", $sum);
+ $out .= "</tr>";
+
+ return $out;
+ }
+
+ public function ajaxFilter(Array $data)
+ {
+ return array('table' => utf8_encode($this->filterTable($data)));
+ }
+
+}
<?php
function filter_account()
{
- global $db;
- $out = '';
- $table = "account";
- $value = "value_eur";
- $add = '';
- if ((strlen($_POST['currency']) > 0) && ($_POST['currency'] == "dm")) {
- $table = "account_dm";
- $value = "value_dm";
- $add = "&cur=dm";
- }
-
- $where[] = sprintf("blz_kto = '%s'", $_POST['blzkto']);
- if (strlen($_POST['year'])) {
- $where[] = sprintf ("datum >= '%04d-01-01'", $_POST['year']);
- $year++;
- $where[] = sprintf ("datum < '%04d-01-01'", $_POST['year']+1);
- }
-
- if (strlen($_POST['deadline']) && strlen(trim($_POST['deadline']))) {
- $date = form_to_yyyymmdd ($_POST['deadline']);
- $where[] = sprintf ("datum < '%s'", $date);
- }
-
- if (strlen($_POST['statement']) && strlen(trim($_POST['statement']))) {
- $where[] = sprintf("statement = '%s'", $_POST['statement']);
- }
-
- if (strlen($_POST['category']) && strlen(trim($_POST['category']))) {
- if (!empty($_POST['ajax'])) $_POST['category'] = utf8_decode($_POST['category']);
- $where[] = sprintf("category = '%s'", $_POST['category']);
- }
-
- if (strlen($_POST['keyword']) && strlen(trim($_POST['keyword']))) {
- if (!empty($_POST['ajax'])) $_POST['keyword'] = utf8_decode($_POST['keyword']);
- $where[] = sprintf("descr ~* '%s'", $_POST['keyword']);
- }
-
- if (strlen($_POST['from_to']) && strlen(trim($_POST['from_to']))) {
- if (!empty($_POST['ajax'])) $_POST['from_to'] = utf8_decode($_POST['from_to']);
- $where[] = sprintf("from_to = '%s'", $_POST['from_to']);
- }
-
- if ($_POST['input'] && !$_POST['output']) {
- $where[] = "$value > 0.0";
- } elseif ($_POST['output'] && !$_POST['input']) {
- $where[] = "$value < 0.0";
- }
-
- $query = "SELECT datum,id,category,descr,$value FROM $table WHERE "
- . implode ($where, " AND ")
- . " ORDER BY datum,id";
-
- $sum = 0.0;
- $sum_in = 0.0;
- $sum_out = 0.0;
- $color = 0;
- foreach ($db->fetchAssocList($query) as $row) {
- $descr = explode ("\n", $row['descr']);
- $date = explode (" ", $row['datum']);
- $date = explode ("-", $date[0]);
- $date = sprintf ("%d.%d.%d", $date[2], $date[1], $date[0]);
-
- $out .= sprintf ("<tr class=\"t%d\">", $color);
- $out .= sprintf ("<td width=\"10%%\" align=\"right\">%s</td>", $date);
- $out .= sprintf ("<td width=\"10%%\" align=\"center\">%s</td>", $row['category']);
- if (strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/') === false)
- $out .= sprintf ("<td width=\"70%%\"><a href=\"edit.php?id=%d%s\" target=\"_new\">%s</a></td>",
- $row['id'], $add, $descr[0]);
- else
- $out .= sprintf ("<td width=\"70%%\"><span route=\"Accounting/EditDescr\" item_id=\"%d\" text=\"%s\">%s</span></td>",
- $row['id'], $add, $descr[0]);
- $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"%s\">%5.2f</td>",
- $row[$value]>0?"in":"out", $row[$value]);
- $sum += $row[$value];
- if ($row[$value] > 0) {
- $sum_in += $row[$value];
+ if ((strlen($_POST['currency']) > 0) && ($_POST['currency'] == "dm")) {
+ $account = new AccountingDM();
} else {
- $sum_out += $row[$value];
+ $account = new Accounting();
}
- $out .= "</tr>";
- $color = !$color;
- }
- if (strlen($_POST['statement'])) {
- $out .= sprintf ("<tr class=\"t%d\">", $color);
- $out .= "<td width=\"90%\" colspan=\"3\"><strong>Summe Einnahmen</strong></td>";
- $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"in\">%5.2f</td>",$sum_in);
- $out .= "</tr>";
- $out .= sprintf ("<tr class=\"t%d\">", $color);
- $out .= "<td width=\"90%\" colspan=\"3\"><strong>Summe Ausgaben</strong></td>";
- $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"out\">%5.2f</td>", $sum_out*-1);
- $out .= "</tr>";
- }
- $out .= sprintf ("<tr class=\"t%d\">", $color);
- $out .= "<td width=\"90%\" colspan=\"3\" align=\"left\"><strong>Summe</strong></td>";
- $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"%s\"><strong>%5.2f</strong></td>",
- $sum>0?"in":"out", $sum);
- $out .= "</tr>";
-
- return $out;
+
+ return $account->filterTable($_POST);
}
if (!empty($_POST['ajax']) && $_POST['ajax'] == 1) {
}).css('top', '70px').css('left', '103px');
$('#filter_popup form input,#filter_popup form select').not('input.button').change(function(e){
- $.post('list.php',
- 'ajax=1&'+$('#filter_popup form').serialize(),
+ $.invoke('Accounting/Filter',
+ $('#filter_popup form').serialize(),
function(data){
- $('table.border tbody').html(UTF8.decode(data));
+ $('table.border tbody').html(data.table);
make_editable('table.smallfont tr span');
});
return false;
});
$('#filter_popup form input.button[type="submit"]').click(function(e){
- $.post('list.php',
- 'ajax=1&'+$('#filter_popup form').serialize(),
+ $.invoke('Accounting/Filter',
+ $('#filter_popup form').serialize(),
function(data){
- $('table.border tbody').html(UTF8.decode(data));
+ $('table.border tbody').html(data.table);
$('#filter_popup').hide();
make_editable('table.smallfont tr span');
});