fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [9817] property: implement periodization for project


From: Sigurd Nes
Subject: [Fmsystem-commits] [9817] property: implement periodization for project budgets
Date: Tue, 31 Jul 2012 09:10:29 +0000

Revision: 9817
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=9817
Author:   sigurdne
Date:     2012-07-31 09:10:29 +0000 (Tue, 31 Jul 2012)
Log Message:
-----------
property: implement periodization for project budgets

Modified Paths:
--------------
    trunk/property/inc/class.boproject.inc.php
    trunk/property/inc/class.menu.inc.php
    trunk/property/inc/class.sogeneric.inc.php
    trunk/property/inc/class.soproject.inc.php
    trunk/property/inc/class.uiproject.inc.php
    trunk/property/js/yahoo/project.edit.js
    trunk/property/setup/setup.inc.php
    trunk/property/setup/tables_current.inc.php
    trunk/property/setup/tables_update.inc.php
    trunk/property/templates/base/project.xsl

Modified: trunk/property/inc/class.boproject.inc.php
===================================================================
--- trunk/property/inc/class.boproject.inc.php  2012-07-29 19:33:18 UTC (rev 
9816)
+++ trunk/property/inc/class.boproject.inc.php  2012-07-31 09:10:29 UTC (rev 
9817)
@@ -853,4 +853,9 @@
                {
                        return $this->so->get_budget($project_id);
                }
+
+               public function get_periodizations_with_outline()
+               {
+                       return $this->so->get_periodizations_with_outline();
+               }
        }

Modified: trunk/property/inc/class.menu.inc.php
===================================================================
--- trunk/property/inc/class.menu.inc.php       2012-07-29 19:33:18 UTC (rev 
9816)
+++ trunk/property/inc/class.menu.inc.php       2012-07-31 09:10:29 UTC (rev 
9817)
@@ -246,6 +246,11 @@
                                                        'text'  => 
lang('periodization'),
                                                        'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'property.uigeneric.index', 'type' => 'periodization') )
                                                ),
+                                               'periodization_outline' => array
+                                               (
+                                                       'text'  => 
lang('periodization outline'),
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'property.uigeneric.index', 'type' => 'periodization_outline') )
+                                               ),
                                                'accounting_config'     => array
                                                (
                                                        'text'  => 
lang('Configuration'),

Modified: trunk/property/inc/class.sogeneric.inc.php
===================================================================
--- trunk/property/inc/class.sogeneric.inc.php  2012-07-29 19:33:18 UTC (rev 
9816)
+++ trunk/property/inc/class.sogeneric.inc.php  2012-07-31 09:10:29 UTC (rev 
9817)
@@ -548,6 +548,13 @@
                                                                'name' => 
'descr',
                                                                'descr' => 
lang('descr'),
                                                                'type' => 
'varchar'
+                                                       ),
+                                                       array
+                                                       (
+                                                               'name' => 
'active',
+                                                               'descr' => 
lang('active'),
+                                                               'type' => 
'checkbox',
+                                                               'default' => 
'checked'
                                                        )
                                                ),
                                                'edit_msg'      => lang('edit'),
@@ -2299,6 +2306,82 @@
                                        );
 
                                break;
+
+                       case 'periodization_outline':
+                               $valueset_month = array();
+
+                               for ($i=1;$i<13;$i++)
+                               {
+                                       $valueset_month[] = array
+                                       (
+                                               'id'    => $i,
+                                               'name'  => $i
+                                       );
+                               }
+
+                               $info = array
+                                       (
+                                               'table'                         
=> 'fm_eco_periodization_outline',
+                                               'id'                            
=> array('name' => 'id', 'type' => 'auto'),
+                                               'fields'                        
=> array
+                                               (
+                                                       array
+                                                       (
+                                                               'name'          
        => 'periodization_id',
+                                                               'descr'         
        => lang('periodization'),
+                                                               'type'          
        => 'select',
+                                                               'nullable'      
        => false,
+                                                               'filter'        
        => true,
+                                                               'sortable'      
=> true,
+                                                               'values_def'    
=> array
+                                                               (
+                                                                       
'valueset'              => false,
+                                                                       
'method'                => 'property.bogeneric.get_list',
+                                                                       
'method_input'  => array('type' => 'periodization',     'selected' => 
'##periodization_id##')
+                                                               )
+                                                       ),
+                                                       array
+                                                       (
+                                                               'name'          
        => 'month',
+                                                               'descr'         
        => lang('month'),
+                                                               'type'          
        => 'select',
+                                                               'nullable'      
        => false,
+                                                               'filter'        
        => true,
+                                                               'sortable'      
=> true,
+                                                               'values_def'    
=> array
+                                                               (
+                                                                       
'valueset'              => $valueset_month,
+                                                               )
+                                                       ),
+                                                       array
+                                                       (
+                                                               'name'          
=> 'value',
+                                                               'descr'         
=> lang('value'),
+                                                               'type'          
=> 'int',
+                                                               'nullable'      
=> false,
+                                                               'size'          
=> 4,
+                                                               'sortable'      
=> true
+                                                       ),
+                                                       array
+                                                       (
+                                                               'name' => 
'remark',
+                                                               'descr' => 
lang('remark'),
+                                                               'type' => 
'varchar',
+                                                               'nullable'      
=> false,
+                                                               'size'          
=> 60,
+                                                               'sortable'      
=> true
+                                                       )
+                                               ),
+                                               'edit_msg'                      
=> lang('edit'),
+                                               'add_msg'                       
=> lang('add'),
+                                               'name'                          
=> lang('periodization'),
+                                               'acl_app'                       
=> 'property',
+                                               'acl_location' => '.admin',
+                                               'menu_selection' => 
'admin::property::accounting::periodization_outline'
+                                       );
+
+                               break;
+
 // START BOOKING TABLES
                        case 'bb_office':
                                $info = array

Modified: trunk/property/inc/class.soproject.inc.php
===================================================================
--- trunk/property/inc/class.soproject.inc.php  2012-07-29 19:33:18 UTC (rev 
9816)
+++ trunk/property/inc/class.soproject.inc.php  2012-07-31 09:10:29 UTC (rev 
9817)
@@ -1028,7 +1028,7 @@
 
                        if($project['budget'])
                        {
-                               $this->updat_budget($id, 
$project['budget_year'], $project['budget']);
+                               $this->updat_budget($id, 
$project['budget_year'], $project['budget_periodization'], $project['budget']);
                        }
 
                        if($project['extra']['contact_phone'] && 
$project['extra']['tenant_id'])
@@ -1232,7 +1232,7 @@
 
                        if($project['budget'])
                        {
-                               $this->updat_budget($project['id'], 
$project['budget_year'], $project['budget']);
+                               $this->updat_budget($project['id'], 
$project['budget_year'], $project['budget_periodization'], $project['budget']);
                        }
 
                        $this->db->query("SELECT sum(budget) AS sum_budget FROM 
fm_project_budget WHERE project_id = " . (int)$project['id'],__LINE__,__FILE__);
@@ -1429,6 +1429,7 @@
                                        (
                                                'project_id'            => 
(int)$project['id'],
                                                'year'                          
=> $this->db->f('year'),
+                                               'month'                         
=> $this->db->f('month'),
                                                'budget'                        
=> (int)$this->db->f('budget'),
                                                'user_id'                       
=> $this->db->f('user_id'),
                                                'entry_date'            => 
$this->db->f('entry_date'),
@@ -1438,11 +1439,11 @@
 
                                foreach($budget as $entry)
                                {
-                                       $sql = "SELECT * FROM fm_project_budget 
WHERE project_id = {$new_project_id} AND year = {$entry['year']}";
+                                       $sql = "SELECT * FROM fm_project_budget 
WHERE project_id = {$new_project_id} AND year = {$entry['year']} AND month = 
{$entry['month']}";
                                        
$this->db->query($sql,__LINE__,__FILE__);
                                        if($this->db->next_record())
                                        {
-                                               $sql = "UPDATE 
fm_project_budget SET budget = budget + {$entry['budget']} WHERE project_id = 
{$new_project_id} AND year = {$entry['year']}";
+                                               $sql = "UPDATE 
fm_project_budget SET budget = budget + {$entry['budget']} WHERE project_id = 
{$new_project_id} AND year = {$entry['year']} AND month = {$entry['month']}";
                                                
$this->db->query($sql,__LINE__,__FILE__);
                                        }
                                        else
@@ -1451,6 +1452,7 @@
                                                (
                                                        'project_id'            
=> $new_project_id,
                                                        'year'                  
        => $entry['year'],
+                                                       'month'                 
        => $entry['month'],
                                                        'budget'                
        => $entry['budget'],
                                                        'user_id'               
        => $entry['user_id'],
                                                        'entry_date'            
=> $entry['entry_date'],
@@ -1511,17 +1513,64 @@
                }
 
 
-               function updat_budget($project_id, $year, $budget)
+               function updat_budget($project_id, $year, $periodization_id, 
$budget)
                {
                        $project_id = (int) $project_id;
                        $year = $year ? (int) $year : date('Y');
+
+                       $periodization_id = (int) $periodization_id;
+                       $periodization_outline = array();
+
+                       if($periodization_id)
+                       {
+                               $this->db->query("SELECT month, value FROM 
fm_eco_periodization_outline WHERE periodization_id = {$periodization_id} ORDER 
BY month ASC",__LINE__,__FILE__);
+                               while ($this->db->next_record())
+                               {
+                                       $periodization_outline[] = array
+                                       (
+                                               'month' => 
$this->db->f('month'),
+                                               'value' => 
$this->db->f('value'),
+                                       );
+                               }
+                       }
+                       else
+                       {
+                               $periodization_outline[] = array
+                               (
+                                       'month' => 0,
+                                       'value' => 100,
+                               );
+                       
+                       }
+                       
+                       foreach ($periodization_outline as $outline)
+                       {
+                               $partial_budget = $budget * $outline['value'] / 
100;
+                               $this->_updat_budget($project_id, $year, 
$outline['month'], $partial_budget);
+                       }
+
+                       $sql = "SELECT sum(budget) as sum_budget FROM 
fm_project_budget WHERE project_id = {$project_id}";
+                       $this->db->query($sql,__LINE__,__FILE__);
+                       $this->db->next_record();
+                       $sum_budget = (int)$this->db->f('sum_budget');
+                       $sql = "UPDATE fm_project SET budget = {$sum_budget} 
WHERE id = {$project_id}";
+                       $this->db->query($sql,__LINE__,__FILE__);
+                       return $sum_budget;
+               }
+
+
+               private function _updat_budget($project_id, $year, $month, 
$budget)
+               {
+                       $month = (int) $month;
                        $budget = (int) $budget;
                        $now = time();
-                       $sql = "SELECT budget FROM fm_project_budget WHERE 
project_id = {$project_id} AND year = $year";
+
+                       $sql = "SELECT budget FROM fm_project_budget WHERE 
project_id = {$project_id} AND year = {$year} AND month = {$month}";
+
                        $this->db->query($sql,__LINE__,__FILE__);
                        if ($this->db->next_record())
                        {
-                               $sql = "UPDATE fm_project_budget SET budget = 
{$budget}, modified_date = {$now} WHERE project_id = {$project_id} AND year = 
$year";
+                               $sql = "UPDATE fm_project_budget SET budget = 
{$budget}, modified_date = {$now} WHERE project_id = {$project_id} AND year = 
{$year} AND month = {$month}";
                                $this->db->query($sql,__LINE__,__FILE__);
                        }
                        else
@@ -1530,6 +1579,7 @@
                                (
                                        'project_id'            => $project_id,
                                        'year'                          => 
$year,
+                                       'month'                         => 
$month,
                                        'budget'                        => 
$budget,
                                        'user_id'                       => 
$this->account,
                                        'entry_date'            => $now,
@@ -1540,19 +1590,31 @@
                                $values = 
$this->db->validate_insert(array_values($value_set));
                                $this->db->query("INSERT INTO fm_project_budget 
({$cols}) VALUES ({$values})",__LINE__,__FILE__);
                        }
-                       $sql = "SELECT sum(budget) as sum_budget FROM 
fm_project_budget WHERE project_id = {$project_id}";
-                       $this->db->query($sql,__LINE__,__FILE__);
-                       $this->db->next_record();
-                       $sum_budget = (int)$this->db->f('sum_budget');
-                       $sql = "UPDATE fm_project SET budget = {$sum_budget} 
WHERE id = {$project_id}";
-                       $this->db->query($sql,__LINE__,__FILE__);
-                       return $sum_budget;
+
                }
 
+
                function get_budget($project_id)
                {
                        $project_id = (int) $project_id;
 
+
+                       $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');
+                               $month = $this->db->f('month');
+               //              $period = $month ? $year . sprintf("%02s", 
$month) : $year . date('m');
+                               $period = $year . sprintf("%02s", $month);
+                               
+                               $project_budget[$period] = 
(int)$this->db->f('budget');
+                       }
+                       unset($year);                   
+
+
                        $sql = "SELECT id AS order_id FROM fm_workorder WHERE 
project_id = {$project_id}";
                        $this->db->query($sql,__LINE__,__FILE__);
 
@@ -1572,20 +1634,57 @@
                                $this->db->query($sql,__LINE__,__FILE__);
                                while ($this->db->next_record())
                                {
-                                       $year = substr( 
$this->db->f('periode'), 0, 4 );
-                                       
$orders[$year][$this->db->f('order')]['actual_cost'] += 
$this->db->f('actual_cost');
+                                       $periode = $this->db->f('periode');
+                                       $year = substr( $periode, 0, 4 );
+       //                              $month = substr( $periode, 4, 2 );
+                                       
+                                       $_found = false;
+                                       for ($i=0;$i<13;$i++)
+                                       {
+                                               $_period = $year . 
sprintf("%02s", $i);
+                                               
if(isset($project_budget[$_period]))
+                                               {
+                                                       
$orders[$_period][$this->db->f('order')]['actual_cost'] += 
$this->db->f('actual_cost');
+                                                       $_found = true;
+                                                       break;
+                                               }
+                                       }
+                                       
+                                       if(!$_found)
+                                       {
+                                               
$orders[$periode][$this->db->f('order')]['actual_cost'] += 
$this->db->f('actual_cost');
+                                       }
                                }
 
                                $sql = "SELECT sum(godkjentbelop) AS 
actual_cost, pmwrkord_code AS order, periode FROM fm_ecobilag WHERE 
pmwrkord_code IN ({$_order_filter}) GROUP BY pmwrkord_code, periode ORDER BY 
pmwrkord_code, periode ASC ";
                                $this->db->query($sql,__LINE__,__FILE__);
                                while ($this->db->next_record())
                                {
-                                       $year = substr( 
$this->db->f('periode'), 0, 4 );
-                                       if(!$year)
+                                       $periode = $this->db->f('periode');
+                                       $year = substr( $periode, 0, 4 );
+       //                              $month = substr( $periode, 4, 2 );
+                                       if(!$periode)
                                        {
                                                $year = date('Y');
+                                               $periode = date('Ym');
                                        }
-                                       
$orders[$year][$this->db->f('order')]['actual_cost'] += 
$this->db->f('actual_cost');
+
+                                       $_found = false;
+                                       for ($i=0;$i<13;$i++)
+                                       {
+                                               $_period = $year . 
sprintf("%02s", $i);
+                                               
if(isset($project_budget[$_period]))
+                                               {
+                                                       
$orders[$_period][$this->db->f('order')]['actual_cost'] += 
$this->db->f('actual_cost');
+                                                       $_found = true;
+                                                       break;
+                                               }
+                                       }
+                                       
+                                       if(!$_found)
+                                       {
+                                               
$orders[$periode][$this->db->f('order')]['actual_cost'] += 
$this->db->f('actual_cost');
+                                       }
                                }
                        }
 
@@ -1593,7 +1692,8 @@
                        $config->read();
                        $tax = 1+(($config->config_data['fm_tax'])/100);
 
-                       $sql = "SELECT fm_workorder.id, EXTRACT(YEAR from 
to_timestamp(start_date) ) as year, sum(calculation) as calculation, 
sum(budget) as budget, sum(contract_sum) as contract_sum, fm_workorder.addition"
+//                     $sql = "SELECT fm_workorder.id, EXTRACT(YEAR from 
to_timestamp(start_date) ) as year, sum(calculation) as calculation, 
sum(budget) as budget, sum(contract_sum) as contract_sum, fm_workorder.addition"
+                       $sql = "SELECT fm_workorder.id, sum(calculation) as 
calculation, sum(budget) as budget, sum(contract_sum) as contract_sum, 
fm_workorder.addition"
                        . " FROM fm_workorder"
                        . " {$this->join} fm_workorder_status ON 
fm_workorder.status  = fm_workorder_status.id"
                        . " WHERE project_id = {$project_id} AND 
(fm_workorder_status.closed IS NULL OR fm_workorder_status.closed != 1)"
@@ -1603,7 +1703,26 @@
 
                        while ($this->db->next_record())
                        {
-                               $year = date('Y');//$this->db->f('year');
+                               $year = date('Y');
+                               $_found = false;
+                               
+                               //move to current
+                               $check_months = array(0, date('m'));
+                               
+                               foreach ($check_months as $i)
+                               {
+                                       $periode = $year . sprintf("%02s", $i);
+                                       if(isset($project_budget[$periode]))
+                                       {
+                                               $_found = true;
+                                               break;
+                                       }
+                               }
+                                       
+                               if(!$_found)
+                               {
+                                       $periode = date('Ym');
+                               }
 
                                if(abs($this->db->f('contract_sum')) > 0)
                                {
@@ -1622,29 +1741,21 @@
                                        $_amount = 0;
                                }
 
-                               $orders[$year][$this->db->f('id')]['amount'] = 
$_amount;
+                               $orders[$periode][$this->db->f('id')]['amount'] 
= $_amount;
                        }
+                       unset($periode);
 
-                       $sort_year = array();
+                       $sort_period = 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())
+                       foreach ($project_budget as $period => $budget)
                        {
-                               $project_budget[$this->db->f('year')] = 
(int)$this->db->f('budget');
-                       }
-                       
-                       foreach ($project_budget as $year => $budget)
-                       {
                                $_sum_orders = 0;
                                $_actual_cost = 0;
 
-                               if(isset($orders[$year]))
+                               if(isset($orders[$period]))
                                {
-                                       foreach ($orders[$year] as $order_id => 
$order)
+                                       foreach ($orders[$period] as $order_id 
=> $order)
                                        {
                                                $_sum_orders += 
$order['amount'];
                        //                      $_sum_orders -= 
$order['actual_cost'];
@@ -1679,30 +1790,30 @@
                                                $_actual_cost += 
$order['actual_cost'];
                                        }
 
-                                       unset($orders[$year]);
+                                       unset($orders[$period]);
                                }
 
                                $values[] = array
                                (
                                        'project_id'            => $project_id,
-                                       'year'                          => 
$year,
+                                       'period'                        => 
$period,
                                        'budget'                        => 
$budget,
                                        'sum_orders'            => $_sum_orders,
                                        'actual_cost'           => 
$_actual_cost,
                                );
 
-                               $sort_year[] = $year;
+                               $sort_period[] = $period;
                        }
 //_debug_array($values);die();
                        unset($order);
                        unset($order_id);
-                       unset($year);
+                       unset($period);
 
                        reset($orders);
 
                        //remaining
 //_debug_array($orders);
-                       foreach ($orders as $year => $_orders)
+                       foreach ($orders as $period => $_orders)
                        {
                                $_sum_orders = 0;
                                $_actual_cost = 0;
@@ -1728,23 +1839,26 @@
                                $values[] = array
                                (
                                        'project_id'            => $project_id,
-                                       'year'                          => 
$year,
+                                       'period'                                
=> $period,
                                        'budget'                        => 0,
                                        'sum_orders'            => $_sum_orders,
                                        'actual_cost'           => 
$_actual_cost,
                                );
 
-                               $sort_year[] = $year;
+                               $sort_period[] = $period;
                        }
 
                        if($values)
                        {
-                               array_multisort($sort_year, SORT_ASC, $values);
+                               array_multisort($sort_period, SORT_ASC, 
$values);
                        }
 
 
                        foreach ($values as &$entry)
                        {
+                               $entry['year'] = substr( $entry['period'], 0, 4 
);
+                               $month = substr( $entry['period'], 4, 2 );
+                               $entry['month'] = $month == '00' ? '' : $month;
                                $entry['diff'] = $entry['budget'] - 
$entry['sum_orders'] - $entry['actual_cost'];
                        }
 
@@ -1755,8 +1869,12 @@
                function delete_year_from_budget($project_id, $data)
                {
                        $project_id = (int) $project_id;
-                       $sql = "DELETE FROM fm_project_budget WHERE project_id 
= {$project_id} AND year IN(" . implode(',', $data) . ')';
-                       $this->db->query($sql,__LINE__,__FILE__);
+                       foreach($data as $entry)
+                       {
+                               $when = explode('_', $entry);
+                               $sql = "DELETE FROM fm_project_budget WHERE 
project_id = {$project_id} AND year =" . (int) $when[0] . ' AND month = ' . 
(int) $when[1];
+                               $this->db->query($sql,__LINE__,__FILE__);
+                       }
                }
 
                function 
update_request_status($project_id='',$status='',$category=0,$coordinator=0)
@@ -2113,4 +2231,23 @@
 
                        return $values;
                }
+
+               public function get_periodizations_with_outline()
+               {
+                       $values = array();
+                       $sql = 'SELECT DISTINCT fm_eco_periodization.id, 
fm_eco_periodization.descr FROM fm_eco_periodization'
+                       . " {$this->join} fm_eco_periodization_outline ON 
fm_eco_periodization.id = fm_eco_periodization_outline.periodization_id";
+                       $this->db->query($sql,__LINE__,__FILE__);
+
+                       while($this->db->next_record())
+                       {
+                               $values[] = array
+                               (
+                                       'id'    => $this->db->f('id'),
+                                       'name'  => $this->db->f('descr'),
+                               );
+                       }
+
+                       return $values;
+               }
        }

Modified: trunk/property/inc/class.uiproject.inc.php
===================================================================
--- trunk/property/inc/class.uiproject.inc.php  2012-07-29 19:33:18 UTC (rev 
9816)
+++ trunk/property/inc/class.uiproject.inc.php  2012-07-31 09:10:29 UTC (rev 
9817)
@@ -1683,7 +1683,7 @@
                                $lang_delete = lang('Check to delete year');
                                foreach($content_budget as & $b_entry)
                                {
-                                       $b_entry['delete_year'] = "<input 
type='checkbox' name='values[delete_b_year][]' value='{$b_entry['year']}' 
title='{$lang_delete}'>";
+                                       $b_entry['delete_year'] = "<input 
type='checkbox' name='values[delete_b_year][]' 
value='{$b_entry['year']}_{$b_entry['month']}' title='{$lang_delete}'>";
                                        $value_remainder -= 
$b_entry['sum_orders'];
                                        $value_remainder -= 
$b_entry['actual_cost'];
                                }
@@ -1710,6 +1710,7 @@
                                (
                                        'name'          => "0",
                                        'values'        =>      
json_encode(array(      array('key' => 
'year','label'=>lang('year'),'sortable'=>false,'resizeable'=>true),
+                                                                               
                                array('key' => 
'month','label'=>lang('month'),'sortable'=>false,'resizeable'=>true),
                                                                                
                                array('key' => 
'budget','label'=>lang('budget'),'sortable'=>false,'resizeable'=>true,'formatter'=>'FormatterAmount0'),
                                                                                
                                array('key' => 'sum_orders','label'=>lang('sum 
orders'),'sortable'=>false,'resizeable'=>true,'formatter'=>'FormatterAmount0'),
                                                                                
                                array('key' => 
'actual_cost','label'=>lang('actual 
cost'),'sortable'=>false,'resizeable'=>true,'formatter'=>'FormatterAmount2'),
@@ -1874,6 +1875,7 @@
                                $year++;
                        }
 
+                       $periodization_list = 
$this->bo->get_periodizations_with_outline();
 
                        $data = array
                                (
@@ -1896,6 +1898,7 @@
                                        'value_origin_type'                     
                => isset($origin)?$origin:'',
                                        'value_origin_id'                       
                => isset($origin_id)?$origin_id:'',
                                        'year_list'                             
                        => array('options' => $year_list),
+                                       'periodization_list'                    
        => array('options' => $periodization_list),
                                        'lang_select_request'                   
        => lang('Select request'),
                                        'lang_select_request_statustext'        
=> lang('Add request for this project'),
                                        'lang_request_statustext'               
        => lang('Link to the request for this project'),

Modified: trunk/property/js/yahoo/project.edit.js
===================================================================
--- trunk/property/js/yahoo/project.edit.js     2012-07-29 19:33:18 UTC (rev 
9816)
+++ trunk/property/js/yahoo/project.edit.js     2012-07-31 09:10:29 UTC (rev 
9817)
@@ -112,6 +112,7 @@
                newTR = document.createElement('tr');
 
                td_sum('Sum');
+               td_empty(1);
                td_sum(tmp_sum1);
                td_sum(tmp_sum2);
                td_sum(tmp_sum3);

Modified: trunk/property/setup/setup.inc.php
===================================================================
--- trunk/property/setup/setup.inc.php  2012-07-29 19:33:18 UTC (rev 9816)
+++ trunk/property/setup/setup.inc.php  2012-07-31 09:10:29 UTC (rev 9817)
@@ -12,7 +12,7 @@
        */
 
        $setup_info['property']['name']                 = 'property';
-       $setup_info['property']['version']              = '0.9.17.648';
+       $setup_info['property']['version']              = '0.9.17.649';
        $setup_info['property']['app_order']    = 8;
        $setup_info['property']['enable']               = 1;
        $setup_info['property']['app_group']    = 'office';
@@ -150,6 +150,7 @@
                'fm_ecomva',
                'fm_ecouser',
                'fm_eco_periodization',
+               'fm_eco_periodization_outline',
                'fm_event',
                'fm_event_action',
                'fm_event_exception',

Modified: trunk/property/setup/tables_current.inc.php
===================================================================
--- trunk/property/setup/tables_current.inc.php 2012-07-29 19:33:18 UTC (rev 
9816)
+++ trunk/property/setup/tables_current.inc.php 2012-07-31 09:10:29 UTC (rev 
9817)
@@ -1230,13 +1230,27 @@
                'fm_eco_periodization' => array(
                        'fd' => array(
                                'id' => array('type' => 'int','precision' => 
'4','nullable' => False),
-                               'descr' => array('type' => 
'varchar','precision' => '64','nullable' => False)
+                               'descr' => array('type' => 
'varchar','precision' => '64','nullable' => False),
+                               'active' => array('type' => 'int','precision' 
=> '2','nullable' => True,'default' => '0'),
                        ),
                        'pk' => array('id'),
                        'ix' => array(),
                        'fk' => array(),
                        'uc' => array()
                ),
+               'fm_eco_periodization_outline' => array(
+                       'fd' => array(
+                               'id' => array('type' => 'auto','precision' => 
4,'nullable' => False),
+                               'periodization_id' => array('type' => 
'int','precision' => '4','nullable' => False),
+                               'month' => array('type' => 'int','precision' => 
'4','nullable' => true),
+                               'value' => array('type' => 
'decimal','precision' => '20','scale' => '2','nullable' => false,'default' => 
'0.00'),
+                               'remark' => array('type' => 
'varchar','precision' => '60','nullable' => False),
+                       ),
+                       'pk' => array('id'),
+                       'ix' => array(),
+                       'fk' => array('fm_eco_periodization' => 
array('periodization_id' => 'id') ),
+                       'uc' => array('periodization_id', 'month')
+               ),
                'fm_order_dim1' => array(
                        'fd' => array(
                                'id' => array('type' => 'int','precision' => 
'4','nullable' => False),
@@ -1446,13 +1460,14 @@
                        'fd' => array(
                                'project_id' => array('type' => 
'int','precision' => 4,'nullable' => False),
                                'year' => array('type' => 'int','precision' => 
4,'nullable' => False),
+                               'month' => array('type' => 'int','precision' => 
2,'nullable' => False,'default' => 0),
                                'budget' => array('type' => 
'decimal','precision' => '20','scale' => '2','nullable' => True,'default' => 
'0.00'),
                                'user_id' => array('type' => 'int','precision' 
=> 4,'nullable' => True),
                                'entry_date' => array('type' => 
'int','precision' => 4,'nullable' => True),
                                'modified_date' => array('type' => 
'int','precision' => 4,'nullable' => True)
                        ),
-                       'pk' => array('project_id','year'),
-                       'fk' => array(),
+                       'pk' => array('project_id','year','month'),
+                       'fk' => array('fm_project' => array('project_id' => 
'id')),
                        'ix' => array(),
                        'uc' => array()
                ),

Modified: trunk/property/setup/tables_update.inc.php
===================================================================
--- trunk/property/setup/tables_update.inc.php  2012-07-29 19:33:18 UTC (rev 
9816)
+++ trunk/property/setup/tables_update.inc.php  2012-07-31 09:10:29 UTC (rev 
9817)
@@ -6465,7 +6465,7 @@
 
        /**
        * Update property version from 0.9.17.647 to 0.9.17.648
-       * Update values
+       * Implement periodizations at project budgetting
        */
        $test[] = '0.9.17.647';
        function property_upgrade0_9_17_647()
@@ -6514,3 +6514,93 @@
                        return $GLOBALS['setup_info']['property']['currentver'];
                }
        }
+       /**
+       * Update property version from 0.9.17.648 to 0.9.17.649
+       * Update values
+       */
+       $test[] = '0.9.17.648';
+       function property_upgrade0_9_17_648()
+       {
+               $GLOBALS['phpgw_setup']->oProc->m_odb->transaction_begin();
+
+               $GLOBALS['phpgw_setup']->oProc->CreateTable(
+                       'fm_eco_periodization_outline',  array(
+                               'fd' => array(
+                                       'id' => array('type' => 
'auto','precision' => '4','nullable' => False),
+                                       'periodization_id' => array('type' => 
'int','precision' => '4','nullable' => False),
+                                       'month' => array('type' => 
'int','precision' => '4','nullable' => true),
+                                       'value' => array('type' => 
'decimal','precision' => '20','scale' => '2','nullable' => false,'default' => 
'0.00'),
+                                       'remark' => array('type' => 
'varchar','precision' => '60','nullable' => False),
+                               ),
+                               'pk' => array('id'),
+                               'ix' => array(),
+                               'fk' => array('fm_eco_periodization' => 
array('periodization_id' => 'id') ),
+                               'uc' => array('periodization_id', 'month')
+                       )
+               );
+
+
+               
$GLOBALS['phpgw_setup']->oProc->AddColumn('fm_eco_periodization','active',array(
+                       'type'          => 'int',
+                       'precision'     => 2,
+                       'nullable'      => true,
+                       'default' => 0
+                       )
+               );
+
+
+               $GLOBALS['phpgw_setup']->oProc->query("UPDATE 
fm_eco_periodization SET active = 1",__LINE__,__FILE__);
+
+               $sql = 'SELECT * FROM fm_project_budget JOIN fm_project ON 
fm_project_budget.project_id = fm_project.id';
+               $GLOBALS['phpgw_setup']->oProc->query($sql,__LINE__,__FILE__);
+
+               $budgets = array();
+               while ($GLOBALS['phpgw_setup']->oProc->next_record())
+               {
+                       $budgets[] = array
+                       (
+                               'project_id'    => 
$GLOBALS['phpgw_setup']->oProc->f('project_id'),
+                               'year'                  => 
$GLOBALS['phpgw_setup']->oProc->f('year'),
+                               'month'                 => 0,
+                               'budget'                => 
$GLOBALS['phpgw_setup']->oProc->f('budget'),
+                               'user_id'               => 
$GLOBALS['phpgw_setup']->oProc->f('user_id'),
+                               'entry_date'    => 
$GLOBALS['phpgw_setup']->oProc->f('entry_date'),
+                               'modified_date' => 
$GLOBALS['phpgw_setup']->oProc->f('modified_date'),
+                       );
+               }
+
+               $GLOBALS['phpgw_setup']->oProc->DropTable('fm_project_budget');
+
+               $GLOBALS['phpgw_setup']->oProc->CreateTable(
+                       'fm_project_budget',  array(
+                               'fd' => array(
+                                       'project_id' => array('type' => 
'int','precision' => 4,'nullable' => False),
+                                       'year' => array('type' => 
'int','precision' => 4,'nullable' => False),
+                                       'month' => array('type' => 
'int','precision' => 2,'nullable' => False,'default' => 0),
+                                       'budget' => array('type' => 
'decimal','precision' => '20','scale' => '2','nullable' => True,'default' => 
'0.00'),
+                                       'user_id' => array('type' => 
'int','precision' => 4,'nullable' => True),
+                                       'entry_date' => array('type' => 
'int','precision' => 4,'nullable' => True),
+                                       'modified_date' => array('type' => 
'int','precision' => 4,'nullable' => True)
+                               ),
+                               'pk' => array('project_id','year','month'),
+                               'fk' => array('fm_project' => 
array('project_id' => 'id')),
+                               'ix' => array(),
+                               'uc' => array()
+                       )
+               );
+
+               foreach ($budgets as $budget)
+               {
+                       $cols = implode(',', array_keys($budget));
+                       $values = 
$GLOBALS['phpgw_setup']->oProc->validate_insert(array_values($budget));
+                       $sql = "INSERT INTO fm_project_budget ({$cols}) VALUES 
({$values})";
+                       
$GLOBALS['phpgw_setup']->oProc->query($sql,__LINE__,__FILE__);
+               }
+
+
+               if($GLOBALS['phpgw_setup']->oProc->m_odb->transaction_commit())
+               {
+                       $GLOBALS['setup_info']['property']['currentver'] = 
'0.9.17.649';
+                       return $GLOBALS['setup_info']['property']['currentver'];
+               }
+       }       

Modified: trunk/property/templates/base/project.xsl
===================================================================
--- trunk/property/templates/base/project.xsl   2012-07-29 19:33:18 UTC (rev 
9816)
+++ trunk/property/templates/base/project.xsl   2012-07-31 09:10:29 UTC (rev 
9817)
@@ -393,27 +393,38 @@
                                                                </td>
                                                                <td>
                                                                        <table>
-                                                                       <tr>
-                                                                       <td>
-                                                                       <input 
type="text" name="values[budget]" value="">
-                                                                               
<xsl:attribute name="title">
-                                                                               
        <xsl:value-of select="php:function('lang', 'Enter the budget')"/>
-                                                                               
</xsl:attribute>
-                                                                       </input>
-                                                                       
<xsl:text> </xsl:text> [ <xsl:value-of select="currency"/> ]
-                                                                       </td>
-                                                                       <td>
-                                                                       <select 
name="values[budget_year]">
-                                                                               
<xsl:attribute name="title">
-                                                                               
        <xsl:value-of select="php:function('lang', 'year')"/>
-                                                                               
</xsl:attribute>
-                                                                               
<option value="0">
-                                                                               
        <xsl:value-of select="php:function('lang', 'year')"/>
-                                                                               
</option>
-                                                                               
<xsl:apply-templates select="year_list/options"/>
-                                                                       
</select>
-                                                                       </td>
-                                                                       </tr>
+                                                                               
<tr>
+                                                                               
        <td>
+                                                                               
                <input type="text" name="values[budget]" value="">
+                                                                               
                        <xsl:attribute name="title">
+                                                                               
                                <xsl:value-of select="php:function('lang', 
'Enter the budget')"/>
+                                                                               
                        </xsl:attribute>
+                                                                               
                </input>
+                                                                               
                <xsl:text> </xsl:text> [ <xsl:value-of select="currency"/> ]
+                                                                               
        </td>
+                                                                               
        <td>
+                                                                               
                <select name="values[budget_year]">
+                                                                               
                        <xsl:attribute name="title">
+                                                                               
                                <xsl:value-of select="php:function('lang', 
'year')"/>
+                                                                               
                        </xsl:attribute>
+                                                                               
                        <option value="0">
+                                                                               
                                <xsl:value-of select="php:function('lang', 
'year')"/>
+                                                                               
                        </option>
+                                                                               
                        <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>
+                                                                               
</tr>
                                                                        </table>
                                                                </td>
                                                        </tr>




reply via email to

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