fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [10975] Property: budget handling


From: Sigurd Nes
Subject: [Fmsystem-commits] [10975] Property: budget handling
Date: Sun, 10 Mar 2013 16:45:27 +0000

Revision: 10975
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10975
Author:   sigurdne
Date:     2013-03-10 16:45:26 +0000 (Sun, 10 Mar 2013)
Log Message:
-----------
Property: budget handling

Modified Paths:
--------------
    trunk/property/inc/class.soXport.inc.php
    trunk/property/inc/class.sobudget.inc.php
    trunk/property/inc/class.soproject.inc.php
    trunk/property/inc/class.soworkorder.inc.php

Modified: trunk/property/inc/class.soXport.inc.php
===================================================================
--- trunk/property/inc/class.soXport.inc.php    2013-03-08 14:12:37 UTC (rev 
10974)
+++ trunk/property/inc/class.soXport.inc.php    2013-03-10 16:45:26 UTC (rev 
10975)
@@ -786,6 +786,7 @@
 
                                foreach ($orders as $order)
                                {
+                                       
phpgwapi_cache::system_clear('property', "budget_order_{$order['order_id']}");
                                        $this->db->query("UPDATE fm_workorder 
SET actual_cost = '{$order['actual_cost']}' WHERE id = 
'{$order['order_id']}'",__LINE__,__FILE__);
                                }
                        }
@@ -795,6 +796,8 @@
                // operator="-" ved tilbakerulling
                public function correct_actual_cost($order_id, $amount, 
$actual_cost_field, $operator)
                {
+                       phpgwapi_cache::system_clear('property', 
"budget_order_{$order_id}");
+
                        $sql = "SELECT type FROM fm_orders WHERE 
id='{$order_id}'";
                        $this->db->query($sql,__LINE__,__FILE__);
                        $this->db->next_record();

Modified: trunk/property/inc/class.sobudget.inc.php
===================================================================
--- trunk/property/inc/class.sobudget.inc.php   2013-03-08 14:12:37 UTC (rev 
10974)
+++ trunk/property/inc/class.sobudget.inc.php   2013-03-10 16:45:26 UTC (rev 
10975)
@@ -651,19 +651,16 @@
                                $_taxcode[$this->db->f('id')] = 
$this->db->f('percent');
                        }
 
-                       $sql = "SELECT DISTINCT fm_workorder.id AS id, 
sum(fm_orders_paid_or_pending_view.amount) AS actual_cost,fm_location1.mva,"
-                               . " fm_b_account.{$b_account_field} as 
{$b_account_field}, district_id, fm_workorder.ecodimb"
+                       $sql = "SELECT DISTINCT fm_workorder.id AS id, 
fm_location1.mva,"
+                               . " fm_b_account.{$b_account_field} AS 
b_account, district_id, fm_workorder.ecodimb"
                                . " FROM fm_workorder"
                                . " {$this->join} fm_workorder_status ON 
fm_workorder.status = fm_workorder_status.id"
                                . " {$this->join} fm_workorder_budget ON 
(fm_workorder.id = fm_workorder_budget.order_id)"
                                . " {$this->join} fm_b_account ON 
fm_workorder.account_id = fm_b_account.id"
                                . " {$this->join} fm_project ON  
fm_workorder.project_id = fm_project.id"
-                               . " {$this->left_join} 
fm_orders_paid_or_pending_view ON fm_workorder.id = 
fm_orders_paid_or_pending_view.order_id"
                                . " {$_join_district}"
                                . " {$this->join} fm_part_of_town ON 
fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id"
-                               . " {$filtermethod_paid}{$filtermethod} 
{$querymethod} {$where} {$filtermethod_direction}"
-                               . " GROUP BY fm_workorder.id, fm_location1.mva,"
-                               . " fm_b_account.{$b_account_field}, 
district_id, fm_workorder.ecodimb";
+                               . " {$filtermethod_order}{$filtermethod} 
{$querymethod} {$where} {$filtermethod_direction}";
 
 //                     _debug_array($sql);
                        //die();
@@ -675,108 +672,64 @@
                                $_id = $this->db->f('id');
                                $_temp_paid_info[$_id] = array
                                (
-                                       'actual_cost'                   => 
$this->db->f('actual_cost'),
+                                       'actual_cost'                   => 0,
                                        'mva'                                   
=> (int)$this->db->f('mva'),
                                        'district_id'                   => 
(int)$this->db->f('district_id'),
                                        'ecodimb'                               
=> (int)$this->db->f('ecodimb'),
-                                       $b_account_field                => 
$this->db->f($b_account_field),
+                                       'b_account'                             
=> $this->db->f('b_account'),
                                );
                        }
 
+                       $soworkorder = CreateObject('property.soworkorder');
 
-                       $sql = "SELECT DISTINCT fm_workorder.id, 
fm_workorder_status.closed, sum(fm_workorder_budget.budget) AS budget, 
sum(fm_workorder_budget.combined_cost) AS combined_cost 
,fm_location1.mva,fm_workorder.start_date,"
-                               . " fm_b_account.{$b_account_field} as 
{$b_account_field}, district_id, fm_workorder.ecodimb"
-                               . " FROM fm_workorder"
-                               . " {$this->join} fm_workorder_status ON 
fm_workorder.status = fm_workorder_status.id"
-                               . " {$this->join} fm_workorder_budget ON 
(fm_workorder.id = fm_workorder_budget.order_id AND fm_workorder_budget.active 
= 1 AND fm_workorder_budget.year = {$year})"
-                               . " {$this->join} fm_b_account ON 
fm_workorder.account_id = fm_b_account.id"
-                               . " {$this->join} fm_project ON  
fm_workorder.project_id = fm_project.id"
-                               . " {$_join_district}"
-                               . " {$this->join} fm_part_of_town ON 
fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id"
-                               . " {$filtermethod_order}{$filtermethod} 
{$querymethod} {$where} {$filtermethod_direction}"
-                               . " GROUP BY fm_workorder.id, 
fm_workorder_status.closed, fm_location1.mva, fm_workorder.start_date,"
-                               . " fm_b_account.{$b_account_field}, 
district_id, fm_workorder.ecodimb";
-//_debug_array($sql);
-                       $this->db->query($sql . $ordermethod,__LINE__,__FILE__);
+                       foreach ($_temp_paid_info as $order_id => &$order_info)
+                       {
+                               $order_budget = 
$soworkorder->get_budget($order_id);
+                               foreach($order_budget as $budget)
+                               {
+                                       if($budget['year'] == $year && 
$budget['active'])
+                                       {
+                                               $order_info['actual_cost']      
        += $budget['actual_cost'];
+                                               $order_info['combined_cost']    
+= $budget['sum_orders'];
+                                               $order_info['budget']           
        += $budget['budget'];
+                                               $order_info['obligation']       
        += $budget['sum_oblications'];
+                                       }
+                               }
+                       }
 
+                       reset($_temp_paid_info);
                        $sum_actual_cost = 0;
                        $actual_cost = array();
                        $sum_obligation_cost = 0;
                        $obligations = array();
                        $sum_hits = 0;
-                       $_local_combined_cost = array();
-//$_test=array();
-                       while ($this->db->next_record())
-                       {
-                               $_id = $this->db->f('id');
-                               if (!isset($_local_combined_cost[$_id]) && ! 
$_combined_cost = $_local_combined_cost[$_id])
-                               {
-                                       $_local_combined_cost[$_id] = 
round($this->db->f('combined_cost'));
-                                       $_combined_cost = 
$_local_combined_cost[$_id];
-                               }
 
-                               $_taxfactor = 1 + 
($_taxcode[(int)$this->db->f('mva')]/100);
-                               $_actual_cost = 
isset($_temp_paid_info[$_id]['actual_cost']) && 
$_temp_paid_info[$_id]['actual_cost'] ? 
round($_temp_paid_info[$_id]['actual_cost']/$_taxfactor) : 0;
-               //              $_actual_cost = 
round($_temp_paid_info[$_id]['actual_cost']);
-                               $_obligation = $_combined_cost - $_actual_cost;
+                       $sum_hits = count($_temp_paid_info);
 
-                               unset($_temp_paid_info[$_id]);
-                               unset($_id);
+                       foreach ($_temp_paid_info as $order_id => $order_info)
+                       {
+                               $_combined_cost = $order_info['combined_cost'];
 
-                               // only the current year
-                               if($this->db->f('start_date') < $start_date)
-                               {
-//                                     $_actual_cost = 0;
-                               }
+                               $_taxfactor             = 1 + 
($_taxcode[(int)$order_info['mva']]/100);
+                               $_actual_cost   = 
round($order_info['actual_cost']/$_taxfactor);
+                               $_obligation    = $order_info['obligation'];
 
-                               $sum_hits += 1;
+                               $sum_obligation_cost += $_obligation;
+                               
$obligations[$order_info['b_account']][$order_info['district_id']][$order_info['ecodimb']]
 += $_obligation;
 
-                               if(!$this->db->f('closed'))
-                               {
-                                       if((int)$this->db->f('budget') >= 0)
-                                       {
-                                               if($_obligation < 0)
-                                               {
-//$_test[] = $_obligation;
-                                                       $_obligation = 0;
-                                               }
-                                       }
-                                       else
-                                       {
-                                               if($_obligation > 0)
-                                               {
-                                                       $_obligation = 0;
-                                               }
-                                       }
-
-                                       $sum_obligation_cost += $_obligation;
-                                       
$obligations[$this->db->f($b_account_field)][(int)$this->db->f('district_id')][(int)$this->db->f('ecodimb')]
 += $_obligation;
-                               }
 //_debug_array($_test);
-                               
$hits[$this->db->f($b_account_field)][(int)$this->db->f('district_id')][(int)$this->db->f('ecodimb')]
 += 1;
-                               $accout_info[$this->db->f($b_account_field)] = 
true;
-                               $district[$this->db->f('district_id')] = true;
-                               $ecodimb[(int)$this->db->f('ecodimb')] = true;
+                               
$hits[$order_info['b_account']][$order_info['district_id']][$order_info['ecodimb']]
 += 1;
+                               $accout_info[$order_info['b_account']] = true;
+                               $district[$order_info['district_id']] = true;
+                               $ecodimb[$order_info['ecodimb']] = true;
 
                                $sum_actual_cost += $_actual_cost;
-                               
$actual_cost[$this->db->f($b_account_field)][(int)$this->db->f('district_id')][(int)$this->db->f('ecodimb')]
 += $_actual_cost;
-
+                               
$actual_cost[$order_info['b_account']][$order_info['district_id']][$order_info['ecodimb']]
 += $_actual_cost;
                        }
 
 
-//                     _debug_array($_temp_paid_info);
-                       
-                       foreach ($_temp_paid_info as $_id => $_paid)
-                       {
-                               $accout_info[$_paid[$b_account_field]] = true;
-                               $district[$_paid['district_id']] = true;
-                               $ecodimb[$_paid['ecodimb']] = true;
 
-                               $_taxfactor = 1 + 
($_taxcode[(int)$_paid['mva']]/100);
-                               $_actual_cost =  
round($_paid['actual_cost']/$_taxfactor);
-                               $sum_actual_cost += $_actual_cost;
-                               
$actual_cost[$_paid[$b_account_field]][(int)$_paid['district_id']][(int)$_paid['ecodimb']]
 += $_actual_cost;
-                       }
+//_debug_array($_temp_paid_info);
 
 //                     _debug_array($obligations);
 

Modified: trunk/property/inc/class.soproject.inc.php
===================================================================
--- trunk/property/inc/class.soproject.inc.php  2013-03-08 14:12:37 UTC (rev 
10974)
+++ trunk/property/inc/class.soproject.inc.php  2013-03-10 16:45:26 UTC (rev 
10975)
@@ -2295,8 +2295,14 @@
                                $deviation = abs($entry['actual_cost']) > 0 ? 
$_deviation : 0;
                                $entry['deviation_period'] = $deviation;
                                $budget_acc +=$entry['budget'];
-                               $deviation_acc += $deviation;
+
+                               if($active_period[$entry['period']])
+                               {
+                                       $deviation_acc += $deviation;
+                               }
+
                                $entry['deviation_acc'] = abs($deviation) > 0 ? 
$deviation_acc : 0;
+
                                $entry['deviation_percent_period'] = 
$deviation/$entry['budget'] * 100;
                                $entry['deviation_percent_acc'] = 
$entry['deviation_acc']/$budget_acc * 100;
                                $entry['closed'] = 
$closed_period[$entry['period']];

Modified: trunk/property/inc/class.soworkorder.inc.php
===================================================================
--- trunk/property/inc/class.soworkorder.inc.php        2013-03-08 14:12:37 UTC 
(rev 10974)
+++ trunk/property/inc/class.soworkorder.inc.php        2013-03-10 16:45:26 UTC 
(rev 10975)
@@ -1255,6 +1255,8 @@
                        $workorder['title'] = 
$this->db->db_addslashes($workorder['title']);
                        $workorder['billable_hours'] = 
(float)str_replace(',','.', $workorder['billable_hours']);
 
+                       phpgwapi_cache::system_clear('property', 
"budget_order_{$workorder['id']}");
+
                        $this->db->query("SELECT 
status,calculation,billable_hours,approved FROM fm_workorder WHERE id = 
{$workorder['id']}",__LINE__,__FILE__);
                        $this->db->next_record();
 
@@ -1682,6 +1684,13 @@
                                return array();
                        }
 
+                       $cached_info = phpgwapi_cache::system_get('property', 
"budget_order_{$order_id}");
+
+                       if($cached_info)
+                       {
+                               return $cached_info;
+                       }
+
                        $closed_period = array();
                        $active_period = array();
 
@@ -1848,11 +1857,10 @@
                        }
 
 //_debug_array($values);die();
+                       $deviation_acc = 0;
+                       $budget_acc = 0;
                        foreach ($values as &$entry)
                        {
-       //                      $entry['year'] = substr( $entry['period'], 0, 4 
);
-       //                      $month = substr( $entry['period'], 4, 2 );
-       //                      $entry['month'] = $month == '00' ? '' : $month;
                                if($active_period[$entry['period']])
                                {
                                        $_diff_start = abs($entry['budget']) > 
0 ? $entry['budget'] : $entry['sum_orders'];
@@ -1865,12 +1873,25 @@
                                $_deviation = $entry['budget'] - 
$entry['actual_cost'];
                                $deviation = abs($entry['actual_cost']) > 0 ? 
$_deviation : 0;
                                $entry['deviation_period'] = $deviation;
-                               $entry['deviation_acc'] += $deviation;
+                               $budget_acc +=$entry['budget'];
+
+                               if($active_period[$entry['period']])
+                               {
+                                       $deviation_acc += $deviation;
+                               }
+
+                               $entry['deviation_acc'] = abs($deviation) > 0 ? 
$deviation_acc : 0;
+
+
                                $entry['deviation_percent_period'] = 
$deviation/$entry['budget'] * 100;
-                               $entry['deviation_percent_acc'] = 
$entry['deviation_acc']/$entry['budget'] * 100;
+                               $entry['deviation_percent_acc'] = 
$entry['deviation_acc']/$budget_acc * 100;
+
                                $entry['closed'] = 
$closed_period[$entry['period']];
                                $entry['active'] = 
$active_period[$entry['period']];
                        }
+
+                       phpgwapi_cache::system_set('property', 
"budget_order_{$order_id}", $values);
+
                        return $values;
                }
 




reply via email to

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