Source for file travel.inc.php
Documentation is available at travel.inc.php
* php functions for travel expenses
* 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: travel.inc.php 138 2007-08-29 12:13:55Z m2mtech $
* @link http://www.ea-geier.at/
* html functions for travel expenses
require_once('code/travel.html.php');
* database functions for travel expenses
require_once('code/travel.db.php');
require_once('code/numbers.inc.php');
require_once('code/date.inc.php');
* generate data for html output of travel expenses
* @param eaInput input data
if (!isset ($in->options)) $in->options = array();
if (!$clientID = $in->getClient($db)) return false; // wrong client
$opt['travel'] = true; // we are in the travel section
$opt['travelurl'] = 'travel';
$opt['decimal'] = $conf['numNumberDecimal'];
switch ($conf['txtNumberSeperator']) {
$sort = $in->getSort(array('id', 'txtName', 'numAmount', 'numTax', 'numDistAmount', 'month'), 'travel');
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('travel')) $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]['travelmonth']))
$month = $_SESSION['filter'][$clientID]['travelmonth'];
$_SESSION['filter'][$clientID]['travelmonth'] = $month;
$in->post['txtMonth'] = $month;
} else unset ($_SESSION['filter'][$clientID]['travelmonth']);
$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]['travelname']))
$name = $_SESSION['filter'][$clientID]['travelname'];
if ($name && ($name != '=')) {
$where['txtName'] = $name;
$_SESSION['filter'][$clientID]['travelname'] = $name;
$in->post['txtWhat'] = $name;
} elseif (isset ($_SESSION['filter'][$clientID]['travelname']))
unset ($_SESSION['filter'][$clientID]['travelname']);
} else $opt['countitems'] = $opt['itemstotal']['count'];
$opt['pages'] = ceil($opt['countitems'] / $opt['lines']);
if ($opt['page'] > $opt['pages']) $opt['page'] = 1;
if (!$opt['items'] = dbLoadTravelItems($db, $clientID, $opt['lines'], $opt['page'], $sort, $where))
* generate data for print output of travel expesnses
* @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', 'txtName', 'numAmount', 'numTax', 'numDistAmount', 'month'), 'travel');
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]['travelmonth'])) {
$month = $_SESSION['filter'][$clientID]['travelmonth'];
if (isset ($_SESSION['filter'][$clientID]['travelname'])) {
$name = $_SESSION['filter'][$clientID]['travelname'];
if ($name && ($name != '=')) {
$where['txtName'] = $name;
if (isset ($where['month'])) $opt['months'] = array($month => true);
$opt['countitems']['total'] = 0;
$vars = array('numAmount', 'numTax', 'numDistAmount');
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]);
if (!$opt['items'][$month] = dbLoadTravelItems($db, $clientID, - 1, - 1, $sort, $where))
* generate data for html output of travel item
* @param eaInput input data
if (!isset ($in->options)) $in->options = array();
if (!$clientID = $in->getClient($db)) return false; // wrong client
$opt['travel'] = true; // we are in the travel section
$opt['travelurl'] = 'travel';
$opt['dateformat'] = $conf['txtDateFormat'];;
$opt['decimal'] = $conf['numNumberDecimal'];
switch ($conf['txtNumberSeperator']) {
$split = explode(',', $conf['txtVatCategories']);
foreach ($split as $item) {
$opt['vatcategories'][$item] = $item . ' %';
// standard vat rate for travelling expenses for Austria
if (!isset ($_POST['txtTax'])) $in->post['txtTax'] = 10;
if (!isset ($_POST['numDistRate']))
$in->post['numDistRate'] = makeNum($conf['numDistRate'], $opt['seperator'], false);
if (($itemID = $in->getGet('item'))
$post['numID'] = $post['id'];
* @param eaInput input data
if (!isset ($_POST['buttonSaveTravelItem'])) return false;
$in->post['buttonSaveTravelItem'] = true;
$clientID = $in->options['client'];
if (!$db->isOwner($clientID)) return false; // wrong client
$vars = array('p:txt:txt', 'p:num:num');
$vars = array('txtTax', 'numDay', 'numNight', 'numTax', 'numAmount', 'numDistance', 'numDistRate', 'numDistAmount');
foreach ($vars as $var) {
if ($in->post($var) !== false) switch($var) { // valid values
if ($in->_check->num($dummy)) $p = $dummy / 100; // valid rate
else $p = - 1; // user defined rate
case 'numDay': case 'numNight':
$sum += makeDot($post[$var], $opt['decimal']);
$dummy = makeDot($post[$var], $opt['decimal']);
&& (log10(abs($sum * $p / (1 + $p) - $dummy)) >= - $opt['decimal']))
$error[$var] = 'wrongvalue';
$dummy = makeDot($post[$var], $opt['decimal']);
if (log10(abs($net - $dummy)) >= - $opt['decimal'])
$error[$var] = 'wrongvalue';
case 'numDistance': case 'numDistRate':
$dummy = makeDot($post[$var], $opt['decimal']);
if (log10(abs($milleage - $dummy)) >= - $opt['decimal'])
$error[$var] = 'wrongvalue';
} else switch($var) { // invalid entries
case 'numDay': case 'numNight':
if ($error[$var] == 'empty') { // if (empty) -> 0
case 'numDistance': case 'numDistRate':
if ($error[$var] == 'empty') { // if (empty) -> 0
if (($error[$var] == 'empty') && ($p != - 1)) { // if (empty) -> calc
$post[$var] = $sum * $p / (1 + $p);
$net = $sum - $post[$var];
if ($error[$var] == 'empty') { // if (empty) -> calc
if ($error[$var] == 'empty') { // if (empty) -> calc
foreach ($vars as $var) if ($in->post($var) !== false) switch ($var) {
case 'numDistance': case 'numDistRate':
$post[$var] = makeNumOnly($post[$var], $opt['seperator']);
$post[$var] = makeNum($post[$var], $opt['seperator'], $opt['decimal']);
$error['txtDate'] = 'wrongformat';
$vars = array('txtVouchers');
foreach ($vars as $var) if (isset ($error[$var]) && $error[$var] == 'empty')
$vars = array('txtTax' => 'vatcategories');
foreach ($vars as $key => $val)
if (!isset ($opt[$val][$post[$key]])) $error[$key] = 'wrongselection';
if ($error) return false; // wrong input
|