phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] bookkeeping/inc class.bobilling.inc.php, NONE, 1.1 cl


From: Bettina Gille <address@hidden>
Subject: [Phpgroupware-cvs] bookkeeping/inc class.bobilling.inc.php, NONE, 1.1 class.bobookkeeping.inc.php, NONE, 1.1 class.bodeliveries.inc.php, NONE, 1.1 class.sobilling.inc.php, NONE, 1.1 class.sodeliveries.inc.php, NONE, 1.1 class.uibilling.inc.php, NONE, 1.1 class.uibookkeeping.inc.php, NONE, 1.1 class.uideliveries.inc.php, NONE, 1.1 hook_sidebox_menu.inc.php, NONE, 1.1 hook_admin.inc.php, 1.10, 1.11 hook_preferences.inc.php, 1.2, 1.3
Date: Mon, 01 Dec 2003 16:31:36 +0000

Update of /cvsroot/phpgroupware/bookkeeping/inc
In directory subversions:/tmp/cvs-serv10111/inc

Modified Files:
        hook_admin.inc.php hook_preferences.inc.php 
Added Files:
        class.bobilling.inc.php class.bobookkeeping.inc.php 
        class.bodeliveries.inc.php class.sobilling.inc.php 
        class.sodeliveries.inc.php class.uibilling.inc.php 
        class.uibookkeeping.inc.php class.uideliveries.inc.php 
        hook_sidebox_menu.inc.php 
Log Message:
added projects invoicing part

--- NEW FILE: hook_sidebox_menu.inc.php ---
<?php
        
/**************************************************************************\
        * phpGroupWare - projects's Sidebox-Menu for idots-template             
   *
        * http://www.phpgroupware.org                                           
   *
        * Written by Pim Snel <address@hidden>                                  
 *
        * --------------------------------------------                          
   *
        *  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.                                           
   *
        
\**************************************************************************/
        /* $Id: hook_sidebox_menu.inc.php,v 1.1 2003/12/01 16:31:34 ceb Exp $ */
        {

 /*
        This hookfile is for generating an app-specific side menu used in the 
idots 
        template set.

        $menu_title speaks for itself
        $file is the array with link to app functions

        display_sidebox can be called as much as you like
 */

                $appname = 'bookkeeping';
                $menu_title = $GLOBALS['phpgw_info']['apps'][$appname]['title'] 
. ' '. lang('Menu');

                $file = array
                (
                        'Billing'               => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uibilling.list_projects&action=mains'),
                        'Deliveries'    => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uideliveries.list_projects&action=mains')
                );

                display_sidebox($appname,$menu_title,$file);

                if ($GLOBALS['phpgw_info']['user']['apps']['preferences'])
                {
                        $menu_title = 
$GLOBALS['phpgw_info']['apps'][$appname]['title'] . ' '. lang('Preferences');
                        $file = Array(
                                'Preferences'           => 
$GLOBALS['phpgw']->link('/index.php','menuaction=bookkeeping.uibookkeeping.preferences'),
                                'Grant Access'          => 
$GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uiaclprefs.index&acl_app='.$appname),
                                'Edit categories'       => 
$GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uicategories.index&cats_app=bookkeeping&cats_level=True&global_cats=True')
                        );
                        display_sidebox($appname,$menu_title,$file);
                }

                if ($GLOBALS['phpgw_info']['user']['apps']['admin'])
                {
                        $menu_title = 
$GLOBALS['phpgw_info']['apps'][$appname]['title'] . ' '. lang('Administration');
                        $file = Array
                        (
                                'Site Configuration'    => 
$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiconfig.index&appname=' 
. $appname),
                                'Global Categories'             => 
$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.index&appname='
 . $appname)
                        );
                        display_sidebox($appname,$menu_title,$file);
                }
        }
?>

Index: hook_admin.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/bookkeeping/inc/hook_admin.inc.php,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** hook_admin.inc.php  23 Apr 2003 01:37:01 -0000      1.10
--- hook_admin.inc.php  1 Dec 2003 16:31:34 -0000       1.11
***************
*** 1,21 ****
  <?php
!       
/*************************************************************************\
!       * phpGroupWare app (Bookkeeping)                                        
  *
!       * http://www.phpgroupware.org                                           
  *
!       * Written by Rick Bakker <address@hidden>                         *
!       * --------------------------------------------                          
  *
!       * 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.                                            
  *
!       
\*************************************************************************/
        /* $Id$ */
  
        {
                $file = Array
                (
!                       'Bookkeeping Admins' => 
$GLOBALS['phpgw']->link('/bookkeeping/admin/index.php')
                );
!               $GLOBALS['phpgw']->common->display_mainscreen($appname,$file);
        }
  ?>
--- 1,23 ----
  <?php
!       
/**************************************************************************\
!       * phpGroupWare - projects administration                                
   *
!       * http://www.phpgroupware.org                                           
   *
!       * --------------------------------------------                          
   *
!       *  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.                                           
   *
!       
\**************************************************************************/
        /* $Id$ */
  
        {
+ // Only Modify the $file and $title variables.....
                $file = Array
                (
!                       'Site Configuration'    => 
$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiconfig.index&appname=' 
. $appname),
!                       'Global Categories'             => 
$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.index&appname='
 . $appname)
                );
! //Do not modify below this line
!               display_section($appname,$appname,$file);
        }
  ?>

Index: hook_preferences.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/bookkeeping/inc/hook_preferences.inc.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** hook_preferences.inc.php    23 Nov 2001 20:04:21 -0000      1.2
--- hook_preferences.inc.php    1 Dec 2003 16:31:34 -0000       1.3
***************
*** 1,23 ****
  <?php
! /*************************************************************************\
! * phpGroupWare app (Bookkeeping)                                          *
! * http://www.phpgroupware.org                                             *
! * Written by Rick Bakker <address@hidden>                         *
! * --------------------------------------------                            *
! * 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.                                              *
! \*************************************************************************/
! 
! /* $Id$ */
  
! {
!       $title = $appname;
!       $file = Array(
!               'Preferences' => 
$GLOBALS['phpgw']->link('/bookkeeping/preferences/index.php')
!       );
!       display_section($appname,$title,$file);
! }
  ?>
- 
--- 1,23 ----
  <?php
!       
/**************************************************************************\
!       * phpGroupWare - Project Prefs                                          
   *
!       * http://www.phpgroupware.org                                           
   *
!       * --------------------------------------------                          
   *
!       * 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.                                            
   *
!       
\**************************************************************************/
!       /* $Id$ */
  
!       {
!               $title = $appname;
!               $file = Array
!               (
!                       'Preferences'     => 
$GLOBALS['phpgw']->link('/index.php','menuaction=bookkeeping.uibookkeeping.preferences'),
!                       'Grant Access'    => 
$GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uiaclprefs.index&acl_app='.$appname),
!                       'Edit categories' => 
$GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uicategories.index&cats_app=projects&cats_level=True&global_cats=True')
!               );
!               display_section($appname,$title,$file);
!       }
  ?>

--- NEW FILE: class.bodeliveries.inc.php ---
<?php
        /*******************************************************************\
        * phpGroupWare - Projects                                           *
        * http://www.phpgroupware.org                                       *
        * This program is part of the GNU project, see http://www.gnu.org/      
*
        *                                                                   *
        * Project Manager                                                   *
        * Written by Bettina Gille address@hidden                   *
        * -----------------------------------------------                   *
        * Copyright 2000 - 2003 Free Software Foundation, Inc               *
        *                                                                   *
        * 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., 675 Mass Ave, Cambridge, MA 02139, USA.         *
        \*******************************************************************/
        /* $Id: class.bodeliveries.inc.php,v 1.1 2003/12/01 16:31:33 ceb Exp $ 
*/
        /* $Source: 
/cvsroot/phpgroupware/bookkeeping/inc/class.bodeliveries.inc.php,v $ */

        class bodeliveries
        {
                var $public_functions = array
                (
                        'check_values'                  => True,
                        'read_hours'                    => True,
                        'read_delivery_hours'   => True,
                        'read_single_delivery'  => True,
                        'delivery'                              => True,
                        'update_delivery'               => True,
                        'read_deliveries'               => True,
                        'get_address_data'              => True,
                        'read_delivery_pos'             => True
                );

                function bodeliveries()
                {
                        $this->sodeliveries     = 
CreateObject('projects.sodeliveries');
                        $this->soprojects       = 
CreateObject('projects.soprojects');
                        $this->contacts         = 
CreateObject('phpgwapi.contacts');
                        $this->boprojects       = 
CreateObject('projects.boprojects');
                }

                function read_hours($project_id, $action)
                {
                        $hours = $this->sodeliveries->read_hours($project_id, 
$action);
                        return $hours;
                }

                function read_delivery_hours($project_id, $delivery_id, $action)
                {
                        $hours = 
$this->sodeliveries->read_delivery_hours($project_id, $delivery_id, $action);
                        return $hours;
                }

                function read_delivery_pos($delivery_id)
                {
                        $hours = 
$this->sodeliveries->read_delivery_pos($delivery_id);
                        return $hours;
                }

                function get_site_config()
                {
                        return $this->boprojects->get_site_config();
                }

                function read_deliveries($start, $query, $sort, $order, $limit, 
$project_id)
                {
                        $co = $this->get_site_config();
                        $del = 
$this->sodeliveries->read_deliveries(array('start' => $start,'query' => 
$query,'sort' => $sort,'order' => $order,'limit' => $limit,
                                                                                
                                        'project_id' => $project_id,'owner' => 
$co['invoice_acl']));
                        $this->total_records = 
$this->sodeliveries->total_records;
                        return $del;
                }

                function read_single_delivery($delivery_id)
                {
                        $del = 
$this->sodeliveries->read_single_delivery($delivery_id);
                        return $del;
                }

                function get_address_data($format, $abid, $afont, $asize)
                {
                        if ($format == 'address')
                        {
                                $address = 
$this->contacts->formatted_address($abid,True,$afont,$asize);
                        }
                        elseif ($format == 'line')
                        {
                                $address = 
$this->contacts->formatted_address_line($abid,True,$afont,$asize);
                        }
                        else
                        {
                                $address = 
$this->contacts->formatted_address_full($abid,True,$afont,$asize);
                        }
                        return $address;
                }

                function check_values($values,$select)
                {
                        if (!$values['choose'])
                        {
                                if (!$values['delivery_num'])
                                {
                                        $error[] = lang('Please enter an ID !');
                                }
                                else
                                {
                                        $num = 
$this->sodeliveries->exists($values);
                                        if ($num)
                                        {
                                                $error[] = lang('That ID has 
been used already !');
                                        }
                                }
                        }

                        if (! is_array($select))
                        {
                                $error[] = lang('The delivery note contains no 
items !');                               
                        }

                        if (! $values['customer'])
                        {
                                $error[] = lang('You have no customer selected 
!');
                        }

                        if (! 
checkdate($values['month'],$values['day'],$values['year']))
                        {
                                $error[] = lang('You have entered an invalid 
date !');
                        }

                        if (is_array($error))
                        {
                                return $error;
                        }
                }

                function delivery($values,$select)
                {
                        if ($values['choose'])
                        {
                                $values['delivery_num'] = 
$this->soprojects->create_deliveryid();
                        }

                        $values['date'] = 
mktime(2,0,0,$values['month'],$values['day'],$values['year']);

                        $delivery_id = 
$this->sodeliveries->delivery($values,$select);
                        return $delivery_id;
                }

                function update_delivery($values,$select)
                {
                        $values['date'] = 
mktime(2,0,0,$values['month'],$values['day'],$values['year']);

                        $this->sodeliveries->update_delivery($values,$select);
                }
        }
?>

--- NEW FILE: class.bobilling.inc.php ---
<?php
        /*******************************************************************\
        * phpGroupWare - Projects                                           *
        * http://www.phpgroupware.org                                       *
        * This program is part of the GNU project, see http://www.gnu.org/      
*
        *                                                                   *
        * Project Manager                                                   *
        * Written by Bettina Gille address@hidden                   *
        * -----------------------------------------------                   *
        * Copyright 2000 - 2003 Free Software Foundation, Inc               *
        *                                                                   *
        * 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., 675 Mass Ave, Cambridge, MA 02139, USA.         *
        \*******************************************************************/
        /* $Id: class.bobilling.inc.php,v 1.1 2003/12/01 16:31:33 ceb Exp $ */
        /* $Source: 
/cvsroot/phpgroupware/bookkeeping/inc/class.bobilling.inc.php,v $ */

        class bobilling
        {
                var $public_functions = array
                (
                        'read_invoices'                 => True,
                        'check_values'                  => True,
                        'read_hours'                    => True,
                        'read_invoice_hours'    => True,
                        'read_invoice_pos'              => True,
                        'invoice'                               => True,
                        'update_invoice'                => True,
                        'read_single_invoice'   => True
                );

                function bobilling()
                {
                        $this->sobilling        = 
CreateObject('projects.sobilling');
                        $this->soprojects       = 
CreateObject('projects.soprojects');
                        $this->contacts         = 
CreateObject('phpgwapi.contacts');
                        $this->boprojects       = 
CreateObject('projects.boprojects');
                }

                function get_site_config()
                {
                        return $this->boprojects->get_site_config();
                }

                function read_invoices($start, $query, $sort, $order, $limit, 
$project_id)
                {
                        $co = $this->get_site_config();

                        $bill = $this->sobilling->read_invoices(array('start' 
=> $start,'query' => $query, 'sort' => $sort,'order' => $order,'limit' => 
$limit,
                                                                                
                                'project_id' => $project_id,'owner' => 
$co['invoice_acl']));
                        $this->total_records = $this->sobilling->total_records;
                        return $bill;
                }

                function read_single_invoice($invoice_id)
                {
                        $bill = 
$this->sobilling->read_single_invoice($invoice_id);
                        return $bill;
                }

                function check_values($values,$select)
                {
                        if (!$values['choose'])
                        {
                                if (!$values['invoice_num'])
                                {
                                        $error[] = lang('Please enter an ID !');
                                }
                                else
                                {
                                        $num = 
$this->sobilling->exists($values);
                                        if ($num)
                                        {
                                                $error[] = lang('That ID has 
been used already !');
                                        }
                                }
                        }

                        if (! is_array($select))
                        {
                                $error[] = lang('The invoice contains no items 
!');                             
                        }

                        if (! $values['customer'])
                        {
                                $error[] = lang('You have no customer selected 
!');
                        }

                        if (! 
checkdate($values['month'],$values['day'],$values['year']))
                        {
                                $error[] = lang('You have entered an invalid 
date !');
                        }

                        if (is_array($error))
                        {
                                return $error;
                        }
                }

                function invoice($values,$select)
                {
                        if ($values['choose'])
                        {
                                $values['invoice_num'] = 
$this->soprojects->create_invoiceid();
                        }

                        $values['date'] = 
mktime(2,0,0,$values['month'],$values['day'],$values['year']);

                        $invoice_id = 
$this->sobilling->invoice($values,$select);
                        return $invoice_id;
                }

                function update_invoice($values,$select)
                {
                        $values['date'] = 
mktime(2,0,0,$values['month'],$values['day'],$values['year']);

                        $this->sobilling->update_invoice($values,$select);
                }

                function read_hours($project_id, $action)
                {
                        $hours = $this->sobilling->read_hours($project_id, 
$action);
                        return $hours;
                }

                function read_invoice_hours($project_id, $invoice_id, $action)
                {
                        $hours = 
$this->sobilling->read_invoice_hours($project_id, $invoice_id, $action);
                        return $hours;
                }

                function read_invoice_pos($invoice_id)
                {
                        $hours = 
$this->sobilling->read_invoice_pos($invoice_id);
                        return $hours;
                }
        }
?>

--- NEW FILE: class.sodeliveries.inc.php ---
<?php
        /*******************************************************************\
        * phpGroupWare - Projects                                           *
        * http://www.phpgroupware.org                                       *
        * This program is part of the GNU project, see http://www.gnu.org/      
*
        *                                                                   *
        * Project Manager                                                   *
        * Written by Bettina Gille address@hidden                   *
        * -----------------------------------------------                   *
        * Copyright 2000 - 2003 Free Software Foundation, Inc               *
        *                                                                   *
        * 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., 675 Mass Ave, Cambridge, MA 02139, USA.         *
        \*******************************************************************/
        /* $Id: class.sodeliveries.inc.php,v 1.1 2003/12/01 16:31:33 ceb Exp $ 
*/
        // $Source: 
/cvsroot/phpgroupware/bookkeeping/inc/class.sodeliveries.inc.php,v $

        class sodeliveries
        {
                var $db;

                function sodeliveries()
                {
                        $this->db                       = $GLOBALS['phpgw']->db;
                        $this->db2                      = $this->db;
                        $this->account          = 
$GLOBALS['phpgw_info']['user']['account_id'];
                }

                function return_join()
                {
                        $dbtype = $GLOBALS['phpgw_info']['server']['db_type'];

                        switch ($dbtype)
                        {
                                case 'pgsql':   $join = ' JOIN '; break;
                                case 'mysql':   $join = ' LEFT JOIN '; break;
                        }
                        return $join;
                }

                function delivery($values,$select)
                {
                        $values['delivery_num'] = 
$this->db->db_addslashes($values['delivery_num']);
                        $this->db->query("INSERT INTO phpgw_p_delivery 
(d_number,project_id,d_date,customer,owner) VALUES ('" . 
$values['delivery_num'] . "',"
                                                        . 
intval($values['project_id']) . ',' . time() . ',' . 
intval($values['customer']) . ',' . $this->account . ')',__LINE__,__FILE__);

                        $this->db2->query("SELECT id from phpgw_p_delivery 
WHERE d_number='" . $values['delivery_num'] . "'",__LINE__,__FILE__);
                        $this->db2->next_record();
                        $delivery_id = $this->db2->f('id');
                        $delivery_id = intval($delivery_id);

                        while(is_array($select) && $entry=each($select))
                        {
                                $this->db->query('INSERT INTO 
phpgw_p_deliverypos (delivery_id,hours_id) VALUES (' . $delivery_id . ',' . 
intval($entry[0])
                                                                . 
')',__LINE__,__FILE__);
                                $this->db2->query("UPDATE phpgw_p_hours set 
status='closed' WHERE status='done' AND id=" . 
intval($entry[0]),__LINE__,__FILE__);
                                $this->db2->query("UPDATE phpgw_p_hours set 
dstatus='d' WHERE id=" . intval($entry[0]),__LINE__,__FILE__);
                        }
                        return $delivery_id;
                }

                function update_delivery($values,$select)
                {
                        $values['delivery_id'] = intval($values['delivery_id']);

                        $values['delivery_num'] = 
$this->db->db_addslashes($values['delivery_num']);
                        $this->db->query("UPDATE phpgw_p_delivery set 
d_number='" . $values['delivery_num'] . "',d_date=" . intval($values['date']) . 
',customer='
                                                                . 
intval($values['customer']) . ' where id=' . 
$values['delivery_id'],__LINE__,__FILE__);

                        $this->db2->query('DELETE FROM phpgw_p_deliverypos 
WHERE delivery_id=' . $values['delivery_id'],__LINE__,__FILE__);

                        while(is_array($select) && $entry=each($select))
                        {
                                $this->db->query('INSERT INTO 
phpgw_p_deliverypos (delivery_id,hours_id) VALUES (' . $values['delivery_id'] . 
','
                                                                . 
intval($entry[0]) . ')',__LINE__,__FILE__);
                                $this->db2->query("UPDATE phpgw_p_hours set 
status='closed' WHERE status='done' AND id=" . 
intval($entry[0]),__LINE__,__FILE__);
                                $this->db2->query("UPDATE phpgw_p_hours set 
dstatus='d' WHERE id=" . intval($entry[0]),__LINE__,__FILE__);
                        }
                }

                function read_hours($project_id, $action)
                {
                        $project_id = intval($project_id);

                        $ordermethod = ' order by end_date asc';

                        if ($action == 'mains')
                        {
                                $parent_hours   = ' OR 
phpgw_p_hours.pro_parent=' . $project_id;
                        }

                        $this->db->query('SELECT phpgw_p_hours.id as 
id,phpgw_p_hours.hours_descr,phpgw_p_activities.descr,phpgw_p_hours.status,'
                                                        . 
'phpgw_p_hours.start_date,phpgw_p_hours.minutes,phpgw_p_hours.minperae FROM 
phpgw_p_hours' . $this->return_join()
                                                        . "phpgw_p_activities 
ON phpgw_p_hours.activity_id=phpgw_p_activities.id WHERE 
(phpgw_p_hours.dstatus='o' "
                                                        . "AND 
phpgw_p_hours.status != 'open') AND (phpgw_p_hours.project_id=" . $project_id . 
$parent_hours
                                                        . ')' . 
$ordermethod,__LINE__,__FILE__);

                        while ($this->db->next_record())
                        {
                                $hours[] = array
                                (
                                        'hours_id'              => 
$this->db->f('id'),
                                        'hours_descr'   => 
$this->db->f('hours_descr'),
                                        'act_descr'             => 
$this->db->f('descr'),
                                        'status'                => 
$this->db->f('status'),
                                        'sdate'                 => 
$this->db->f('start_date'),
                                        'edate'                 => 
$this->db->f('end_date'),
                                        'minutes'               => 
$this->db->f('minutes'),
                                        'minperae'              => 
$this->db->f('minperae')
                                );
                        }
                        return $hours;
                }

                function read_delivery_hours($project_id, $delivery_id, $action)
                {
                        $project_id             = intval($project_id);
                        $delivery_id    = intval($delivery_id);

                        $ordermethod = ' order by end_date asc';

                        if ($action == 'mains' || $action == 'amains')
                        {
                                $parent_search = ' OR 
phpgw_p_hours.pro_parent=' . $project_id;
                        }

                        $this->db->query('SELECT phpgw_p_hours.id as 
id,phpgw_p_hours.hours_descr,phpgw_p_activities.descr,phpgw_p_hours.status,'
                                                        . 
'phpgw_p_hours.start_date,phpgw_p_hours.minutes,phpgw_p_hours.minperae FROM 
phpgw_p_hours' . $this->return_join()
                                                        . 'phpgw_p_activities 
ON phpgw_p_hours.activity_id=phpgw_p_activities.id' . $this->return_join() . 
'phpgw_p_deliverypos '
                                                        . 'ON 
phpgw_p_hours.id=phpgw_p_deliverypos.hours_id WHERE (phpgw_p_hours.project_id=' 
. $project_id
                                                        . $parent_search  . ') 
AND phpgw_p_deliverypos.delivery_id=' . $delivery_id . 
$ordermethod,__LINE__,__FILE__);

                        while ($this->db->next_record())
                        {
                                $hours[] = array
                                (
                                        'hours_id'              => 
$this->db->f('id'),
                                        'hours_descr'   => 
$this->db->f('hours_descr'),
                                        'act_descr'             => 
$this->db->f('descr'),
                                        'status'                => 
$this->db->f('status'),
                                        'sdate'                 => 
$this->db->f('start_date'),
                                        'edate'                 => 
$this->db->f('end_date'),
                                        'minutes'               => 
$this->db->f('minutes'),
                                        'minperae'              => 
$this->db->f('minperae')
                                );
                        }
                        return $hours;
                }


                function read_deliveries($values)
                {
                        $project_id = intval($values['project_id']);
                        $sort           = 
(isset($values['sort'])?$values['sort']:'ASC');
                        $order          = $values['order'];
                        $query          = $values['query'];
                        $owner          = ($values['owner'] == 
'yes'?True:False);
                        $limit          = 
(isset($values['limit'])?$values['limit']:True);
                        $start          = intval($values['start']);

                        if ($order)
                        {
                                $ordermethod = " order by $order $sort";
                        }
                        else
                        {
                                $ordermethod = ' order by d_date asc';
                        }

                        if ($query)
                        {
                                $querymethod = " AND (d_number like '%$query%' 
OR title like '%$query%')";
                        }

                        if ($owner)
                        {
                                $acl_select = ' AND phpgw_p_delivery.owner=' . 
$this->account;
                        }

                        if ($project_id)
                        {
                                $sql = 'SELECT phpgw_p_delivery.id as 
id,d_number,title,d_date,phpgw_p_delivery.project_id,phpgw_p_delivery.customer '
                                        . 'FROM 
phpgw_p_delivery,phpgw_p_projects WHERE phpgw_p_delivery.project_id=' . 
$project_id
                                        . ' AND 
phpgw_p_delivery.project_id=phpgw_p_projects.id';
                        }
                else
                        {
                                $sql = 'SELECT phpgw_p_delivery.id as 
id,d_number,title,d_date,phpgw_p_delivery.project_id,phpgw_p_delivery.customer '
                                        . 'FROM 
phpgw_p_delivery,phpgw_p_projects WHERE 
phpgw_p_delivery.project_id=phpgw_p_projects.id';
                        }

                        $this->db2->query($sql . $acl_select,__LINE__,__FILE__);
                        $this->total_records = $this->db2->num_rows();

                        if ($limit)
                        {
                                $this->db->limit_query($sql  . $acl_select . 
$querymethod,$start,__LINE__,__FILE__);
                        }
                        else
                        {
                                $this->db->query($sql  . $acl_select . 
$querymethod,__LINE__,__FILE__);
                        }

                        while ($this->db->next_record())
                        {
                                $del[] = array
                                (
                                        'delivery_id'   => $this->db->f('id'),
                                        'project_id'    => 
$this->db->f('project_id'),
                                        'delivery_num'  => 
$this->db->f('d_number'),
                                        'title'                 => 
$this->db->f('title'),
                                        'date'                  => 
$this->db->f('d_date'),
                                        'customer'              => 
$this->db->f('customer')
                                );
                        }
                        return $del;
                }

                function read_single_delivery($delivery_id)
                {
                        $this->db->query('SELECT 
phpgw_p_delivery.customer,d_number,phpgw_p_delivery.project_id,d_date,title,p_number
 '
                                                        . 'FROM 
phpgw_p_delivery,phpgw_p_projects WHERE phpgw_p_delivery.id=' . 
intval($delivery_id)
                                                        . ' AND 
phpgw_p_delivery.project_id=phpgw_p_projects.id',__LINE__,__FILE__);

                        if ($this->db->next_record())
                        {
                                $del['date']                    = 
$this->db->f('date');
                                $del['delivery_num']    = 
$this->db->f('d_number');
                                $del['title']                   = 
$this->db->f('title');
                                $del['customer']                = 
$this->db->f('customer');
                                $del['project_id']              = 
$this->db->f('project_id');
                                $del['project_num']             = 
$this->db->f('p_number');
                        }
                        return $del;
                }

                function exists($values)
                {
                        $values['delivery_id'] = intval($values['delivery_id']);

                        if ($values['delivery_id'] && ($values['delivery_id'] 
!= 0))
                        {
                                $editexists = ' and id !=' . 
$values['delivery_id'];
                        }
                        $this->db->query("select count(*) from phpgw_p_delivery 
where d_number='" . $values['delivery_num'] . "'" . 
$editexists,__LINE__,__FILE__);

                        $this->db->next_record();

                        if ($this->db->f(0))
                        {
                                return True;
                        }
                        else
                        {
                                return False;
                        }
                }

                function read_delivery_pos($delivery_id)
                {
                        $this->db->query('SELECT 
phpgw_p_hours.hours_descr,phpgw_p_hours.minperae,phpgw_p_hours.minutes,'
                                                        . 
'phpgw_p_activities.descr,phpgw_p_hours.start_date, phpgw_p_hours.end_date FROM 
phpgw_p_hours,phpgw_p_activities,'
                                                        . 'phpgw_p_deliverypos 
WHERE phpgw_p_deliverypos.hours_id=phpgw_p_hours.id AND 
phpgw_p_deliverypos.delivery_id='
                                                        . intval($delivery_id) 
. ' AND phpgw_p_hours.activity_id=phpgw_p_activities.id',__LINE__,__FILE__);

                        while ($this->db->next_record())
                        {
                                $hours[] = array
                                (
                                        'hours_descr'   => 
$this->db->f('hours_descr'),
                                        'act_descr'             => 
$this->db->f('descr'),
                                        'sdate'                 => 
$this->db->f('start_date'),
                                        'edate'                 => 
$this->db->f('end_date'),
                                        'minutes'               => 
$this->db->f('minutes'),
                                        'minperae'              => 
$this->db->f('minperae')
                                );
                        }
                        return $hours;
                }
        }
?>

--- NEW FILE: class.uibookkeeping.inc.php ---
<?php
        /*******************************************************************\
        * phpGroupWare - Projects                                           *
        * http://www.phpgroupware.org                                       *
        * This program is part of the GNU project, see http://www.gnu.org/      
*
        *                                                                   *
        * Project Manager                                                   *
        * Written by Bettina Gille address@hidden                   *
        * -----------------------------------------------                   *
        * Copyright 2000 - 2003 Free Software Foundation, Inc               *
        *                                                                   *
        * 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  *
[...2234 lines suppressed...]
                        {
                                $values['emonth'] = date('m',time());
                                $values['eday'] = date('d',time());
                                $values['eyear'] = date('Y',time());
                        }
                        else
                        {
                                $values['eday'] = date('d',$values['edate']);
                                $values['emonth'] = date('m',$values['edate']);
                                $values['eyear'] = date('Y',$values['edate']);
                        }

                        
$GLOBALS['phpgw']->template->set_var('end_date_select',$GLOBALS['phpgw']->common->dateformatorder($this->sbox->getYears('values[eyear]',$values['eyear']),
                                                                                
                                                                                
                        
$this->sbox->getMonthText('values[emonth]',$values['emonth']),
                                                                                
                                                                                
                        $this->sbox->getDays('values[eday]',$values['eday'])));

                        $GLOBALS['phpgw']->template->pfp('out','mstone_edit');
                }
        }
?>

--- NEW FILE: class.sobilling.inc.php ---
<?php
        /*******************************************************************\
        * phpGroupWare - Projects                                           *
        * http://www.phpgroupware.org                                       *
        * This program is part of the GNU project, see http://www.gnu.org/      
*
        *                                                                   *
        * Project Manager                                                   *
        * Written by Bettina Gille address@hidden                   *
        * -----------------------------------------------                   *
        * Copyright 2000 - 2003 Free Software Foundation, Inc               *
        *                                                                   *
        * 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., 675 Mass Ave, Cambridge, MA 02139, USA.         *
        \*******************************************************************/
        /* $Id: class.sobilling.inc.php,v 1.1 2003/12/01 16:31:33 ceb Exp $ */
        /* $Source: 
/cvsroot/phpgroupware/bookkeeping/inc/class.sobilling.inc.php,v $ */

        class sobilling
        {
                var $db;
                var $grants;

                function sobilling()
                {
                        $this->db               = $GLOBALS['phpgw']->db;
                        $this->db2              = $this->db;
                        $this->account  = 
$GLOBALS['phpgw_info']['user']['account_id'];
                }

                function return_join()
                {
                        $dbtype = $GLOBALS['phpgw_info']['server']['db_type'];

                        switch ($dbtype)
                        {
                                case 'pgsql':   $join = ' JOIN '; break;
                                case 'mysql':   $join = ' LEFT JOIN '; break;
                        }
                        return $join;
                }

                function read_invoices($values)
                {
                        $project_id = intval($values['project_id']);
                        $sort           = 
(isset($values['sort'])?$values['sort']:'ASC');
                        $order          = $values['order'];
                        $query          = $values['query'];
                        $owner          = ($values['owner'] == 
'yes'?True:False);
                        $limit          = 
(isset($values['limit'])?$values['limit']:True);
                        $start          = intval($values['start']);

                        if ($order)
                        {
                                $ordermethod = " order by $order $sort";
                        }
                        else
                        {
                                $ordermethod = ' order by i_date asc';
                        }

                        if ($query)
                        {
                                $querymethod = " AND (i_number like '%$query%' 
OR title like '%$query%' " . "OR i_sum like '%$query%') ";
                        }

                        if ($owner)
                        {
                                $acl_select = ' AND phpgw_p_invoice.owner=' . 
$this->account;
                        }

                        if ($project_id)
                        {
                                $sql = 'SELECT phpgw_p_invoice.id as 
id,i_number,i_date,phpgw_p_invoice.project_id,phpgw_p_invoice.customer,i_sum,title
 '
                                        . 'FROM 
phpgw_p_invoice,phpgw_p_projects WHERE 
phpgw_p_invoice.project_id=phpgw_p_projects.id '
                                        . 'AND phpgw_p_projects.id=' . 
$project_id . ' AND phpgw_p_invoice.project_id=' . $project_id;
                        }
                        else
                        {
                                $sql = 'SELECT phpgw_p_invoice.id as 
id,i_number,title,i_date,i_sum,phpgw_p_invoice.project_id,phpgw_p_invoice.customer
 '
                                        . 'FROM 
phpgw_p_invoice,phpgw_p_projects WHERE 
phpgw_p_invoice.project_id=phpgw_p_projects.id';
                        }

                        $this->db2->query($sql . $acl_select,__LINE__,__FILE__);
                        $this->total_records = $this->db2->num_rows();

                        if ($limit)
                        {
                                $this->db->limit_query($sql  . $acl_select. 
$querymethod,$start,__LINE__,__FILE__);
                        }
                        else
                        {
                                $this->db->query($sql  . $acl_select. 
$querymethod,__LINE__,__FILE__);
                        }

                        while ($this->db->next_record())
                        {
                                $bill[] = array
                                (
                                        'invoice_id'    => $this->db->f('id'),
                                        'invoice_num'   => 
$this->db->f('i_number'),
                                        'title'                 => 
$this->db->f('title'),
                                        'date'                  => 
$this->db->f('i_date'),
                                        'sum'                   => 
$this->db->f('i_sum'),
                                        'project_id'    => 
$this->db->f('project_id'),
                                        'customer'              => 
$this->db->f('customer')
                                );
                        }
                        return $bill;
                }

                function exists($values)
                {
                        $values['invoice_id'] = intval($values['invoice_id']);

                        if ($values['invoice_id'] && ($values['invoice_id'] != 
0))
                        {
                                $editexists = ' and id !=' . 
$values['invoice_id'];
                        }

                        $this->db->query("select count(*) from phpgw_p_invoice 
where i_number='" . $values['invoice_num'] . "'" . 
$editexists,__LINE__,__FILE__);

                        $this->db->next_record();

                        if ($this->db->f(0))
                        {
                                return True;
                        }
                        else
                        {
                                return False;
                        }
                }

                function invoice($values,$select)
                {
                        $values['invoice_num'] = 
$this->db->db_addslashes($values['invoice_num']);
                        $this->db->query("INSERT INTO phpgw_p_invoice 
(i_number,i_sum,project_id,customer,i_date,owner) VALUES ('" . 
$values['invoice_num'] . "',0,"
                                                        . 
intval($values['project_id']) . ',' . intval($values['customer']) . ',' . 
intval($values['date']) . ',' . $this->account . ')',__LINE__,__FILE__);

                        $this->db2->query("SELECT id from phpgw_p_invoice WHERE 
i_number='" . $values['invoice_num'] . "'",__LINE__,__FILE__);
                        $this->db2->next_record();
                        $invoice_id = $this->db2->f('id');
                        $invoice_id = intval($invoice_id);

                        while(is_array($select) && $entry=each($select))
                        {
                                $this->db->query('INSERT INTO 
phpgw_p_invoicepos (invoice_id,hours_id) VALUES (' . $invoice_id . ',' . 
intval($entry[0]) . ')',__LINE__,__FILE__);
                                $this->db2->query("UPDATE phpgw_p_hours SET 
status='billed' WHERE id=" . intval($entry[0]),__LINE__,__FILE__);
                        }

                        $this->db->query('SELECT billperae,minutes,minperae 
FROM phpgw_p_hours,phpgw_p_invoicepos '
                                                        .'WHERE 
phpgw_p_invoicepos.invoice_id=' . $invoice_id . ' AND 
phpgw_p_hours.id=phpgw_p_invoicepos.hours_id',__LINE__,__FILE__);
                        while ($this->db->next_record())
                        {
                                if 
($GLOBALS['phpgw_info']['user']['preferences']['projects']['bill'] == 'wu')
                                {
                                        $aes = 
ceil($this->db->f('minutes')/$this->db->f('minperae'));
                                        $sum = $this->db->f('billperae')*$aes;
                                        $sum_sum += $sum;
                                }
                                else
                                {
                                        $aes = $this->db->f('minutes')/60;
                                        $sum = $this->db->f('billperae')*$aes;
                                        $sum_sum += $sum;
                                }
                        }
                        $this->db->query('UPDATE phpgw_p_invoice SET 
i_sum=round(' . $sum_sum . ',2) WHERE id=' . $invoice_id,__LINE__,__FILE__);
                        return $invoice_id;
                }

                function update_invoice($values,$select)
                {
                        $values['invoice_num']  = 
$this->db->db_addslashes($values['invoice_num']);
                        $values['invoice_id']   = intval($values['invoice_id']);

                        $this->db->query("UPDATE phpgw_p_invoice set 
i_number='" . $values['invoice_num'] . "',i_date=" . intval($values['date']) . 
',customer='
                                                        . 
intval($values['customer']) . ' WHERE id=' . 
$values['invoice_id'],__LINE__,__FILE__);

                        $this->db2->query('DELETE FROM phpgw_p_invoicepos WHERE 
invoice_id=' . $values['invoice_id'],__LINE__,__FILE__);

                        while(is_array($select) && $entry=each($select))
                        {
                                $this->db->query('INSERT INTO 
phpgw_p_invoicepos (invoice_id,hours_id) VALUES (' . $values['invoice_id'] . ','
                                                                . 
intval($entry[0]) . ')',__LINE__,__FILE__);
                                $this->db2->query("UPDATE phpgw_p_hours SET 
status='billed' WHERE id=" . intval($entry[0]),__LINE__,__FILE__);
                        }

                        $this->db->query('SELECT billperae,minutes,minperae 
FROM phpgw_p_hours,phpgw_p_invoicepos '
                                                        .'WHERE 
phpgw_p_invoicepos.invoice_id=' . $values['invoice_id'] . ' AND 
phpgw_p_hours.id='
                                                        . 
'phpgw_p_invoicepos.hours_id',__LINE__,__FILE__);

                        while($this->db->next_record())
                        {
                                if 
($GLOBALS['phpgw_info']['user']['preferences']['projects']['bill'] == 'wu')
                                {
                                        $aes = 
ceil($this->db->f('minutes')/$this->db->f('minperae'));
                                        $sum = $this->db->f('billperae')*$aes;
                                        $sum_sum += $sum;
                                }
                                else
                                {
                                        $aes = $this->db->f('minutes')/60;
                                        $sum = $this->db->f('billperae')*$aes;
                                        $sum_sum += $sum;
                                }
                        }

                        $this->db2->query('UPDATE phpgw_p_invoice SET 
i_sum=round(' . $sum_sum . ',2) WHERE id=' . 
$values['invoice_id'],__LINE__,__FILE__);
                }

                function read_hours($project_id, $action)
                {
                        $project_id = intval($project_id);

                        $ordermethod = ' order by end_date asc';

                        if ($action == 'mains')
                        {
                                $parent_hours   = ' OR 
phpgw_p_hours.pro_parent=' . $project_id;
                        }

                        $this->db->query('SELECT phpgw_p_hours.id as 
id,phpgw_p_hours.hours_descr,phpgw_p_activities.descr,phpgw_p_hours.status,'
                                                . 
'phpgw_p_hours.start_date,phpgw_p_hours.end_date,phpgw_p_hours.minutes,phpgw_p_hours.minperae,phpgw_p_hours.billperae,'
                                                . 'phpgw_p_hours.employee FROM 
phpgw_p_hours ' . $this->return_join() . ' phpgw_p_activities ON '
                                                . 
'phpgw_p_hours.activity_id=phpgw_p_activities.id ' . $this->return_join() . ' 
phpgw_p_projectactivities ON '
                                                . 
"phpgw_p_hours.activity_id=phpgw_p_projectactivities.activity_id WHERE 
(phpgw_p_hours.status='done' OR "
                                                . 
"phpgw_p_hours.status='closed') AND (phpgw_p_hours.project_id=" . $project_id . 
$parent_hours . ') AND '
                                                . 
'phpgw_p_projectactivities.project_id=' . $project_id . " AND 
phpgw_p_projectactivities.billable='Y' "
                                                . 'AND 
phpgw_p_projectactivities.activity_id=phpgw_p_hours.activity_id' . 
$ordermethod,__LINE__,__FILE__);

                        while ($this->db->next_record())
                        {
                                $hours[] = array
                                (
                                        'hours_id'              => 
$this->db->f('id'),
                                        'hours_descr'   => 
$this->db->f('hours_descr'),
                                        'act_descr'             => 
$this->db->f('descr'),
                                        'status'                => 
$this->db->f('status'),
                                        'sdate'                 => 
$this->db->f('start_date'),
                                        'edate'                 => 
$this->db->f('end_date'),
                                        'minutes'               => 
$this->db->f('minutes'),
                                        'minperae'              => 
$this->db->f('minperae'),
                                        'billperae'             => 
$this->db->f('billperae'),
                                        'employee'              => 
$this->db->f('employee')
                                );
                        }
                        return $hours;
                }

                function read_invoice_hours($project_id, $invoice_id, $action)
                {
                        $project_id = intval($project_id);

                        $ordermethod = ' order by end_date asc';

                        if ($action == 'mains' || $action == 'amains')
                        {
                                $parent_search = ' OR 
phpgw_p_hours.pro_parent=' . $project_id;
                        }

                        $this->db->query('SELECT phpgw_p_hours.id as 
id,phpgw_p_hours.hours_descr,phpgw_p_activities.descr,phpgw_p_hours.status,'
                                                . 
'phpgw_p_hours.start_date,phpgw_p_hours.end_date,phpgw_p_hours.minutes,phpgw_p_hours.minperae,phpgw_p_hours.billperae
 FROM '
                                                . 'phpgw_p_hours ' . 
$this->return_join() . ' phpgw_p_activities ON 
phpgw_p_hours.activity_id=phpgw_p_activities.id '
                                                . $this->return_join() . ' 
phpgw_p_invoicepos ON phpgw_p_invoicepos.hours_id=phpgw_p_hours.id WHERE '
                                                . '(phpgw_p_hours.project_id=' 
. $project_id . $parent_search . ') AND phpgw_p_invoicepos.invoice_id='
                                                . intval($invoice_id) . 
$ordermethod,__LINE__,__FILE__);

                        while ($this->db->next_record())
                        {
                                $hours[] = array
                                (
                                        'hours_id'              => 
$this->db->f('id'),
                                        'hours_descr'   => 
$this->db->f('hours_descr'),
                                        'act_descr'             => 
$this->db->f('descr'),
                                        'status'                => 
$this->db->f('status'),
                                        'sdate'                 => 
$this->db->f('start_date'),
                                        'edate'                 => 
$this->db->f('end_date'),
                                        'minutes'               => 
$this->db->f('minutes'),
                                        'minperae'              => 
$this->db->f('minperae'),
                                        'billperae'             => 
$this->db->f('billperae'),
                                        'employee'              => 
$this->db->f('employee')
                                );
                        }
                        return $hours;
                }

                function read_single_invoice($invoice_id)
                {
                        $this->db->query('SELECT 
phpgw_p_invoice.customer,i_number,phpgw_p_invoice.project_id,i_date,i_sum,title,p_number
 '
                                                        . 'FROM 
phpgw_p_invoice,phpgw_p_projects WHERE phpgw_p_invoice.id=' . 
intval($invoice_id)
                                                        . ' AND 
phpgw_p_invoice.project_id=phpgw_p_projects.id',__LINE__,__FILE__);

                        if ($this->db->next_record())
                        {
                                $bill['date']                   = 
$this->db->f('i_date');
                                $bill['invoice_num']    = 
$this->db->f('i_number');
                                $bill['title']                  = 
$this->db->f('title');
                                $bill['customer']               = 
$this->db->f('customer');
                                $bill['project_id']             = 
$this->db->f('project_id');
                                $bill['project_num']    = 
$this->db->f('p_number');
                                $bill['sum']                    = 
$this->db->f('i_sum');
                        }
                        return $bill;
                }

                function read_invoice_pos($invoice_id)
                {
                        $this->db->query('SELECT 
phpgw_p_hours.minutes,phpgw_p_hours.minperae,phpgw_p_hours.hours_descr,phpgw_p_hours.billperae,'
                                        . 
'phpgw_p_activities.descr,phpgw_p_hours.start_date,phpgw_p_hours.end_date FROM 
phpgw_p_hours,phpgw_p_activities,'
                                        . 'phpgw_p_invoicepos WHERE 
phpgw_p_invoicepos.hours_id=phpgw_p_hours.id AND phpgw_p_invoicepos.invoice_id='
                                        . $invoice_id . ' AND 
phpgw_p_hours.activity_id=phpgw_p_activities.id',__LINE__,__FILE__);

                        while ($this->db->next_record())
                        {
                                $hours[] = array
                                (
                                        'hours_descr'   => 
$this->db->f('hours_descr'),
                                        'act_descr'             => 
$this->db->f('descr'),
                                        'sdate'                 => 
$this->db->f('start_date'),
                                        'edate'                 => 
$this->db->f('end_date'),
                                        'minutes'               => 
$this->db->f('minutes'),
                                        'minperae'              => 
$this->db->f('minperae'),
                                        'billperae'             => 
$this->db->f('billperae')
                                );
                        }
                        return $hours;
                }
        }
?>

--- NEW FILE: class.bobookkeeping.inc.php ---
<?php
        /*******************************************************************\
        * phpGroupWare - Projects                                           *
        * http://www.phpgroupware.org                                       *
        * This program is part of the GNU project, see http://www.gnu.org/      
*
        *                                                                   *
        * Project Manager                                                   *
        * Written by Bettina Gille address@hidden                   *
        * -----------------------------------------------                   *
        * Copyright 2000 - 2003 Free Software Foundation, Inc               *
        *                                                                   *
        * 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  *
[...1113 lines suppressed...]
                                        }
                                }
                                //unset($prefs);
                        }
                        return $returncode;
                }

                function get_site_config()
                {
                        $this->config = 
CreateObject('phpgwapi.config','projects');
                        $this->config->read_repository();

                        if ($this->config->config_data)
                        {
                                $items = $this->config->config_data;
                        }
                        return $items;
                }
        }
?>

--- NEW FILE: class.uideliveries.inc.php ---
<?php
        /*******************************************************************\
        * phpGroupWare - Projects                                           *
        * http://www.phpgroupware.org                                       *
        * This program is part of the GNU project, see http://www.gnu.org/      
*
        *                                                                   *
        * Project Manager                                                   *
        * Written by Bettina Gille address@hidden                   *
        * -----------------------------------------------                   *
        * Copyright 2000 - 2003 Free Software Foundation, Inc               *
        *                                                                   *
        * 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., 675 Mass Ave, Cambridge, MA 02139, USA.         *
        \*******************************************************************/
        /* $Id: class.uideliveries.inc.php,v 1.1 2003/12/01 16:31:33 ceb Exp $ 
*/
        // $Source: 
/cvsroot/phpgroupware/bookkeeping/inc/class.uideliveries.inc.php,v $

        class uideliveries
        {
                var $action;
                var $grants;
                var $start;
                var $filter;
                var $sort;
                var $order;
                var $cat_id;

                var $public_functions = array
                (
                        'list_projects'         => True,
                        'delivery'                      => True,
                        'list_deliveries'       => True,
                        'show_delivery'         => True,
                        'fail'                          => True
                );

                function uideliveries()
                {
                        $action = get_var('action',array('POST','GET'));

                        $this->boprojects                               = 
CreateObject('projects.boprojects',True, $action);
                        $this->bodeliveries                             = 
CreateObject('bookkeeping.bodeliveries');
                        $this->nextmatchs                               = 
CreateObject('phpgwapi.nextmatchs');
                        $this->sbox                                             
= CreateObject('phpgwapi.sbox');
                        $this->cats                                             
= CreateObject('phpgwapi.categories');
                        $this->account                                  = 
$GLOBALS['phpgw_info']['user']['account_id'];
                        $this->grants                                   = 
$GLOBALS['phpgw']->acl->get_grants('projects');
                        $this->grants[$this->account]   = PHPGW_ACL_READ + 
PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;

                        $this->start                                    = 
$this->boprojects->start;
                        $this->query                                    = 
$this->boprojects->query;
                        $this->filter                                   = 
$this->boprojects->filter;
                        $this->order                                    = 
$this->boprojects->order;
                        $this->sort                                             
= $this->boprojects->sort;
                        $this->cat_id                                   = 
$this->boprojects->cat_id;
                }

                function save_sessiondata($action)
                {
                        $data = array
                        (
                                'start'         => $this->start,
                                'query'         => $this->query,
                                'filter'        => $this->filter,
                                'order'         => $this->order,
                                'sort'          => $this->sort,
                                'cat_id'        => $this->cat_id
                        );
                        $this->boprojects->save_sessiondata($data, $action);
                }

                function set_app_langs()
                {
                        
$GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
                        
$GLOBALS['phpgw']->template->set_var('row_on',$GLOBALS['phpgw_info']['theme']['row_on']);
                        
$GLOBALS['phpgw']->template->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']);

                        
$GLOBALS['phpgw']->template->set_var('lang_category',lang('Category'));
                        
$GLOBALS['phpgw']->template->set_var('lang_select',lang('Select'));
                        
$GLOBALS['phpgw']->template->set_var('lang_descr',lang('Description'));
                        
$GLOBALS['phpgw']->template->set_var('lang_title',lang('Title'));
                        
$GLOBALS['phpgw']->template->set_var('lang_none',lang('None'));
                        
$GLOBALS['phpgw']->template->set_var('lang_start_date',lang('Start Date'));
                        
$GLOBALS['phpgw']->template->set_var('lang_end_date',lang('End Date'));
                        
$GLOBALS['phpgw']->template->set_var('lang_work_date',lang('Work date'));
                        
$GLOBALS['phpgw']->template->set_var('lang_title',lang('Title'));
                        
$GLOBALS['phpgw']->template->set_var('lang_status',lang('Status'));
                        
$GLOBALS['phpgw']->template->set_var('lang_budget',lang('Budget'));
                        
$GLOBALS['phpgw']->template->set_var('lang_customer',lang('Customer'));
                        
$GLOBALS['phpgw']->template->set_var('lang_coordinator',lang('Coordinator'));
                        
$GLOBALS['phpgw']->template->set_var('lang_edit',lang('Edit'));
                        
$GLOBALS['phpgw']->template->set_var('lang_done',lang('Done'));
                        
$GLOBALS['phpgw']->template->set_var('lang_hours',lang('Work hours'));
                        
$GLOBALS['phpgw']->template->set_var('lang_project_num',lang('Project ID'));
                        
$GLOBALS['phpgw']->template->set_var('lang_project',lang('Project'));
                        
$GLOBALS['phpgw']->template->set_var('lang_stats',lang('Statistics'));
                        
$GLOBALS['phpgw']->template->set_var('lang_delivery_num',lang('Delivery ID'));
                        
$GLOBALS['phpgw']->template->set_var('lang_delivery_date',lang('Delivery 
date'));
                        
$GLOBALS['phpgw']->template->set_var('lang_activity',lang('Activity'));
                        
$GLOBALS['phpgw']->template->set_var('lang_select',lang('Select'));
                        
$GLOBALS['phpgw']->template->set_var('lang_print_delivery',lang('Print 
delivery'));
                        
$GLOBALS['phpgw']->template->set_var('lang_sumaes',lang('Sum workunits'));
                        
$GLOBALS['phpgw']->template->set_var('lang_position',lang('Position'));
                        
$GLOBALS['phpgw']->template->set_var('lang_workunits',lang('Workunits'));
                        
$GLOBALS['phpgw']->template->set_var('lang_delivery_date',lang('Delivery 
date'));
                        
$GLOBALS['phpgw']->template->set_var('lang_work_date',lang('Work date'));
                        
$GLOBALS['phpgw']->template->set_var('lang_submit',lang('Submit'));
                        
$GLOBALS['phpgw']->template->set_var('lang_jobs',lang('Jobs'));
                }

                function display_app_header()
                {
                        if 
($GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'] != 
'idots')
                        {
                                
$GLOBALS['phpgw']->template->set_file(array('header' => 'header.tpl'));
                                
$GLOBALS['phpgw']->template->set_block('header','projects_header');

                                
$GLOBALS['phpgw']->template->set_var('link_billing',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uibilling.list_projects&action=mains'));
                                
$GLOBALS['phpgw']->template->set_var('lang_billing',lang('Billing'));
                                
$GLOBALS['phpgw']->template->set_var('link_delivery',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uideliveries.list_projects&action=mains'));
                                
$GLOBALS['phpgw']->template->set_var('lang_delivery',lang('Deliveries'));

                                
$GLOBALS['phpgw']->template->fp('app_header','projects_header');
                        }
                        $this->set_app_langs();
                        $GLOBALS['phpgw']->common->phpgw_header();
                        echo parse_navbar();
                }

                function list_projects()
                {
                        $action         = get_var('action',array('POST','GET'));
                        $pro_parent     = 
get_var('pro_parent',array('POST','GET'));

                        $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . ($pro_parent?lang('list jobs'):lang('list projects'));
                        $this->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('projects_list_t' => 
'bill_list.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('projects_list_t','projects_list','list');

                        if (!$action)
                        {
                                $action = 'mains';
                        }

                        $link_data = array
                        (
                                'menuaction'    => 
'projects.uideliveries.list_projects',
                                'pro_parent'    => $pro_parent,
                                'action'                => $action,
                                'cat_id'                => $this->cat_id
                        );

                        if (!$this->start)
                        {
                                $this->start = 0;
                        }

                        if (!$pro_parent)
                        {
                                $pro_parent = 0;
                        }

                        $pro = 
$this->boprojects->list_projects($this->start,True,$this->query,$this->filter,$this->sort,$this->order,'active',$this->cat_id,$action,$pro_parent);

// --------------------- nextmatch variable template-declarations 
------------------------

                        $left = 
$this->nextmatchs->left('/index.php',$this->start,$this->boprojects->total_records,$link_data);
                        $right = 
$this->nextmatchs->right('/index.php',$this->start,$this->boprojects->total_records,$link_data);
                        $GLOBALS['phpgw']->template->set_var('left',$left);
                        $GLOBALS['phpgw']->template->set_var('right',$right);

                        
$GLOBALS['phpgw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->boprojects->total_records,$this->start));

// ------------------------- end nextmatch template 
--------------------------------------

                        if ($action == 'mains')
                        {
                                $action_list= '<form method="POST" action="' . 
$GLOBALS['phpgw']->link('/index.php',$link_data) . '" name="form">' . "\n"
                                                        . '<select 
name="cat_id" onChange="this.form.submit();"><option value="">' . lang('Select 
category') . '</option>' . "\n"
                                                        . 
$this->cats->formatted_list('select','all',$this->cat_id,True) . '</select>';
                                
$GLOBALS['phpgw']->template->set_var(lang_header,lang('Project list'));
                        }
                        else
                        {
                                $action_list= '<form method="POST" action="' . 
$GLOBALS['phpgw']->link('/index.php',$link_data) .'" name="form">' . "\n"
                                                        . '<select 
name="pro_parent" onChange="this.form.submit();"><option value="">' . 
lang('Select main project') . '</option>' . "\n"
                                                        . 
$this->boprojects->select_project_list('mains', $status, $pro_parent) . 
'</select>';
                                
$GLOBALS['phpgw']->template->set_var('lang_header',lang('Job list'));
                        }

                        $GLOBALS['filter']      = $this->filter;
                        $GLOBALS['query']       = $this->query;

                        
$GLOBALS['phpgw']->template->set_var('action_list',$action_list);
                        
$GLOBALS['phpgw']->template->set_var('filter_action',$GLOBALS['phpgw']->link('/index.php',$link_data));
                        
$GLOBALS['phpgw']->template->set_var('filter_list',$this->nextmatchs->new_filter($this->filter));
                        
$GLOBALS['phpgw']->template->set_var('search_action',$GLOBALS['phpgw']->link('/index.php',$link_data));
                        
$GLOBALS['phpgw']->template->set_var('search_list',$this->nextmatchs->search(array('query'
 => $this->query)));

// ---------------- list header variable template-declarations 
--------------------------

                        
$GLOBALS['phpgw']->template->set_var(sort_number,$this->nextmatchs->show_sort_order($this->sort,'num',$this->order,'/index.php',lang('Project
 ID'),$link_data));

                        if ($action == 'mains')
                        {
                                
$GLOBALS['phpgw']->template->set_var(sort_action,$this->nextmatchs->show_sort_order($this->sort,'customer',$this->order,'/index.php',lang('Customer'),$link_data));
                                $lang_action = '<td width="5%" align="center">' 
. lang('Jobs') . '</td>' . "\n";
                                
$GLOBALS['phpgw']->template->set_var('lang_action',$lang_action);
                        }
                        else
                        {
                                
$GLOBALS['phpgw']->template->set_var(sort_action,$this->nextmatchs->show_sort_order($this->sort,'start_date',$this->order,'/index.php',lang('Start
 date'),$link_data));
                                
$GLOBALS['phpgw']->template->set_var('lang_action','');
                        }

                        
$GLOBALS['phpgw']->template->set_var('sort_status',$this->nextmatchs->show_sort_order($this->sort,'status',$this->order,'/index.php',lang('Status'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_title',$this->nextmatchs->show_sort_order($this->sort,'title',$this->order,'/index.php',lang('Title'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_end_date',$this->nextmatchs->show_sort_order($this->sort,'end_date',$this->order,'/index.php',lang('Date
 due'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_coordinator',$this->nextmatchs->show_sort_order($this->sort,'coordinator',$this->order,'/index.php',lang('Coordinator'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('h_lang_part',lang('Delivery note'));
                        
$GLOBALS['phpgw']->template->set_var('h_lang_partlist',lang('Delivery list'));

// -------------- end header declaration ---------------------------------------

            for ($i=0;$i<count($pro);$i++)
            {
                                
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);
                                $edate = $pro[$i]['edate'];
                                if ($edate == 0)
                                {
                                        $edateout = '&nbsp;';
                                }
                                else
                                {
                                        $month  = 
$GLOBALS['phpgw']->common->show_date(time(),'n');
                                        $day    = 
$GLOBALS['phpgw']->common->show_date(time(),'d');
                                        $year   = 
$GLOBALS['phpgw']->common->show_date(time(),'Y');

                                        $edate = $edate + (60*60) * 
$GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'];
                                        $edateout = 
$GLOBALS['phpgw']->common->show_date($edate,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
                                        if (mktime(2,0,0,$month,$day,$year) == 
$edate) { $edateout = '<b>' . $edateout . '</b>'; }
                                        if (mktime(2,0,0,$month,$day,$year) >= 
$edate) { $edateout = '<font color="CC0000"><b>' . $edateout . '</b></font>'; }
                                }

                                if ($action == 'mains')
                                {
                                        $td_action = 
($pro[$i]['customerout']?$pro[$i]['customerout']:'&nbsp;');
                                }
                                else
                                {
                                        $td_action = 
($pro[$i]['sdateout']?$pro[$i]['sdateout']:'&nbsp;');
                                }

// --------------- template declaration for list records 
-------------------------------------

                                $GLOBALS['phpgw']->template->set_var(array
                                (
                                        'number'                => 
$pro[$i]['number'],
                                        'td_action'             => $td_action,
                                        'status'                => 
lang($pro[$i]['status']),
                                        'title'                 => 
($pro[$i]['title']?$pro[$i]['title']:'&nbsp;'),
                                        'end_date'              => $edateout,
                                        'coordinator'   => 
$pro[$i]['coordinatorout']
                                ));

                                $link_data['project_id'] = 
$pro[$i]['project_id'];
                                $link_data['menuaction'] = 
'projects.uideliveries.delivery';

                                
$GLOBALS['phpgw']->template->set_var('part',$GLOBALS['phpgw']->link('/index.php',$link_data));
                                
$GLOBALS['phpgw']->template->set_var('lang_part',lang('Delivery'));

                                $link_data['menuaction']        = 
'projects.uideliveries.list_deliveries';
                                $link_data['action']            = 'del';
                                
$GLOBALS['phpgw']->template->set_var('partlist',$GLOBALS['phpgw']->link('/index.php',$link_data));
                                
$GLOBALS['phpgw']->template->set_var('lang_partlist',lang('Delivery list'));

                                if ($action == 'mains')
                                {
                                        $action_entry = '<td align="center"><a 
href="' . 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uideliveries.list_projects'
                                                                                
                                                . '&pro_parent=' . 
$pro[$i]['project_id'] . '&action=subs') . '">' . lang('Jobs')
                                                                                
                                                . '</a></td>' . "\n";
                                        
$GLOBALS['phpgw']->template->set_var('action_entry',$action_entry);
                                }
                                else
                                {
                                        
$GLOBALS['phpgw']->template->set_var('action_entry','');
                                }

                                
$GLOBALS['phpgw']->template->parse('list','projects_list',True);
                        }

// ------------------------- end record declaration ------------------------

                        
$GLOBALS['phpgw']->template->set_var('lang_all_partlist',lang('All delivery 
notes'));
                        
$GLOBALS['phpgw']->template->set_var('all_partlist',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uideliveries.list_deliveries&action=del'
                                                                                
        . '&project_id='));

                        
$GLOBALS['phpgw']->template->set_var('lang_all_part2list','');
                        
$GLOBALS['phpgw']->template->set_var('all_part2list','');

                        
$GLOBALS['phpgw']->template->pfp('out','projects_list_t',True);
                        $this->save_sessiondata($action);
                }

                function delivery()
                {
                        $action                 = 
get_var('action',array('POST','GET'));
                        $project_id             = 
get_var('project_id',array('POST','GET'));

                        $Delivery               = 
get_var('Delivery',array('POST','GET'));
                        $delivery_id    = 
get_var('delivery_id',array('POST','GET'));

                        $values                 = 
get_var('values',array('POST'));
                        $select                 = 
get_var('select',array('POST'));
                        $referer                = 
get_var('referer',array('POST'));

                        if (! $Delivery)
                        {
                                $referer = 
$GLOBALS['HTTP_SERVER_VARS']['HTTP_REFERER'] ? 
$GLOBALS['HTTP_SERVER_VARS']['HTTP_REFERER'] : $GLOBALS['HTTP_REFERER'];
                        }

                        if (!$project_id)
                        {
                                Header('Location: ' . $referer);
                        }

                        $nopref = $this->boprojects->check_prefs();
                        if (is_array($nopref))
                        {
                                
$GLOBALS['phpgw']->template->set_var('pref_message',$GLOBALS['phpgw']->common->error_list($nopref));
                        }
                        else
                        {
                                $prefs = $this->boprojects->get_prefs();
                        }

                        if ($Delivery)
                        {
                                $values['project_id']   = $project_id;
                                $pro = 
$this->boprojects->read_single_project($project_id);
                                $values['customer']             = 
$pro['customer'];

                                if ($delivery_id)
                                {
                                        $values['delivery_id'] = $delivery_id;
                                }

                                $error = 
$this->bodeliveries->check_values($values, $select);
                                if (is_array($error))
                                {
                                        
$GLOBALS['phpgw']->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error));
                                }
                                else
                                {
                                        if ($delivery_id)
                                        {
                                                
$this->bodeliveries->update_delivery($values, $select);
                                        }
                                        else
                                        {
                                                $delivery_id = 
$this->bodeliveries->delivery($values, $select);
                                        }
                                }
                        }

                        $link_data = array
                        (
                                'menuaction'    => 
'projects.uideliveries.delivery',
                                'pro_parent'    => $pro_parent,
                                'action'                => $action,
                                'project_id'    => $project_id,
                                'delivery_id'   => $delivery_id
                        );

                        $this->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('hours_list_t' => 
'del_listhours.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('hours_list_t','hours_list','list');

                        $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('create delivery');

                        
$GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data));

                        
$GLOBALS['phpgw']->template->set_var('hidden_vars','<input type="hidden" 
name="referer" value="' . $referer . '">');
                        
$GLOBALS['phpgw']->template->set_var('doneurl',$referer);

                        $pro = 
$this->boprojects->read_single_project($project_id);

                        $title = $GLOBALS['phpgw']->strip_html($pro['title']);
                        if (! $title)  $title  = '&nbsp;';
                        $GLOBALS['phpgw']->template->set_var('project',$title . 
' [' . $GLOBALS['phpgw']->strip_html($pro['number']) . ']');

                        if (!$pro['customer'])
                        {
                                
$GLOBALS['phpgw']->template->set_var('customer',lang('You have no customer 
selected !'));
                        }
                        else
                        {
                                $customer = 
$this->boprojects->read_single_contact($pro['customer']);
                                if (!$customer[0]['org_name']) { $customername 
= $customer[0]['n_given'] . ' ' . $customer[0]['n_family']; }
                                else { $customername = $customer[0]['org_name'] 
. ' [ ' . $customer[0]['n_given'] . ' ' . $customer[0]['n_family'] . ' ]'; }
                                
$GLOBALS['phpgw']->template->set_var('customer',$customername);
                        }

                        if(!$delivery_id)
                        {
                                
$GLOBALS['phpgw']->template->set_var('lang_choose',lang('Generate Delivery ID 
?'));
                                
$GLOBALS['phpgw']->template->set_var('choose','<input type="checkbox" 
name="values[choose]" value="True">');
                                
$GLOBALS['phpgw']->template->set_var('print_delivery',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uideliveries.fail'));
                                
$GLOBALS['phpgw']->template->set_var('delivery_num',$values['delivery_num']);
                                $hours = 
$this->bodeliveries->read_hours($project_id, $action);
                        }
                        else
                        {
                                
$GLOBALS['phpgw']->template->set_var('lang_choose','');
                                
$GLOBALS['phpgw']->template->set_var('choose','');
                                
$GLOBALS['phpgw']->template->set_var('print_delivery',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uideliveries.show_delivery'
                                                                                
                                                                . 
'&delivery_id=' . $delivery_id));
                                $del = 
$this->bodeliveries->read_single_delivery($delivery_id);
                                
$GLOBALS['phpgw']->template->set_var('delivery_num',$del['delivery_num']);
                                $hours = 
$this->bodeliveries->read_delivery_hours($project_id, $delivery_id, $action);
                        }

                        if ($del['date'])
                        {
                                $values['month'] = date('m',$del['date']);
                                $values['day'] = date('d',$del['date']);
                                $values['year'] = date('Y',$del['date']);
                        }
                        else
                        {
                                $values['month'] = date('m',time());
                                $values['day'] = date('d',time());
                                $values['year'] = date('Y',time());
                        }

                        
$GLOBALS['phpgw']->template->set_var('date_select',$GLOBALS['phpgw']->common->dateformatorder($this->sbox->getYears('values[year]',$values['year']),
                                                                                
                                                                                
$this->sbox->getMonthText('values[month]',$values['month']),
                                                                                
                                                                                
$this->sbox->getDays('values[day]',$values['day'])));

                        if ($prefs['bill'] == 'wu')
                        {
                                
$GLOBALS['phpgw']->template->set_var('lang_sumaes',lang('Sum workunits'));
                                
$GLOBALS['phpgw']->template->set_var('lang_workunits',lang('Workunits'));
                        }
                        else
                        {
                                
$GLOBALS['phpgw']->template->set_var('lang_sumaes',lang('Sum hours'));
                                
$GLOBALS['phpgw']->template->set_var('lang_workunits',lang('Hours'));
                        }

                        $sumaes=0;
                        if (is_array($hours))
                        {
                                while (list($null,$note) = each($hours))
                                {
                                        
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);

                                        $select = '<input type="checkbox" 
name="select[' . $note['hours_id'] . ']" value="True" checked>';

                                        $activity = 
$GLOBALS['phpgw']->strip_html($note['act_descr']);
                                        if (! $activity)  $activity  = '&nbsp;';

                                        $hours_descr = 
$GLOBALS['phpgw']->strip_html($note['hours_descr']);
                                        if (! $hours_descr)  $hours_descr  = 
'&nbsp;';

                                        $start_date = $note['sdate'];
                                        if ($start_date == 0) { $start_dateout 
= '&nbsp;'; }
                                        else
                                        {
                                                $start_date = $start_date + 
(60*60) * $GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'];
                                                $start_dateout = 
$GLOBALS['phpgw']->common->show_date($start_date,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
                                        }

                                        if ($prefs['bill'] == 'wu')
                                        {
                                                if ($note['minperae'] != 0)
                                                {
                                                        $aes = 
ceil($note['minutes']/$note['minperae']);
                                                }
                                                $sumaes += $aes;
                                        }
                                        else
                                        {
                                                $aes = 
floor($note['minutes']/60) . ':'
                                                                . 
sprintf("%02d",(int)($note['minutes']-floor($note['minutes']/60)*60));

                                                $sumhours += $note['minutes'];
                                                $sumaes = floor($sumhours/60) . 
':'
                                                                . 
sprintf("%02d",(int)($sumhours-floor($sumhours/60)*60));
                                        }
// --------------------- template declaration for list records 
---------------------------

                                        
$GLOBALS['phpgw']->template->set_var(array('select' => $select,
                                                                                
'activity' => $activity,
                                                                        
'hours_descr' => $hours_descr,
                                                                                
'status' => lang($note['status']),
                                                                        
'start_date' => $start_dateout,
                                                                                
        'aes' => $aes));

                                        if (($note['status'] != 'billed') && 
($note['status'] != 'closed'))
                                        {
                                                $link_data['menuaction']        
= 'projects.uiprojecthours.edit_hours';
                                                $link_data['hours_id']          
= $note['hours_id'];
                                                
$GLOBALS['phpgw']->template->set_var('edithour',$GLOBALS['phpgw']->link('/index.php',$link_data));
                                                
$GLOBALS['phpgw']->template->set_var('lang_edit_entry',lang('Edit'));
                                        }
                                        else
                                        {
                                                
$GLOBALS['phpgw']->template->set_var('edithour','');
                                                
$GLOBALS['phpgw']->template->set_var('lang_edit_entry','&nbsp;');
                                        }
                                        
$GLOBALS['phpgw']->template->fp('list','hours_list',True);

// -------------------------- end record declaration --------------------------
                                }
                        }

                        if ($delivery_id && ($action != 'amains') && ($action 
!= 'asubs'))
                        {
                                $hours = 
$this->bodeliveries->read_hours($project_id, $action);
                                if (is_array($hours))
                                {
                                        while (list($null,$note) = each($hours))
                                        {
                                                
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);

                                                $select = '<input 
type="checkbox" name="select[' . $note['hours_id'] . ']" value="True">';

                                                $activity = 
$GLOBALS['phpgw']->strip_html($note['act_descr']);
                                                if (! $activity)  $activity  = 
'&nbsp;';
        
                                                $hours_descr = 
$GLOBALS['phpgw']->strip_html($note['hours_descr']);
                                                if (! $hours_descr)  
$hours_descr  = '&nbsp;';

                                                $start_date = $note['sdate'];
                                                if ($start_date == 0) { 
$start_dateout = '&nbsp;'; }
                                                else
                                                {
                                                        $start_date = 
$start_date + (60*60) * 
$GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'];
                                                        $start_dateout = 
$GLOBALS['phpgw']->common->show_date($start_date,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
                                                }

                                        if ($prefs['bill'] == 'wu')
                                        {
                                                if ($note['minperae'] != 0)
                                                {
                                                        $aes = 
ceil($note['minutes']/$note['minperae']);
                                                }
                                        //      $sumaes += $aes;
                                        }
                                        else
                                        {
                                                $aes = 
floor($note['minutes']/60) . ':'
                                                                . 
sprintf("%02d",(int)($note['minutes']-floor($note['minutes']/60)*60));

                                        /*      $sumhours += $note['minutes'];
                                                $sumaes = floor($sumhours/60) . 
':'
                                                                . 
sprintf("%02d",(int)($sumhours-floor($sumhours/60)*60)); */
                                        }

// --------------------- template declaration for list records 
---------------------------

                                                
$GLOBALS['phpgw']->template->set_var(array('select' => $select,
                                                                                
        'activity' => $activity,
                                                                                
'hours_descr' => $hours_descr,
                                                                                
        'status' => lang($note['status']),
                                                                                
'start_date' => $start_dateout,
                                                                                
        '       aes' => $aes));

                                                if (($note['status'] != 
'billed') && ($note['status'] != 'closed'))
                                                {
                                                        
$link_data['menuaction']        = 'projects.uiprojecthours.edit_hours';
                                                        $link_data['hours_id']  
        = $note['hours_id'];
                                                        
$GLOBALS['phpgw']->template->set_var('edithour',$GLOBALS['phpgw']->link('/index.php',$link_data));
                                                        
$GLOBALS['phpgw']->template->set_var('lang_edit_entry',lang('Edit'));
                                                }
                                                else
                                                {
                                                        
$GLOBALS['phpgw']->template->set_var('edithour','');
                                                        
$GLOBALS['phpgw']->template->set_var('lang_edit_entry','&nbsp;');
                                                }
                                                
$GLOBALS['phpgw']->template->fp('list','hours_list',True);

// -------------------------- end record declaration --------------------------
                                        }
                                }
                        }

                        $GLOBALS['phpgw']->template->set_var(sum_aes,$sumaes);

                        if (! $delivery_id)
                        {
                                
$GLOBALS['phpgw']->template->set_var('delivery','<input type="submit" 
name="Delivery" value="' . lang('Create delivery') . '">');
                        } 
                        else
                        {
                                
$GLOBALS['phpgw']->template->set_var('delivery','<input type="submit" 
name="Delivery" value="' . lang('Update delivery') . '">');
                        }

                        if ($action == 'amains' || $action == 'asubs')
                        {
                                
$GLOBALS['phpgw']->template->set_var('delivery','');
                        }

                        
$GLOBALS['phpgw']->template->pfp('out','hours_list_t',True);
                }

                function list_deliveries()
                {
                        $action         = get_var('action',array('POST','GET'));
                        $project_id     = 
get_var('project_id',array('POST','GET'));

                        $this->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('projects_list_t' => 
'bill_listinvoice.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('projects_list_t','projects_list','list');

                        $link_data = array
                        (
                                'menuaction'    => 
'projects.uideliveries.list_deliveries',
                                'action'                => $action,
                                'project_id'    => $project_id
                        );

                        $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('list deliveries');

                        
$GLOBALS['phpgw']->template->set_var('search_action',$GLOBALS['phpgw']->link('/index.php',$link_data));
                        
$GLOBALS['phpgw']->template->set_var('search_list',$this->nextmatchs->search(array('query'
 => $this->query)));

                        if (! $this->start)
                        {
                                $this->start = 0;
                        }

                        if (!$project_id)
                        {
                                $project_id = '';
                        }

                        $del = 
$this->bodeliveries->read_deliveries($this->start, $this->query, $this->sort, 
$this->order, True, $project_id);

// -------------------- nextmatch variable template-declarations 
-----------------------------

                        $left = 
$this->nextmatchs->left('/index.php',$this->start,$this->bodeliveries->total_records,$link_data);
                        $right = 
$this->nextmatchs->right('/index.php',$this->start,$this->bodeliveries->total_records,$link_data);
                        $GLOBALS['phpgw']->template->set_var('left',$left);
                        $GLOBALS['phpgw']->template->set_var('right',$right);

                        
$GLOBALS['phpgw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->bodeliveries->total_records,$this->start));

// ------------------------ end nextmatch template 
-------------------------------------------

// ---------------- list header variable template-declarations 
-------------------------------

                        
$GLOBALS['phpgw']->template->set_var('sort_num',$this->nextmatchs->show_sort_order($this->sort,'num',$this->order,'/index.php',lang('Delivery
 ID'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_customer',$this->nextmatchs->show_sort_order($this->sort,'customer',$this->order,'/index.php',lang('Customer'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_title',$this->nextmatchs->show_sort_order($this->sort,'title',$this->order,'/index.php',lang('Title'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_date',$this->nextmatchs->show_sort_order($this->sort,'date',$this->order,'/index.php',lang('Date'),$link_data));
                        $GLOBALS['phpgw']->template->set_var('sort_sum','');
                        
$GLOBALS['phpgw']->template->set_var('lang_data',lang('Delivery'));

// -------------- end header declaration -----------------

                        if (is_array($del))
                        {
                                while (list($null,$note) = each($del))
                                {
                                        
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);
                                        $title = 
$GLOBALS['phpgw']->strip_html($note['title']);
                                        if (! $title) $title  = '&nbsp;';

                                        $date = $note['date'];
                                        if ($date == 0)
                                                $dateout = '&nbsp;';
                                        else
                                        {
                                                $date = $date + (60*60) * 
$GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'];
                                                $dateout = 
$GLOBALS['phpgw']->common->show_date($date,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
                                        }

                                        if ($note['customer'] != 0) 
                                        {
                                                $customer = 
$this->boprojects->read_single_contact($note['customer']);
                                if (!$customer[0]['org_name']) { $customerout = 
$customer[0]['n_given'] . ' ' . $customer[0]['n_family']; }
                                else { $customerout = $customer[0]['org_name'] 
. ' [ ' . $customer[0]['n_given'] . ' ' . $customer[0]['n_family'] . ' ]'; }
                                        }
                                        else { $customerout = '&nbsp;'; }

                                        
$GLOBALS['phpgw']->template->set_var('sum','');

// ------------------ template declaration for list records 
----------------------------------

                                        
$GLOBALS['phpgw']->template->set_var(array('num' => 
$GLOBALS['phpgw']->strip_html($note['delivery_num']),
                                                                        
'customer' => $customerout,
                                                                                
'title' => $title,
                                                                                
'date' => $dateout));

                                        $link_data['delivery_id']       = 
$note['delivery_id'];
                                        $link_data['project_id']        = 
$note['project_id'];
                                        $link_data['menuaction']        = 
'projects.uideliveries.delivery';
                                        
$GLOBALS['phpgw']->template->set_var('td_data',$GLOBALS['phpgw']->link('/index.php',$link_data));
                                        
$GLOBALS['phpgw']->template->set_var('lang_td_data',lang('Delivery'));

                                        
$GLOBALS['phpgw']->template->fp('list','projects_list',True);

// ------------------------ end record declaration 
--------------------------------------------
                                }
                        }
                        
$GLOBALS['phpgw']->template->pfp('out','projects_list_t',True);
                        $this->save_sessiondata('del');
                }

                function show_delivery()
                {
                        $delivery_id = get_var('delivery_id',array('GET'));

                        $this->set_app_langs();

                        
$GLOBALS['phpgw']->template->set_file(array('del_list_t' => 
'del_deliveryform.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('del_list_t','del_list','list');

                        $error = $this->boprojects->check_prefs();
                        if (is_array($error))
                        {
                                
$GLOBALS['phpgw']->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error));
                        }
                        else
                        {
                                $prefs = $this->boprojects->read_prefs();
                                
$GLOBALS['phpgw']->template->set_var('myaddress',$this->bodeliveries->get_address_data('line',$prefs['abid'],$prefs['ifont'],$prefs['mysize']));
                                
$GLOBALS['phpgw']->template->set_var('fulladdress',$this->bodeliveries->get_address_data('full',$prefs['abid'],$prefs['ifont'],$prefs['mysize']));
                        }

                        
$GLOBALS['phpgw']->template->set_var('site_title',$GLOBALS['phpgw_info']['site_title']);
                        $charset = 
$GLOBALS['phpgw']->translation->translate('charset');
                        
$GLOBALS['phpgw']->template->set_var('charset',$charset);
                        
$GLOBALS['phpgw']->template->set_var('font',$prefs['ifont']);
                        
$GLOBALS['phpgw']->template->set_var('fontsize',$prefs['allsize']);
                        
$GLOBALS['phpgw']->template->set_var('img_src',$GLOBALS['phpgw_info']['server']['webserver_url']
 . '/projects/doc/logo.jpg');
                        
$GLOBALS['phpgw']->template->set_var('lang_delivery_note_for_project',lang('Delivery
 note for project'));

                        $del = 
$this->bodeliveries->read_single_delivery($delivery_id);

                        if ($prefs)
                        {
                                
$GLOBALS['phpgw']->template->set_var('customer',$this->bodeliveries->get_address_data('address',$del['customer'],$prefs['ifont'],$prefs['allsize']));
                        }

                        $del['date'] = $del['date'] + (60*60) * 
$GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'];
                        $delivery_dateout = 
$GLOBALS['phpgw']->common->show_date($del['date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
                        
$GLOBALS['phpgw']->template->set_var('delivery_date',$delivery_dateout);

                        
$GLOBALS['phpgw']->template->set_var('delivery_num',$GLOBALS['phpgw']->strip_html($del['delivery_num']));
                        
$GLOBALS['phpgw']->template->set_var('project_num',$GLOBALS['phpgw']->strip_html($del['project_num']));
                        $title = $GLOBALS['phpgw']->strip_html($del['title']);
                        if (! $title) { $title  = '&nbsp;'; }
                        $GLOBALS['phpgw']->template->set_var('title',$title);

                        if ($prefs['bill'] == 'wu')
                        {
                                
$GLOBALS['phpgw']->template->set_var('lang_sumaes',lang('Sum workunits'));
                                
$GLOBALS['phpgw']->template->set_var('lang_workunits',lang('Workunits'));
                        }
                        else
                        {
                                
$GLOBALS['phpgw']->template->set_var('lang_sumaes',lang('Sum hours'));
                                
$GLOBALS['phpgw']->template->set_var('lang_workunits',lang('Hours'));
                        }

                        $pos = 0;
                        $hours = 
$this->bodeliveries->read_delivery_pos($delivery_id);

                        if (is_array($hours))
                        {
                                while (list($null,$note) = each($hours))
                                {
                                        $pos++;
                                        
$GLOBALS['phpgw']->template->set_var('pos',$pos);

                                        if ($note['sdate'] == 0)
                                        {
                                                $hours_dateout = '&nbsp;';
                                        }
                                        else
                                        {
                                                $note['sdate'] = $note['sdate'] 
+ (60*60) * 
$GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'];
                                                $hours_dateout = 
$GLOBALS['phpgw']->common->show_date($note['sdate'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
                                        }

                                        
$GLOBALS['phpgw']->template->set_var('hours_date',$hours_dateout);

                                        if ($prefs['bill'] == 'wu')
                                        {
                                                if ($note['minperae'] != 0)
                                                {
                                                        $aes = 
ceil($note['minutes']/$note['minperae']);
                                                }
                                                $sumaes += $aes;
                                        }
                                        else
                                        {
                                                $aes = 
floor($note['minutes']/60) . ':'
                                                                . 
sprintf("%02d",(int)($note['minutes']-floor($note['minutes']/60)*60));

                                                $sumhours += $note['minutes'];
                                                $sumaes = floor($sumhours/60) . 
':'
                                                                . 
sprintf("%02d",(int)($sumhours-floor($sumhours/60)*60));
                                        }

                                        
$GLOBALS['phpgw']->template->set_var('aes',$aes);
                                        $act_descr = 
$GLOBALS['phpgw']->strip_html($note['act_descr']);
                                        if (! $act_descr) { $act_descr  = 
'&nbsp;'; }
                                        
$GLOBALS['phpgw']->template->set_var('act_descr',$act_descr);
                                        
$GLOBALS['phpgw']->template->set_var('billperae',$note['billperae']);
                                        $hours_descr = 
$GLOBALS['phpgw']->strip_html($note['hours_descr']);
                                        if (! $hours_descr) { $hours_descr  = 
'&nbsp;'; }
                                        
$GLOBALS['phpgw']->template->set_var('hours_descr',$hours_descr);
                                        
$GLOBALS['phpgw']->template->fp('list','del_list',True);
                                }
                        }
                        $GLOBALS['phpgw']->template->set_var('sumaes',$sumaes);

                        
$GLOBALS['phpgw']->template->pfp('out','del_list_t',True);
                        $GLOBALS['phpgw']->common->phpgw_exit();
                }

                function fail()
                {
                        echo '<p><center>' . lang('You have to CREATE a 
delivery or invoice first !');
                        echo '</center>';
                        $GLOBALS['phpgw']->common->phpgw_exit();
                }
        }
?>

--- NEW FILE: class.uibilling.inc.php ---
<?php
        /*******************************************************************\
        * phpGroupWare - Bookkeeping                                        *
        * http://www.phpgroupware.org                                       *
        * This program is part of the GNU project, see http://www.gnu.org/      
*
        *                                                                   *
        * Accounting application for the Project Manager                    *
        * Written by Bettina Gille address@hidden                   *
        * -----------------------------------------------                   *
        * Copyright 2000 - 2003 Free Software Foundation, Inc               *
        *                                                                   *
        * 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., 675 Mass Ave, Cambridge, MA 02139, USA.         *
        \*******************************************************************/
        /* $Id: class.uibilling.inc.php,v 1.1 2003/12/01 16:31:33 ceb Exp $ */
        // $Source: 
/cvsroot/phpgroupware/bookkeeping/inc/class.uibilling.inc.php,v $

        class uibilling
        {
                var $action;
                var $grants;
                var $start;
                var $filter;
                var $sort;
                var $order;
                var $cat_id;

                var $public_functions = array
                (
                        'list_projects'         => True,
                        'invoice'                       => True,
                        'list_invoices'         => True,
                        'fail'                          => True,
                        'show_invoice'          => True
                );

                function uibilling()
                {
                        $action = get_var('action',array('POST','GET'));

                        $this->boprojects                               = 
CreateObject('projects.boprojects',True, $action);
                        $this->bobilling                                = 
CreateObject('projects.bobilling');
                        $this->bodeliveries                             = 
CreateObject('projects.bodeliveries');
                        $this->nextmatchs                               = 
CreateObject('phpgwapi.nextmatchs');
                        $this->sbox                                             
= CreateObject('phpgwapi.sbox');
                        $this->cats                                             
= CreateObject('phpgwapi.categories');
                        $this->account                                  = 
$GLOBALS['phpgw_info']['user']['account_id'];
                        $this->grants                                   = 
$GLOBALS['phpgw']->acl->get_grants('projects');
                        $this->grants[$this->account]   = PHPGW_ACL_READ + 
PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;

                        $this->start                                    = 
$this->boprojects->start;
                        $this->query                                    = 
$this->boprojects->query;
                        $this->filter                                   = 
$this->boprojects->filter;
                        $this->order                                    = 
$this->boprojects->order;
                        $this->sort                                             
= $this->boprojects->sort;
                        $this->cat_id                                   = 
$this->boprojects->cat_id;
                }

                function save_sessiondata($action)
                {
                        $data = array
                        (
                                'start'         => $this->start,
                                'query'         => $this->query,
                                'filter'        => $this->filter,
                                'order'         => $this->order,
                                'sort'          => $this->sort,
                                'cat_id'        => $this->cat_id
                        );
                        $this->boprojects->save_sessiondata($data, $action);
                }

                function set_app_langs()
                {
                        
$GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
                        
$GLOBALS['phpgw']->template->set_var('row_on',$GLOBALS['phpgw_info']['theme']['row_on']);
                        
$GLOBALS['phpgw']->template->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']);

                        
$GLOBALS['phpgw']->template->set_var('lang_category',lang('Category'));
                        
$GLOBALS['phpgw']->template->set_var('lang_select',lang('Select'));
                        
$GLOBALS['phpgw']->template->set_var('lang_descr',lang('Description'));
                        
$GLOBALS['phpgw']->template->set_var('lang_title',lang('Title'));
                        
$GLOBALS['phpgw']->template->set_var('lang_none',lang('None'));
                        
$GLOBALS['phpgw']->template->set_var('lang_start_date',lang('Start Date'));
                        
$GLOBALS['phpgw']->template->set_var('lang_end_date',lang('End Date'));
                        
$GLOBALS['phpgw']->template->set_var('lang_projects',lang('Projects'));
                        
$GLOBALS['phpgw']->template->set_var('lang_project',lang('Project'));
                        
$GLOBALS['phpgw']->template->set_var('lang_jobs',lang('Jobs'));
                        
$GLOBALS['phpgw']->template->set_var('lang_title',lang('Title'));
                        
$GLOBALS['phpgw']->template->set_var('lang_status',lang('Status'));
                        
$GLOBALS['phpgw']->template->set_var('lang_customer',lang('Customer'));
                        
$GLOBALS['phpgw']->template->set_var('lang_coordinator',lang('Coordinator'));
                        
$GLOBALS['phpgw']->template->set_var('lang_edit',lang('Edit'));
                        
$GLOBALS['phpgw']->template->set_var('lang_done',lang('Done'));
                        
$GLOBALS['phpgw']->template->set_var('lang_hours',lang('Work hours'));
                        
$GLOBALS['phpgw']->template->set_var('lang_minperae',lang('Minutes per 
workunit'));
                        
$GLOBALS['phpgw']->template->set_var('lang_invoices',lang('Invoices'));
                        
$GLOBALS['phpgw']->template->set_var('lang_invoice_num',lang('Invoice ID'));
                        
$GLOBALS['phpgw']->template->set_var('lang_project_num',lang('Project ID'));
                        
$GLOBALS['phpgw']->template->set_var('lang_invoice_date',lang('Invoice date'));
                        
$GLOBALS['phpgw']->template->set_var('lang_stats',lang('Statistics'));
                        
$GLOBALS['phpgw']->template->set_var('lang_activity',lang('Activity'));
                        
$GLOBALS['phpgw']->template->set_var('lang_sum',lang('Sum'));
                        
$GLOBALS['phpgw']->template->set_var('lang_print_invoice',lang('Print 
invoice'));
                        
$GLOBALS['phpgw']->template->set_var('lang_netto',lang('Sum net'));
                        
$GLOBALS['phpgw']->template->set_var('lang_tax',lang('tax'));
                        
$GLOBALS['phpgw']->template->set_var('lang_position',lang('Position'));
                        
$GLOBALS['phpgw']->template->set_var('lang_work_date',lang('Work date'));
                        
$GLOBALS['phpgw']->template->set_var('lang_submit',lang('Submit'));
                }

                function display_app_header()
                {
                        if 
($GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'] != 
'idots')
                        if 
($GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'] != 
'idots')
                        {
                                
$GLOBALS['phpgw']->template->set_file(array('header' => 'header.tpl'));
                                
$GLOBALS['phpgw']->template->set_block('header','projects_header');

                                if ($this->boprojects->isprojectadmin('pad'))
                                {
                                        
$GLOBALS['phpgw']->template->set_var('admin_info',lang('Administrator'));
                                        
$GLOBALS['phpgw']->template->set_var('break1','&nbsp;|&nbsp;');
                                        
$GLOBALS['phpgw']->template->set_var('space1','&nbsp;&nbsp;&nbsp;');
                                        
$GLOBALS['phpgw']->template->set_var('link_activities',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_activities&action=act'));
                                                                                
                         
                                        
$GLOBALS['phpgw']->template->set_var('lang_activities',lang('Activities'));     
                                                                                
                                          
                                        
$GLOBALS['phpgw']->template->set_var('link_budget',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_budget&action=mains'));
                                        
$GLOBALS['phpgw']->template->set_var('lang_budget',lang('budget'));
                                }

                                if ($this->boprojects->isprojectadmin('pbo'))
                                {
                                        
$GLOBALS['phpgw']->template->set_var('book_info',lang('Bookkeeper'));
                                        
$GLOBALS['phpgw']->template->set_var('break2','&nbsp;|&nbsp;');
                                        
$GLOBALS['phpgw']->template->set_var('space2','&nbsp;&nbsp;&nbsp;');
                                        
$GLOBALS['phpgw']->template->set_var('link_billing',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uibilling.list_projects&action=mains'));
                                        
$GLOBALS['phpgw']->template->set_var('lang_billing',lang('Billing'));
                                        
$GLOBALS['phpgw']->template->set_var('link_delivery',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uideliveries.list_projects&action=mains'));
                                        
$GLOBALS['phpgw']->template->set_var('lang_delivery',lang('Deliveries'));
                                }

                                
$GLOBALS['phpgw']->template->set_var('link_jobs',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_projects&action=subs'));
                                
$GLOBALS['phpgw']->template->set_var('link_hours',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.list_hours'));
                                
$GLOBALS['phpgw']->template->set_var('link_statistics',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uistatistics.list_projects&action=mains'));
                                
$GLOBALS['phpgw']->template->set_var('lang_statistics',lang('Statistics'));
                                
$GLOBALS['phpgw']->template->set_var('link_projects',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_projects&action=mains'));
                                
$GLOBALS['phpgw']->template->set_var('lang_projects',lang('Projects'));
                                
$GLOBALS['phpgw']->template->set_var('link_archiv',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.archive&action=amains'));
                                
$GLOBALS['phpgw']->template->set_var('lang_archiv',lang('archive'));

                                
$GLOBALS['phpgw']->template->fp('app_header','projects_header');
                        }
                        $this->set_app_langs();
                        $GLOBALS['phpgw']->common->phpgw_header();
                        echo parse_navbar();
                }

                function format_tax($tax = '')
                {
                        $comma = strrpos($tax,',');
                        if (is_string($comma) && !$comma)
                        {
                                $newtax = $tax;
                        }
                        else
                        {
                                $newtax = str_replace(',','.',$tax);
                        }
                        return $newtax;
                }

                function list_projects()
                {
                        $action         = get_var('action',array('POST','GET'));
                        $pro_parent     = 
get_var('pro_parent',array('POST','GET'));

                        $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . ($pro_parent?lang('list jobs'):lang('list projects'));
                        $this->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('projects_list_t' => 
'bill_list.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('projects_list_t','projects_list','list');

                        if (!$action)
                        {
                                $action = 'mains';
                        }

                        $link_data = array
                        (
                                'menuaction'    => 
'projects.uibilling.list_projects',
                                'pro_parent'    => $pro_parent,
                                'action'                => $action
                        );

                        if (!$this->start)
                        {
                                $this->start = 0;
                        }

                        if (!$action)
                        {
                                $action = 'mains';
                        }

                        if (!$pro_parent)
                        {
                                $pro_parent = 0;
                        }

                        $pro = 
$this->boprojects->list_projects($this->start,True,$this->query,$this->filter,$this->sort,$this->order,'active',$this->cat_id,$action,$pro_parent);

// --------------------- nextmatch variable template-declarations 
------------------------

                        $left = 
$this->nextmatchs->left('/index.php',$this->start,$this->boprojects->total_records,$link_data);
                        $right = 
$this->nextmatchs->right('/index.php',$this->start,$this->boprojects->total_records,$link_data);
                        $GLOBALS['phpgw']->template->set_var('left',$left);
                        $GLOBALS['phpgw']->template->set_var('right',$right);

                        
$GLOBALS['phpgw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->boprojects->total_records,$this->start));

// ------------------------- end nextmatch template 
--------------------------------------

                        if ($action == 'mains')
                        {
                                $action_list= '<form method="POST" action="' . 
$GLOBALS['phpgw']->link('/index.php',$link_data) . '" name="form">' . "\n"
                                                        . '<select 
name="cat_id" onChange="this.form.submit();"><option value="">' . lang('Select 
category') . '</option>' . "\n"
                                                        . 
$this->cats->formatted_list('select','all',$this->cat_id,True) . '</select>';
                        }
                        else
                        {
                                $action_list= '<form method="POST" action="' . 
$GLOBALS['phpgw']->link('/index.php',$link_data) .'" name="form">' . "\n"
                                                        . '<select 
name="pro_parent" onChange="this.form.submit();"><option value="">' . 
lang('Select main project') . '</option>' . "\n"
                                                        . 
$this->boprojects->select_project_list('mains', $status, $pro_parent) . 
'</select>';
                        }

                        $GLOBALS['filter']      = $this->filter;
                        $GLOBALS['query']       = $this->query;

                        
$GLOBALS['phpgw']->template->set_var('action_list',$action_list);
                        
$GLOBALS['phpgw']->template->set_var('filter_action',$GLOBALS['phpgw']->link('/index.php',$link_data));
                        
$GLOBALS['phpgw']->template->set_var('filter_list',$this->nextmatchs->new_filter($this->filter));
                        
$GLOBALS['phpgw']->template->set_var('search_action',$GLOBALS['phpgw']->link('/index.php',$link_data));
                        
$GLOBALS['phpgw']->template->set_var('search_list',$this->nextmatchs->search(array('query'
 => $this->query)));

// ---------------- list header variable template-declarations 
--------------------------

                        
$GLOBALS['phpgw']->template->set_var(sort_number,$this->nextmatchs->show_sort_order($this->sort,'num',$this->order,'/index.php',lang('Project
 ID'),$link_data));

                        if ($action == 'mains')
                        {
                                
$GLOBALS['phpgw']->template->set_var('sort_action',$this->nextmatchs->show_sort_order($this->sort,'customer',$this->order,'/index.php',lang('Customer'),$link_data));
                                $lang_action = '<td width="5%" align="center">' 
. lang('Jobs') . '</td>' . "\n";
                                
$GLOBALS['phpgw']->template->set_var('lang_action',$lang_action);
                        }
                        else
                        {
                                
$GLOBALS['phpgw']->template->set_var('sort_action',$this->nextmatchs->show_sort_order($this->sort,'start_date',$this->order,'/index.php',lang('Start
 date'),$link_data));
                                
$GLOBALS['phpgw']->template->set_var('lang_action','');
                        }

                        
$GLOBALS['phpgw']->template->set_var('sort_status',$this->nextmatchs->show_sort_order($this->sort,'status',$this->order,'/index.php',lang('Status'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_title',$this->nextmatchs->show_sort_order($this->sort,'title',$this->order,'/index.php',lang('Title'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_end_date',$this->nextmatchs->show_sort_order($this->sort,'end_date',$this->order,'/index.php',lang('Date
 due'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_coordinator',$this->nextmatchs->show_sort_order($this->sort,'coordinator',$this->order,'/index.php',lang('Coordinator'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('h_lang_part',lang('Invoice'));
                        
$GLOBALS['phpgw']->template->set_var('h_lang_partlist',lang('Invoice list'));

// -------------- end header declaration ---------------------------------------

            for ($i=0;$i<count($pro);$i++)
            {
                                
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);
                                $edate = $pro[$i]['edate'];
                                if ($edate == 0)
                                {
                                        $edateout = '&nbsp;';
                                }
                                else
                                {
                                        $month  = 
$GLOBALS['phpgw']->common->show_date(time(),'n');
                                        $day    = 
$GLOBALS['phpgw']->common->show_date(time(),'d');
                                        $year   = 
$GLOBALS['phpgw']->common->show_date(time(),'Y');

                                        $edate = $edate + (60*60) * 
$GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'];
                                        $edateout = 
$GLOBALS['phpgw']->common->show_date($edate,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
                                        if (mktime(2,0,0,$month,$day,$year) == 
$edate) { $edateout = '<b>' . $edateout . '</b>'; }
                                        if (mktime(2,0,0,$month,$day,$year) >= 
$edate) { $edateout = '<font color="CC0000"><b>' . $edateout . '</b></font>'; }
                                }

                                if ($action == 'mains')
                                {
                                        $td_action = 
($pro[$i]['customerout']?$pro[$i]['customerout']:'&nbsp;');
                                }
                                else
                                {
                                        $td_action = 
($pro[$i]['sdateout']?$pro[$i]['sdateout']:'&nbsp;');
                                }

// --------------- template declaration for list records 
-------------------------------------

                                $GLOBALS['phpgw']->template->set_var(array
                                (
                                        'number'                => 
$pro[$i]['number'],
                                        'td_action'             => $td_action,
                                        'status'                => 
lang($pro[$i]['status']),
                                        'title'                 => 
($pro[$i]['title']?$pro[$i]['title']:'&nbsp;'),
                                        'end_date'              => $edateout,
                                        'coordinator'   => 
$pro[$i]['coordinatorout']
                                ));

                                $link_data['project_id'] = 
$pro[$i]['project_id'];
                                $link_data['menuaction'] = 
'projects.uibilling.invoice';

                                
$GLOBALS['phpgw']->template->set_var('part',$GLOBALS['phpgw']->link('/index.php',$link_data));
                                
$GLOBALS['phpgw']->template->set_var('lang_part',lang('Invoice'));

                                $link_data['menuaction']        = 
'projects.uibilling.list_invoices';
                                $link_data['action']            = 'bill';
                                
$GLOBALS['phpgw']->template->set_var('partlist',$GLOBALS['phpgw']->link('/index.php',$link_data));
                                
$GLOBALS['phpgw']->template->set_var('lang_partlist',lang('Invoice list'));

                                if ($action == 'mains')
                                {
                                        $action_entry = '<td align="center"><a 
href="' . 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uibilling.list_projects&pro_parent='
                                                                                
                                                . $pro[$i]['project_id'] . 
'&action=subs') . '">' . lang('Jobs')
                                                                                
                                                . '</a></td>' . "\n";
                                        
$GLOBALS['phpgw']->template->set_var('action_entry',$action_entry);
                                }
                                else
                                {
                                        
$GLOBALS['phpgw']->template->set_var('action_entry','');
                                }

                                
$GLOBALS['phpgw']->template->parse('list','projects_list',True);
                        }

// ------------------------- end record declaration ------------------------

                        
$GLOBALS['phpgw']->template->set_var('lang_all_partlist',lang('All invoices'));
                        
$GLOBALS['phpgw']->template->set_var('all_partlist',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uibilling.list_invoices&action=bill'
                                                                                
        . '&project_id='));
                        
$GLOBALS['phpgw']->template->set_var('lang_all_part2list','');
                        
$GLOBALS['phpgw']->template->set_var('all_part2list','');

                        
$GLOBALS['phpgw']->template->pfp('out','projects_list_t',True);
                        $this->save_sessiondata($action);
                }

                function list_invoices()
                {
                        $action         = get_var('action',array('POST','GET'));
                        $project_id     = 
get_var('project_id',array('POST','GET'));

                        $this->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('projects_list_t' => 
'bill_listinvoice.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('projects_list_t','projects_list','list');

                        $link_data = array
                        (
                                'menuaction'    => 
'projects.uibilling.list_invoices',
                                'action'                => $action
                        );

                        $nopref = $this->boprojects->check_prefs();
                        if (is_array($nopref))
                        {
                                
$GLOBALS['phpgw']->template->set_var('pref_message',$GLOBALS['phpgw']->common->error_list($nopref));
                        }
                        else
                        {
                                $prefs = $this->boprojects->get_prefs();
                        }

                        if (!$this->start)
                        {
                                $this->start = 0;
                        }

                        $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('list invoices');

                        
$GLOBALS['phpgw']->template->set_var('search_action',$GLOBALS['phpgw']->link('/index.php',$link_data));
                        
$GLOBALS['phpgw']->template->set_var('search_list',$this->nextmatchs->search(array('query'
 => $this->query)));

                        if (! $this->start)
                        {
                                $this->start = 0;
                        }

                        if (! $project_id)
                        {
                                $project_id = '';
                        }

                        $bill = 
$this->bobilling->read_invoices($this->start,$this->query,$this->sort,$this->order,True,$project_id);

// -------------------- nextmatch variable template-declarations 
-----------------------------

                        $left = 
$this->nextmatchs->left('/index.php',$start,$this->bobilling->total_records,$link_data);
                        $right = 
$this->nextmatchs->right('/index.php',$start,$this->bobilling->total_records,$link_data);
                        $GLOBALS['phpgw']->template->set_var('left',$left);
                        $GLOBALS['phpgw']->template->set_var('right',$right);

                        
$GLOBALS['phpgw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->bobilling->total_records,$start));

// ------------------------ end nextmatch template 
-------------------------------------------

// ------------------- list header variable template-declarations 
----------------------------

                        
$GLOBALS['phpgw']->template->set_var('sort_num',$this->nextmatchs->show_sort_order($sort,'num',$order,'/index.php',lang('Invoice
 ID'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_customer',$this->nextmatchs->show_sort_order($sort,'customer',$order,'/index.php',lang('Customer'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_title',$this->nextmatchs->show_sort_order($sort,'title',$order,'/index.php',lang('Title'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_date',$this->nextmatchs->show_sort_order($sort,'date',$order,'/index.php',lang('Date'),$link_data));
                        $GLOBALS['phpgw']->template->set_var('sort_sum','<td 
width="10%" align="right" bgcolor="' . $GLOBALS['phpgw_info']['theme']['th_bg'] 
. '">'
                        . $prefs['currency'] . '&nbsp;' . 
$this->nextmatchs->show_sort_order($sort,'sum',$order,'/index.php',lang('Sum'),$link_data)
 . '</td>');
                        
$GLOBALS['phpgw']->template->set_var('lang_data',lang('Invoice'));

// --------------------  --- end header declaration ---------             
--------------------

                        if (is_array($bill))
                        {
                                while (list($null,$inv) = each($bill))
                                {
                                        
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);
                                        $title = 
$GLOBALS['phpgw']->strip_html($inv['title']);
                                        if (! $title) $title = '&nbsp;';

                                        $date = $inv['date'];
                                        if ($date == 0)
                                                $dateout = '&nbsp;';
                                        else
                                        {
                                                $date = $date + (60*60) * 
$GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'];
                                                $dateout = 
$GLOBALS['phpgw']->common->show_date($date,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
                                        }

                                        if ($inv['customer'] != 0) 
                                        {
                                                $customer = 
$this->boprojects->read_single_contact($inv['customer']);
                                if (!$customer[0]['org_name']) { $customerout = 
$customer[0]['n_given'] . ' ' . $customer[0]['n_family']; }
                                else { $customerout = $customer[0]['org_name'] 
. ' [ ' . $customer[0]['n_given'] . ' ' . $customer[0]['n_family'] . ' ]'; }
                                        }
                                        else { $customerout = '&nbsp;'; }

                                        
$GLOBALS['phpgw']->template->set_var('sum','<td align="right">' . $inv['sum'] . 
'</td>');

// --------------------- template declaration for list records 
----------------------------

                                        
$GLOBALS['phpgw']->template->set_var(array('num' => 
$GLOBALS['phpgw']->strip_html($inv['invoice_num']),
                                                                                
'customer' => $customerout,
                                                                                
'title' => $title,
                                                                                
'date' => $dateout));

                                        $link_data['invoice_id']        = 
$inv['invoice_id'];
                                        $link_data['project_id']        = 
$inv['project_id'];
                                        $link_data['menuaction']        = 
'projects.uibilling.invoice';
                                        
$GLOBALS['phpgw']->template->set_var('td_data',$GLOBALS['phpgw']->link('/index.php',$link_data));
                                        
$GLOBALS['phpgw']->template->set_var('lang_td_data',lang('Invoice'));
                                        
$GLOBALS['phpgw']->template->fp('list','projects_list',True);

// ------------------------- end record declaration 
--------------------------------------
                                }
                        }
                        
$GLOBALS['phpgw']->template->pfp('out','projects_list_t',True);
                        $this->save_sessiondata('bill');
                }

                function invoice()
                {
                        $action         = get_var('action',array('POST','GET'));
                        $project_id     = 
get_var('project_id',array('POST','GET'));
                        $Invoice        = 
get_var('Invoice',array('POST','GET'));
                        $invoice_id     = 
get_var('invoice_id',array('POST','GET'));

                        $values         = get_var('values',array('POST'));
                        $select         = get_var('select',array('POST'));
                        $referer        = get_var('referer',array('POST'));

                        if (! $Invoice)
                        {
                                $referer = 
$GLOBALS['HTTP_SERVER_VARS']['HTTP_REFERER'] ? 
$GLOBALS['HTTP_SERVER_VARS']['HTTP_REFERER'] : $GLOBALS['HTTP_REFERER'];
                        }

                        if (!$project_id)
                        {
                                Header('Location: ' . $referer);
                        }

                        $this->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('hours_list_t' => 
'bill_listhours.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('hours_list_t','hours_list','list');

                        $nopref = $this->boprojects->check_prefs();
                        if (is_array($nopref))
                        {
                                
$GLOBALS['phpgw']->template->set_var('pref_message',$GLOBALS['phpgw']->common->error_list($nopref));
                        }
                        else
                        {
                                $prefs = $this->boprojects->get_prefs();
                        }

                        if ($Invoice)
                        {
                                $values['project_id']   = $project_id;
                                if ($invoice_id)
                                {
                                        $values['invoice_id'] = $invoice_id;
                                }
                                $pro = 
$this->boprojects->read_single_project($project_id);
                                $values['customer']             = 
$pro['customer'];

                                $error = 
$this->bobilling->check_values($values,$select);
                                if (is_array($error))
                                {
                                        
$GLOBALS['phpgw']->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error));
                                }
                                else
                                {
                                        if ($invoice_id)
                                        {
                                                
$this->bobilling->update_invoice($values,$select);
                                        }
                                        else
                                        {
                                                $invoice_id = 
$this->bobilling->invoice($values,$select);
                                        }
                                }
                        }

                        $link_data = array
                        (
                                'menuaction'    => 'projects.uibilling.invoice',
                                'action'                => $action,
                                'project_id'    => $project_id,
                                'invoice_id'    => $invoice_id
                        );

                        $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('create invoice');

                        
$GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data));
                        
$GLOBALS['phpgw']->template->set_var('currency',$prefs['currency']);

                        
$GLOBALS['phpgw']->template->set_var('hidden_vars','<input type="hidden" 
name="referer" value="' . $referer . '">');
                        
$GLOBALS['phpgw']->template->set_var('doneurl',$referer);

                        $pro = 
$this->boprojects->read_single_project($project_id);

                        $title = $GLOBALS['phpgw']->strip_html($pro['title']);
                        if (! $title)  $title  = '&nbsp;';
                        $GLOBALS['phpgw']->template->set_var('project',$title . 
' [' . $GLOBALS['phpgw']->strip_html($pro['number']) . ']');

                        if (!$pro['customer'])
                        {
                                
$GLOBALS['phpgw']->template->set_var('customer',lang('You have no customer 
selected !'));
                        }
                        else
                        {
                                $customer = 
$this->boprojects->read_single_contact($pro['customer']);

                                if (!$customer[0]['org_name']) { $customername 
= $customer[0]['n_given'] . ' ' . $customer[0]['n_family']; }
                                else { $customername = $customer[0]['org_name'] 
. ' [ ' . $customer[0]['n_given'] . ' ' . $customer[0]['n_family'] . ' ]'; }
                                
$GLOBALS['phpgw']->template->set_var('customer',$customername);
                        }

                        if (!$invoice_id)
                        {
                                
$GLOBALS['phpgw']->template->set_var('lang_choose',lang('Generate Invoice ID 
?'));
                                
$GLOBALS['phpgw']->template->set_var('choose','<input type="checkbox" 
name="values[choose]" value="True">');
                                
$GLOBALS['phpgw']->template->set_var('print_invoice',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uibilling.fail'));
                                
$GLOBALS['phpgw']->template->set_var('invoice_num',$values['invoice_num']);
                                $hours = 
$this->bobilling->read_hours($project_id, $action);
                        }
                        else
                        {
                                
$GLOBALS['phpgw']->template->set_var('lang_choose','');
                                
$GLOBALS['phpgw']->template->set_var('choose','');
                                
$GLOBALS['phpgw']->template->set_var('print_invoice',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uibilling.show_invoice'
                                                                                
                                                                . 
'&invoice_id=' . $invoice_id));
                                $bill = 
$this->bobilling->read_single_invoice($invoice_id);
                                
$GLOBALS['phpgw']->template->set_var('invoice_num',$bill['invoice_num']);
                                $hours = 
$this->bobilling->read_invoice_hours($project_id, $invoice_id, $action);
                        }

                        if ($bill['date'])
                        {
                                $values['month'] = date('m',$bill['date']);
                                $values['day'] = date('d',$bill['date']);
                                $values['year'] = date('Y',$bill['date']);
                        }
                        else
                        {
                                $values['month'] = date('m',time());
                                $values['day'] = date('d',time());
                                $values['year'] = date('Y',time());
                        }

                        
$GLOBALS['phpgw']->template->set_var('date_select',$GLOBALS['phpgw']->common->dateformatorder($this->sbox->getYears('values[year]',$values['year']),
                                                                                
                                                                                
$this->sbox->getMonthText('values[month]',$values['month']),
                                                                                
                                                                                
$this->sbox->getDays('values[day]',$values['day'])));    
                        if ($prefs['bill'] == 'wu')
                        {
                                
$GLOBALS['phpgw']->template->set_var('lang_billperae',lang('Bill per 
workunit'));
                                
$GLOBALS['phpgw']->template->set_var('lang_workunits',lang('Workunits'));
                        }
                        else
                        {
                                
$GLOBALS['phpgw']->template->set_var('lang_billperae',lang('Bill per hour'));
                                
$GLOBALS['phpgw']->template->set_var('lang_workunits',lang('Hours'));
                        }

                        $sumaes=0;
                        if (is_array($hours))
                        {
                                while (list($null,$inv) = each($hours))
                                {
                                        
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);

                                        $select = '<input type="checkbox" 
name="select[' . $inv['hours_id'] . ']" value="True" checked>';

                                        $activity = 
$GLOBALS['phpgw']->strip_html($inv['act_descr']);
                                        if (! $activity)  $activity  = '&nbsp;';

                                        $hours_descr = 
$GLOBALS['phpgw']->strip_html($inv['hours_descr']);
                                        if (! $hours_descr)  $hours_descr  = 
'&nbsp;';

                                        $start_date = $inv['sdate'];
                                        if ($start_date == 0) { $start_dateout 
= '&nbsp;'; }
                                        else
                                        {
                                                $start_date = $start_date + 
(60*60) * $GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'];
                                                $start_dateout = 
$GLOBALS['phpgw']->common->show_date($start_date,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
                                        }

                                        if ($prefs['bill'] == 'wu')
                                        {
                                                if ($inv['minperae'] != 0)
                                                {
                                                        $aes = 
ceil($inv['minutes']/$inv['minperae']);
                                                }
                                                $onehour = 
$aes*$inv['billperae'];
                                                $sumaes += $aes;
                                                // $summe += 
$inv['billperae']*$aes;
                                        }
                                        else
                                        {
                                                $onehour = 
($inv['minutes']/60)*$inv['billperae'];

                                                $aes = 
floor($inv['minutes']/60) . ':'
                                                                . sprintf 
("%02d",(int)($inv['minutes']-floor($inv['minutes']/60)*60));

                                                $sumhours += $inv['minutes'];
                                                $sumaes = floor($sumhours/60) . 
':'
                                                                . sprintf 
("%02d",(int)($sumhours-floor($sumhours/60)*60));

                                                // $summe = 
($sumhours/60)*$inv['billperae'];
                                        }

                                        $summe += $onehour;

// --------------------- template declaration for list records 
---------------------------

                                        
$GLOBALS['phpgw']->template->set_var(array('select' => $select,
                                                                                
'activity' => $activity,
                                                                        
'hours_descr' => $hours_descr,
                                                                                
'status' => lang($inv['status']),
                                                                        
'start_date' => $start_dateout,
                                                                                
        'aes' => $aes,
                                                                        
'billperae' => $inv['billperae'],
                                                                                
'sum' => sprintf("%01.2f",round($onehour,2))));

                                        if (($inv['status'] != 'billed') && 
($inv['status'] != 'closed'))
                                        {
                                                $link_data['menuaction']        
= 'projects.uiprojecthours.edit_hours';
                                                $link_data['hours_id']          
= $inv['hours_id'];
                                                
$GLOBALS['phpgw']->template->set_var('edithour',$GLOBALS['phpgw']->link('/index.php',$link_data));
                                                
$GLOBALS['phpgw']->template->set_var('lang_edit_entry',lang('Edit'));
                                        }
                                        else
                                        {
                                                
$GLOBALS['phpgw']->template->set_var('edithour','');
                                                
$GLOBALS['phpgw']->template->set_var('lang_edit_entry','&nbsp;');
                                        }
                                        
$GLOBALS['phpgw']->template->fp('list','hours_list',True);

// -------------------------- end record declaration --------------------------
                                }
                        }

                        if ($invoice_id && ($action != 'amains') && ($action != 
'asubs'))
                        {
                                $hours = 
$this->bobilling->read_hours($project_id, $action);
                                if (is_array($hours))
                                {
                                        while (list($null,$inv) = each($hours))
                                        {
                                                
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);

                                                $select = '<input 
type="checkbox" name="select[' . $inv['hours_id'] . ']" value="True">';

                                                $activity = 
$GLOBALS['phpgw']->strip_html($inv['act_descr']);
                                                if (! $activity)  $activity  = 
'&nbsp;';

                                                $hours_descr = 
$GLOBALS['phpgw']->strip_html($inv['hours_descr']);
                                                if (! $hours_descr)  
$hours_descr  = '&nbsp;';

                                                $start_date = $inv['sdate'];
                                                if ($start_date == 0) { 
$start_dateout = '&nbsp;'; }
                                                else
                                                {
                                                        $start_date = 
$start_date + (60*60) * 
$GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'];
                                                        $start_dateout = 
$GLOBALS['phpgw']->common->show_date($start_date,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
                                                }

                                                if ($prefs['bill'] == 'wu')
                                                {
                                                        if ($inv['minperae'] != 
0)
                                                        {
                                                                $aes = 
ceil($inv['minutes']/$inv['minperae']);
                                                        }
                                                        $onehour = 
$aes*$inv['billperae'];
                                                }
                                                else
                                                {
                                                        $onehour = 
($inv['minutes']/60)*$inv['billperae'];
                                                        $aes = 
floor($inv['minutes']/60) . ':'
                                                                        . 
sprintf ("%02d",(int)($inv['minutes']-floor($inv['minutes']/60)*60));
                                                }

// --------------------- template declaration for list records 
---------------------------

                                                
$GLOBALS['phpgw']->template->set_var(array('select' => $select,
                                                                                
        'activity' => $activity,
                                                                                
'hours_descr' => $hours_descr,
                                                                                
        'status' => lang($inv['status']),
                                                                                
'start_date' => $start_dateout,
                                                                                
                'aes' => $aes,
                                                                                
'billperae' => $inv['billperae'],
                                                                                
        'sum' => sprintf("%01.2f",round($onehour,2))));

                                                if (($inv['status'] != 
'billed') && ($inv['status'] != 'closed'))
                                                {
                                                        
$link_data['menuaction']        = 'projects.uiprojecthours.edit_hours';
                                                        $link_data['hours_id']  
        = $inv['hours_id'];
                                                        
$GLOBALS['phpgw']->template->set_var('edithour',$GLOBALS['phpgw']->link('/index.php',$link_data));
                                                        
$GLOBALS['phpgw']->template->set_var('lang_edit_entry',lang('Edit'));
                                                }
                                                else
                                                {
                                                        
$GLOBALS['phpgw']->template->set_var('edithour','');
                                                        
$GLOBALS['phpgw']->template->set_var('lang_edit_entry','&nbsp;');
                                                }
                                                
$GLOBALS['phpgw']->template->fp('list','hours_list',True);

// -------------------------- end record declaration --------------------------
                                        }
                                }
                        }

                        $GLOBALS['phpgw']->template->set_var('sum_aes',$sumaes);
                        
$GLOBALS['phpgw']->template->set_var('sum_sum',sprintf("%01.2f",round($summe,2)));

                        if (! $invoice_id)
                        {
                                
$GLOBALS['phpgw']->template->set_var('invoice','<input type="submit" 
name="Invoice" value="' . lang('Create invoice') . '">');
                        }
                        else
                        {
                                
$GLOBALS['phpgw']->template->set_var('invoice','<input type="submit" 
name="Invoice" value="' . lang('Update invoice') . '">');
                        }

                        if ($action == 'amains' || $action == 'asubs')
                        {
                                
$GLOBALS['phpgw']->template->set_var('invoice','');
                        }

                        
$GLOBALS['phpgw']->template->pfp('out','hours_list_t',True);
                }

                function fail()
                {
                        echo '<p><center>' . lang('You have to CREATE a 
delivery or invoice first !');
                        echo '</center>';
                        $GLOBALS['phpgw']->common->phpgw_exit();
                }

                function show_invoice()
                {
                        $invoice_id     = get_var('invoice_id',array('GET'));

                        $this->set_app_langs();

                        
$GLOBALS['phpgw']->template->set_file(array('bill_list_t' => 
'bill_invoiceform.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('bill_list_t','bill_list','list');

                        $error = $this->boprojects->check_prefs();
                        if (is_array($error))
                        {
                                
$GLOBALS['phpgw']->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error));
                        }
                        else
                        {
                                $prefs = $this->boprojects->get_prefs();
                                
$GLOBALS['phpgw']->template->set_var('currency',$prefs['currency']);
                                
$GLOBALS['phpgw']->template->set_var('myaddress',$this->bodeliveries->get_address_data('line',$prefs['abid'],$prefs['ifont'],$prefs['mysize']));
                                
$GLOBALS['phpgw']->template->set_var('fulladdress',$this->bodeliveries->get_address_data('full',$prefs['abid'],$prefs['ifont'],$prefs['mysize']));
                        }

                        
$GLOBALS['phpgw']->template->set_var('site_title',$GLOBALS['phpgw_info']['site_title']);
                        $charset = 
$GLOBALS['phpgw']->translation->translate('charset');
                        
$GLOBALS['phpgw']->template->set_var('charset',$charset);
                        
$GLOBALS['phpgw']->template->set_var('font',$prefs['ifont']);
                        
$GLOBALS['phpgw']->template->set_var('fontsize',$prefs['allsize']);
                        
$GLOBALS['phpgw']->template->set_var('img_src',$GLOBALS['phpgw_info']['server']['webserver_url']
 . '/projects/doc/logo.jpg');
                        
$GLOBALS['phpgw']->template->set_var('lang_invoice_for_project',lang('Invoice 
for project'));

                        $bill = 
$this->bobilling->read_single_invoice($invoice_id);

                        if ($prefs)
                        {
                                
$GLOBALS['phpgw']->template->set_var('customer',$this->bodeliveries->get_address_data('address',$bill['customer'],$prefs['ifont'],$prefs['allsize']));
                        }

                        $bill['date'] = $bill['date'] + (60*60) * 
$GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'];
                        $invoice_dateout = 
$GLOBALS['phpgw']->common->show_date($bill['date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
                        
$GLOBALS['phpgw']->template->set_var('invoice_date',$invoice_dateout);

                        
$GLOBALS['phpgw']->template->set_var('invoice_num',$GLOBALS['phpgw']->strip_html($bill['invoice_num']));
                        
$GLOBALS['phpgw']->template->set_var('project_num',$GLOBALS['phpgw']->strip_html($bill['project_num']));
                        $title = $GLOBALS['phpgw']->strip_html($bill['title']);
                        if (! $title) { $title  = '&nbsp;'; }
                        $GLOBALS['phpgw']->template->set_var('title',$title);

                        if ($prefs['bill'] == 'wu')
                        {
                                
$GLOBALS['phpgw']->template->set_var('lang_per',lang('per workunit'));
                                
$GLOBALS['phpgw']->template->set_var('lang_workunits',lang('Workunits'));
                        }
                        else
                        {
                                
$GLOBALS['phpgw']->template->set_var('lang_per',lang('per hour'));
                                
$GLOBALS['phpgw']->template->set_var('lang_workunits',lang('Hours'));
                        }

                        $pos = 0;
                        $sum_netto = 0;
                        $hours = 
$this->bobilling->read_invoice_pos($invoice_id);

                        if (is_array($hours))
                        {
                                while (list($null,$inv) = each($hours))
                                {
                                        $pos++;
                                        
$GLOBALS['phpgw']->template->set_var('pos',$pos);

                                        if ($inv['sdate'] == 0)
                                        {
                                                $hours_dateout = '&nbsp;';
                                        }
                                        else
                                        {
                                                $inv['sdate'] = $inv['sdate'] + 
(60*60) * $GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'];
                                                $hours_dateout = 
$GLOBALS['phpgw']->common->show_date($inv['sdate'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
                                        }

                                        
$GLOBALS['phpgw']->template->set_var('hours_date',$hours_dateout);

                                        if ($prefs['bill'] == 'wu')
                                        {
                                                if ($inv['minperae'] != 0)
                                                {
                                                        $aes = 
ceil($inv['minutes']/$inv['minperae']);
                                                }
                                                $onehour = 
$inv['billperae']*$aes;
                                        // $sum_netto += $onehour;
                                        }
                                        else
                                        {
                                                $onehour = 
($inv['minutes']/60)*$inv['billperae'];

                                                $aes = 
floor($inv['minutes']/60) . ':'
                                                                . sprintf 
("%02d",(int)($inv['minutes']-floor($inv['minutes']/60)*60));

                                                // $sumhours += $inv['minutes'];
                                                // $sum_netto = 
($sumhours/60)*$inv['billperae'];
                                        }

                                        $sum_netto += $onehour;

                                        
$GLOBALS['phpgw']->template->set_var('billperae',$inv['billperae']);
                                        
$GLOBALS['phpgw']->template->set_var('sumpos',sprintf("%01.2f",round($onehour,2)));
                                        
$GLOBALS['phpgw']->template->set_var('aes',$aes);

                                        $act_descr = 
$GLOBALS['phpgw']->strip_html($inv['act_descr']);
                                        if (! $act_descr) { $act_descr  = 
'&nbsp;'; }
                                        
$GLOBALS['phpgw']->template->set_var('act_descr',$act_descr);

                                        
$GLOBALS['phpgw']->template->set_var('billperae',$inv['billperae']);

                                        $hours_descr = 
$GLOBALS['phpgw']->strip_html($inv['hours_descr']);
                                        if (! $hours_descr) { $hours_descr  = 
'&nbsp;'; }
                                        
$GLOBALS['phpgw']->template->set_var('hours_descr',$hours_descr);

                                        
$GLOBALS['phpgw']->template->fp('list','bill_list',True);
                                }
                        }
                        /*      if ($sum == $sum_netto) { 
$t->set_var('error_hint',''); }
                        else { $t->set_var('error_hint',lang('Error in 
calculation sum does not match !')); } */
                        $GLOBALS['phpgw']->template->set_var('error_hint','');

                        $tax = $this->format_tax($prefs['tax']);
            $GLOBALS['phpgw']->template->set_var('tax',$tax);

                        $taxpercent = ($tax/100);
                        $sum_tax = $sum_netto*$taxpercent;

                        
$GLOBALS['phpgw']->template->set_var('sum_netto',sprintf("%01.2f",round($sum_netto,2)));
                        
$GLOBALS['phpgw']->template->set_var('sum_tax',sprintf("%01.2f",round($sum_tax,2)));

                        $sum_sum = $sum_tax + $sum_netto;
                        
$GLOBALS['phpgw']->template->set_var('sum_sum',sprintf("%01.2f",round($sum_sum,2)));
                //      $GLOBALS['phpgw']->template->set_var('sumaes',$sumaes);

                        
$GLOBALS['phpgw']->template->pfp('out','bill_list_t',True);
                        $GLOBALS['phpgw']->common->phpgw_exit();
                }
        }
?>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]