parent::__construct('account_names', $id, 'blz_kto');
}
+ public function getAccounts($currency, $display=false)
+ {
+ if ($currency == "eur")
+ $table = "account";
+ else
+ $table = "account_dm";
+
+ $sql = sprintf("SELECT DISTINCT %s.blz_kto,name FROM %s JOIN account_names using(blz_kto)%s ORDER BY name",
+ $table, $table,
+ $display === false ? '' : ' WHERE display = '.$display);
+ return $this->db->fetchObjectList($sql);
+ }
+
+ public function name()
+ {
+ if (!$this->data)
+ return 'Unbekannt';
+
+ $both = explode (":", $this->data->blz_kto);
+ if (count($both) > 1)
+ return sprintf ("%s (BLZ %s, Konto %s)", $this->data->name, $both[0], $both[1]);
+ else
+ return sprintf ("%s (%s)", $this->data->name, $this->data->blz_kto);
+ }
+
}
?>
--- /dev/null
+<?php
+
+abstract class AccountTable extends DatabaseTable {
+ protected $valuecolumn;
+
+ public function __construct($table, $id)
+ {
+ parent::__construct($table, $id);
+ }
+
+ public function sum($blzkto)
+ {
+ $sql = sprintf("SELECT sum(%s) FROM %s WHERE blz_kto = %s",
+ $this->valuecolumn,
+ $this->table,
+ $this->db->quote($blzkto));
+ return $this->db->fetchValue($sql);
+ }
+
+ public function distinctYears($blzkto)
+ {
+ $sql = sprintf("SELECT DISTINCT substr(datum::text,0,5) AS year FROM %s ".
+ "WHERE blz_kto = %s ORDER BY year DESC",
+ $this->table, $this->db->quote($blzkto));
+ return $this->db->fetchObjectList($sql);
+ }
+
+ public function distinctCategories($blzkto)
+ {
+ $sql = sprintf("SELECT DISTINCT category FROM %s WHERE blz_kto = %s ORDER BY category",
+ $this->table, $this->db->quote($blzkto));
+ return $this->db->fetchObjectList($sql);
+ }
+
+ public function distinctFromTo($blzkto, $period=false)
+ {
+ $sql = sprintf("SELECT DISTINCT from_to FROM %s WHERE blz_kto = %s%s ORDER BY from_to",
+ $this->table, $this->db->quote($blzkto),
+ $period === false ? '' : ' AND ' . $period);
+ return $this->db->fetchObjectList($sql);
+ }
+
+ public function distinctStatements($blzkto)
+ {
+ $sql = sprintf("SELECT DISTINCT statement FROM %s WHERE blz_kto = %s ORDER BY statement DESC",
+ $this->table, $this->db->quote($blzkto));
+ return $this->db->fetchObjectList($sql);
+ }
+
+}
+
+?>