fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [10676] Property: update accounting reporting


From: Sigurd Nes
Subject: [Fmsystem-commits] [10676] Property: update accounting reporting
Date: Tue, 15 Jan 2013 20:33:58 +0000

Revision: 10676
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10676
Author:   sigurdne
Date:     2013-01-15 20:33:58 +0000 (Tue, 15 Jan 2013)
Log Message:
-----------
Property: update accounting reporting

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

Modified: trunk/property/inc/class.soproject.inc.php
===================================================================
--- trunk/property/inc/class.soproject.inc.php  2013-01-15 10:00:59 UTC (rev 
10675)
+++ trunk/property/inc/class.soproject.inc.php  2013-01-15 20:33:58 UTC (rev 
10676)
@@ -47,6 +47,7 @@
                        $this->custom           = 
createObject('property.custom_fields');
 
                        $this->db           = & $GLOBALS['phpgw']->db;
+                       $this->db2           = clone ($this->db);
                        $this->join                     = & $this->db->join;
                        $this->left_join        = & $this->db->left_join;
                        $this->like                     = & $this->db->like;
@@ -692,7 +693,7 @@
                                        $sql_workder_date_filter = '';
                                        if ($start_date)
                                        {
-                                               $sql_workder_date_filter = "AND 
fm_workorder.start_date >= $start_date AND fm_workorder.start_date <= $end_date 
";
+                                               $sql_workder_date_filter = "AND 
fm_workorder.start_date >= {$start_date} AND fm_workorder.start_date <= 
{$end_date} ";
                                        }
 
 /*
@@ -705,24 +706,26 @@
 
 */
 
+                                       $get_spesific = false; 
                                        if ($filter_year && $filter_year != 
'all')
                                        {
+                                               $get_spesific = true; 
                                                $_year_arr = array();
                                                for ($i=1;$i<14;$i++)
                                                {
                                                        $_year_arr[] = 
sprintf("%04s%02s", $filter_year, $i);
                                                }
 
-                                               $sql_filter_period = 'AND 
periode IN (' . implode(',', $_year_arr) . ')';
+                                               $sql_filter_period = 'AND 
(periode IN (' . implode(',', $_year_arr) . ') OR periode IS NULL)';
 
-                                               $sql_workder  = "SELECT 
fm_workorder.id, sum(fm_workorder_budget.budget) AS budget, 
sum(fm_workorder_budget.combined_cost) AS combined_cost,"
+                                               $sql_workder  = "SELECT 
fm_workorder.id,"// sum(fm_workorder_budget.budget) AS budget, 
sum(fm_workorder_budget.combined_cost) AS combined_cost,"
                                                . " billable_hours, closed, 
sum(fm_orders_paid_or_pending_view.amount) AS actual_cost"
                                                . " 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 year 
= '{$filter_year}')"
-                                               . " {$this->join} 
fm_workorder_budget ON (fm_workorder.id = fm_workorder_budget.order_id )"
-//                                             . " {$this->left_join} 
fm_orders_paid_or_pending_view ON (fm_workorder.id = 
fm_orders_paid_or_pending_view.order_id {$sql_filter_period})"
-                                               . " {$this->left_join} 
fm_orders_paid_or_pending_view ON (fm_workorder.id = 
fm_orders_paid_or_pending_view.order_id AND( periode < {$filter_year}13 OR 
periode IS NULL))"
+//                                             . " {$this->join} 
fm_workorder_budget ON (fm_workorder.id = fm_workorder_budget.order_id )"
+                                               . " {$this->left_join} 
fm_orders_paid_or_pending_view ON (fm_workorder.id = 
fm_orders_paid_or_pending_view.order_id {$sql_filter_period})"
+//                                             . " {$this->left_join} 
fm_orders_paid_or_pending_view ON (fm_workorder.id = 
fm_orders_paid_or_pending_view.order_id AND( periode < {$filter_year}13 OR 
periode IS NULL))"
                                                . " WHERE project_id = 
'{$project['project_id']}' {$sql_workder_date_filter} OR (project_id = 
'{$project['project_id']}' AND fm_workorder_status.closed IS NULL)"
                                                . " GROUP BY fm_workorder.id, 
billable_hours, closed";
 //_debug_array($sql_workder);
@@ -734,7 +737,7 @@
                                                . " billable_hours, closed, 
actual_cost, pending_cost"
                                                . " 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->left_join} 
fm_workorder_budget ON (fm_workorder.id = fm_workorder_budget.order_id AND 
active = 1)"
                                                . " {$this->left_join} 
fm_orders_pending_cost_view ON fm_workorder.id = 
fm_orders_pending_cost_view.order_id"
                                                . " WHERE project_id = 
'{$project['project_id']}' {$sql_workder_date_filter}"
                                                . " GROUP BY fm_workorder.id, 
billable_hours, closed, actual_cost, pending_cost";
@@ -749,12 +752,27 @@
 
                                        while ($this->db->next_record())
                                        {
-                                               $_combined_cost = 
$this->db->f('combined_cost');
+                                               if($get_spesific)
+                                               {
+                                                       
$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 year = {$filter_year} AND order_id =" . 
$this->db->f('id'),__LINE__,__FILE__);
+                                                        
$this->db2->next_record();
+
+                                                       $_combined_cost = 
$this->db2->f('combined_cost');
+                                                       $_budget = 
$this->db2->f('budget');
+                                               }
+                                               else
+                                               {
+                                                       $_combined_cost = 
$this->db->f('combined_cost');
+                                                       $_budget = 
$this->db->f('budget');
+                                               }
+
                                                $_actual_cost =  
$this->db->f('actual_cost') + (float)$this->db->f('pending_cost');
                                                if(!$this->db->f('closed'))
                                                {
 //$test[] = $this->db->f('id');
-
+/*
                                                        if ($filter_year && 
$filter_year != 'all')
                                                        {
                                                                if($filter_year 
== date('Y'))
@@ -766,7 +784,10 @@
                                                        {
                                                                $_obligation = 
$_combined_cost - $_actual_cost;
                                                        }
-                                                       
if((int)$this->db->f('budget') >= 0)
+*/
+                                                       $_obligation = 
$_combined_cost - $_actual_cost;
+
+                                                       if((int)$_budget >= 0)
                                                        {
                                                                if($_obligation 
< 0)
                                                                {
@@ -2068,11 +2089,12 @@
 
                        $project_total_budget = array_sum($project_budget);
 
-                       $sql = "SELECT fm_workorder.id AS order_id, 
fm_workorder_budget.combined_cost, fm_workorder_budget.budget, 
fm_workorder_budget.year, fm_workorder_budget.month, fm_workorder_status.closed"
+                       $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 project_id = {$project_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";
 //     _debug_array($sql);die();
                        $this->db->query($sql,__LINE__,__FILE__);
 

Modified: trunk/property/inc/class.soworkorder.inc.php
===================================================================
--- trunk/property/inc/class.soworkorder.inc.php        2013-01-15 10:00:59 UTC 
(rev 10675)
+++ trunk/property/inc/class.soworkorder.inc.php        2013-01-15 20:33:58 UTC 
(rev 10676)
@@ -1380,6 +1380,18 @@
                        $value_set_invoice      = 
$this->db->validate_update($value_set_invoice);
                        $this->db->query("UPDATE fm_ecobilag SET 
{$value_set_invoice} WHERE pmwrkord_code = '{$workorder['id']}'" 
,__LINE__,__FILE__);
 
+                       $_active_period = array
+                       (
+                               'active_b_period' => 
isset($workorder['active_b_period']) && $workorder['active_b_period'] ? 
$workorder['active_b_period'] : array(),
+                               'active_orig_b_period' => 
isset($workorder['active_orig_b_period']) && $workorder['active_orig_b_period'] 
? $workorder['active_orig_b_period'] : array()
+                       );
+
+                       $this->activate_period_from_budget($workorder['id'], 
$_active_period);
+
+                       unset($_close_period);
+                       unset($_active_period);
+
+
                        if($workorder['delete_b_period'])
                        {
                                $this->db->query("SELECT sum(budget) AS budget 
FROM fm_workorder_budget WHERE order_id = 
'{$workorder['id']}'",__LINE__,__FILE__);
@@ -1679,7 +1691,7 @@
                        $active_period = array();
                        $_dummy_period = '';
 
-                       $sql = "SELECT fm_workorder_budget.budget, 
fm_workorder_budget.combined_cost, year, month, closed"
+                       $sql = "SELECT 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}'"
                        . " ORDER BY year, month";
@@ -1706,7 +1718,7 @@
                                );
 
                                $closed_period[$period] = false;
-                               $active_period[$period] = true;
+                               $active_period[$period] = 
$this->db->f('active');
                        }
 
 //                     if ( $order_budget )
@@ -1875,7 +1887,49 @@
                        }
                }
 
+               /**
+               * Set active status on budget periods
+               *
+               * @return void
+               */
 
+               function activate_period_from_budget($order_id, $data)
+               {
+                       $close_period = array();
+                       $open_period = array();
+//_debug_array($data);die();
+                       foreach($data['active_orig_b_period'] as $period)
+                       {
+                               if(!in_array($period, $data['active_b_period']))
+                               {
+                                       $inactive_period[] = $period;
+                               }
+                       }
+
+                       foreach($data['active_b_period'] as $period)
+                       {
+                               if(!in_array($period, 
$data['active_orig_b_period']))
+                               {
+                                       $active_period[] = $period;
+                               }
+                       }
+
+                       foreach ($active_period as $period)
+                       {
+                               $when = explode('_', $period);
+                               $sql = "UPDATE fm_workorder_budget SET active = 
1 WHERE order_id = {$order_id} AND year =" . (int) $when[0] . ' AND month = ' . 
(int) $when[1];
+                               $this->db->query($sql,__LINE__,__FILE__);
+                       }
+
+                       foreach ($inactive_period as $period)
+                       {
+                               $when = explode('_', $period);
+                               $sql = "UPDATE fm_workorder_budget SET active = 
0 WHERE order_id = {$order_id} AND year =" . (int) $when[0] . ' AND month = ' . 
(int) $when[1];
+                               $this->db->query($sql,__LINE__,__FILE__);
+                       }
+               }
+
+
                /**
                * Recalculate actual cost from payment history for all 
workorders
                *

Modified: trunk/property/inc/class.uiworkorder.inc.php
===================================================================
--- trunk/property/inc/class.uiworkorder.inc.php        2013-01-15 10:00:59 UTC 
(rev 10675)
+++ trunk/property/inc/class.uiworkorder.inc.php        2013-01-15 20:33:58 UTC 
(rev 10676)
@@ -1835,8 +1835,8 @@
                                                                                
                                array('key' => 
'deviation_percent_acc','label'=>lang('percent'). '::' . 
lang('accumulated'),'sortable'=>false,'resizeable'=>true,'formatter'=>'FormatterAmount2'),
                                                                                
                                //~ array('key' => 
'closed','label'=>lang('closed'),'sortable'=>false,'resizeable'=>true,'formatter'=>'FormatterCenter'),
                                                                                
                                //~ array('key' => 'closed_orig','hidden' => 
true),
-                                                                               
                                //~ array('key' => 
'active','label'=>lang('active'),'sortable'=>false,'resizeable'=>true,'formatter'=>'FormatterCenter'),
-                                                                               
                                //~ array('key' => 'active_orig','hidden' => 
true),
+                                                                               
                                array('key' => 
'active','label'=>lang('active'),'sortable'=>false,'resizeable'=>true,'formatter'=>'FormatterCenter'),
+                                                                               
                                array('key' => 'active_orig','hidden' => true),
                                                                                
                                array('key' => 'flag_active','hidden' => true),
                                                                                
                                array('key' => 
'delete_period','label'=>lang('Delete'),'sortable'=>false,'resizeable'=>true,'formatter'=>'FormatterCenter')
                                                                                
                        )




reply via email to

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