Source for file cashbook.db.php
Documentation is available at cashbook.db.php
* database functions for cash book
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* @author m2mtech <tech@m2m.at>
* @copyright 2007 m2m server software gmbh
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
* @version $Id: cashbook.db.php 139 2007-08-29 20:49:58Z m2mtech $
* @link http://www.ea-geier.at/
* standard client db functions
require_once('code/clients.db.php');
require_once('code/numbers.inc.php');
$opt['decimal'] = $db->conf['numNumberDecimal'];
$vars = array('txtID', 'txtName', 'abcInOut', 'txtCashBank', 'numAmount', 'txtDistributor', 'numAmountDist', 'txtTax', 'numAmountTax', 'year', 'month', 'day');
foreach ($vars as $var) if (isset ($data[$var])) switch ($var) {
case 'numAmount': case 'numAmountDist': case 'numAmountTax':
$what[$var] = makeDot($data[$var], $opt['decimal']);
default: $what[$var] = $data[$var];
if (isset ($data['numSaveTemplate'])) $what['template'] = 1;
else $what['template'] = 0;
$what['lastModified'] = $db->now();
$what['who'] = $db->user['mail'];
$table = $db->table('cashbook');
if (isset ($data['numID'])) { // old item
if (!$db->update($what, $table, array('id' => $id))) return false;
if (!$db->insert($what, $table)) return false;
if (!$id = $db->lastID()) return false;
return $data['numID'] = $id;
* @param integer clientID
$table = $db->table('cashbook');
if (!$data = $db->selectOne('*', $table, array('id' => $item))) return false;
* get number of cashbook items
* @param integer clientID
* @return integer number of items
$table = $db->table('cashbook');
$what = 'count(id) as c, sum(numAmount) as numAmount, sum(numAmountDist) as numAmountDist, sum(numAmountTax) as numAmountTax, abcInOut';
if (!$where) $where = '';
if (isset ($where['txtName'])) { // we have to prepare it ourselves
$where = "txtName like '%" . $db->escape($where['txtName'], true) . "%'";
unset ($filters['txtName']);
if ($filters) { // other filters available
foreach ($filters as $key => $value)
$where .= ' and ' . $db->escapeKey($key) . ' = ' . $db->escape($value);
if (!$dummy = $db->select($what, $table, $where, '', - 1, - 1, 'abcInOut'))
$vars = array('numAmount', 'numAmountDist', 'numAmountTax');
foreach ($vars as $var) $data[$var] = 0;
foreach ($dummy as $item) {
switch ($item['abcInOut']) {
foreach ($vars as $var) $data[$var] += $item[$var];
foreach ($vars as $var) $data[$var] -= $item[$var];
$data['count'] += $item['c'];
$data[$item['abcInOut']] = $item;
* load multiple cash book item
* @param integer clientID
* @param integer number of items
* @param integer number page
* @param string sorting string
function dbLoadCashBookItems(&$db, $client, $num = 10, $page = 1, $sort = false, $where = false) {
$table = $db->table('cashbook');
if (!$where) $where = '';
if (isset ($where['txtName'])) { // we have to prepare it ourselves
$where = "txtName like '%" . $db->escape($where['txtName'], true) . "%'";
unset ($filters['txtName']);
if ($filters) { // other filters available
foreach ($filters as $key => $value)
$where .= ' and ' . $db->escapeKey($key) . ' = ' . $db->escape($value);
if (!$sort) $sort = 'id asc';
if ($page == - 1) $offset = - 1;
else $offset = $num * ($page - 1);
if (!$data = $db->select('*', $table, $where, $sort, $num, $offset))
* @param integer clientID
* @return array templates
$table = $db->table('cashbook');
if (!$dummy = $db->select('id, txtName', $table, array('template' => 1))) return false;
$templates[$val['id']] = $val['txtName'];
* @param integer clientID
* @return array templates
$table = $db->table('cashbook');
if (!$dummy = $db->select('distinct month, year', $table, '', 'year desc, month desc'))
foreach ($dummy as $val) {
$comb = $val['year'] . '-' . $val['month'];
switch ($db->conf['txtDateFormat']) {
$months[$comb] = $val['month'] . '.' . $val['year'];
* prepare the sql data for output
* @param array configuration data
* @param array cashbook item
static $separator = false;
if (!$decimal) $decimal = $conf['numNumberDecimal'];
if (!$separator) switch ($conf['txtNumberSeperator']) {
if (!$date) $date = $conf['txtDateFormat'];
$vars = array('numAmount', 'numAmountDist', 'numAmountTax');
$data[$var] = makeNum($data[$var], $separator, $decimal);
if ($numOnly) return true;
|