fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [14500] property::ticket: budget per year


From: Sigurd Nes
Subject: [Fmsystem-commits] [14500] property::ticket: budget per year
Date: Sat, 28 Nov 2015 16:54:52 +0000

Revision: 14500
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=14500
Author:   sigurdne
Date:     2015-11-28 16:54:51 +0000 (Sat, 28 Nov 2015)
Log Message:
-----------
property::ticket: budget per year

Modified Paths:
--------------
    trunk/property/inc/class.botts.inc.php
    trunk/property/inc/class.sotts.inc.php
    trunk/property/inc/class.uitts.inc.php
    trunk/property/setup/setup.inc.php
    trunk/property/setup/tables_current.inc.php
    trunk/property/setup/tables_update.inc.php
    trunk/property/templates/base/tts.xsl

Modified: trunk/property/inc/class.botts.inc.php
===================================================================
--- trunk/property/inc/class.botts.inc.php      2015-11-28 10:03:06 UTC (rev 
14499)
+++ trunk/property/inc/class.botts.inc.php      2015-11-28 16:54:51 UTC (rev 
14500)
@@ -1680,6 +1680,15 @@
                        return $values;
                }
 
+               public function get_budgets($id)
+               {
+                       $budgets = $this->so->get_budgets($id);
+                       foreach($budgets as &$budget)
+                       {
+                               $budget['created_on_date'] = 
$GLOBALS['phpgw']->common->show_date($payment['created_on'],$this->dateformat);
+                       }
+                       return $budgets;
+               }
                public function get_payments($id)
                {
                        $payments = $this->so->get_payments($id);

Modified: trunk/property/inc/class.sotts.inc.php
===================================================================
--- trunk/property/inc/class.sotts.inc.php      2015-11-28 10:03:06 UTC (rev 
14499)
+++ trunk/property/inc/class.sotts.inc.php      2015-11-28 16:54:51 UTC (rev 
14500)
@@ -394,7 +394,10 @@
 
                        $actual_cost_field = 'fm_tts_tickets.actual_cost';
                        $actual_cost_group_field = 
',fm_tts_tickets.actual_cost';
+                       $budget_field = 'fm_tts_tickets.budget';
+                       $budget_group_field = ',fm_tts_tickets.budget';
                        $date_join = '';
+                       $date_budget_join = '';
 
                        if ($start_date)
                        {
@@ -408,11 +411,18 @@
                                {
                                        $end_period     = date('Ym', $end_date);
                                        $start_period   = date('Ym', 
$start_date);
-                                       $filtermethod .= " OR 
(fm_tts_payments.period >= {$start_period} AND fm_tts_payments.period <= 
{$end_period}))";
+                                       $filtermethod .= " OR 
(fm_tts_payments.period >= {$start_period} AND fm_tts_payments.period <= 
{$end_period})";
                                        $date_join = "LEFT JOIN fm_tts_payments 
ON ( fm_tts_tickets.id=fm_tts_payments.ticket_id AND fm_tts_payments.period >= 
$start_period AND fm_tts_payments.period <= $end_period )";
                                        $actual_cost_field = 
'SUM(fm_tts_payments.amount) AS actual_cost';
                                        $actual_cost_group_field = '';
 
+
+                                       $start_budget_period = date('Y', 
$end_date) . '00';
+                                       $end_budget_period = date('Y', 
$start_date) . '13';
+                                       $filtermethod .= " OR 
(fm_tts_budget.period >= {$start_budget_period} AND fm_tts_budget.period <= 
{$end_budget_period}))";
+                                       $date_budget_join = "LEFT JOIN 
fm_tts_budget ON ( fm_tts_tickets.id=fm_tts_budget.ticket_id AND 
fm_tts_budget.period >= $start_budget_period AND fm_tts_budget.period <= 
$end_budget_period )";
+                                       $budget_field = 
'SUM(fm_tts_budget.amount) AS budget';
+                                       $budget_group_field = '';
                                }
                                else
                                {
@@ -490,7 +500,7 @@
                        $return_fields = 
"fm_tts_tickets.id,fm_tts_tickets.assignedto,fm_tts_tickets.status,fm_tts_tickets.user_id,"
                        . 
"fm_tts_tickets.subject,fm_tts_tickets.address,fm_tts_tickets.location_code,fm_tts_tickets.priority,fm_tts_tickets.cat_id,fm_tts_tickets.group_id,"
                        . 
"fm_tts_tickets.entry_date,fm_tts_tickets.modified_date,fm_tts_tickets.finnish_date,fm_tts_tickets.finnish_date2,fm_tts_tickets.order_id,fm_tts_tickets.vendor_id,"
-                       . 
"fm_tts_tickets.budget,fm_tts_tickets.billable_hours,fm_district.descr as 
district,fm_tts_views.id as 
view,fm_location1.loc1_name,fm_tts_tickets.ecodimb,fm_tts_tickets.order_dim1 
{$result_order_field}";
+                       . "fm_tts_tickets.billable_hours,fm_district.descr as 
district,fm_tts_views.id as 
view,fm_location1.loc1_name,fm_tts_tickets.ecodimb,fm_tts_tickets.order_dim1 
{$result_order_field}";
 
                        $custom_cols = $this->custom->find('property', 
'.ticket', 0, '', 'ASC', 'attrib_sort', true, true);
                        
@@ -499,11 +509,11 @@
                                $return_fields .= 
",fm_tts_tickets.{$custom_col['column_name']}";
                        }
 
-                       $sql = "SELECT DISTINCT 
{$return_fields},{$actual_cost_field} FROM fm_tts_tickets"
+                       $sql = "SELECT DISTINCT 
{$return_fields},$budget_field,{$actual_cost_field} FROM fm_tts_tickets"
                                . " {$this->left_join} fm_location1 ON 
fm_tts_tickets.loc1=fm_location1.loc1"
                                . " {$this->left_join} fm_part_of_town ON 
fm_location1.part_of_town_id=fm_part_of_town.part_of_town_id"
                                . " {$this->left_join} fm_district ON 
fm_district.id = fm_part_of_town.district_id"
-                               . " {$order_join}{$date_join}"
+                               . " 
{$order_join}{$date_join}{$date_budget_join}"
                                . " LEFT OUTER JOIN fm_tts_views ON 
(fm_tts_tickets.id = fm_tts_views.id AND 
fm_tts_views.account_id='{$this->account}')";
 
                        if(isset($custom_filter['joinmethod_datatype']) && 
$custom_filter['joinmethod_datatype'])
@@ -515,13 +525,13 @@
                        }
 
                        $group_fields = str_ireplace(array('fm_district.descr 
as district', 'fm_tts_views.id as view'), 
array('fm_district.descr','fm_tts_views.id'), $return_fields);
-                       $sql .= " {$filtermethod} {$querymethod} GROUP BY 
{$group_fields}{$actual_cost_group_field}";
+                       $sql .= " {$filtermethod} {$querymethod} GROUP BY 
{$group_fields}{$budget_group_field}{$actual_cost_group_field}";
 
-                       $sql_cnt = "SELECT DISTINCT fm_tts_tickets.budget 
,{$actual_cost_field}, fm_tts_tickets.id FROM fm_tts_tickets"
+                       $sql_cnt = "SELECT DISTINCT 
{$budget_field},{$actual_cost_field}, fm_tts_tickets.id FROM fm_tts_tickets"
                                . " {$this->left_join} fm_location1 ON 
fm_tts_tickets.loc1=fm_location1.loc1"
                                . " {$this->left_join} fm_part_of_town ON 
fm_location1.part_of_town_id=fm_part_of_town.part_of_town_id"
                                . " {$this->left_join} fm_district ON 
fm_district.id = fm_part_of_town.district_id"
-                               . " {$order_join}{$date_join}"
+                               . " 
{$order_join}{$date_join}{$date_budget_join}"
                                . " LEFT OUTER JOIN fm_tts_views ON 
(fm_tts_tickets.id = fm_tts_views.id AND 
fm_tts_views.account_id='{$this->account}')";
 
                        if(isset($custom_filter['joinmethod_datatype']) && 
$custom_filter['joinmethod_datatype'])
@@ -1107,7 +1117,7 @@
                        $oldcat_id                              = 
$this->db->f('cat_id');
                        $old_status                     = 
$this->db->f('status');
                        $ticket['old_status']   = $old_status; // used for 
custom functions
-                       $old_budget                     = 
$this->db->f('budget');
+               //      $old_budget                     = 
$this->db->f('budget');
                        $old_billable_hours             = 
(float)$this->db->f('billable_hours');
                //      $old_billable_rate      = $this->db->f('billable_rate');
                        $old_subject                    = 
$this->db->f('subject');
@@ -1460,6 +1470,32 @@
 
                        if($order_add || $order_edit)
                        {
+                               if ((int)$ticket['budget'])
+                               {
+
+                                       $this->db->query("SELECT sum(amount) AS 
budget FROM fm_tts_budget WHERE ticket_id = {$id}", __LINE__,__FILE__);
+                                       $this->db->next_record();
+                                       $old_budget = $this->db->f('budget');
+                                       $new_budget =str_replace(',', '.', 
($old_budget + $ticket['budget']));
+
+                                       $this->db->query("UPDATE fm_tts_tickets 
SET budget='{$new_budget}' WHERE id='$id'",__LINE__,__FILE__);
+
+                                       $value_set_cost = array
+                                       (
+                                               'ticket_id'     => $id,
+                                               'amount'        => 
str_replace(',', '.', $ticket['budget']),
+                                               'period'        => 
$ticket['budget_period'] . '01',
+                                               'created_on'=> time(),
+                                               'created_by'=> $this->account
+                                       );
+
+                                       $cols_cost = implode(',', 
array_keys($value_set_cost));
+                                       $values_cost    = 
$this->db->validate_insert(array_values($value_set_cost));
+                                       $this->db->query("INSERT INTO 
fm_tts_budget ({$cols_cost}) VALUES ({$values_cost})");
+
+                                       
$this->historylog->add('B',$id,(float)$new_budget , $old_budget);
+                                       $receipt['message'][]= array('msg' => 
lang('budget changed'));
+                               }
                                if ((int)$ticket['actual_cost'])
                                {
 
@@ -1510,7 +1546,7 @@
                                        $receipt['message'][]= array('msg' => 
lang('building part has been updated'));
                                        $this->fields_updated[] = 
'building_part';
                                }
-
+/*
                                if ($old_budget != $ticket['budget'])
                                {
                                        $this->fields_updated[] = 'budget';
@@ -1518,7 +1554,7 @@
                                                . "' where 
id='$id'",__LINE__,__FILE__);
                                        
$this->historylog->add('B',$id,$ticket['budget'],$old_budget);
                                }
-
+*/
                                $value_set['vendor_id']                 = 
$ticket['vendor_id'];
                                $value_set['b_account_id']              = 
$ticket['b_account_id'];
                                $value_set['order_descr']               = 
$this->db->db_addslashes($ticket['order_descr']);
@@ -1745,6 +1781,30 @@
                        return $values;
                }
 
+               public function get_budgets($id)
+               {
+                       $id = (int) $id;
+                       $values = array();
+                       $sql = "SELECT * FROM fm_tts_budget WHERE ticket_id = 
{$id}  ORDER BY period ASC";
+
+                       $this->db->query($sql, __LINE__,__FILE__);
+
+                       while ($this->db->next_record())
+                       {
+                               $values[] = array
+                               (
+                                       'id'            => $this->db->f('id'),
+                                       'ticket_id'     => 
$this->db->f('ticket_id'),
+                                       'amount'        => 
$this->db->f('amount'),
+                                       'period'        => 
$this->db->f('period'),
+                                       'created_on'=> 
$this->db->f('created_on'),
+                                       'created_by'=> 
$this->db->f('created_by'),
+                                       'remark'        => 
$this->db->f('remark', true)
+                               );
+                       }
+                       return $values;
+               }
+
                public function get_payments($id)
                {
                        $id = (int) $id;

Modified: trunk/property/inc/class.uitts.inc.php
===================================================================
--- trunk/property/inc/class.uitts.inc.php      2015-11-28 10:03:06 UTC (rev 
14499)
+++ trunk/property/inc/class.uitts.inc.php      2015-11-28 16:54:51 UTC (rev 
14500)
@@ -3303,11 +3303,32 @@
                                                                                
                                array('key' => 
'remark','label'=>lang('remark'),'sortable'=>false,'resizeable'=>true)))
                                );
 
-                       $payments = $this->bo->get_payments($id);
+                       $budgets = $this->bo->get_budgets($id);
 
                        $datavalues[4] = array
                                (
                                        'name'                                  
=> "4",
+                                       'values'                                
=> json_encode($budgets),
+                                       'total_records'                 => 
count($budgets),
+                                       'permission'                    => "''",
+                                       'is_paginator'                  => 1,
+                                       'edit_action'                   => "''",
+                                       'footer'                                
=> 0
+                               );
+
+                       $myColumnDefs[5] = array
+                               (
+                                       'name'          => "5",
+                                       'values'        =>      
json_encode(array(      array('key' => 
'period','label'=>lang('period'),'sortable'=>true,'resizeable'=>true),
+                                                                               
                                array('key' => 
'amount','label'=>lang('amount'),'sortable'=>true,'resizeable'=>true, 
'formatter'=> 'FormatterAmount2'),
+                                                                               
                                array('key' => 
'remark','label'=>lang('remark'),'sortable'=>false,'resizeable'=>true)))
+                               );
+
+                       $payments = $this->bo->get_payments($id);
+
+                       $datavalues[5] = array
+                               (
+                                       'name'                                  
=> "5",
                                        'values'                                
=> json_encode($payments),
                                        'total_records'                 => 
count($payments),
                                        'permission'                    => "''",
@@ -3388,7 +3409,7 @@
                        }
 
                        $year   = date('Y') -1;
-                       $limit  = $year + 3;
+                       $limit  = $year + 4;
 
                        while ($year < $limit)
                        {

Modified: trunk/property/setup/setup.inc.php
===================================================================
--- trunk/property/setup/setup.inc.php  2015-11-28 10:03:06 UTC (rev 14499)
+++ trunk/property/setup/setup.inc.php  2015-11-28 16:54:51 UTC (rev 14500)
@@ -12,7 +12,7 @@
        */
 
        $setup_info['property']['name']                 = 'property';
-       $setup_info['property']['version']              = '0.9.17.694';
+       $setup_info['property']['version']              = '0.9.17.695';
        $setup_info['property']['app_order']    = 8;
        $setup_info['property']['enable']               = 1;
        $setup_info['property']['app_group']    = 'office';
@@ -141,6 +141,7 @@
                'fm_tts_history',
                'fm_tts_views',
                'fm_tts_payments',
+               'fm_tts_budget',
                'fm_org_unit',
                'fm_ecoart',
                'fm_ecoavvik',

Modified: trunk/property/setup/tables_current.inc.php
===================================================================
--- trunk/property/setup/tables_current.inc.php 2015-11-28 10:03:06 UTC (rev 
14499)
+++ trunk/property/setup/tables_current.inc.php 2015-11-28 16:54:51 UTC (rev 
14500)
@@ -1119,6 +1119,21 @@
                        'fk' => array('fm_tts_tickets' => array('ticket_id' => 
'id')),
                        'uc' => array()
                ),
+               'fm_tts_budget' => array(
+                       'fd' => array(
+                               'id' => array('type' => 'auto','nullable' => 
False),
+                               'ticket_id' => array('type' => 
'int','precision' => '4','nullable' => False),
+                               'amount' => array('type' => 
'decimal','precision' => '20','scale' => '2','default' => '0','nullable' => 
false),
+                               'period' => array('type' => 'int','precision' 
=> '4','nullable' => false),
+                               'remark' => array('type' => 'text','nullable' 
=> true),
+                               'created_on' => array('type' => 'int', 
'precision' => 4,'nullable' => true),
+                               'created_by' => array('type' => 'int', 
'precision' => 4,'nullable' => true),
+                       ),
+                       'pk' => array('id'),
+                       'ix' => array(),
+                       'fk' => array('fm_tts_tickets' => array('ticket_id' => 
'id')),
+                       'uc' => array()
+               ),
                'fm_org_unit' => array(
                        'fd' => array(
                                'id' => array('type' => 'int','precision' => 
'4','nullable' => False),

Modified: trunk/property/setup/tables_update.inc.php
===================================================================
--- trunk/property/setup/tables_update.inc.php  2015-11-28 10:03:06 UTC (rev 
14499)
+++ trunk/property/setup/tables_update.inc.php  2015-11-28 16:54:51 UTC (rev 
14500)
@@ -8623,4 +8623,67 @@
                        $GLOBALS['setup_info']['property']['currentver'] = 
'0.9.17.694';
                        return $GLOBALS['setup_info']['property']['currentver'];
                }
-       }
\ No newline at end of file
+       }
+
+       /**
+       * Update property version from 0.9.17.694 to 0.9.17.695
+       * differentiate budget.
+       */
+       $test[] = '0.9.17.694';
+       function property_upgrade0_9_17_694()
+       {
+               $GLOBALS['phpgw_setup']->oProc->m_odb->transaction_begin();
+
+               $GLOBALS['phpgw_setup']->oProc->CreateTable(
+                       'fm_tts_budget', array(
+                               'fd' => array(
+                                       'id' => array('type' => 
'auto','nullable' => False),
+                                       'ticket_id' => array('type' => 
'int','precision' => '4','nullable' => False),
+                                       'amount' => array('type' => 
'decimal','precision' => '20','scale' => '2','default' => '0','nullable' => 
false),
+                                       'period' => array('type' => 
'int','precision' => '4','nullable' => false),
+                                       'remark' => array('type' => 
'text','nullable' => true),
+                                       'created_on' => array('type' => 'int', 
'precision' => 4,'nullable' => true),
+                                       'created_by' => array('type' => 'int', 
'precision' => 4,'nullable' => true),
+                               ),
+                               'pk' => array('id'),
+                               'ix' => array(),
+                               'fk' => array('fm_tts_tickets' => 
array('ticket_id' => 'id')),
+                               'uc' => array()
+                       )
+               );
+
+               $GLOBALS['phpgw_setup']->oProc->query("SELECT id, budget, 
entry_date FROM fm_tts_tickets WHERE budget != 0  ORDER BY entry_date");
+
+               $tickets = array();
+               while ($GLOBALS['phpgw_setup']->oProc->next_record())
+               {
+                       $tickets[] = array
+                       (
+                               'id'                            => 
$GLOBALS['phpgw_setup']->oProc->f('id'),
+                               'budget'                => 
$GLOBALS['phpgw_setup']->oProc->f('budget'),
+                               'entry_date'            => 
$GLOBALS['phpgw_setup']->oProc->f('entry_date')
+                       );
+               }
+
+               foreach($tickets as $ticket)
+               {
+                       $period = date('Ym', $ticket['entry_date']);
+                       $value_set = array
+                       (
+                               'ticket_id'     => $ticket['id'],
+                               'amount'        => $ticket['budget'],
+                               'period'        => $period,
+                               'created_on'=> $ticket['entry_date']
+                       );
+                       $cols = implode(',', array_keys($value_set));
+                       $values = 
$GLOBALS['phpgw_setup']->oProc->validate_insert(array_values($value_set));
+                       $sql = "INSERT INTO fm_tts_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.695';
+                       return $GLOBALS['setup_info']['property']['currentver'];
+               }
+       }

Modified: trunk/property/templates/base/tts.xsl
===================================================================
--- trunk/property/templates/base/tts.xsl       2015-11-28 10:03:06 UTC (rev 
14499)
+++ trunk/property/templates/base/tts.xsl       2015-11-28 16:54:51 UTC (rev 
14500)
@@ -934,15 +934,47 @@
                                                                                
                </td>
                                                                                
        </tr>
                                                                                
        <tr>
+                                                                               
                <td>&nbsp;<br/>&nbsp;<br/></td>
+                                                                               
        </tr>
+                                                                               
        <tr>
                                                                                
                <td valign="top">
                                                                                
                        <label>
                                                                                
                                <xsl:value-of select="php:function('lang', 
'cost estimate')"/>
                                                                                
                        </label>
                                                                                
                </td>
-                                                                               
                <td><input type="text" name="values[budget]" 
value="{value_budget}"><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>
+                                                                               
                        <input type="text" name="values[budget]">
+                                                                               
                                <xsl:attribute name="title">
+                                                                               
                                        <xsl:value-of 
select="php:function('lang', 'Enter actual cost')"/>
+                                                                               
                                </xsl:attribute>
+                                                                               
                        </input>
+                                                                               
                        <xsl:text> </xsl:text> [ <xsl:value-of 
select="currency"/> ]
+                                                                               
                        <xsl:variable name="lang_period"><xsl:value-of 
select="php:function('lang', 'period')"/></xsl:variable>
+
+                                                                               
                        <select name="values[budget_period]">
+                                                                               
                                <xsl:attribute name="title">
+                                                                               
                                        <xsl:value-of select='$lang_period'/>
+                                                                               
                                </xsl:attribute>
+                                                                               
                                <xsl:apply-templates 
select="year_list/options"/>
+                                                                               
                        </select>
+                                                                               
                        <xsl:text> </xsl:text> [ <xsl:value-of 
select='$lang_period'/> ]
                                                                                
                </td>
                                                                                
        </tr>
                                                                                
        <tr>
+                                                                               
                <td valign="center" class="th_text">
+                                                                               
                        <label>
+                                                                               
                                <xsl:value-of select="php:function('lang', 
'budget')"/>
+                                                                               
                        </label>
+                                                                               
                </td>
+                                                                               
                <td>
+                                                                               
                        <div id="paging_4"> </div>
+                                                                               
                        <div id="datatable-container_4"/>
+                                                                               
                </td>
+                                                                               
        </tr>
+                                                                               
        <tr>
+                                                                               
                <td>&nbsp;<br/>&nbsp;<br/></td>
+                                                                               
        </tr>
+                                                                               
        <tr>
                                                                                
                <td valign="top">
                                                                                
                        <label>
                                                                                
                                <xsl:value-of select="php:function('lang', 
'payment')"/>
@@ -968,14 +1000,14 @@
                                                                                
                </td>
                                                                                
        </tr>
                                                                                
        <tr>
-                                                                               
                <td valign="top" class="th_text">
+                                                                               
                <td valign="center" class="th_text">
                                                                                
                        <label>
                                                                                
                                <xsl:value-of select="php:function('lang', 
'actual cost')"/>
                                                                                
                        </label>
                                                                                
                </td>
                                                                                
                <td>
-                                                                               
                        <div id="paging_4"> </div>
-                                                                               
                        <div id="datatable-container_4"/>
+                                                                               
                        <div id="paging_5"> </div>
+                                                                               
                        <div id="datatable-container_5"/>
                                                                                
                </td>
                                                                                
        </tr>
                                                                                
        <tr>
@@ -1149,9 +1181,9 @@
                                                                        </label>
                                                                </td>
                                                                <td>
-                                                                       <div 
id="paging_5"> </div>
-                                                                       <div 
id="datatable-container_5"/>
-                                                                       <div 
id="datatable-buttons_5"/>
+                                                                       <div 
id="paging_6"> </div>
+                                                                       <div 
id="datatable-container_6"/>
+                                                                       <div 
id="datatable-buttons_6"/>
                                                                </td>
                                                        </tr>
                                                </table>




reply via email to

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