Source for file purchasebook.inc.php
Documentation is available at purchasebook.inc.php
* php 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.inc.php 130 2007-08-17 14:24:44Z m2mtech $
* @link http://www.ea-geier.at/
* html functions for purchase book
require_once('code/purchasebook.html.php');
* database functions for purchase book
require_once('code/purchasebook.db.php');
require_once('code/numbers.inc.php');
require_once('code/date.inc.php');
* generate data for html output of purchase book
* @param eaInput input data
if (!isset ($in->options)) $in->options = array();
if (!$clientID = $in->getClient($db)) return false; // wrong client
$opt['purchasebook'] = true; // we are in the purchase-book section
$opt['purchasebookurl'] = 'purchasebook';
$opt['decimal'] = $conf['numNumberDecimal'];
switch ($conf['txtNumberSeperator']) {
$sort = $in->getSort(array('id', 'txtID', 'txtName', 'numAmount', 'month'), 'purchasebook');
if (strpos($sort, 'month') !== false) {
if (strpos($sort, 'asc')) $sort = 'year asc, month asc, day asc';
else $sort = 'year desc, month desc, day desc';
if (!$opt['page'] = $in->getPage('purchasebook')) $opt['page'] = 1;
$opt['lines'] = $conf['numLinesPerPage'];
// if javascript is disabled get filter variables from post
if (isset ($_POST) && !empty($_POST)) {
$vars = array('p:txt:txt');
$month = $in->getGet('date', 'txt');
if (!$month) $month = $in->post('txtMonth');
if (!$month && isset ($_SESSION['filter'][$clientID]['purchasebookmonth']))
$month = $_SESSION['filter'][$clientID]['purchasebookmonth'];
if (preg_match('/(\d{4})-(\d{2})/', $month, $match)) {
$where['year'] = $match[1];
$where['month'] = $match[2];
$_SESSION['filter'][$clientID]['purchasebookmonth'] = $month;
$in->post['txtMonth'] = $month;
} else unset ($_SESSION['filter'][$clientID]['purchasebookmonth']);
$name = $in->getGet('find', 'txt');
if (!$name) $name = $in->post('txtWhat');
if (isset ($in->error['txtWhat']) && ($in->error['txtWhat'] == 'empty')) {
unset ($in->error['txtWhat']);
if (!$name && isset ($_SESSION['filter'][$clientID]['purchasebookname']))
$name = $_SESSION['filter'][$clientID]['purchasebookname'];
if ($name && ($name != '=')) {
$where['txtName'] = $name;
$_SESSION['filter'][$clientID]['purchasebookname'] = $name;
$in->post['txtWhat'] = $name;
} elseif (isset ($_SESSION['filter'][$clientID]['purchasebookname']))
unset ($_SESSION['filter'][$clientID]['purchasebookname']);
} else $opt['countitems'] = $opt['itemstotal']['count'];
$opt['pages'] = ceil($opt['countitems'] / $opt['lines']);
if ($opt['page'] > $opt['pages']) $opt['page'] = 1;
* generate data for print output of purchase book
* @param eaInput input data
if (!isset ($in->options)) $in->options = array();
if (!$clientID = $in->getClient($db)) return false; // wrong client
$sort = $in->getSort(array('id', 'txtID', 'txtName', 'numAmount', 'month'), 'purchasebook');
if (strpos($sort, 'month') !== false) {
if (strpos($sort, 'asc')) $sort = 'year asc, month asc, day asc';
else $sort = 'year desc, month desc, day desc';
if (isset ($_SESSION['filter'][$clientID]['purchasebookmonth'])) {
$month = $_SESSION['filter'][$clientID]['purchasebookmonth'];
if (isset ($_SESSION['filter'][$clientID]['purchasebookname'])) {
$name = $_SESSION['filter'][$clientID]['purchasebookname'];
if ($name && ($name != '=')) {
$where['txtName'] = $name;
if (isset ($where['month'])) $opt['months'] = array($month => true);
$opt['countitems']['total'] = 0;
$vars = array('numAmount');
foreach ($vars as $var) $opt['itemstotal']['total'][$var] = 0;
foreach ($opt['months'] as $month => $monthNotUsed) {
$opt['where'][$month] = $where;
$opt['countitems'][$month] = $opt['itemstotal'][$month]['count'];
$opt['countitems']['total'] += $opt['countitems'][$month];
$opt['itemstotal']['total'][$var] +=
makeDot($opt['itemstotal'][$month][$var]);
* generate data for html output of purchase book item
* @param eaInput input data
if (!isset ($in->options)) $in->options = array();
if (!$clientID = $in->getClient($db)) return false; // wrong client
$opt['purchasebook'] = true; // we are in the purchase-book section
$opt['purchasebookurl'] = 'purchasebook';
$opt['dateformat'] = $conf['txtDateFormat'];;
$opt['decimal'] = $conf['numNumberDecimal'];
switch ($conf['txtNumberSeperator']) {
if (($itemID = $in->getGet('item'))
$post['numID'] = $post['id'];
* save purchase book item
* @param eaInput input data
if (!isset ($_POST['buttonSavePurchaseBookItem'])) return false;
$in->post['buttonSavePurchaseBookItem'] = true;
$clientID = $in->options['client'];
if (!$db->isOwner($clientID)) return false; // wrong client
$vars = array('p:txt:txt', 'p:num:num');
$error['txtDate'] = 'wrongformat';
// check/prepare number format
$vars = array('numAmount');
foreach ($vars as $var) if (isset ($post[$var]))
$post[$var] = makeNum($post[$var], $opt['seperator'], $opt['decimal']);
if ($error) return false; // wrong input
|