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

Source for file purchasebook.db.php

Documentation is available at purchasebook.db.php

  1. <?php 
  2. /**
  3.  * database 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.db.php 130 2007-08-17 14:24:44Z m2mtech $
  24.  * @link       http://www.ea-geier.at/
  25.  */
  26.  
  27. /**
  28.  * standard client db functions
  29.  */
  30. require_once('code/clients.db.php');
  31.  
  32. /**
  33.  * number functions
  34.  */
  35. require_once('code/numbers.inc.php');
  36.  
  37. /**
  38.  * date functions
  39.  */
  40. require_once('code/date.inc.php');
  41.  
  42. /**
  43.  * save purchase-book item
  44.  *
  45.  * @param    eaDB    database
  46.  * @param    integer client
  47.  * @param    array    data
  48.  */
  49. function dbSavePurchaseBookItem(&$db$client&$data
  50.     dbChangeToClientDB($db$client);
  51.  
  52.     // prepare number format
  53.     $opt['decimal'$db->conf['numNumberDecimal'];
  54.  
  55.     // prepare variables
  56.     $vars array('txtID''txtName''txtVendor''numAmount''year''month''day');
  57.     foreach ($vars as $varif (isset($data[$var])) switch ($var{
  58.         case 'numAmount':
  59.             $what[$varmakeDot($data[$var]$opt['decimal']);
  60.             break;
  61.         default$what[$var$data[$var];
  62.     }
  63.     
  64.     $what['lastModified'$db->now();
  65.     
  66.     $what['who'$db->user['mail'];
  67.  
  68.     $table $db->table('purchasebook');
  69.  
  70.     if (isset($data['numID'])) // old item
  71.         $id $data['numID'];
  72.         if (!$db->update($what$tablearray('id' => $id))) return false;
  73.     else {
  74.         if (!$db->insert($what$table)) return false;
  75.         if (!$id $db->lastID()) return false;
  76.     }
  77.  
  78.     return $data['numID'$id;
  79. }
  80.  
  81. /**
  82.  * load purchase-book item
  83.  *
  84.  * @param    eaDB    database
  85.  * @param    integer clientID
  86.  * @param    integer itemID
  87.  * @return    array    data
  88.  */
  89. function dbLoadPurchaseBookItem(&$db$client$item{
  90.     dbChangeToClientDB($db$client);
  91.  
  92.     $table $db->table('purchasebook');
  93.  
  94.     if (!$data $db->selectOne('*'$tablearray('id' => $item))) return false;
  95.  
  96.     dbPreparePurchaseBookSQLData($db->conf$data);
  97.     
  98.     return $data;
  99. }
  100.  
  101. /**
  102.  * get number of purchase-book items
  103.  *
  104.  * @param    eaDB    database
  105.  * @param    integer clientID
  106.  * @param    array    filter
  107.  * @return    integer number of items
  108.  */
  109. function dbCountPurchaseBookItems(&$db$client$where false
  110.     dbChangeToClientDB($db$client);
  111.  
  112.     $table $db->table('purchasebook');
  113.  
  114.     $what 'count(id) as c, sum(numAmount) as numAmount';
  115.  
  116.     if (!$where$where '';
  117.     if (isset($where['txtName'])) // we have to prepare it ourselves 
  118.         $filters $where;
  119.         $where "txtName like '%" $db->escape($where['txtName']true"%'";    
  120.         unset($filters['txtName']);
  121.         if ($filters// other filters available
  122.             foreach ($filters as $key => $value)
  123.                 $where .= ' and ' $db->escapeKey($key' = ' $db->escape($value);
  124.         }        
  125.     }
  126.  
  127.     if (!$dummy $db->selectOne($what$table$where)) return false;
  128.     
  129.     if (!$dummy['c']return false;
  130.     
  131.     $data['count'$dummy['c'];
  132.     $data['numAmount'$dummy['numAmount'];
  133.  
  134.     dbPreparePurchaseBookSQLData($db->conf$data);
  135.     
  136.     return $data;
  137.  
  138.  
  139. }
  140.  
  141. /**
  142.  * load multiple purchase-book item
  143.  *
  144.  * @param    eaDB    database
  145.  * @param    integer clientID
  146.  * @param    integer number of items
  147.  * @param    integer number page
  148.  * @param    string    sorting string
  149.  * @param    array    filtering
  150.  * @return    array    data
  151.  */
  152. function dbLoadPurchaseBookItems(&$db$client$num 10$page 1$sort false$where false
  153.     dbChangeToClientDB($db$client);
  154.  
  155.     $table $db->table('purchasebook');
  156.  
  157.     if (!$where$where '';
  158.     if (isset($where['txtName'])) // we have to prepare it ourselves 
  159.         $filters $where;
  160.         $where "txtName like '%" $db->escape($where['txtName']true"%'";    
  161.         unset($filters['txtName']);
  162.         if ($filters// other filters available
  163.             foreach ($filters as $key => $value)
  164.                 $where .= ' and ' $db->escapeKey($key' = ' $db->escape($value);
  165.         }        
  166.     }
  167.  
  168.     
  169.     if (!$sort$sort 'id asc';
  170.  
  171.     if ($page == -1$offset = -1;
  172.     else $offset $num ($page 1);
  173.  
  174.     if (!$data $db->select('*'$table$where$sort$num$offset))
  175.         return false;
  176.         
  177.     foreach ($data as $key => $valdbPreparePurchaseBookSQLData($db->conf$data[$key]);    
  178.     return $data;
  179. }
  180.  
  181. /**
  182.  * prepare the sql data for output
  183.  *
  184.  * @param    array    configuration data
  185.  * @param    array    purchase-book item
  186.  */
  187. function dbPreparePurchaseBookSQLData(&$conf&$data{
  188.     static $decimal false;
  189.     static $separator false;
  190.     static $date false;
  191.  
  192.     if (!$decimal$decimal $conf['numNumberDecimal'];
  193.     if (!$separatorswitch ($conf['txtNumberSeperator']{
  194.         case 'komma':
  195.             $separator ',';
  196.             break;
  197.         case 'dot'default:
  198.             $separator '.';
  199.             break;
  200.     }
  201.     if (!$date$date $conf['txtDateFormat'];
  202.     
  203.     // prepare numbers
  204.         $numVars['numAmount';
  205.     foreach ($numVars as $var
  206.         $data[$varmakeNum($data[$var]$separator$decimal);
  207.  
  208.     // prepare date
  209.         $data['txtDate'dateFormat($data$date);    
  210. }
  211.  
  212. /**
  213.  * get months in database
  214.  *
  215.  * @param    eaDB    database
  216.  * @param    integer clientID
  217.  * @return    array    templates
  218.  */
  219. function dbGetPurchaseBookMonths(&$db$client
  220.     dbChangeToClientDB($db$client);
  221.  
  222.     $table $db->table('purchasebook');
  223.  
  224.     if (!$dummy $db->select('distinct month, year'$table'''year desc, month desc'))
  225.         return false;
  226.     
  227.     foreach ($dummy as $val{
  228.         $comb $val['year''-' $val['month'];
  229.         switch ($db->conf['txtDateFormat']{
  230.             case 'DD.MM.YYYY':
  231.                 $months[$comb$val['month''.' $val['year'];
  232.                 break;
  233.             case 'YYYY-MM-DD':
  234.                 $months[$comb$comb;
  235.                 break;
  236.         }
  237.     }
  238.     
  239.     return $months;
  240. }
  241.  
  242. ?>

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