[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [9704] property: calculation
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [9704] property: calculation |
Date: |
Mon, 02 Jul 2012 11:53:50 +0000 |
Revision: 9704
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=9704
Author: sigurdne
Date: 2012-07-02 11:53:50 +0000 (Mon, 02 Jul 2012)
Log Message:
-----------
property: calculation
Modified Paths:
--------------
trunk/property/inc/class.soproject.inc.php
Modified: trunk/property/inc/class.soproject.inc.php
===================================================================
--- trunk/property/inc/class.soproject.inc.php 2012-07-02 08:16:29 UTC (rev
9703)
+++ trunk/property/inc/class.soproject.inc.php 2012-07-02 11:53:50 UTC (rev
9704)
@@ -1543,23 +1543,23 @@
$sql = "SELECT id AS order_id FROM fm_workorder WHERE
project_id = {$project_id}";
$this->db->query($sql,__LINE__,__FILE__);
$orders = array();
+ $_orders = array();
while ($this->db->next_record())
{
- $orders[] = $this->db->f('order_id');
+ $_orders[] = $this->db->f('order_id');
}
- $actual_cost = array();
- foreach($orders as $order)
+ foreach($_orders as $_order)
{
- $sql = "SELECT sum(godkjentbelop) AS
actual_cost, periode FROM fm_ecobilagoverf WHERE pmwrkord_code = '{$order}'
GROUP BY periode ORDER BY periode ASC ";
+ $sql = "SELECT sum(godkjentbelop) AS
actual_cost, periode FROM fm_ecobilagoverf WHERE pmwrkord_code = '{$_order}'
GROUP BY periode ORDER BY periode ASC ";
$this->db->query($sql,__LINE__,__FILE__);
while ($this->db->next_record())
{
$year = substr(
$this->db->f('periode'), 0, 4 );
- $cost_info[$year]['actual_cost'] +=
$this->db->f('actual_cost');
+ $orders[$year][$_order]['actual_cost']
+= $this->db->f('actual_cost');
}
- $sql = "SELECT sum(godkjentbelop) AS
actual_cost, periode FROM fm_ecobilag WHERE pmwrkord_code = '{$order}' GROUP BY
periode ORDER BY periode ASC ";
+ $sql = "SELECT sum(godkjentbelop) AS
actual_cost, periode FROM fm_ecobilag WHERE pmwrkord_code = '{$_order}' GROUP
BY periode ORDER BY periode ASC ";
$this->db->query($sql,__LINE__,__FILE__);
while ($this->db->next_record())
{
@@ -1568,7 +1568,7 @@
{
$year = date('Y');
}
- $cost_info[$year]['actual_cost'] +=
$this->db->f('actual_cost');
+ $orders[$year][$_order]['actual_cost']
+= $this->db->f('actual_cost');
}
}
@@ -1584,10 +1584,9 @@
$this->db->query($sql,__LINE__,__FILE__);
- $orders = array();
while ($this->db->next_record())
{
- $year = $this->db->f('year');
+ $year = date('Y');//$this->db->f('year');
if($this->db->f('contract_sum') > 0)
{
@@ -1606,79 +1605,100 @@
$_amount = 0;
}
- $orders[] = array
- (
- 'order_id' => $this->db->f('id'),
- 'year' => $year,
- 'amount' => $_amount
- );
+ $orders[$year][$this->db->f('id')]['amount'] =
$_amount;
}
- foreach ($orders as $order)
- {
- $cost_info[$year]['sum_orders'] +=
$order['amount'];
- $sql = "SELECT godkjentbelop as amount FROM
fm_ecobilagoverf WHERE pmwrkord_code = '{$order['order_id']}'";
- $this->db->query($sql,__LINE__,__FILE__);
- while ($this->db->next_record())
- {
- $cost_info[$year]['sum_orders'] -=
$this->db->f('amount');
- }
- $sql = "SELECT godkjentbelop as amount FROM
fm_ecobilag WHERE pmwrkord_code = '{$order['order_id']}'";
- $this->db->query($sql,__LINE__,__FILE__);
- while ($this->db->next_record())
- {
- $cost_info[$year]['sum_orders'] -=
$this->db->f('amount');
- }
- }
-
$sort_year = array();
$values = array();
$sql = "SELECT * FROM fm_project_budget WHERE
project_id = {$project_id}";
$this->db->query($sql,__LINE__,__FILE__);
+ $project_budget = array();
while ($this->db->next_record())
{
- $year = $this->db->f('year');
- $_actual_cost =
isset($cost_info[$year]['actual_cost']) && $cost_info[$year]['actual_cost'] ?
$cost_info[$year]['actual_cost'] : 0;
- $_sum_orders =
isset($cost_info[$year]['sum_orders']) && $cost_info[$year]['sum_orders'] > 0
? $cost_info[$year]['sum_orders'] : 0;
- if(isset($cost_info[$year]))
+ $project_budget[$this->db->f('year')] =
(int)$this->db->f('budget');
+ }
+
+
+ foreach ($project_budget as $year => $budget)
+ {
+ if(isset($orders[$year]))
{
- unset($cost_info[$year]);
+
+ $_sum_orders = 0;
+ $_actual_cost= 0;
+
+ foreach ($orders[$year] as $order_id =>
$order)
+ {
+ $_sum_orders +=
$order['amount'];
+ $_sum_orders -=
$order['actual_cost'];
+
+ if($budget > 0)
+ {
+ $_sum_orders =
$_sum_orders > 0 ? $_sum_orders : 0;
+ }
+ else // income
+ {
+ $_sum_orders =
$_sum_orders < 0 ? $_sum_orders : 0;
+ }
+
+ $_actual_cost +=
$order['actual_cost'];
+ }
+
+ unset($orders[$year]);
+
}
+ else
+ {
+ $_sum_orders = 0;
+ $_actual_cost = 0;
+ }
- $sort_year[] = $year;
$values[] = array
(
'project_id' => $project_id,
- 'year' =>
$this->db->f('year'),
- 'budget' =>
(int)$this->db->f('budget'),
+ 'year' =>
$year,
+ 'budget' =>
$budget,
'sum_orders' => $_sum_orders,
'actual_cost' =>
$_actual_cost,
- 'user_id' =>
$this->db->f('user_id'),
- 'entry_date' =>
$this->db->f('entry_date'),
- 'modified_date' =>
$this->db->f('modified_date')
);
+
+ $sort_year[] = $year;
}
+
+ unset($order);
+ unset($order_id);
+ unset($year);
- if($cost_info && count($cost_info))
+ reset($orders);
+
+
+ //remaining
+ foreach ($orders as $year => $_orders)
{
- foreach($cost_info as $year => $cost_info)
+ $_sum_orders = 0;
+ $_actual_cost = 0;
+
+ foreach ($_orders as $order_id => $order)
{
- $sort_year[] = $year;
- $values[] = array
- (
- 'project_id' =>
$project_id,
- 'year'
=> $year ,
- 'budget'
=> 0,
- 'sum_orders' =>
isset($cost_info['sum_orders']) && $cost_info['sum_orders'] > 0 ?
$cost_info['sum_orders'] : 0,
- 'actual_cost' =>
isset($cost_info['actual_cost']) && $cost_info['actual_cost'] ?
$cost_info['actual_cost'] : 0,
- 'user_id'
=> 0,
- 'entry_date' => 0,
- 'modified_date' => 0
- );
+ $_sum_orders += $order['amount'];
+ $_sum_orders -= $order['actual_cost'];
+ $_sum_orders = $_sum_orders > 0 ?
$_sum_orders : 0;
+ $_actual_cost += $order['actual_cost'];
}
+
+ $values[] = array
+ (
+ 'project_id' => $project_id,
+ 'year' =>
$year,
+ 'budget' => 0,
+ 'sum_orders' => $_sum_orders,
+ 'actual_cost' =>
$_actual_cost,
+ );
+
+ $sort_year[] = $year;
}
if($values)
@@ -1686,6 +1706,7 @@
array_multisort($sort_year, SORT_ASC, $values);
}
+//_debug_array( $values);die();
return $values;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [9704] property: calculation,
Sigurd Nes <=