ea-Geiercode
[ class tree: ea-Geier ] [ index: ea-Geier ] [ all elements ]

Source for file travel.inc.php

Documentation is available at travel.inc.php

  1. <?php 
  2. /**
  3.  * php functions for travel expenses
  4.  *
  5.  * LICENSE:
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
  13.  * GNU General Public License for more details.
  14.  * You should have received a copy of the GNU General Public License along
  15.  * with this program; if not, write to the Free Software Foundation, Inc.,
  16.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17.  *
  18.  * @package       ea-Geier
  19.  * @subpackage code
  20.  * @author       m2mtech <tech@m2m.at>
  21.  * @copyright  2007 m2m server software gmbh
  22.  * @license       http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
  23.  * @version       $Id: travel.inc.php 138 2007-08-29 12:13:55Z m2mtech $
  24.  * @link       http://www.ea-geier.at/
  25.  */
  26.  
  27. /**
  28.  * html functions for travel expenses
  29.  */
  30. require_once('code/travel.html.php');
  31.  
  32. /**
  33.  * database functions for travel expenses
  34.  */
  35. require_once('code/travel.db.php');
  36.  
  37. /**
  38.  * number functions
  39.  */
  40. require_once('code/numbers.inc.php');
  41.  
  42. /**
  43.  * date functions
  44.  */
  45. require_once('code/date.inc.php');
  46.  
  47. /**
  48.  * generate data for html output of travel expenses
  49.  *
  50.  * @param    eaDB    database
  51.  * @param    eaInput input data
  52.  */
  53. function genOptTravel(&$db&$in{
  54.     $conf =$db->conf;
  55.     $user =$db->user;
  56.  
  57.     if (!isset($in->options)) $in->options array();
  58.     $opt =$in->options;
  59.  
  60.     if (!$clientID $in->getClient($db)) return false// wrong client
  61.     
  62.     $opt['travel'true// we are in the travel section
  63.     $opt['travelurl''travel';
  64.  
  65.     // prepare number format
  66.     $opt['decimal'$conf['numNumberDecimal'];
  67.     switch ($conf['txtNumberSeperator']{
  68.         case 'komma':
  69.             $opt['seperator'',';
  70.             break;
  71.         case 'dot'default:
  72.             $opt['seperator''.';
  73.             break;
  74.     }
  75.     
  76.     // sorting
  77.     $sort $in->getSort(array('id''txtName''numAmount''numTax''numDistAmount''month')'travel');
  78.  
  79.     if (strpos($sort'month'!== false{
  80.         if (strpos($sort'asc')) $sort 'year asc, month asc, day asc';
  81.         else $sort 'year desc, month desc, day desc';
  82.     }
  83.  
  84.     // pagenumber
  85.     if (!$opt['page'$in->getPage('travel')) $opt['page'1;
  86.     
  87.     // lines per page
  88.     $opt['lines'$conf['numLinesPerPage'];
  89.  
  90.     // if javascript is disabled get filter variables from post
  91.     if (isset($_POST&& !empty($_POST)) {
  92.         $vars array('p:txt:txt')
  93.         $in->check($vars);
  94.     }            
  95.  
  96.     $where array();
  97.     // filter months
  98.     $month $in->getGet('date''txt');
  99.     if (!$month$month $in->post('txtMonth');
  100.     if (!$month && isset($_SESSION['filter'][$clientID]['travelmonth'])) 
  101.         $month $_SESSION['filter'][$clientID]['travelmonth'];
  102.     if ($month{
  103.         $match false;
  104.         if ($dummy splitMonthYear($month)) {
  105.             $where += $dummy;
  106.             $_SESSION['filter'][$clientID]['travelmonth'$month;
  107.             $in->post['txtMonth'$month;
  108.         else unset($_SESSION['filter'][$clientID]['travelmonth']);
  109.     }
  110.  
  111.     // filter name
  112.         $name $in->getGet('find''txt');
  113.     if (!$name$name $in->post('txtWhat');
  114.     if (isset($in->error['txtWhat']&& ($in->error['txtWhat'== 'empty')) {
  115.         $name '=';
  116.         unset ($in->error['txtWhat']);
  117.     }
  118.     if (!$name && isset($_SESSION['filter'][$clientID]['travelname'])) 
  119.         $name $_SESSION['filter'][$clientID]['travelname'];
  120.     if ($name && ($name != '=')) {
  121.         if (strpos($name'='!== false$name trim(substr($name1));
  122.         $where['txtName'$name;
  123.         $_SESSION['filter'][$clientID]['travelname'$name;
  124.         $in->post['txtWhat'$name;
  125.     elseif (isset($_SESSION['filter'][$clientID]['travelname']))
  126.         unset($_SESSION['filter'][$clientID]['travelname']);
  127.  
  128.     $opt['months'dbGetTravelMonths($db$clientID);
  129.  
  130.     // load items
  131.     if (!$opt['itemstotal'dbCountTravelItems($db$clientID$where)) {
  132.         if ($where{
  133.             $opt['countitems'0;
  134.             return true;
  135.         }
  136.         return false;
  137.     else $opt['countitems'$opt['itemstotal']['count'];
  138.  
  139.     $opt['pages'ceil($opt['countitems'$opt['lines']);
  140.     
  141.     if ($opt['page'$opt['pages']$opt['page'1;
  142.  
  143.     if (!$opt['items'dbLoadTravelItems($db$clientID$opt['lines']$opt['page']$sort$where))
  144.         return false;
  145.     
  146.     return true;    
  147. }
  148.  
  149. /**
  150.  * generate data for print output of travel expesnses
  151.  *
  152.  * @param    eaDB    database
  153.  * @param    eaInput input data
  154.  */
  155. function genOptTravelPrint(&$db&$in{
  156.     $conf =$db->conf;
  157.     $user =$db->user;
  158.  
  159.     if (!isset($in->options)) $in->options array();
  160.     $opt =$in->options;
  161.  
  162.     if (!$clientID $in->getClient($db)) return false// wrong client
  163.     
  164.     // sorting
  165.     $sort $in->getSort(array('id''txtName''numAmount''numTax''numDistAmount''month')'travel');
  166.  
  167.     if (strpos($sort'month'!== false{
  168.         if (strpos($sort'asc')) $sort 'year asc, month asc, day asc';
  169.         else $sort 'year desc, month desc, day desc';
  170.     }
  171.  
  172.     $where array();
  173.     // filter months
  174.     if (isset($_SESSION['filter'][$clientID]['travelmonth'])) {
  175.         $month $_SESSION['filter'][$clientID]['travelmonth'];
  176.         if ($dummy splitMonthYear($month)) $where += $dummy;
  177.     }
  178.  
  179.     // filter name
  180.     if (isset($_SESSION['filter'][$clientID]['travelname'])) {
  181.         $name $_SESSION['filter'][$clientID]['travelname'];
  182.         if ($name && ($name != '=')) {
  183.             if (strpos($name'='!== false$name trim(substr($name1));
  184.             $where['txtName'$name;
  185.         }
  186.     }
  187.     
  188.     $opt['months'dbGetTravelMonths($db$clientID);
  189.  
  190.     // show only one month?
  191.     if (isset($where['month'])) $opt['months'array($month => true);
  192.  
  193.     $opt['countitems']['total'0;
  194.     $vars array('numAmount''numTax''numDistAmount');
  195.     foreach ($vars as $var$opt['itemstotal']['total'][$var0;        
  196.     foreach ($opt['months'as $month => $monthNotUsed{
  197.         if ($dummy splitMonthYear($month)) $where $dummy $where;
  198.         $opt['where'][$month$where;
  199.  
  200.         // load items
  201.         if ($opt['itemstotal'][$monthdbCountTravelItems($db$clientID$where)) {
  202.             $opt['countitems'][$month$opt['itemstotal'][$month]['count'];
  203.             $opt['countitems']['total'+= $opt['countitems'][$month];
  204.             foreach ($vars as $var)
  205.                 $opt['itemstotal']['total'][$var+=
  206.                     makeDot($opt['itemstotal'][$month][$var]);
  207.         else continue;
  208.         
  209.         if (!$opt['items'][$monthdbLoadTravelItems($db$clientID-1-1$sort$where)) 
  210.         continue;        
  211.     }
  212.     
  213.     dbPrepareTravelSQLData($conf$opt['itemstotal']['total']true);    
  214.  
  215.     return true;    
  216. }
  217.  
  218.  
  219. /**
  220.  * generate data for html output of travel item
  221.  *
  222.  * @param    eaDB    database
  223.  * @param    eaInput input data
  224.  */
  225. function genOptTravelItem(&$db&$in{
  226.     $conf =$db->conf;
  227.     $user =$db->user;
  228.  
  229.     if (!isset($in->options)) $in->options array();
  230.     $opt =$in->options;
  231.  
  232.     if (!$clientID $in->getClient($db)) return false// wrong client
  233.     
  234.     $opt['travel'true// we are in the travel section
  235.     $opt['travelurl''travel';
  236.  
  237.     // prepare date format
  238.     $opt['dateformat'$conf['txtDateFormat'];;
  239.  
  240.     // prepare number format
  241.     $opt['decimal'$conf['numNumberDecimal'];
  242.     switch ($conf['txtNumberSeperator']{
  243.         case 'komma':
  244.             $opt['seperator'',';
  245.             break;
  246.         case 'dot'default:
  247.             $opt['seperator''.';
  248.             break;
  249.     }
  250.  
  251.     // prepare vat values
  252.     $split explode(','$conf['txtVatCategories']);
  253.     foreach ($split as $item{
  254.         $item trim($item);
  255.         $opt['vatcategories'][$item$item ' %'
  256.     }
  257.     
  258.     // standard vat rate for travelling expenses for Austria
  259.     if (!isset($_POST['txtTax'])) $in->post['txtTax'10;
  260.  
  261.     // standard milage rate
  262.     if (!isset($_POST['numDistRate'])) 
  263.         $in->post['numDistRate'makeNum($conf['numDistRate']$opt['seperator']false);
  264.     
  265.     // load old data
  266.     if (($itemID $in->getGet('item')) 
  267.         && ($dummy dbLoadTravelItem($db$clientID$itemID))) {
  268.         $in->post =$dummy;
  269.         $post =$in->post;
  270.         $post['numID'$post['id'];
  271.     }
  272.     
  273.     return true;    
  274. }
  275.  
  276. /**
  277.  * save travel item
  278.  *
  279.  * @param    eaDB    database
  280.  * @param    eaInput input data
  281.  */
  282. function saveTravelItem(&$db&$in
  283.     if (!isset($_POST['buttonSaveTravelItem'])) return false;
  284.     $in->post['buttonSaveTravelItem'true;
  285.  
  286.     $conf =$db->conf;
  287.     $user =$db->user;
  288.  
  289.     $clientID $in->options['client'];
  290.     if (!$db->isOwner($clientID)) return false// wrong client
  291.  
  292.     // check for errors
  293.     $vars array('p:txt:txt''p:num:num');
  294.     $in->check($vars);
  295.  
  296.     $error =$in->error;
  297.     $post =$in->post;
  298.     $opt =$in->options;
  299.  
  300.     // check amounts
  301.     $vars array('txtTax''numDay''numNight''numTax''numAmount''numDistance''numDistRate''numDistAmount');
  302.     $sum 0$milleage 1;
  303.     foreach ($vars as $var{
  304.         if ($in->post($var!== falseswitch($var// valid values
  305.             case 'txtTax':                
  306.                 $dummy $post[$var]
  307.                 if ($in->_check->num($dummy)) $p $dummy 100// valid rate
  308.                 else $p = -1// user defined rate
  309.                 break;
  310.             case 'numDay'case 'numNight':
  311.                 $sum += makeDot($post[$var]$opt['decimal']);
  312.                 break;                            
  313.             case 'numTax':
  314.                 $dummy makeDot($post[$var]$opt['decimal']);
  315.                 if (($p != -1
  316.                     && (log10(abs($sum $p ($p$dummy)) >= -$opt['decimal']))
  317.                     $error[$var'wrongvalue';        
  318.                 $net $sum $dummy;
  319.                 break;                            
  320.             case 'numAmount':
  321.                 $dummy makeDot($post[$var]$opt['decimal']);
  322.                 if (log10(abs($net $dummy)) >= -$opt['decimal'])
  323.                     $error[$var'wrongvalue';        
  324.                 break;                            
  325.             case 'numDistance'case 'numDistRate':
  326.                 $milleage *= makeDotOnly($post[$var]);
  327.                 break;                            
  328.             case 'numDistAmount':
  329.                 $dummy makeDot($post[$var]$opt['decimal']);
  330.                 if (log10(abs($milleage $dummy)) >= -$opt['decimal'])
  331.                     $error[$var'wrongvalue';        
  332.                 break;                            
  333.         else switch($var// invalid entries
  334.             case 'txtTax':
  335.                 $p = -1;
  336.                 break;
  337.             case 'numDay'case 'numNight':
  338.                 if ($error[$var== 'empty'// if (empty) -> 0
  339.                     unset($error[$var]);
  340.                     $post[$var0;
  341.                 }
  342.                 break;
  343.             case 'numDistance'case 'numDistRate':
  344.                 if ($error[$var== 'empty'// if (empty) -> 0
  345.                     unset($error[$var]);
  346.                     $post[$var0;
  347.                     $milleage 0;
  348.                 }
  349.                 break;
  350.             case 'numTax':
  351.                 if (($error[$var== 'empty'&& ($p != -1)) // if (empty) -> calc
  352.                     unset($error[$var]);
  353.                     $post[$var$sum $p ($p);
  354.                     $net $sum $post[$var];
  355.                 else $net $sum;
  356.                 break;                            
  357.             case 'numAmount':
  358.                 if ($error[$var== 'empty'// if (empty) -> calc
  359.                     unset($error[$var]);
  360.                     $post[$var$net;
  361.                 }
  362.                 break;                            
  363.             case 'numDistAmount':
  364.                 if ($error[$var== 'empty'// if (empty) -> calc
  365.                     unset($error[$var]);
  366.                     $post[$var$milleage;
  367.                 }
  368.                 break;                            
  369.         }
  370.     }
  371.  
  372.     foreach ($vars as $varif ($in->post($var!== falseswitch ($var{
  373.         case 'txtTax':
  374.             break;
  375.         case 'numDistance'case 'numDistRate':
  376.             $post[$varmakeNumOnly($post[$var]$opt['seperator']);
  377.             break;    
  378.         default:
  379.             $post[$varmakeNum($post[$var]$opt['seperator']$opt['decimal']);
  380.     }
  381.  
  382.     // txtDate -> check date
  383.     if ($dummy checkDateFormat($post['txtDate']$conf['txtDateFormat'])) {
  384.         $post += $dummy;
  385.     else {
  386.         $error['txtDate''wrongformat';
  387.     }
  388.  
  389.     // allow empty
  390.     $vars array('txtVouchers');
  391.     foreach ($vars as $varif (isset($error[$var]&& $error[$var== 'empty')
  392.         unset($error[$var]);
  393.  
  394.     // check valid selection
  395.     $vars array('txtTax' => 'vatcategories');
  396.     foreach ($vars as $key => $val
  397.         if (!isset($opt[$val][$post[$key]])) $error[$key'wrongselection';
  398.  
  399.     if ($errorreturn false// wrong input
  400.  
  401.     // save item    
  402.     return dbSaveTravelItem($db$clientID$post);
  403. }
  404.  
  405. ?>

Documentation generated on Sun, 09 Sep 2007 17:09:42 +0200 by phpDocumentor 1.3.1