[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [10640] property: bufferproject
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [10640] property: bufferproject |
Date: |
Thu, 03 Jan 2013 14:54:53 +0000 |
Revision: 10640
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10640
Author: sigurdne
Date: 2013-01-03 14:54:52 +0000 (Thu, 03 Jan 2013)
Log Message:
-----------
property: bufferproject
Modified Paths:
--------------
trunk/property/inc/class.soproject.inc.php
trunk/property/js/yahoo/project.edit.js
trunk/property/templates/base/project.xsl
Modified: trunk/property/inc/class.soproject.inc.php
===================================================================
--- trunk/property/inc/class.soproject.inc.php 2013-01-02 13:30:46 UTC (rev
10639)
+++ trunk/property/inc/class.soproject.inc.php 2013-01-03 14:54:52 UTC (rev
10640)
@@ -869,7 +869,7 @@
. " WHERE
project_id={$project_id}",__LINE__,__FILE__);
$_orders = array();
-
+
while ($this->db->next_record())
{
$values[] = array(
@@ -910,7 +910,7 @@
foreach ($values as &$entry)
{
$_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
@@ -941,7 +941,7 @@
}
$_diff_start = abs($entry['budget']) > 0 ?
$entry['budget'] : $_combined_cost;
- $entry['diff'] = $_diff_start -
$entry['obligation'] - $entry['actual_cost'];
+ $entry['diff'] = $_diff_start -
$entry['obligation'] - $entry['actual_cost'];
// $entry['diff'] = $entry['budget'] -
$entry['obligation'] - $entry['actual_cost'];
}
@@ -1077,7 +1077,7 @@
if($project['budget'])
{
- $this->update_budget($id,
$project['budget_year'], $project['budget_periodization'], $project['budget']);
+ $this->update_budget($id,
$project['budget_year'], $project['budget_periodization'],
$project['budget'],$project['budget_periodization_all']);
}
if($project['extra']['contact_phone'] &&
$project['extra']['tenant_id'])
@@ -1311,12 +1311,17 @@
$this->_update_buffer_budget($project['id'], $project['budget_year'],
$project['budget'], null,null);
}
+
+ if(isset($project['transfer_amount']) &&
$project['transfer_amount'] && isset($project['transfer_target']) &&
$project['transfer_target'])
+ {
+
$this->_update_buffer_budget($project['id'], date('Y',$project['start_date']),
$project['transfer_amount'], null,$project['transfer_target']);
+ }
}
else // investment or operation
{
if($project['budget'])
{
- $this->update_budget($project['id'],
$project['budget_year'], $project['budget_periodization'], $project['budget']);
+ $this->update_budget($project['id'],
$project['budget_year'], $project['budget_periodization'],
$project['budget'],$project['budget_periodization_all']);
}
$this->db->query("SELECT sum(budget) AS
sum_budget FROM fm_project_budget WHERE project_id = " .
(int)$project['id'],__LINE__,__FILE__);
@@ -1409,7 +1414,7 @@
{
$historylog->add('B',$project['id'],0, $old_budget);
}
-
+
$sql = "SELECT sum(budget) AS
sum_budget FROM fm_project_budget WHERE project_id = {$new_project_id}";
$this->db->query($sql,__LINE__,__FILE__);
$this->db->next_record();
@@ -1418,7 +1423,7 @@
$sql = "SELECT ecodimb FROM fm_project
WHERE id = {$new_project_id}";
$this->db->query($sql,__LINE__,__FILE__);
$this->db->next_record();
- $ecodimb_new_project =
(int)$this->db->f('ecodimb');
+ $ecodimb_new_project =
(int)$this->db->f('ecodimb');
$sql = "SELECT reserve FROM fm_project
WHERE id = " . (int)$project['id'];
$this->db->query($sql,__LINE__,__FILE__);
@@ -1429,7 +1434,7 @@
{
$historylog->add('B',$new_project_id, $new_budget_new_project,
$old_budget_new_project);
}
-
+
$this->db->query("UPDATE fm_workorder
SET project_id = {$new_project_id}, ecodimb = {$ecodimb_new_project} WHERE
project_id = {$project['id']}",__LINE__,__FILE__);
$this->db->query("UPDATE fm_project SET
reserve = 0 WHERE reserve IS NULL AND id = {$new_project_id}"
,__LINE__,__FILE__);
$this->db->query("UPDATE fm_project SET
budget = {$new_budget_new_project}, reserve = reserve + {$reserve_old_project}
WHERE id = {$new_project_id}" ,__LINE__,__FILE__);
@@ -1624,27 +1629,37 @@
}
- function update_budget($project_id, $year, $periodization_id,
$budget)
+ function update_budget($project_id, $year, $periodization_id,
$budget, $budget_periodization_all = false,$action = 'update')
{
$project_id = (int) $project_id;
$year = $year ? (int) $year : date('Y');
$periodization_id = (int) $periodization_id;
$periodization_outline = array();
+ $skip_period = 0;
if($periodization_id)
{
$this->db->query("SELECT month,
value,dividend,divisor FROM fm_eco_periodization_outline WHERE periodization_id
= {$periodization_id} ORDER BY month ASC",__LINE__,__FILE__);
while ($this->db->next_record())
{
+ $month = $this->db->f('month');
+ if($month < date('n'))
+ {
+ $skip_period ++;
+ }
$periodization_outline[] = array
(
- 'month' =>
$this->db->f('month'),
+ 'month' => $month,
'value' =>
$this->db->f('value'),
'dividend' =>
$this->db->f('dividend'),
'divisor' =>
$this->db->f('divisor')
);
}
+ if($skip_period && $skip_period ==
count($periodization_outline))
+ {
+ $skip_period -= 1;
+ }
}
else
{
@@ -1656,21 +1671,43 @@
'divisor' => 1,
);
-
+
}
-
- foreach ($periodization_outline as $outline)
+
+ //reset skip in case of 'all'
+ if($budget_periodization_all)
{
+ $skip_period = 0;
+ }
+
+ $percentage_to_move = 0;
+ foreach ($periodization_outline as $_key => $outline)
+ {
+ if($skip_period && $skip_period == ($_key+1))
+ {
+ if ($outline['dividend'] &&
$outline['divisor'])
+ {
+ $percentage_to_move +=
$outline['dividend'] / $outline['divisor'];
+ }
+ else
+ {
+ $percentage_to_move +=
$outline['value']/100;
+ }
+
+ continue;
+ }
+
if ($outline['dividend'] && $outline['divisor'])
{
- $partial_budget = $budget *
$outline['dividend'] / $outline['divisor'];
+ $partial_budget = $budget *
$outline['dividend'] / $outline['divisor'];
}
else
{
- $partial_budget = $budget *
$outline['value'] / 100;
+ $partial_budget = $budget *
$outline['value'] / 100;
}
+ $partial_budget = $partial_budget * (1 +
$percentage_to_move);
- $this->_update_budget($project_id, $year,
$outline['month'], $partial_budget);
+ $this->_update_budget($project_id, $year,
$outline['month'], $partial_budget, $action);
}
$sql = "SELECT sum(budget) as sum_budget FROM
fm_project_budget WHERE project_id = {$project_id}";
@@ -1708,9 +1745,9 @@
private function _update_buffer_budget($project_id, $year,
$amount, $from_project, $to_project)
{
- $year = (int) $year;
- $amount = (int) $amount;
-
+ $year = (int) $year;
+ $amount = (int) $amount;
+
if(!$year)
{
$year = date('Y');
@@ -1730,7 +1767,7 @@
{
throw new
Exception('property_soproject::update_buffer_budget() - wrong input');
}
-
+
$value_set = array
(
'buffer_project_id' => $project_id,
@@ -1744,12 +1781,42 @@
'active' => 1
);
+ $from_project = (int) $from_project;
+ $to_project = (int) $to_project;
+
$cols = implode(',', array_keys($value_set));
$values =
$this->db->validate_insert(array_values($value_set));
$this->db->query("INSERT INTO fm_project_buffer_budget
({$cols}) VALUES ({$values})",__LINE__,__FILE__);
+
+ $this->db->query("SELECT sum(amount_in) AS amount_in,
sum(amount_out) AS amount_out FROM fm_project_buffer_budget WHERE
buffer_project_id = " . (int)$project_id,__LINE__,__FILE__);
+ $this->db->next_record();
+
+ $new_budget =(int)$this->db->f('amount_in') +
(int)$this->db->f('amount_out');
+
+ $this->db->query("SELECT budget FROM fm_project WHERE
id = " . (int)$project_id,__LINE__,__FILE__);
+ $this->db->next_record();
+ $old_budget = (int)$this->db->f('budget');
+
+ if ($old_budget != $new_budget)
+ {
+ $this->db->query("UPDATE fm_project SET budget
= {$new_budget} WHERE id = " . (int)$project_id,__LINE__,__FILE__);
+ $historylog =
CreateObject('property.historylog','project');
+ $historylog->add('B',$project_id,$new_budget,
$old_budget);
+ }
+
+ /**
+ * Transfer fund to another project
+ **/
+ if( $amount_out )
+ {
+ $this->db->query("SELECT periodization_id FROM
fm_project WHERE id = {$to_project}",__LINE__,__FILE__);
+ $this->db->next_record();
+ $periodization_id =
$this->db->f('periodization_id');
+ $this->update_budget($to_project, $year,
$periodization_id, $amount_out, 'add');
+ }
}
- private function _update_budget($project_id, $year, $month,
$budget)
+ private function _update_budget($project_id, $year, $month,
$budget, $action = 'update')
{
$month = (int) $month;
$budget = (int) $budget;
@@ -1801,7 +1868,7 @@
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');
@@ -1871,7 +1938,7 @@
}
}
}
-
+
if(!$_found)
{
$_orders[$periode][$_order_id]['actual_cost'] += $this->db->f('actual_cost');
@@ -1908,7 +1975,8 @@
$_sum_oblications[$order_id] += $order['combined_cost'];
$_sum_oblications[$order_id] -= $order['actual_cost'];
-
if($project_total_budget >= 0)
+ //
if($project_total_budget >= 0)
+ if($_budget >= 0)
{
if($_sum_oblications[$order_id] < 0)
@@ -2036,7 +2104,7 @@
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'];
+ $entry['diff'] = $_diff_start -
$entry['sum_oblications'] - $entry['actual_cost'];
}
else
{
@@ -2318,7 +2386,7 @@
break;
case 'workorder':
-
+
$table = 'fm_workorder';
$status_table = 'fm_workorder_status';
$title_field = 'fm_workorder.title';
Modified: trunk/property/js/yahoo/project.edit.js
===================================================================
--- trunk/property/js/yahoo/project.edit.js 2013-01-02 13:30:46 UTC (rev
10639)
+++ trunk/property/js/yahoo/project.edit.js 2013-01-03 14:54:52 UTC (rev
10640)
@@ -127,8 +127,12 @@
//call getTotalSum(name of column) in property.js
tmp_sum1 = getTotalSum('amount_in',0,paginator,datatable);
tmp_sum2 = getTotalSum('amount_out',0,paginator,datatable);
- tmp_sum3 = tmp_sum1 + tmp_sum2;
+ tmp_sum3 = parseInt(tmp_sum1.replace(/ /g,''))
+ - parseInt(tmp_sum2.replace(/ /g,''));
+
+ tmp_sum3 = YAHOO.util.Number.format(tmp_sum3, {decimalPlaces:0,
decimalSeparator:",", thousandsSeparator:" "});
+
if(typeof(tableYUI0)=='undefined')
{
tableYUI0 =
YAHOO.util.Dom.getElementsByClassName("yui-dt-data","tbody")[0].parentNode;
Modified: trunk/property/templates/base/project.xsl
===================================================================
--- trunk/property/templates/base/project.xsl 2013-01-02 13:30:46 UTC (rev
10639)
+++ trunk/property/templates/base/project.xsl 2013-01-03 14:54:52 UTC (rev
10640)
@@ -388,7 +388,7 @@
</xsl:when>
</xsl:choose>
<xsl:choose>
- <xsl:when
test="value_project_id!='' and mode='edit'">
+ <xsl:when
test="value_project_id!='' and mode='edit' and project_type_id !=3">
<tr>
<td valign="top">
<xsl:value-of select="php:function('lang', 'move')"/>
@@ -430,17 +430,28 @@
<xsl:apply-templates select="year_list/options"/>
</select>
</td>
-
<td>
-
<select name="values[budget_periodization]">
-
<xsl:attribute name="title">
-
<xsl:value-of select="php:function('lang',
'periodization')"/>
-
</xsl:attribute>
-
<option value="0">
-
<xsl:value-of select="php:function('lang',
'periodization')"/>
-
</option>
-
<xsl:apply-templates
select="periodization_list/options"/>
-
</select>
-
</td>
+
<xsl:choose>
+
<xsl:when test="project_type_id !='3'">
+
<td>
+
<select name="values[budget_periodization]">
+
<xsl:attribute name="title">
+
<xsl:value-of
select="php:function('lang', 'periodization')"/>
+
</xsl:attribute>
+
<option value="0">
+
<xsl:value-of
select="php:function('lang', 'periodization')"/>
+
</option>
+
<xsl:apply-templates
select="periodization_list/options"/>
+
</select>
+
</td>
+
<td>
+
<input type="checkbox"
name="values[budget_periodization_all]" value="True">
+
<xsl:attribute name="title">
+
<xsl:value-of
select="php:function('lang', 'all')"/>
+
</xsl:attribute>
+
</input>
+
</td>
+
</xsl:when>
+
</xsl:choose>
</tr>
</table>
</td>
@@ -454,45 +465,77 @@
<div
id="datatable-container_0"/>
</td>
</tr>
- <xsl:choose>
- <xsl:when test="project_type_id !='3'">
-
+ <xsl:choose>
+ <xsl:when
test="project_type_id !='3'">
+ <tr>
+
<td valign="top">
+
<xsl:value-of select="lang_reserve"/>
+
</td>
+
<td><input type="text" name="values[reserve]"
value="{value_reserve}"><xsl:attribute name="title"><xsl:value-of
select="lang_reserve_statustext"/></xsl:attribute></input><xsl:text>
</xsl:text> [ <xsl:value-of select="currency"/> ]
+
</td>
+ </tr>
+ <tr>
+
<td valign="top">
+
<xsl:value-of select="lang_sum"/>
+
</td>
+
<td><xsl:value-of select="value_sum"/><xsl:text> </xsl:text> [ <xsl:value-of
select="currency"/> ]
+
</td>
+ </tr>
+ <tr>
+
<td valign="top">
+
<xsl:value-of select="lang_remainder"/>
+
</td>
+
<td><xsl:value-of select="value_remainder"/><xsl:text> </xsl:text> [
<xsl:value-of select="currency"/> ]
+
</td>
+ </tr>
+ <tr>
+
<td valign="top">
+
<xsl:value-of select="lang_reserve_remainder"/>
+
</td>
+
<td>
+
<xsl:value-of select="value_reserve_remainder"/><xsl:text> </xsl:text>
[ <xsl:value-of select="currency"/> ]
+
<xsl:text> </xsl:text> ( <xsl:value-of
select="value_reserve_remainder_percent"/>
+
<xsl:text> % )</xsl:text>
+
</td>
+ </tr>
+
</xsl:when>
+
<xsl:otherwise>
+
<tr>
+
<td valign="top">
+
<xsl:value-of select="php:function('lang', 'transfer')"/>
+
</td>
+
<td>
+
<table>
+
<tr>
+
<td valign="top">
+
<xsl:value-of
select="php:function('lang', 'amount')"/>
+
</td>
+
<td valign="top">
+
<xsl:value-of
select="php:function('lang', 'project')"/>
+
</td>
+
</tr>
+
<tr>
+
<td>
+
<input type="text"
name="values[transfer_amount]" value="">
+
<xsl:attribute name="title">
+
<xsl:value-of
select="php:function('lang', 'amount to transfer')"/>
+
</xsl:attribute>
+
</input>
+
</td>
+
<td>
+
<input type="text"
name="values[transfer_target]" value="">
+
<xsl:attribute name="title">
+
<xsl:value-of
select="php:function('lang', 'target project')"/>
+
</xsl:attribute>
+
</input>
+
</td>
+
</tr>
+
</table>
+
</td>
+
</tr>
+
</xsl:otherwise>
+ </xsl:choose>
<tr>
- <td
valign="top">
-
<xsl:value-of select="lang_reserve"/>
- </td>
- <td><input
type="text" name="values[reserve]" value="{value_reserve}"><xsl:attribute
name="title"><xsl:value-of
select="lang_reserve_statustext"/></xsl:attribute></input><xsl:text>
</xsl:text> [ <xsl:value-of select="currency"/> ]
- </td>
- </tr>
- <tr>
- <td
valign="top">
-
<xsl:value-of select="lang_sum"/>
- </td>
-
<td><xsl:value-of select="value_sum"/><xsl:text> </xsl:text> [ <xsl:value-of
select="currency"/> ]
- </td>
- </tr>
- <tr>
- <td
valign="top">
-
<xsl:value-of select="lang_remainder"/>
- </td>
-
<td><xsl:value-of select="value_remainder"/><xsl:text> </xsl:text> [
<xsl:value-of select="currency"/> ]
- </td>
- </tr>
- <tr>
- <td
valign="top">
-
<xsl:value-of select="lang_reserve_remainder"/>
- </td>
- <td>
-
<xsl:value-of select="value_reserve_remainder"/><xsl:text> </xsl:text> [
<xsl:value-of select="currency"/> ]
-
<xsl:text> </xsl:text> ( <xsl:value-of
select="value_reserve_remainder_percent"/>
-
<xsl:text> % )</xsl:text>
- </td>
- </tr>
- </xsl:when>
- <xsl:otherwise>
- </xsl:otherwise>
- </xsl:choose>
- <tr>
<td
class="th_text" valign="top">
<xsl:value-of select="lang_workorder_id"/>
</td>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [10640] property: bufferproject,
Sigurd Nes <=