fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [11025] property: budget handling


From: Sigurd Nes
Subject: [Fmsystem-commits] [11025] property: budget handling
Date: Thu, 04 Apr 2013 12:35:31 +0000

Revision: 11025
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11025
Author:   sigurdne
Date:     2013-04-04 12:35:30 +0000 (Thu, 04 Apr 2013)
Log Message:
-----------
property: budget handling

Modified Paths:
--------------
    trunk/property/inc/class.soXport.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-04-04 08:13:58 UTC (rev 
11024)
+++ trunk/property/inc/class.soXport.inc.php    2013-04-04 12:35:30 UTC (rev 
11025)
@@ -769,6 +769,8 @@
 
                public function 
update_actual_cost_from_archive($orders_affected)
                {
+                       $soworkorder = CreateObject('property.soworkorder');
+
                        $orders = array();
                        if($orders_affected)
                        {
@@ -788,6 +790,29 @@
                                {
                                        
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__);
+
+
+                                       $this->db->query("SELECT max(periode) 
AS period, max(amount) AS amount FROM fm_orders_paid_or_pending_view WHERE 
order_id =  {$order['order_id']}",__LINE__,__FILE__);
+                                       $this->db->next_record();
+                                       $period         =       
$this->db->f('period');
+                                       $amount         =       
$this->db->f('amount');
+                                       $year           =       $period ? (int) 
substr($period,0,4) : date('Y');
+
+                                       $this->db->query("SELECT order_id FROM 
fm_workorder_budget WHERE order_id = {$order['order_id']} AND year = 
{$year}",__LINE__,__FILE__);
+                                       if(!$this->db->next_record())
+                                       {
+                                               try
+                                               {
+                                                       
$soworkorder->transfer_budget($order['order_id'], $amount, $year);
+                                               }
+                                               catch(Exception $e)
+                                               {
+                                                       if ( $e )
+                                                       {
+                                                               
phpgwapi_cache::message_set($e->getMessage(), 'error'); 
+                                                       }
+                                               }
+                                       }
                                }
                        }
                }

Modified: trunk/property/inc/class.soproject.inc.php
===================================================================
--- trunk/property/inc/class.soproject.inc.php  2013-04-04 08:13:58 UTC (rev 
11024)
+++ trunk/property/inc/class.soproject.inc.php  2013-04-04 12:35:30 UTC (rev 
11025)
@@ -1002,115 +1002,7 @@
                        return $values;
                }
 
-               //FIXME
-               function project_workorder_data_old($data = array())
-               {
-                       $project_id = (int) $data['project_id'];
-                       $year = (int) $data['year'];
-                       $values = array();
 
-                       $filter_year = '';
-                       if($year)
-                       {
-//                             $start_date = mktime(0, 0, 0, 1, 1, $year)
-//                             $end_date = mktime(23, 59, 59, 12, 31, $year)
-                               $filter_year = "AND fm_workorder_budget.year = 
{$year}";
-                       }
-
-                       $this->db->query("SELECT DISTINCT fm_workorder.title, 
fm_workorder.actual_cost, fm_workorder.id as 
workorder_id,fm_workorder.contract_sum,"
-                               . " fm_workorder.vendor_id, 
fm_workorder.calculation,fm_workorder.rig_addition,fm_workorder.addition,fm_workorder.deviation,fm_workorder.charge_tenant,"
-                               . " fm_workorder_status.descr as status, 
fm_workorder_status.closed, fm_workorder.account_id as b_account_id"
-                               . " 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"
-                               . " WHERE project_id={$project_id} 
{$filter_year}",__LINE__,__FILE__);
-
-                       $_orders = array();
-
-                       while ($this->db->next_record())
-                       {
-                               $values[] = array(
-                                       'workorder_id'          => 
$this->db->f('workorder_id'),
-                                       'title'                         => 
$this->db->f('title',true),
-                                       'deviation'                     => 
$this->db->f('deviation'),
-                                       'calculation'           => 
$this->db->f('calculation'),
-                                       'actual_cost'           => 0,
-                                       'obligation'            => 0,
-                                       'vendor_id'                     => 
$this->db->f('vendor_id'),
-                                       'charge_tenant'         => 
$this->db->f('charge_tenant'),
-                                       'status'                        => 
$this->db->f('status'),
-                                       'closed'                        => 
!!$this->db->f('closed'),
-                                       'b_account_id'          => 
$this->db->f('b_account_id'),
-                                       'contract_sum'          => 
(int)$this->db->f('contract_sum'),
-                                       'addition_percentage'   => 
(int)$this->db->f('addition')
-                               );
-                               $_orders[] = $this->db->f('workorder_id');
-                       }
-
-                       if($_orders)
-                       {
-                               $_actual_cost_arr = array();
-
-                               $sql_cost = "SELECT order_id, sum(amount) AS 
actual_cost"
-                               . " FROM fm_workorder {$this->join} 
fm_orders_paid_or_pending_view ON fm_workorder.id = 
fm_orders_paid_or_pending_view.order_id"
-                               . ' WHERE order_id IN (' . implode(',', 
$_orders ) .') GROUP BY order_id';
-                               $this->db->query($sql_cost,__LINE__,__FILE__);
-                               while ($this->db->next_record())
-                               {
-                                       
$_actual_cost_arr[$this->db->f('order_id')] = $this->db->f('actual_cost');
-                               }
-                       }
-
-                       foreach ($values as &$entry)
-                       {
-                               $this->db2->query("SELECT 
sum(fm_workorder_budget.budget) AS budget,"
-                                . " sum(fm_workorder_budget.combined_cost) AS 
combined_cost"
-                                . " FROM fm_workorder_budget WHERE active =1 
AND order_id ='{$entry['workorder_id']}'",__LINE__,__FILE__);
-                                $this->db2->next_record();
-
-                               $entry['combined_cost'] = 
$this->db2->f('combined_cost');
-                               $entry['budget'] = $this->db2->f('budget');
-
-
-                               $_combined_cost = 
round($entry['combined_cost']);
-
-                               $_actual_cost = 
isset($_actual_cost_arr[$entry['workorder_id']]) && 
$_actual_cost_arr[$entry['workorder_id']] ? 
$_actual_cost_arr[$entry['workorder_id']] : 0;
-
-               //              FIXME
-               //              $_taxfactor = 1 + 
($_taxcode[(int)$this->db->f('mvakode')]/100);
-               //              $_actual_cost = round($actual_cost/$_taxfactor);
-
-                               $entry['actual_cost'] = $_actual_cost;
-
-                               $_obligation = 0;
-                               if(!$entry['closed'])
-                               {
-                                       $_obligation = $_combined_cost - 
$_actual_cost;
-                                       if($entry['budget'] >= 0)
-                                       {
-                                               if($_obligation < 0)
-                                               {
-                                                       $_obligation = 0;
-                                               }
-                                       }
-                                       else
-                                       {
-                                               if($_obligation > 0)
-                                               {
-                                                       $_obligation = 0;
-                                               }
-                                       }
-                                       $entry['obligation'] = $_obligation;
-                               }
-
-                               $_diff_start = abs($entry['budget']) > 0 ? 
$entry['budget'] : $_combined_cost;
-                               $entry['diff'] = $_diff_start - 
$entry['obligation'] - $entry['actual_cost'];
-//                             $entry['diff'] =  $entry['budget'] - 
$entry['obligation'] - $entry['actual_cost'];
-                       }
-
-                       return $values;
-               }
-
                function branch_p_list($project_id = '')
                {
                        $selected = array();
@@ -2369,344 +2261,7 @@
 
                }
 
-               function get_budget_old($project_id)
-               {
-                       $project_id = (int) $project_id;
-                       $closed_period = array();
-                       $active_period = array();
-                       $project_budget = array();
-                       $project_total_budget = 0;
 
-                       $sql = "SELECT fm_project_budget.year, 
fm_project_budget.month, fm_project_budget.budget, fm_project_budget.closed, 
fm_project_budget.active, sum(combined_cost) AS order_amount"
-                       . " FROM fm_project_budget {$this->left_join} 
fm_workorder ON fm_project_budget.project_id = fm_workorder.project_id WHERE 
fm_project_budget.project_id = {$project_id}"
-                       . " GROUP BY fm_project_budget.year, 
fm_project_budget.month, fm_project_budget.budget, fm_project_budget.closed, 
fm_project_budget.active"
-                       . " ORDER BY fm_project_budget.year, 
fm_project_budget.month";
-                       $this->db->query($sql,__LINE__,__FILE__);
-//     _debug_array($sql);
-                       while ($this->db->next_record())
-                       {
-                               $period = $this->db->f('year') . 
sprintf("%02s", $this->db->f('month'));
-
-                               $project_budget[$period] = 
(int)$this->db->f('budget');
-                               $closed_period[$period] = 
!!$this->db->f('closed');
-                               $active_period[$period] = 
!!$this->db->f('active');
-                       }
-
-                       $project_total_budget = array_sum($project_budget);
-
-                       $sql = "SELECT fm_workorder.id AS order_id, 
sum(fm_workorder_budget.combined_cost) AS combined_cost, 
sum(fm_workorder_budget.budget) AS budget, fm_workorder_budget.year, 
fm_workorder_budget.month, fm_workorder_status.closed"
-                               . " 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"
-                               . " WHERE fm_workorder_budget.active = 1 AND 
project_id = {$project_id}"
-                               . " GROUP BY fm_workorder.id, 
fm_workorder_budget.year, fm_workorder_budget.month, fm_workorder_status.closed"
-                               . " ORDER BY fm_workorder_budget.year, 
fm_workorder_budget.month";
-//     _debug_array($sql);die();
-                       $this->db->query($sql,__LINE__,__FILE__);
-
-                       $_order_list = array();
-                       $_orders = array();
-                       $_order_info = array();
-                       while ($this->db->next_record())
-                       {
-                               $period = $this->db->f('year') . 
sprintf("%02s", $this->db->f('month'));
-                               $_order_id = $this->db->f('order_id');
-                               $_order_list[] = $_order_id;
-                               $_temp_info = array
-                               (
-                                       'combined_cost' => 
$this->db->f('combined_cost'),
-                                       'budget'                => 
$this->db->f('budget'),
-                                       'actual_cost'   => 0, //for now..
-                                       'closed'                => 
!!$this->db->f('closed')
-                               );
-
-                               $_orders[$period][$_order_id] = $_temp_info;
-                               $_order_info[$_order_id] = $_temp_info;
-                       }
-
-//_debug_array($_orders);
-//die();
-$test = 0;
-                       if ( $_order_list )
-                       {
-                               $sql = "SELECT order_id, periode, amount AS 
actual_cost"
-                               . " FROM fm_workorder {$this->join} 
fm_orders_paid_or_pending_view ON fm_workorder.id = 
fm_orders_paid_or_pending_view.order_id"
-                               . ' WHERE order_id IN (' . implode(',', 
$_order_list ) .') ORDER BY periode ASC';
-//_debug_array($sql);
-                               $this->db->query($sql,__LINE__,__FILE__);
-                               while ($this->db->next_record())
-                               {
-                                       $_order_id = $this->db->f('order_id');
-                                       $periode = $this->db->f('periode');
-                                       if(!$periode)
-                                       {
-                                               $periode = date('Ym');
-                                       }
-
-                                       $year = substr( $periode, 0, 4 );
-
-                                       $_found = false;
-                                       if(isset($project_budget[$periode]))
-                                       {
-                                               
$_orders[$periode][$_order_id]['actual_cost'] += $this->db->f('actual_cost');
-                                               $_found = true;
-                                       }
-                                       else
-                                       {
-                                               for ($i=0;$i<13;$i++)
-                                               {
-                                                       $_period = $year . 
sprintf("%02s", $i);
-                                                       
if(isset($project_budget[$_period]))
-                                                       {
-                                                               
$_orders[$_period][$_order_id]['actual_cost'] += $this->db->f('actual_cost');
-//_debug_array($test+=$this->db->f('actual_cost'));
-                                                               $_found = true;
-                                                               break;
-                                                       }
-                                               }
-                                       }
-
-                                       if(!$_found)
-                                       {
-                                               
$_orders[$periode][$_order_id]['actual_cost'] += $this->db->f('actual_cost');
-                                       }
-                               }
-                       }
-
-
-                       if($_orders)
-                       {
-                               ksort($_orders);
-                       }
-
-
-//_debug_array($_orders);
-//die();
-
-                       $sort_period = array();
-                       $values = array();
-//_debug_array($project_budget);die();
-//$test = 0;
-                       $_current_period = date('Ym');
-                       $_delay_period = 0;
-                       foreach ($project_budget as $period => $_budget)
-                       {
-                               $_sum_orders = array();
-                               $_sum_oblications = array();
-                               $_actual_cost = 0;
-
-                               if(isset($_orders[$period]))
-                               {
-//_debug_array($_orders[$period]);//die();
-
-                                       foreach ($_orders[$period] as $order_id 
=> $order)
-                                       {
-                                               $_actual_cost += 
$order['actual_cost'];
-//_debug_array( $test+= $order['actual_cost']);
-                                               $_sum_orders[$order_id] += 
$order['combined_cost'];
-
-                                               
if(!$_order_info[$order_id]['closed'])
-                                               {
-//_debug_array($order_id);
-                                                       
$_sum_oblications[$order_id] += $order['combined_cost'];
-                                                       
$_sum_oblications[$order_id] -= $order['actual_cost'];
-//_debug_array($_sum_oblications[$order_id]);
-                                       //              
if($project_total_budget >= 0)
-                                       //              if($_budget >= 0)
-                                                       
if($_order_info[$order_id]['budget'] >= 0)
-                                                       {
-
-                                                               
if($_sum_oblications[$order_id] < 0)
-                                                               {
-                                                                       
$_sum_oblications[$order_id] = 0;
-                                                               }
-                                                       }
-                                                       else // income
-                                                       {
-                                                               
if($_sum_oblications[$order_id] > 0)
-                                                               {
-                                                                       
$_sum_oblications[$order_id] = 0;
-                                                               }
-                                                       }
-                                               }
-
-                                               //override if periode is closed
-                                               
if(!isset($active_period[$period]) || !$active_period[$period])
-                                               {
-                                                       $_delay_period += 
$_sum_oblications[$order_id];
-                                                       
$_sum_oblications[$order_id] = 0;
-                                               }
-                                               else if ((int)$_current_period 
> (int)$period)
-                                               {
-                                                       $_delay_period += 
$_sum_oblications[$order_id];
-                                                       
$_sum_oblications[$order_id] = 0;
-                                               }
-
-                                               //override if periode is closed
-                                               
if(isset($closed_period[$period]) && $closed_period[$period])
-                                               {
-                                                       
$_sum_oblications[$order_id] = 0;
-                                               }
-                                       }
-
-                                       unset($_orders[$period]);
-                               }
-
-                               if(isset($active_period[$period]) && 
$active_period[$period] && $_delay_period && (int) $_current_period < 
(int)$period)
-                               {
-                                       $_sum_oblications[] += $_delay_period;
-                                       $_delay_period =0;
-                               }
-//die();
-                               $values[] = array
-                               (
-                                       'project_id'                    => 
$project_id,
-                                       'period'                                
=> $period,
-                                       'budget'                                
=> $_budget,
-                                       'sum_orders'                    => 
array_sum($_sum_orders),
-                                       'sum_oblications'               => 
array_sum($_sum_oblications),
-                                       'actual_cost'                   => 
$_actual_cost,
-                                       'deviation_acc'                 => 0
-                               );
-
-                               $sort_period[] = $period;
-                       }
-
-                       if($_delay_period && $values)
-                       {
-                               $i = count($values) -1;
-                               //last one
-                               $values[$i]['sum_oblications'] += 
$_delay_period;
-                               $_delay_period = 0;
-                       }
-
-//_debug_array( $values);die();
-                       unset($order);
-                       unset($order_id);
-                       unset($period);
-
-                       reset($_orders);
-
-                       //remaining
-
-
-                       foreach ($_orders as $period => $orders)
-                       {
-                               $_sum_orders = array();
-                               $_sum_oblications = array();
-                               $_actual_cost = 0;
-
-                               foreach ($orders as $order_id => $order)
-                               {
-                                       $_actual_cost += $order['actual_cost'];
-
-                                       $_sum_orders[$order_id] += 
$order['combined_cost'];
-
-                                       if(!$_order_info[$order_id]['closed'])
-                                       {
-                                               $_sum_oblications[$order_id] -= 
$order['actual_cost'];
-                                               $_sum_oblications[$order_id] += 
$order['combined_cost'];
-
-                                               if($project_total_budget >= 0)
-                                               {
-                                                       
if($_sum_oblications[$order_id] < 0)
-                                                       {
-                                                               
$_sum_oblications[$order_id] = 0;
-                                                       }
-                                               }
-                                               else // income
-                                               {
-                                                       
if($_sum_oblications[$order_id] > 0)
-                                                       {
-                                                               
$_sum_oblications[$order_id] = 0;
-                                                       }
-                                               }
-                                       }
-
-                                       //override if periode is closed
-                                       if(!isset($active_period[$period]) || 
!$active_period[$period])
-                                       {
-                                               $_delay_period += 
$_sum_oblications[$order_id];
-                                               $_sum_oblications[$order_id] = 
0;
-                                       }
-                                       else if ((int)$_current_period > 
(int)$period)
-                                       {
-                                               $_delay_period += 
$_sum_oblications[$order_id];
-                                               $_sum_oblications[$order_id] = 
0;
-                                       }
-
-                                       //override if periode is closed
-                                       if(isset($closed_period[$period]) && 
$closed_period[$period])
-                                       {
-                                               $_sum_oblications[$order_id] = 
0;
-                                       }
-                               }
-
-                               if(isset($active_period[$period]) && 
$active_period[$period] && $_delay_period && (int) $_current_period < 
(int)$period)
-                               {
-                                       $_sum_oblications[] += $_delay_period;
-                                       $_delay_period =0;
-                               }
-
-                               $values[] = array
-                               (
-                                       'project_id'                    => 
$project_id,
-                                       'period'                                
=> $period,
-                                       'budget'                                
=> 0,
-                                       'sum_orders'                    => 
array_sum($_sum_orders),
-                                       'sum_oblications'               => 
array_sum($_sum_oblications),
-                                       'actual_cost'                   => 
$_actual_cost,
-                                       'deviation_acc'                 => 0
-                               );
-
-                               $sort_period[] = $period;
-                       }
-
-                       if($_delay_period && $values)
-                       {
-                               $i = count($values) -1;
-                               //last one
-                               $values[$i]['sum_oblications'] += 
$_delay_period;
-                       }
-
-
-                       if($values)
-                       {
-                               array_multisort($sort_period, SORT_ASC, 
$values);
-                       }
-
-
-                       $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'];
-                                       $entry['diff'] = $_diff_start - 
$entry['sum_oblications'] - $entry['actual_cost'];
-                               }
-                               else
-                               {
-                                       $entry['diff'] =  0;
-                               }
-                               $_deviation = $entry['budget'] - 
$entry['actual_cost'];
-                               $deviation = abs($entry['actual_cost']) > 0 ? 
$_deviation : 0;
-                               $entry['deviation_period'] = $deviation;
-                               $budget_acc +=$entry['budget'];
-                               $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']];
-                               $entry['active'] = 
$active_period[$entry['period']];
-                       }
-
-                       return $values;
-               }
-
                function delete_period_from_budget($project_id, $data)
                {
                        $project_id = (int) $project_id;

Modified: trunk/property/inc/class.soworkorder.inc.php
===================================================================
--- trunk/property/inc/class.soworkorder.inc.php        2013-04-04 08:13:58 UTC 
(rev 11024)
+++ trunk/property/inc/class.soworkorder.inc.php        2013-04-04 12:35:30 UTC 
(rev 11025)
@@ -2036,65 +2036,9 @@
 
                        
execMethod('property.soXport.update_actual_cost_from_archive',$orders);
 
-                       $config = CreateObject('phpgwapi.config','property');
-                       $config->read_repository();
-                       $tax = 1+(($config->config_data['fm_tax'])/100);
 
-//                     $this->db->query("UPDATE fm_project_budget SET 
order_amount = 0",__LINE__,__FILE__);
-/**
- * FIXME: won't work for periodized order that last several years
- *
- **/
 
-/*
-                       foreach ($orders as $id => $dummy)
-                       {
-                               $this->db->query("SELECT project_id, 
start_date, combined_cost, budget,calculation,contract_sum,addition,ecodimb 
FROM fm_workorder WHERE id = {$id}",__LINE__,__FILE__);
-                               $this->db->next_record();
 
-                               $old_combined_cost      = 
$this->db->f('combined_cost');
-                               $budget                         = 
$this->db->f('budget');
-                               $calculation            = 
$this->db->f('calculation');
-                               $contract_sum           = 
$this->db->f('contract_sum');
-                               $addition                       = 
$this->db->f('addition');
-                               $project_id                     = 
$this->db->f('project_id');
-                               $start_date                     = 
$this->db->f('start_date');
-                               $old_ecodimb            = 
(int)$this->db->f('ecodimb');
-
-                               if ( abs((int)$contract_sum) > 0)
-                               {
-                                       $addition = 1 + ((int)$addition/100);
-                                       $combined_cost = (int)$contract_sum * 
$addition;
-                               }
-                               else if (abs($calculation) > 0)
-                               {
-                                       $combined_cost = $calculation * $tax;
-                               }
-                               else
-                               {
-                                       $combined_cost = (int)$budget;
-                               }
-
-                               if($old_combined_cost != $combined_cost)
-                               {
-                                       
//_debug_array(array($old_combined_cost,$combined_cost));
-                                       $this->db->query("UPDATE fm_workorder 
SET combined_cost = '{$combined_cost}' WHERE id = {$id}",__LINE__,__FILE__);
-                               }
-
-                               $this->db->query("SELECT 
periodization_id,ecodimb FROM fm_project WHERE id = 
{$project_id}",__LINE__,__FILE__);
-                               $this->db->next_record();
-                               $periodization_id       = 
$this->db->f('periodization_id');
-                               $ecodimb                        = 
(int)$this->db->f('ecodimb');
-
-                               if($old_ecodimb != $ecodimb)
-                               {
-                                       $this->db->query("UPDATE fm_workorder 
SET ecodimb = {$ecodimb} WHERE id = {$id}",__LINE__,__FILE__);
-                               }
-
-               //              $this->_update_project_budget($project_id, 
date('Y', $start_date), $periodization_id, $combined_cost);
-                               $this->_update_order_budget($id, date('Y', 
$start_date), $periodization_id, $budget, $contract_sum, $combined_cost);
-                       }
-*/
                        $config = CreateObject('phpgwapi.config','property');
                        $config->read_repository();
 
@@ -2175,7 +2119,14 @@
                public function transfer_budget($id, $budget, $year)
                {
 //_debug_array($budget);die();
-                       $this->db->transaction_begin();
+                       if ( $this->db->get_transaction() )
+                       {
+                               $this->global_lock = true;
+                       }
+                       else
+                       {
+                               $this->db->transaction_begin();
+                       }
 
                        $id = (int) $id;
                        $year = (int) $year;
@@ -2236,7 +2187,11 @@
                                if( !abs( $last_budget ) > 0 )
                                {
                                        $this->_update_order_budget($id, $year, 
$periodization_id, 0, 0, 0, 'update', true);
-                                       $this->db->transaction_commit();
+                                       if ( !$this->global_lock )
+                                       {
+                                               $this->db->transaction_commit();
+                                       }
+
                                        return;
 //                                     throw new 
Exception('property_workorder::transfer_budget() - no budget to transfer for 
this investment order: ' . $id);
                                }
@@ -2280,7 +2235,11 @@
                                $this->_update_order_budget($id, $year, 
$periodization_id, $new_budget, $new_budget, $new_budget, $action = 'update', 
true);
                        }
 //die();
-                       $this->db->transaction_commit();
+                       if ( !$this->global_lock )
+                       {
+                               $this->db->transaction_commit();
+                       }
+
                }
 
                /**




reply via email to

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