Source for file purchasebook.db.php
Documentation is available at purchasebook.db.php
* database functions for purchase 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: purchasebook.db.php 130 2007-08-17 14:24:44Z m2mtech $
* @link http://www.ea-geier.at/
* standard client db functions
require_once('code/clients.db.php');
require_once('code/numbers.inc.php');
require_once('code/date.inc.php');
* save purchase-book item
$opt['decimal'] = $db->conf['numNumberDecimal'];
$vars = array('txtID', 'txtName', 'txtVendor', 'numAmount', 'year', 'month', 'day');
foreach ($vars as $var) if (isset ($data[$var])) switch ($var) {
$what[$var] = makeDot($data[$var], $opt['decimal']);
default: $what[$var] = $data[$var];
$what['lastModified'] = $db->now();
$what['who'] = $db->user['mail'];
$table = $db->table('purchasebook');
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;
* load purchase-book item
* @param integer clientID
$table = $db->table('purchasebook');
if (!$data = $db->selectOne('*', $table, array('id' => $item))) return false;
* get number of purchase-book items
* @param integer clientID
* @return integer number of items
$table = $db->table('purchasebook');
$what = 'count(id) as c, sum(numAmount) as numAmount';
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->selectOne($what, $table, $where)) return false;
if (!$dummy['c']) return false;
$data['count'] = $dummy['c'];
$data['numAmount'] = $dummy['numAmount'];
* load multiple purchase-book item
* @param integer clientID
* @param integer number of items
* @param integer number page
* @param string sorting string
$table = $db->table('purchasebook');
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))
* prepare the sql data for output
* @param array configuration data
* @param array purchase-book item
static $separator = false;
if (!$decimal) $decimal = $conf['numNumberDecimal'];
if (!$separator) switch ($conf['txtNumberSeperator']) {
if (!$date) $date = $conf['txtDateFormat'];
$numVars[] = 'numAmount';
foreach ($numVars as $var)
$data[$var] = makeNum($data[$var], $separator, $decimal);
* @param integer clientID
* @return array templates
$table = $db->table('purchasebook');
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'];
|