phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] projects/inc/class.boprojects.inc.php, 1.141


From: nomail
Subject: [Phpgroupware-cvs] projects/inc/class.boprojects.inc.php, 1.141
Date: Mon, 21 Jun 2004 01:02:36 +0200

Update of /projects/inc
Modified Files:
        Branch: 
          class.boprojects.inc.php

date: 2004/06/20 23:02:36;  author: ceb;  state: Exp;  lines: +139 -98

Log Message:
update
=====================================================================
Index: projects/inc/class.boprojects.inc.php
diff -u projects/inc/class.boprojects.inc.php:1.140 
projects/inc/class.boprojects.inc.php:1.141
--- projects/inc/class.boprojects.inc.php:1.140 Sat Jun 19 22:47:31 2004
+++ projects/inc/class.boprojects.inc.php       Sun Jun 20 23:02:36 2004
@@ -511,21 +511,32 @@
                        }
                }
 
-               function calculate_budget($factor = 0,$minutes, $project_id = 
0,$project_array = 0,$is_billable = False)
+               function calculate_budget($data = 0)
                {
                        if($this->siteconfig['accounting'] == 'activity')
                        {
-                               $budget = 
$this->sohours->calculate_activity_budget(array('project_id' => 
$project_id,'project_array' => $project_array));
-                               return 
$is_billable?$budget['bbudget']:$budget['budget'];
+                               $budget = 
$this->sohours->calculate_activity_budget(array('project_id' => 
$data['project_id'],'project_array' => $data['project_array']));
+                               return 
$data['is_billable']?$budget['bbudget']:$budget['budget'];
                        }
                        else
                        {
-                               $factor_per_minute = $factor/60;
-                               return round($factor_per_minute*$minutes,2);
+                               $factor_per_minute = $data['factor']/60;
+
+                               $surcharge = 
$data['surcharge']>0?$this->return_value('charge',$data['surcharge']):0;
+                               $budget = 
round($factor_per_minute*$data['minutes'],2);
+                               if($surcharge>0)
+                               {
+                                       $add_surcharge = 
($budget*$surcharge)/100;
+                                       return $budget + $add_surcharge;
+                               }
+                               else
+                               {
+                                       return $budget;
+                               }
                        }
                }
 
-// BUGET FOR ACTIVIES
+// BUDGET FOR ACTIVIES
 
                function get_activity_budget($params)
                {
@@ -589,11 +600,11 @@
 
                        if($params['page'] == 'budget')
                        {
-                               $acc['u_budget'] = 
$this->calculate_budget(0,0,$params['project_id']);
-                               $acc['b_budget'] = 
$this->calculate_budget(0,0,$params['project_id'],0,True);
+                               $acc['u_budget'] = 
$this->calculate_budget(array('project_id' => $params['project_id']));
+                               $acc['b_budget'] = 
$this->calculate_budget(array('project_id' => 
$params['project_id'],'is_billable' => True));
 
-                               $acc['u_budget_jobs'] = 
$this->calculate_budget(0,0,0,$sub_pro);
-                               $acc['b_budget_jobs'] = 
$this->calculate_budget(0,0,0,$sub_pro,True);
+                               $acc['u_budget_jobs'] = 
$this->calculate_budget(array('project_array' => $sub_pro));
+                               $acc['b_budget_jobs'] = 
$this->calculate_budget(array('project_array' => $sub_pro,'is_billable' => 
True));
                        }
                        return $acc;
                }
@@ -645,14 +656,31 @@
                                        return $acc;
                                }
 
-                               $uhours_pro = 
$this->get_time_used(array('project_id' => $params['project_id']));
+                               // ------ project only -------
 
-                               if($params['billable'] == 'Y')
+                               $h_pro = 
$this->sohours->get_time_used(array('project_id' => $params['project_id']));
+
+                               if(is_array($h_pro))
+                               {
+                                       foreach($h_pro as $hp)
+                                       {
+                                               if($hp['billable'] == 'Y')
+                                               {
+                                                       $uhours_pro_bill += 
$h_pro['minutes'];
+                                               } 
+                                               elseif($hp['billable'] == 'N')
+                                               {
+                                                       $uhours_pro_nobill += 
$h_pro['minutes'];
+                                               }
+                                       }
+                                       $uhours_pro = $uhours_pro_bill + 
$uhours_pro_nobill;
+                               }
+                               else
                                {
-                                       $uhours_pro_nobill      = 
$this->sohours->get_time_used(array('project_id' => 
$params['project_id'],'no_billable' => True));
-                                       $uhours_pro_bill        = $uhours_pro - 
$uhours_pro_nobill;
+                                       $uhours_pro_bill = $uhours_pro_nobill = 
$uhours_pro = 0;
                                }
-                               elseif($params['billable'] == 'N')
+
+                               if($params['billable'] == 'N')
                                {
                                        $uhours_pro_nobill      = $uhours_pro;
                                        $uhours_pro_bill        = 0;
@@ -670,13 +698,40 @@
                                $formatted_ahours_pro           = 
$this->sohours->format_wh($params['ptime'] - $uhours_pro);
                                $acc['ahours_pro']                      = 
$formatted_ahours_pro['whwm'];
 
-                               $uhours_jobs                    = 
$this->sohours->get_time_used(array('project_array' => $sub_pro));
-                               $uhours_jobs_bill               = 
$this->sohours->get_time_used(array('project_array' => 
$sub_pro_bill,'is_billable' => True));
+                               // ------ jobs included ------
 
-                               $jobs_nobill_billpro    = 
$this->sohours->get_time_used(array('project_array' => 
$sub_pro_bill,'no_billable' => True));
-                               $jobs_nobill                    = 
$this->sohours->get_time_used(array('project_array' => $sub_pro_nobill));
+                               $h_jobs_bill = 
$this->sohours->get_time_used(array('project_array' => $sub_pro_bill)); // 
project is billable
 
-                               $uhours_jobs_nobill             = 
$jobs_nobill_billpro + $jobs_nobill;
+                               if(is_array($h_jobs_bill))
+                               {
+                                       foreach($h_jobs_bill as $hjb)
+                                       {
+                                               if($hjb['billable'] == 'Y')
+                                               {
+                                                       $uhours_jobs_bill += 
$hjb['minutes'];
+                                               } 
+                                               elseif($hjb['billable'] == 'N')
+                                               {
+                                                       $uhours_jobs_nobill += 
$hjb['minutes'];
+                                               }
+                                       }
+                               }
+                               else
+                               {
+                                       $uhours_jobs_bill = $uhours_jobs_nobill 
= 0;
+                               }
+
+                               $h_jobs_nobill = 
$this->sohours->get_time_used(array('project_array' => $sub_pro_nobill)); // 
project is not billable
+
+                               if(is_array($h_jobs_nobill))
+                               {
+                                       foreach($h_jobs_nobill as $hjnb)
+                                       {
+                                               $uhours_jobs_nobill += 
$hjnb['minutes'];
+                                       }
+                               }
+
+                               $uhours_jobs = $uhours_jobs_bill + 
$uhours_jobs_nobill;
 
                                $formatted_uhours_jobs                  = 
$this->sohours->format_wh($uhours_jobs);
                                $formatted_uhours_jobs_bill             = 
$this->sohours->format_wh($uhours_jobs_bill);
@@ -695,12 +750,28 @@
                                        switch($params['accounting'])
                                        {
                                                case 'project':
-                                                       $acc['u_budget']        
= $this->calculate_budget($params['project_accounting_factor'],$uhours_pro);
-                                                       $acc['b_budget']        
= 
$this->calculate_budget($params['project_accounting_factor'],$uhours_pro_bill);
+                                                       if(is_array($h_pro))
+                                                       {
+                                                               foreach($h_pro 
as $hp)
+                                                               {
+                                                                       
if($params['billable'] == 'Y' && $hp['billable'] == 'Y')
+                                                                       {
+                                                                               
$acc['b_budget'] += $this->calculate_budget(array('factor' => 
$params['project_accounting_factor'],'minutes' => $hp['minutes'],
+                                                                               
                                                                                
                        'surcharge' => $hp['surcharge']));
+                                                                       }
+                                                                       else
+                                                                       {
+                                                                               
$acc['nb_budget'] += $this->calculate_budget(array('factor' => 
$params['project_accounting_factor'],'minutes' => $hp['minutes'],
+                                                                               
                                                                                
                        'surcharge' => $hp['surcharge']));
+                                                                       }
+                                                               }
+                                                               
$acc['u_budget'] = $acc['nb_budget'] + $acc['b_budget'];
+                                                       }
                                                        break;
                                                case 'employee':
                                                        $emps_pro = 
$this->sohours->get_employee_time_used(array('project_id' => 
$params['project_id']));
                                                        
//_debug_array($emps_pro);
+
                                                        
for($i=0;$i<count($emps_pro);$i++)
                                                        {
                                                                $factor = 
$this->soconfig->return_value('acc',$emps_pro[$i]['employee']);
@@ -724,72 +795,63 @@
                                                                                
                }
                                                                                
        }
                                                                                
}
-                                                                               
$bill   = $this->calculate_budget($wh['factor'],$wh['minutes']);
-                                                                               
$acc['u_budget'] += $bill;
-                                                                       }
-                                                               }
-                                                       }
+                                                                               
$bill   = 
$this->calculate_budget($wh['factor'],$wh['minutes'],$wh['surcharge']);
 
-                                                       if($params['billable'] 
== 'Y')
-                                                       {
-                                                               $emps_pro_bill 
= $this->sohours->get_employee_time_used(array('project_id' => 
$params['project_id'],'is_billable' => True));
-                                                               
for($i=0;$i<count($emps_pro_bill);$i++)
-                                                               {
-                                                                       $factor 
= $this->soconfig->return_value('acc',$emps_pro_bill[$i]['employee']);
-                                                                       
if(is_array($emps_pro_bill[$i]['hours']))
-                                                                       {
-                                                                               
foreach($emps_pro_bill[$i]['hours'] as $wh)
+                                                                               
if($wh['billable'] == 'Y')
                                                                                
{
-                                                                               
        $wh['factor'] = 0;
-                                                                               
        if(is_array($factor))
-                                                                               
        {
-                                                                               
                for($j=0;$j<count($factor);++$j)
-                                                                               
                {
-                                                                               
                        if($wh['sdate']>=$factor[$j]['sdate'] && 
$wh['edate']<=$factor[$j]['edate'])
-                                                                               
                        {
-                                                                               
                                $wh['factor'] = $factor[$j]['factor'];
-                                                                               
                        }
-                                                                               
                        else if($factor[$j]['sdate']==0)
-                                                                               
                        {
-                                                                               
                                $wh['factor'] = $factor[$j]['factor'];
-                                                                               
                        }
-                                                                               
                }
-                                                                               
        }
-                                                                               
        $bill   = $this->calculate_budget($wh['factor'],$wh['minutes']);
                                                                                
        $acc['b_budget'] += $bill;
                                                                                
}
+                                                                               
else
+                                                                               
{
+                                                                               
        $acc['nb_budget'] += $bill;
+                                                                               
}
                                                                        }
                                                                }
                                                        }
+
+                                                       $acc['u_budget'] = 
$acc['b_budget'] + $acc['nb_budget'];
+                                                       if($params['billable'] 
== 'N')
+                                                       {
+                                                               
$acc['b_budget'] = 0;
+                                                       }
                                                        
//_debug_array($emps_pro);
                                                        break;
                                        }
 
                                        for($i=0;$i<count($subs);$i++)
                                        {
-                                               $pro_budget = 0;
+                                               $sub_b_budget = $sub_nb_budget 
= 0;
                                                switch($subs[$i]['accounting'])
                                                {
                                                        case 'project':
-                                                               $time_used      
= $this->get_time_used(array('project_id' => $subs[$i]['project_id']));
-                                                               $pro_budget     
= $this->calculate_budget($subs[$i]['acc_factor'],$time_used);
+                                                               $h_sub = 
$this->sohours->get_time_used(array('project_id' => $subs[$i]['project_id']));
 
-                                                               
if($subs[$i]['billable'] == 'Y')
+                                                               
if(is_array($h_sub))
                                                                {
-                                                                       
$time_used_bill         = $this->get_time_used(array('project_id' => 
$subs[$i]['project_id'],'is_billable' => True));
-                                                                       
$pro_budget_bill        = 
$this->calculate_budget($subs[$i]['acc_factor'],$time_used_bill);
+                                                                       
foreach($h_sub as $hs)
+                                                                       {
+                                                                               
if($subs[$i]['billable'] == 'Y' && $hs['billable'] == 'Y')
+                                                                               
{
+                                                                               
        $sub_b_budget += $this->calculate_budget(array('factor' => 
$subs[$i]['project_accounting_factor'],'minutes' => $hs['minutes'],
+                                                                               
                                                                                
                        'surcharge' => $hs['surcharge']));
+                                                                               
}
+                                                                               
else
+                                                                               
{
+                                                                               
        $sub_nb_budget += $this->calculate_budget(array('factor' => 
$subs[$i]['project_accounting_factor'],'minutes' => $hs['minutes'],
+                                                                               
                                                                                
                        'surcharge' => $hs['surcharge']));
+                                                                               
}
+                                                                       }
                                                                }
                                                                break;
                                                        case 'employee':
-                                                               $emps_pro = 
$this->sohours->get_employee_time_used(array('project_id' => 
$subs[$i]['project_id']));
+                                                               $emps_sub = 
$this->sohours->get_employee_time_used(array('project_id' => 
$subs[$i]['project_id']));
 
-                                                               $pro_budget = 
$pro_budget_bill = 0;
-                                                               
for($k=0;$k<count($emps_pro);$k++)
+                                                               
for($k=0;$k<count($emps_sub);$k++)
                                                                {
-                                                                       $factor 
= $this->soconfig->return_value('acc',$emps_pro[$k]['employee']);
-                                                                       
if(is_array($emps_pro[$k]['hours']))
+                                                                       $factor 
= $this->soconfig->return_value('acc',$emps_sub[$k]['employee']);
+                                                                       
if(is_array($emps_sub[$k]['hours']))
                                                                        {
-                                                                               
foreach($emps_pro[$k]['hours'] as $wh)
+                                                                               
foreach($emps_sub[$k]['hours'] as $wh)
                                                                                
{
                                                                                
        $wh['factor'] = 0;
                                                                                
        if(is_array($factor))
@@ -806,48 +868,26 @@
                                                                                
                        }
                                                                                
                }
                                                                                
        }
-                                                                               
        $bill   = $this->calculate_budget($wh['factor'],$wh['minutes']);
-                                                                               
        $pro_budget += $bill;
-                                                                               
}
-                                                                       }
-                                                               }
-                                                               
if($subs[$i]['billable'] == 'Y')
-                                                               {
-                                                                       
$emps_pro_bill = $this->sohours->get_employee_time_used(array('project_id' => 
$subs[$i]['project_id'],'is_billable' => True));
-                                                                       
for($k=0;$k<count($emps_pro_bill);$k++)
-                                                                       {
-                                                                               
$factor = $this->soconfig->return_value('acc',$emps_pro_bill[$k]['employee']);
 
-                                                                               
if(is_array($emps_pro_bill[$k]['hours']))
-                                                                               
{
-                                                                               
        foreach($emps_pro_bill[$k]['hours'] as $wh)
+                                                                               
        if($subs[$i]['billable'] == 'Y' && $wh['billable'] == 'Y')
                                                                                
        {
-                                                                               
                $wh['factor'] = 0;
-                                                                               
                if(is_array($factor))
-                                                                               
                {
-                                                                               
                        for($j=0;$j<count($factor);++$j)
-                                                                               
                        {
-                                                                               
                                if($wh['sdate']>=$factor[$j]['sdate'] && 
$wh['edate']<=$factor[$j]['edate'])
-                                                                               
                                {
-                                                                               
                                        $wh['factor'] = $factor[$j]['factor'];
-                                                                               
                                }
-                                                                               
                                else if($factor[$j]['sdate']==0)
-                                                                               
                                {
-                                                                               
                                        $wh['factor'] = $factor[$j]['factor'];
-                                                                               
                                }
-                                                                               
                        }
-                                                                               
                }
-                                                                               
                $bill   = $this->calculate_budget($wh['factor'],$wh['minutes']);
-                                                                               
                $pro_budget_bill += $bill;
+                                                                               
                $sub_b_budget += $this->calculate_budget(array('factor' => 
$wh['factor'],'minutes' => $wh['minutes'],
+                                                                               
                                                                                
                                'surcharge' => $wh['surcharge']));
+                                                                               
        }
+                                                                               
        else
+                                                                               
        {
+                                                                               
                $sub_nb_budget += $this->calculate_budget(array('factor' => 
$wh['factor'],'minutes' => $wh['minutes'],
+                                                                               
                                                                                
                                'surcharge' => $wh['surcharge']));
                                                                                
        }
                                                                                
}
                                                                        }
                                                                }
                                                                break;
                                                }
-                                               $acc['u_budget_jobs'] += 
$pro_budget;
-                                               $acc['b_budget_jobs'] += 
$pro_budget_bill;
+                                               $nb_budget_jobs += 
$sub_nb_budget;
+                                               $acc['b_budget_jobs'] += 
$sub_b_budget;
                                        }
+                                       $acc['u_budget_jobs'] = 
$acc['b_budget_jobs'] + $nb_budget_jobs;
                                }
                                //_debug_array($acc);
                                return $acc;
@@ -2131,6 +2171,7 @@
                        switch($action)
                        {
                                case 'event':   $list = 
$this->list_events($type); break;
+                               case 'charge':  $list = 
$this->list_surcharges(); break;
                                default:                $list = 
$this->list_roles(); break;
                        }
 




reply via email to

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