fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [11799] property: more on budget handling


From: Sigurd Nes
Subject: [Fmsystem-commits] [11799] property: more on budget handling
Date: Sun, 09 Mar 2014 18:45:25 +0000

Revision: 11799
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11799
Author:   sigurdne
Date:     2014-03-09 18:45:24 +0000 (Sun, 09 Mar 2014)
Log Message:
-----------
property: more on budget handling

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

Modified: trunk/property/inc/class.soproject.inc.php
===================================================================
--- trunk/property/inc/class.soproject.inc.php  2014-03-09 11:58:48 UTC (rev 
11798)
+++ trunk/property/inc/class.soproject.inc.php  2014-03-09 18:45:24 UTC (rev 
11799)
@@ -2057,15 +2057,21 @@
                        $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"
+                       $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, project_type_id"
+                       . " FROM fm_project"
+                       . " {$this->left_join} fm_project_budget ON 
fm_project_budget.project_id = fm_project.id"
+                       . " {$this->left_join} fm_workorder ON fm_project.id = 
fm_workorder.project_id"
+                       . " WHERE fm_project_budget.project_id = {$project_id}"
+                       . " GROUP BY project_type_id, 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__);
 
                        while($this->db->next_record())
                        {
-                               $period = $this->db->f('year') . 
sprintf("%02s", $this->db->f('month'));
+                               $project_type_id                = (int) 
$this->db->f('project_type_id');
+                               $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');
@@ -2203,13 +2209,23 @@
                        $corretion               = $total_sum >= 0 ? 1 : -1;
                        $deviation_acc   = 0;
                        $budget_acc              = 0;
+                       $_year = 0;
                        foreach($values as &$entry)
                        {
                                $entry['year']   = substr($entry['period'], 0, 
4);
                                $month                   = 
substr($entry['period'], 4, 2);
                                $entry['month']  = $month == '00' ? '' : $month;
 
-                               //if($closed_period[$entry['period']])
+                               /**
+                                * operation: start over each year
+                                */
+                               if($project_type_id == 1 && $_year != 
$entry['year'])
+                               {
+                                       $_year = $entry['year'];
+                                       $deviation_acc   = 0;
+                                       $budget_acc              = 0;
+                               }
+
                                if(abs($entry['actual_cost']) > 0 )
                                {
                                        $_diff_start     = 
abs($entry['budget']) > 0 ? $entry['budget'] : $entry['sum_orders'];
@@ -2217,6 +2233,8 @@
 
                                        $_deviation      = $entry['budget'] - 
$entry['actual_cost'];
                                        $deviation       = $_deviation;
+                                       $deviation_acc += $deviation;
+
                                }
                                else
                                {
@@ -2227,11 +2245,6 @@
                                $entry['deviation_period'] = $deviation;
                                $budget_acc +=$entry['budget'];
 
-                               if($closed_period[$entry['period']])
-                               {
-                                       $deviation_acc += $deviation;
-                               }
-
                                $entry['deviation_acc'] = abs($deviation) > 0 ? 
$deviation_acc : 0;
 
                                $entry['deviation_percent_period']       = 
$corretion * $deviation / $entry['budget'] * 100;

Modified: trunk/property/inc/class.soworkorder.inc.php
===================================================================
--- trunk/property/inc/class.soworkorder.inc.php        2014-03-09 11:58:48 UTC 
(rev 11798)
+++ trunk/property/inc/class.soworkorder.inc.php        2014-03-09 18:45:24 UTC 
(rev 11799)
@@ -1780,7 +1780,7 @@
                        }
                        $continuous = false;
 
-//                     $cached_info = phpgwapi_cache::system_get('property', 
"budget_order_{$order_id}");
+                       $cached_info = phpgwapi_cache::system_get('property', 
"budget_order_{$order_id}");
 
                        if($cached_info)
                        {
@@ -1793,9 +1793,13 @@
                        $sum_year_budget                 = array();
                        $sum_year_combined_cost  = array();
 
-                       $sql = "SELECT continuous, fm_workorder.start_date , 
fm_workorder_budget.budget, fm_workorder_budget.combined_cost, year, month, 
active, 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}'"
+                       $sql = "SELECT continuous, fm_workorder.start_date , 
fm_workorder_budget.budget, fm_workorder_budget.combined_cost,"
+                       . " project_type_id, year, month, active, closed"
+                       . " FROM fm_workorder"
+                       . " {$this->join} fm_project ON fm_workorder.project_id 
= fm_project.id"
+                       . " {$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__);
@@ -1803,10 +1807,11 @@
                        $_order_budget                   = array();
                        while($this->db->next_record())
                        {
-                               $year            = (int) $this->db->f('year');
-                               $month           = (int) $this->db->f('month');
-                               $continuous      = !!$this->db->f('continuous');
-                               $period          = sprintf("%s%02d", $year, 
$month
+                               $project_type_id        = (int) 
$this->db->f('project_type_id');
+                               $year                           = (int) 
$this->db->f('year');
+                               $month                          = (int) 
$this->db->f('month');
+                               $continuous                     = 
!!$this->db->f('continuous');
+                               $period                         = 
sprintf("%s%02d", $year, $month
                                );
 
                                $budget                                  = 
(int) $this->db->f('budget');
@@ -2202,16 +2207,27 @@
 //_debug_array($values);die();
                        $deviation_acc   = 0;
                        $budget_acc              = 0;
+                       $_year = 0;
                        foreach($values as &$entry)
                        {
-//                             if($closed_period[$entry['period']])
+                               /**
+                                * operation: start over each year
+                                */
+                               if($project_type_id == 1 && $_year != 
$entry['year'])
+                               {
+                                       $_year = $entry['year'];
+                                       $deviation_acc   = 0;
+                                       $budget_acc              = 0;
+                               }
+
                                if( abs($entry['actual_cost']) > 0 )
                                {
-                                       $_diff_start     = 
abs($entry['budget']) > 0 ? $entry['budget'] : $entry['sum_orders'];
-                                       $entry['diff']   = $_diff_start - 
$entry['sum_oblications'] - $entry['actual_cost'];
+                                       $_diff_start    = abs($entry['budget']) 
> 0 ? $entry['budget'] : $entry['sum_orders'];
+                                       $entry['diff']  = $_diff_start - 
$entry['sum_oblications'] - $entry['actual_cost'];
 
-                                       $_deviation      = $entry['budget'] - 
$entry['actual_cost'];
-                                       $deviation       = $_deviation;
+                                       $_deviation             = 
$entry['budget'] - $entry['actual_cost'];
+                                       $deviation              = $_deviation;
+                                       $deviation_acc += $deviation;
                                }
                                else
                                {
@@ -2222,11 +2238,6 @@
                                $entry['deviation_period'] = $deviation;
                                $budget_acc +=$entry['budget'];
 
-                               if($closed_period[$entry['period']])
-                               {
-                                       $deviation_acc += $deviation;
-                               }
-
                                $entry['deviation_acc'] = abs($deviation) > 0 ? 
$deviation_acc : 0;
 
 




reply via email to

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