fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [10663] property: rekkef?\195?\184lge


From: Sigurd Nes
Subject: [Fmsystem-commits] [10663] property: rekkef?\195?\184lge
Date: Fri, 11 Jan 2013 14:35:10 +0000

Revision: 10663
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10663
Author:   sigurdne
Date:     2013-01-11 14:35:09 +0000 (Fri, 11 Jan 2013)
Log Message:
-----------
property: rekkef?\195?\184lge

Modified Paths:
--------------
    trunk/property/inc/class.boworkorder.inc.php
    trunk/property/inc/class.soproject.inc.php
    trunk/property/inc/class.soworkorder.inc.php
    trunk/property/inc/class.uiproject.inc.php
    trunk/property/inc/class.uiworkorder.inc.php

Modified: trunk/property/inc/class.boworkorder.inc.php
===================================================================
--- trunk/property/inc/class.boworkorder.inc.php        2013-01-10 14:32:29 UTC 
(rev 10662)
+++ trunk/property/inc/class.boworkorder.inc.php        2013-01-11 14:35:09 UTC 
(rev 10663)
@@ -819,6 +819,11 @@
                        return $ser_list;
                }
 
+               public function get_budget($order_id)
+               {
+                       return $this->so->get_budget($order_id);
+               }
+
                /**
                * Recalculate actual cost from payment history for all 
workorders
                *

Modified: trunk/property/inc/class.soproject.inc.php
===================================================================
--- trunk/property/inc/class.soproject.inc.php  2013-01-10 14:32:29 UTC (rev 
10662)
+++ trunk/property/inc/class.soproject.inc.php  2013-01-11 14:35:09 UTC (rev 
10663)
@@ -2018,9 +2018,9 @@
                        $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, start_date"
+                       $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,start_date"
+                       . " 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);

Modified: trunk/property/inc/class.soworkorder.inc.php
===================================================================
--- trunk/property/inc/class.soworkorder.inc.php        2013-01-10 14:32:29 UTC 
(rev 10662)
+++ trunk/property/inc/class.soworkorder.inc.php        2013-01-11 14:35:09 UTC 
(rev 10663)
@@ -1598,7 +1598,171 @@
                        }
                }
 
+
                /**
+               * Get periodized budget for an order
+               *
+               * @return array Array with budget information.
+               */
+
+               function get_budget($order_id)
+               {
+
+                       $closed_period = array();
+                       $active_period = array();
+
+                       $sql = "SELECT fm_workorder_budget.budget, 
fm_workorder_budget.combined_cost, year, month, 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 order_id = '{$order_id}'"
+                       . " ORDER BY year, month";
+
+                       $this->db->query($sql,__LINE__,__FILE__);
+                       $order_budget = array();
+                       while ($this->db->next_record())
+                       {
+                               $period = sprintf("%s%02d",
+                                                       $this->db->f('year'),
+                                                       $this->db->f('month')
+                                               );
+
+                               $order_budget[$period] = array
+                               (
+                                       'order_id'                      => 
$order_id,
+                                       'budget'                        => 
(int)$this->db->f('budget'),
+                                       'combined_cost'         => 
(int)$this->db->f('combined_cost'),
+                                       'year'                          => 
(int)$this->db->f('year'),
+                                       'month'                         => 
(int)$this->db->f('month'),
+                                       'actual_cost'           => 0, //for 
now..
+                                       'closed_order'          => false,
+                               );
+
+                               $closed_period[$period] = false;
+                               $active_period[$period] = true;
+                       }
+
+
+                       if ( $order_budget )
+                       {
+                               $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 = '{$order_id}' ORDER BY 
periode ASC";
+//_debug_array($sql);
+                               $this->db->query($sql,__LINE__,__FILE__);
+                               while ($this->db->next_record())
+                               {
+                                       $periode = $this->db->f('periode');
+                                       if(!$periode)
+                                       {
+                                               $periode = date('Ym');
+                                       }
+
+                                       $year = substr( $periode, 0, 4 );
+
+                                       $_found = false;
+                                       if(isset($order_budget[$periode]))
+                                       {
+                                               
$order_budget[$periode]['actual_cost'] += $this->db->f('actual_cost');
+                                               $_found = true;
+                                       }
+                                       else
+                                       {
+                                               for ($i=0;$i<13;$i++)
+                                               {
+                                                       $_period = $year . 
sprintf("%02s", $i);
+                                                       
if(isset($order_budget[$_period]))
+                                                       {
+                                                               
$order_budget[$_period]['actual_cost'] += $this->db->f('actual_cost');
+//_debug_array($test+=$this->db->f('actual_cost'));
+                                                               $_found = true;
+                                                               break;
+                                                       }
+                                               }
+                                       }
+
+                                       if(!$_found)
+                                       {
+                                               
$order_budget[$periode]['actual_cost'] += $this->db->f('actual_cost');
+                                       }
+                               }
+                       }
+
+                       $sort_period = array();
+                       $values = array();
+//_debug_array($project_budget);die();
+//$test = 0;
+                       $_delay_period = 0;
+                       foreach ($order_budget as $period => $_budget)
+                       {
+                               $_sum_orders = 0;
+                               $_sum_oblications = 0;
+                               $_actual_cost = 0;
+
+                               $_actual_cost += $_budget['actual_cost'];
+//_debug_array( $test+= $_budget['actual_cost']);
+                               $_sum_orders += $_budget['combined_cost'];
+
+                               if(!$_budget['closed_order'])
+                               {
+                                       $_sum_oblications += 
$_budget['combined_cost'];
+                                       $_sum_oblications -= 
$_budget['actual_cost'];
+
+                       //              if($project_total_budget >= 0)
+                                       if($_budget['budget'] >= 0)
+                                       {
+                                               if($_sum_oblications < 0)
+                                               {
+                                                       $_sum_oblications = 0;
+                                               }
+                                       }
+                                       else // income
+                                       {
+                                               if($_sum_oblications > 0)
+                                               {
+                                                       $_sum_oblications = 0;
+                                               }
+                                       }
+                               }
+
+                               //override if periode is closed
+                               if(!isset($active_period[$period]) || 
!$active_period[$period])
+                               {
+                                       $_delay_period += $_sum_oblications;
+                                       $_sum_oblications = 0;
+                               }
+                               //override if periode is closed
+                               if(isset($closed_period[$period]) && 
$closed_period[$period])
+                               {
+                                       $_sum_oblications = 0;
+                               }
+
+                               if(isset($active_period[$period]) && 
$active_period[$period] && $_delay_period)
+                               {
+                                       $_sum_oblications[] += $_delay_period;
+                                       $_delay_period =0;
+                               }
+//die();
+                               $values[] = array
+                               (
+                                       'period'                                
=> $period,
+                                       'budget'                                
=> $_budget['budget'],
+                                       'sum_orders'                    => 
$_sum_orders,
+                                       'sum_oblications'               => 
$_sum_oblications,
+                                       'actual_cost'                   => 
$_actual_cost,
+                               );
+
+                               $sort_period[] = $period;
+                       }
+                       
+                       if($values)
+                       {
+                               array_multisort($sort_period, SORT_ASC, 
$values);
+                       }
+
+                       return $values;
+
+               }
+
+               /**
                * Recalculate actual cost from payment history for all 
workorders
                *
                * @return void

Modified: trunk/property/inc/class.uiproject.inc.php
===================================================================
--- trunk/property/inc/class.uiproject.inc.php  2013-01-10 14:32:29 UTC (rev 
10662)
+++ trunk/property/inc/class.uiproject.inc.php  2013-01-11 14:35:09 UTC (rev 
10663)
@@ -1711,6 +1711,8 @@
 
                        //---datatable 
settings---------------------------------------------------      
 
+                       $sum_actual_cost = 0;
+                       $sum_oblications = 0;
 
                        if($id)
                        {
@@ -1718,9 +1720,17 @@
                                $lang_delete = lang('Check to delete period');
                                $lang_close = lang('Check to close period');
                                $lang_active = lang('Check to activate period');
+                               $values['sum'] = 0;
 
                                foreach($content_budget as & $b_entry)
                                {
+                                       if($b_entry['active'])
+                                       {
+                                               $sum_actual_cost        += 
$b_entry['actual_cost'];
+                                               $sum_oblications        += 
$b_entry['sum_oblications'];
+                                               $values['sum']          += 
$b_entry['budget'];
+                                       }
+
                                        $checked = $b_entry['closed'] ? 
'checked="checked"' : '';
                                        $checked2 = $b_entry['active'] ? 
'checked="checked"' : '';                                      
 
@@ -1730,20 +1740,24 @@
                                        $b_entry['closed_orig'] = "<input 
type='checkbox' name='values[closed_orig_b_period][]' 
value='{$b_entry['year']}_{$b_entry['month']}' $checked>";
                                        $b_entry['active'] = "<input 
type='checkbox' name='values[active_b_period][]' 
value='{$b_entry['year']}_{$b_entry['month']}' title='{$lang_active}' 
$checked2>";
                                        $b_entry['active_orig'] = "<input 
type='checkbox' name='values[active_orig_b_period][]' 
value='{$b_entry['year']}_{$b_entry['month']}' $checked2>";
-                                       $value_remainder -= 
$b_entry['sum_orders'];
-                                       $value_remainder -= 
$b_entry['actual_cost'];
+                                       
                                }
                                unset($b_entry);
                        }
 
+                       if(isset($values['reserve']) && $values['reserve']!=0)
+                       {
+                               
$reserve_remainder=$values['reserve']-$values['deviation'];
+                               $remainder_percent= 
number_format(($reserve_remainder/$values['reserve'])*100, 2, ',', '');
+                               $values['sum'] = $values['sum'] + 
$values['reserve'];
+                       }
+
+                       $value_remainder = $values['sum'] - $sum_actual_cost - 
$sum_oblications;
                        $values['sum']  = number_format($values['sum'], 0, ',', 
' ');
                        $value_remainder = number_format($value_remainder, 0, 
',', ' ');
 
-
 //_debug_array($content_budget);die();
 
-
-
                        if( isset($values['project_type_id']) && 
$values['project_type_id']==3)
                        {
 

Modified: trunk/property/inc/class.uiworkorder.inc.php
===================================================================
--- trunk/property/inc/class.uiworkorder.inc.php        2013-01-10 14:32:29 UTC 
(rev 10662)
+++ trunk/property/inc/class.uiworkorder.inc.php        2013-01-11 14:35:09 UTC 
(rev 10663)
@@ -1361,6 +1361,10 @@
                        if($id)
                        {
                                $record_history = 
$this->bo->read_record_history($id);
+                               $content_budget = $this->bo->get_budget($id);
+//_debug_array($content_budget);die();
+
+
                        }
                        else
                        {




reply via email to

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