Source for file balance.inc.php
Documentation is available at balance.inc.php
* php functions for accounting balance
* 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: balance.inc.php 143 2007-09-03 22:30:04Z m2mtech $
* @link http://www.ea-geier.at/
* html functions for accounting balance
require_once('code/balance.html.php');
* database functions for accounting balance
require_once('code/balance.db.php');
require_once('code/numbers.inc.php');
* generate data for html output of accounting balance
* @param eaInput input data
if (!isset ($in->options)) $in->options = array();
if (!$clientID = $in->getClient($db)) return false; // wrong client
$opt['balance'] = true; // we are in the balance section
$opt['balanceurl'] = 'balance';
$opt['decimal'] = $conf['numNumberDecimal'];
switch ($conf['txtNumberSeperator']) {
if (!$year = $in->getGet('year')) {
if (isset ($_POST['numYear']) && !empty($_POST['numYear'])) {
$vars = array('p:num:numYear');
$year = $in->post('numYear');
if (!$year) $year = date('Y');
$in->post['lines']['in'] = array('1' => true);
$in->post['lines']['out'] = array('1' => true);
$in->post['sum']['in'] = 0;
$in->post['sum']['out'] = 0;
$opt['categories']['total']['out'] += $opt['travels']['total'];
$opt['categories']['total']['out'] += $opt['depreciation']['total'];
if (!isset ($_POST['numYear'])
$post['numID'] = $post['id'];
// prepare options derived from data
$in->post['numYear'] = $year;
$opt['total']['in'] = makeNum($opt['categories']['total']['in'] + $in->post['sum']['in'], $opt['seperator'], $opt['decimal']);
$opt['total']['out'] = makeNum($opt['categories']['total']['out'] + $in->post['sum']['out'], $opt['seperator'], $opt['decimal']);
$opt['total']['inout'] = makeNum($opt['categories']['total']['in'] + $in->post['sum']['in'] - $opt['categories']['total']['out'] + $in->post['sum']['out'], $opt['seperator'], $opt['decimal']);
* @param eaInput input data
if (!isset ($_POST['buttonSaveBalance'])) return false;
$in->post['buttonSaveBalance'] = true;
$clientID = $in->options['client'];
if (!$db->isOwner($clientID)) return false; // wrong client
$vars = array('p:txt:txt', 'p:num:num');
$dirs = array('in' => 'In', 'out' => 'Out');
foreach ($dirs as $dir => $dirVar) {
$post['lines'][$dir] = array();
for ($i = 1; $i < 100; $i++ ) { // artificial limit to 100 entries
$txtLine = 'txt' . $dirVar . $line;
$numLine = 'num' . $dirVar . $line;
$txtCurrent = 'txt' . $dirVar . $i;
$numCurrent = 'num' . $dirVar . $i;
if (!isset ($post[$txtCurrent])) break; // no text variable left
if (!isset ($post[$numCurrent])) break; // no number variable left
if (!isset ($error[$txtCurrent])) $empty = false;
elseif ($error[$txtCurrent] != 'empty') $empty = false;
if (isset ($error[$numCurrent]) && ($error[$numCurrent] != 'empty'))
$num = makeDot($post[$numCurrent], $opt['decimal']) * 1;
if ($num != 0) $empty = false;
unset ($post[$txtCurrent]);
unset ($post[$numCurrent]);
if (isset ($error[$txtCurrent])) unset ($error[$txtCurrent]);
if (isset ($error[$numCurrent])) unset ($error[$numCurrent]);
$post['lines'][$dir][$line] = true;
if ($line == $i) { $line++ ; continue; }
$post[$txtLine] = $post[$txtCurrent];
unset ($post[$txtCurrent]);
$post[$numLine] = $post[$numCurrent];
unset ($post[$numCurrent]);
if (isset ($error[$txtCurrent])) {
$error[$txtLine] = $error[$txtCurrent];
unset ($error[$txtCurrent]);
if (isset ($error[$numCurrent])) {
$error[$numLine] = $error[$numCurrent];
unset ($error[$numCurrent]);
foreach ($numVars as $var) if (isset ($post[$var]))
$post[$var] = makeNum($post[$var], $opt['seperator'], $opt['decimal']);
// prepare options changed by saved data:
$opt['total']['in'] = makeNum($sum['in'] + $opt['categories']['total']['in'], $opt['seperator'], $opt['decimal']);
$opt['total']['out'] = makeNum($sum['out'] + $opt['categories']['total']['out'], $opt['seperator'], $opt['decimal']);
$opt['total']['inout'] = makeNum($sum['in'] + $opt['categories']['total']['in'] - $sum['out'] - $opt['categories']['total']['out'], $opt['seperator'], $opt['decimal']);
$post['lines']['in'][count($post['lines']['in']) + 1] = true;
$post['lines']['out'][count($post['lines']['out']) + 1] = true;
if ($error) return false; // wrong input
|