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

Source for file purchasebook.inc.php

Documentation is available at purchasebook.inc.php

  1. <?php 
  2. /**
  3.  * php functions for purchase book
  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: purchasebook.inc.php 130 2007-08-17 14:24:44Z m2mtech $
  24.  * @link       http://www.ea-geier.at/
  25.  */
  26.  
  27. /**
  28.  * html functions for purchase book
  29.  */
  30. require_once('code/purchasebook.html.php');
  31.  
  32. /**
  33.  * database functions for purchase book
  34.  */
  35. require_once('code/purchasebook.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 purchase book
  49.  *
  50.  * @param    eaDB    database
  51.  * @param    eaInput input data
  52.  */
  53. function genOptPurchaseBook(&$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['purchasebook'true// we are in the purchase-book section
  63.     $opt['purchasebookurl''purchasebook';
  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''txtID''txtName''numAmount''month')'purchasebook');
  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('purchasebook')) $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]['purchasebookmonth'])) 
  101.         $month $_SESSION['filter'][$clientID]['purchasebookmonth'];
  102.     if ($month{
  103.         $match false;
  104.         if (preg_match('/(\d{4})-(\d{2})/'$month$match)) {
  105.             $where['year'$match[1];
  106.             $where['month'$match[2];
  107.             $_SESSION['filter'][$clientID]['purchasebookmonth'$month;
  108.             $in->post['txtMonth'$month;
  109.         else unset($_SESSION['filter'][$clientID]['purchasebookmonth']);
  110.     }
  111.  
  112.     // filters name
  113.     
  114.     $name $in->getGet('find''txt');
  115.     if (!$name$name $in->post('txtWhat');
  116.     if (isset($in->error['txtWhat']&& ($in->error['txtWhat'== 'empty')) {
  117.         $name '=';
  118.         unset ($in->error['txtWhat']);
  119.     }
  120.     if (!$name && isset($_SESSION['filter'][$clientID]['purchasebookname'])) 
  121.         $name $_SESSION['filter'][$clientID]['purchasebookname'];
  122.     if ($name && ($name != '=')) {
  123.         if (strpos($name'='!== false$name trim(substr($name1));
  124.         $where['txtName'$name;
  125.         $_SESSION['filter'][$clientID]['purchasebookname'$name;
  126.         $in->post['txtWhat'$name;
  127.     elseif (isset($_SESSION['filter'][$clientID]['purchasebookname']))
  128.         unset($_SESSION['filter'][$clientID]['purchasebookname']);
  129.  
  130.     $opt['months'dbGetPurchaseBookMonths($db$clientID);
  131.  
  132.     // load items
  133.     if (!$opt['itemstotal'dbCountPurchaseBookItems($db$clientID$where)) {
  134.         if ($where{
  135.             $opt['countitems'0;
  136.             return true;
  137.         }
  138.         return false;
  139.     else $opt['countitems'$opt['itemstotal']['count'];
  140.  
  141.     $opt['pages'ceil($opt['countitems'$opt['lines']);
  142.     
  143.     if ($opt['page'$opt['pages']$opt['page'1;
  144.  
  145.     if (!$opt['items'dbLoadPurchaseBookItems($db$clientID$opt['lines']$opt['page']$sort$where))
  146.         return false;
  147.     
  148.     return true;    
  149. }
  150.  
  151. /**
  152.  * generate data for print output of purchase book
  153.  *
  154.  * @param    eaDB    database
  155.  * @param    eaInput input data
  156.  */
  157. function genOptPurchaseBookPrint(&$db&$in{
  158.     $conf =$db->conf;
  159.     $user =$db->user;
  160.  
  161.     if (!isset($in->options)) $in->options array();
  162.     $opt =$in->options;
  163.  
  164.     if (!$clientID $in->getClient($db)) return false// wrong client
  165.     
  166.     // sorting
  167.     $sort $in->getSort(array('id''txtID''txtName''numAmount''month')'purchasebook');
  168.  
  169.     if (strpos($sort'month'!== false{
  170.         if (strpos($sort'asc')) $sort 'year asc, month asc, day asc';
  171.         else $sort 'year desc, month desc, day desc';
  172.     }
  173.  
  174.     $where array();
  175.     // filter months
  176.     if (isset($_SESSION['filter'][$clientID]['purchasebookmonth'])) {
  177.         $month $_SESSION['filter'][$clientID]['purchasebookmonth'];
  178.         if ($dummy splitMonthYear($month)) $where += $dummy;
  179.     }
  180.  
  181.     // filter name
  182.     if (isset($_SESSION['filter'][$clientID]['purchasebookname'])) {
  183.         $name $_SESSION['filter'][$clientID]['purchasebookname'];
  184.         if ($name && ($name != '=')) {
  185.             if (strpos($name'='!== false$name trim(substr($name1));
  186.             $where['txtName'$name;
  187.         }
  188.     }
  189.     
  190.     $opt['months'dbGetPurchaseBookMonths($db$clientID);
  191.  
  192.     // show only one month?
  193.     if (isset($where['month'])) $opt['months'array($month => true);
  194.  
  195.     $opt['countitems']['total'0;
  196.     $vars array('numAmount');
  197.     foreach ($vars as $var$opt['itemstotal']['total'][$var0;        
  198.     foreach ($opt['months'as $month => $monthNotUsed{
  199.         if ($dummy splitMonthYear($month)) $where $dummy $where;
  200.         $opt['where'][$month$where;
  201.  
  202.         // load items
  203.         if ($opt['itemstotal'][$monthdbCountPurchaseBookItems($db$clientID$where)) {
  204.             $opt['countitems'][$month$opt['itemstotal'][$month]['count'];
  205.             $opt['countitems']['total'+= $opt['countitems'][$month];
  206.             foreach ($vars as $var)
  207.                 $opt['itemstotal']['total'][$var+=
  208.                     makeDot($opt['itemstotal'][$month][$var]);
  209.         else continue;
  210.         
  211.         if (!$opt['items'][$monthdbLoadPurchaseBookItems($db$clientID-1-1$sort$where)) 
  212.         continue;        
  213.     }
  214.     
  215.     dbPreparePurchaseBookSQLData($conf$opt['itemstotal']['total']true);    
  216.  
  217.     return true;    
  218. }
  219.  
  220. /**
  221.  * generate data for html output of purchase book item
  222.  *
  223.  * @param    eaDB    database
  224.  * @param    eaInput input data
  225.  */
  226. function genOptPurchaseBookItem(&$db&$in{
  227.     $conf =$db->conf;
  228.     $user =$db->user;
  229.  
  230.     if (!isset($in->options)) $in->options array();
  231.     $opt =$in->options;
  232.  
  233.     if (!$clientID $in->getClient($db)) return false// wrong client
  234.     
  235.     $opt['purchasebook'true// we are in the purchase-book section
  236.     $opt['purchasebookurl''purchasebook';
  237.  
  238.     // prepare date format
  239.     $opt['dateformat'$conf['txtDateFormat'];;
  240.  
  241.     // prepare number format
  242.     $opt['decimal'$conf['numNumberDecimal'];
  243.     switch ($conf['txtNumberSeperator']{
  244.         case 'komma':
  245.             $opt['seperator'',';
  246.             break;
  247.         case 'dot'default:
  248.             $opt['seperator''.';
  249.             break;
  250.     }
  251.  
  252.     // load old data
  253.     if (($itemID $in->getGet('item')) 
  254.         && ($dummy dbLoadPurchaseBookItem($db$clientID$itemID))) {
  255.         $in->post =$dummy;
  256.         $post =$in->post;
  257.         $post['numID'$post['id'];
  258.     }
  259.     
  260.     return true;    
  261. }
  262.  
  263. /**
  264.  * save purchase book item
  265.  *
  266.  * @param    eaDB    database
  267.  * @param    eaInput input data
  268.  */
  269. function savePurchaseBookItem(&$db&$in
  270.     if (!isset($_POST['buttonSavePurchaseBookItem'])) return false;
  271.     $in->post['buttonSavePurchaseBookItem'true;
  272.  
  273.     $conf =$db->conf;
  274.     $user =$db->user;
  275.  
  276.     $clientID $in->options['client'];
  277.     if (!$db->isOwner($clientID)) return false// wrong client
  278.  
  279.     // check for errors
  280.     $vars array('p:txt:txt''p:num:num');
  281.     $in->check($vars);
  282.  
  283.     $error =$in->error;
  284.     $post =$in->post;
  285.     $opt =$in->options;
  286.  
  287.     // txtDate -> check date
  288.     if ($dummy checkDateFormat($post['txtDate']$conf['txtDateFormat'])) {
  289.         $post += $dummy;
  290.     else {
  291.         $error['txtDate''wrongformat';
  292.     }
  293.  
  294.     // check/prepare number format
  295.     $vars array('numAmount');
  296.     foreach ($vars as $varif (isset($post[$var]))
  297.         $post[$varmakeNum($post[$var]$opt['seperator']$opt['decimal']);
  298.  
  299.     if ($errorreturn false// wrong input
  300.     // save item    
  301.     return dbSavePurchaseBookItem($db$clientID$post);
  302. }
  303.  
  304. ?>

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