Source for file assets.inc.php
Documentation is available at assets.inc.php
* php functions for assets 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: assets.inc.php 130 2007-08-17 14:24:44Z m2mtech $
* @link http://www.ea-geier.at/
* html functions for assets book
require_once('code/assets.html.php');
* database functions for assets book
require_once('code/assets.db.php');
require_once('code/numbers.inc.php');
require_once('code/date.inc.php');
* generate data for html output of assets book
* @param eaInput input data
if (!isset ($in->options)) $in->options = array();
if (!$clientID = $in->getClient($db)) return false; // wrong client
$opt['assets'] = true; // we are in the assets book section
$opt['assetsurl'] = 'assets';
$opt['decimal'] = $conf['numNumberDecimal'];
switch ($conf['txtNumberSeperator']) {
$sort = $in->getSort(array('id', 'txtName', 'purchaseDate', 'numAmount'), 'assets');
if (!$opt['page'] = $in->getPage('assets')) $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');
$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]['assetsname']))
$name = $_SESSION['filter'][$clientID]['assetsname'];
if ($name && ($name != '=')) {
$where['txtName'] = $name;
$_SESSION['filter'][$clientID]['assetsname'] = $name;
$in->post['txtWhat'] = $name;
} elseif (isset ($_SESSION['filter'][$clientID]['assetsname']))
unset ($_SESSION['filter'][$clientID]['assetsname']);
// get year to show values for for depreciation and value
$year = $in->getGet('depreciation', 'num'); // from depr select
if (!$year) $year = $in->getGet('value', 'num'); // from value select
if (!$year) $year = $in->post('numDepreciation'); // from depr post
if (!$year) $year = $in->post('numValue'); // from value post
if ($year) $_SESSION['show'][$clientID]['assetsyear'] = $year; // store in session
if (!$year && isset ($_SESSION['show'][$clientID]['assetsyear']))
$year = $_SESSION['show'][$clientID]['assetsyear']; // from session
if (!$year) $year = date('Y'); // this year
// generate options for heading
if (!isset ($opt['year'][$year])) $year = key($opt['year']);
} else $opt['countitems'] = $opt['itemstotal']['count'];
$opt['pages'] = ceil($opt['countitems'] / $opt['lines']);
if ($opt['page'] > $opt['pages']) $opt['page'] = 1;
if (!$opt['items'] = dbLoadAssetsItems($db, $clientID, $opt['lines'], $opt['page'], $sort, $where))
$in->post['numDepreciation'] = $year;
$in->post['numValue'] = $year;
foreach ($opt['items'] as $key => $item) {
$firstYear = reset($item['lines']);
$lastYear = end($item['lines']);
$nullValue = makeNum(0, $opt['seperator'], $opt['decimal']);
if ($firstYear > $year) {
$opt['items'][$key]['numDepreciation'] = $nullValue;
$opt['items'][$key]['numValue'] = $nullValue;
$opt['items'][$key]['numDepreciation'] = $nullValue;
$opt['items'][$key]['numValue'] = $item['numValue' . key($item['lines'])];
$opt['items'][$key]['numDepreciation'] = $item['numDepreciation' . $years[$year]];
$opt['items'][$key]['numValue'] = $item['numValue' . $years[$year]];
if (!isset ($in->options)) $in->options = array();
if (!$clientID = $in->getClient($db)) return false; // wrong client
$opt['decimal'] = $conf['numNumberDecimal'];
switch ($conf['txtNumberSeperator']) {
$sort = $in->getSort(array('id', 'txtName', 'purchaseDate', 'numAmount'), 'assets');
if (isset ($_SESSION['filter'][$clientID]['assetsname'])) {
$name = $_SESSION['filter'][$clientID]['assetsname'];
if ($name && ($name != '=')) {
$where['txtName'] = $name;
// get year to show values for for depreciation and value
$year = date('Y'); // this year
if (isset ($_SESSION['show'][$clientID]['assetsyear']))
$year = $_SESSION['show'][$clientID]['assetsyear']; // from session
$in->post['numDepreciation'] = $year;
$in->post['numValue'] = $year;
} else $opt['countitems'] = $opt['itemstotal']['count'];
foreach ($opt['items'] as $key => $item) {
$firstYear = reset($item['lines']);
$lastYear = end($item['lines']);
$nullValue = makeNum(0, $opt['seperator'], $opt['decimal']);
if ($firstYear > $year) {
$opt['items'][$key]['numDepreciation'] = $nullValue;
$opt['items'][$key]['numValue'] = $nullValue;
$opt['items'][$key]['numDepreciation'] = $nullValue;
$opt['items'][$key]['numValue'] = $item['numValue' . key($item['lines'])];
$opt['items'][$key]['numDepreciation'] = $item['numDepreciation' . $years[$year]];
$opt['items'][$key]['numValue'] = $item['numValue' . $years[$year]];
* generate data for html output of assets book item
* @param eaInput input data
if (!isset ($in->options)) $in->options = array();
if (!$clientID = $in->getClient($db)) return false; // wrong client
$opt['assets'] = true; // we are in the assets book section
$opt['assetsurl'] = 'assetsitem';
$opt['dateformat'] = $conf['txtDateFormat'];;
$opt['decimal'] = $conf['numNumberDecimal'];
switch ($conf['txtNumberSeperator']) {
if (!isset ($post['numValue1'])) $post['numValue1'] = '';
$post['lines'] = array(1 => date('Y'));
if (($itemID = $in->getGet('item'))
$post['numID'] = $post['id'];
// prepare options derived from data
* @param eaInput input data
if (!isset ($_POST['buttonSaveAssetsItem'])) return false;
$in->post['buttonSaveAssetsItem'] = true;
$clientID = $in->options['client'];
if (!$db->isOwner($clientID)) return false; // wrong client
$vars = array('p:txt:txt', 'p:num:num');
// calculate values if there are base values
$error['txtDate'] = 'wrongformat';
// check depriciation entries
$amount = abs(makeDot($post['numAmount'], $opt['decimal']));
if (!$amount) $calc = false;
$numVars = array('numAmount');
$lifetime = abs($post['numLifeTime']) % 100;
$method = $in->post('txtDeprMethod');
case 'lin1': case 'lin6': break;
$depr = makeDot($amount / $lifetime);
for ($i = 1; $i <= $lifetime + 1; $i++ ) {
$thisDepr = $depr; // default
if ($i == 1) { // first year might be different
if ($month > 6) $thisDepr = makeDot($amount / $lifetime / 2);
$thisDepr = makeDot((13 - $post['month']) * $amount / $lifetime / 12);
if ($thisDepr + 1 < $amount) $amount -= $thisDepr;
case 'lin6': case 'lin1':
if ($i > $lifetime) break 2;
} else { if ($i > $lifetime) break; }
$numVars[] = 'numDepreciation' . $i;
$numVars[] = 'numValue' . $i;
$post['lines'][$i] = $year++ ;
for ($i = 1; $i <= $lifetime + 1; $i++ ) {
if (!isset ($post['numDepreciation' . $i])) break;
if (!isset ($post['numValue' . $i])) break;
$amount = makeDot($post['numValue' . $i]);
foreach ($numVars as $var) if (isset ($post[$var]))
$post[$var] = makeNum($post[$var], $opt['seperator'], $opt['decimal']);
if ($error) return false; // wrong input
* check & store post variables
* @param eaInput input data
* @param string variable name
* @param mixed variable value
if (!isset ($post[$var])) { // !var -> set
$post[$var] = makeNum($val, $opt['seperator'], $opt['decimal']);
if (isset ($error[$var]) && ($error[$var] == 'empty')) { // empty var -> set
$post[$var] = makeNum($val, $opt['seperator'], $opt['decimal']);
if (isset ($error[$var])) // other error -> do nothing
if (log10(abs(makeDot($post[$var], $opt['decimal']) - $val)) >= - $opt['decimal'] - 0.1) {
$error[$var] = 'wrongvalue';
|