fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [11492] add summation and fix checklist acl_location


From: Sigurd Nes
Subject: [Fmsystem-commits] [11492] add summation and fix checklist acl_location
Date: Tue, 26 Nov 2013 19:04:56 +0000

Revision: 11492
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11492
Author:   sigurdne
Date:     2013-11-26 19:04:56 +0000 (Tue, 26 Nov 2013)
Log Message:
-----------
add summation and fix checklist acl_location

Modified Paths:
--------------
    trunk/property/inc/class.bocondition_survey.inc.php
    trunk/property/inc/class.menu.inc.php
    trunk/property/inc/class.socondition_survey.inc.php
    trunk/property/inc/class.uicondition_survey.inc.php

Added Paths:
-----------
    trunk/property/templates/base/condition_survey_summation.xsl

Modified: trunk/property/inc/class.bocondition_survey.inc.php
===================================================================
--- trunk/property/inc/class.bocondition_survey.inc.php 2013-11-26 19:02:08 UTC 
(rev 11491)
+++ trunk/property/inc/class.bocondition_survey.inc.php 2013-11-26 19:04:56 UTC 
(rev 11492)
@@ -311,20 +311,34 @@
 
                public function get_summation($id)
                {
-                       $survey = $this->so->read_single(array('id' => $id));
+                       $surveys = array();
+                       
+                       if($id == -1)
+                       {
+                               $values = $this->so->read(array('allrows' => 
true ));
+                               foreach ($values as $survey)
+                               {
+                                       $surveys[$survey['id']]['multiplier'] = 
$survey['multiplier'];
+                               }
+                       }
+                       else
+                       {
+                               $surveys[$id] = 
$this->so->read_single(array('id' => $id));
+                       }
 
                        $data = $this->so->get_summation($id);
-//$total = 0;
+
+//_debug_array($surveys);
 //_debug_array($data);
                        $values =array();
                        $i=0;
                        foreach ($data as $entry)
                        {
-                               $entry['amount'] = $entry['amount'] * 
$survey['multiplier'];
-                               $i = $entry['building_part'] . '_' . 
$entry['category'];
+                               $entry['amount'] = $entry['amount'] * 
$surveys[$entry['condition_survey_id']]['multiplier'];
+                               $i = 
"{$entry['building_part']}_{$entry['category']}";
                                
-                               $values[$i]['building_part'] = 
$entry['building_part'];
-                               $values[$i]['category'] = $entry['category'];
+                               
$values[$entry['condition_survey_id']][$i]['building_part'] = 
$entry['building_part'];
+                               
$values[$entry['condition_survey_id']][$i]['category'] = $entry['category'];
                                
                                $diff = $entry['year'] - date('Y');
                                if($diff < 0)
@@ -339,25 +353,56 @@
        
                                for ($j = 1; $j < 7 ; $j++ )
                                {
-                                       $values[$i]["period_{$j}"] += 0;
-                                       $values[$i]['sum'] += 0;
+                                       
$values[$entry['condition_survey_id']][$i]["period_{$j}"] += 0;
+                                       
$values[$entry['condition_survey_id']][$i]['sum'] += 0;
                                        if($j == $period)
                                        {
-                                               $values[$i]["period_{$j}"] += 
$entry['amount'];
-                                               $values[$i]['sum'] += 
$entry['amount'];
+                                               
$values[$entry['condition_survey_id']][$i]["period_{$j}"] += $entry['amount'];
+                                               
$values[$entry['condition_survey_id']][$i]['sum'] += $entry['amount'];
                                        }
                                }
                        }
                        unset($entry);
 
-                       $ret    =array();
-                       foreach ($values as $entry)
+                       $ret = array();
+
+                       $_values = array();
+                       foreach ($values as $condition_survey_id => $entry)
                        {
+                               foreach($entry as $type => $_entry)
+                               {
+                                       $_values[$type]['building_part']        
= $_entry['building_part'];
+                                       $_values[$type]['category']             
        = $_entry['category'];
+                                       $_values[$type]['period_1']             
        += $_entry['period_1'];
+                                       $_values[$type]['period_2']             
        += $_entry['period_2'];
+                                       $_values[$type]['period_3']             
        += $_entry['period_3'];
+                                       $_values[$type]['period_4']             
        += $_entry['period_4'];
+                                       $_values[$type]['period_5']             
        += $_entry['period_5'];
+                                       $_values[$type]['period_6']             
        += $_entry['period_6'];
+                                       $_values[$type]['sum']                  
        += $_entry['sum'];
+                               }
+                       }
+                       unset($_entry);
+                       unset($entry);
+
+                       foreach($_values as $entry)
+                       {
                                $ret[] = $entry;
                        }
 
-//_debug_array($total);
-//_debug_array($ret);
+                       foreach ($ret as $key => $row) 
+                       {
+                               $building_part[$key]  = $row['building_part'];
+                               $category[$key] = $row['category'];
+                       }
+
+                       // Sort the data with account_lastname ascending, 
account_firstname ascending
+                       // Add $data as the last parameter, to sort by the 
common key
+                       if($ret)
+                       {
+                               array_multisort($building_part, SORT_ASC, 
$category, SORT_ASC, $ret);
+                       }
+
                        return $ret;
                }
 

Modified: trunk/property/inc/class.menu.inc.php
===================================================================
--- trunk/property/inc/class.menu.inc.php       2013-11-26 19:02:08 UTC (rev 
11491)
+++ trunk/property/inc/class.menu.inc.php       2013-11-26 19:04:56 UTC (rev 
11492)
@@ -833,7 +833,16 @@
                                                        (
                                                                'url'   => 
$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 
'property.uicondition_survey.index')),
                                                                'text'  => 
lang('condition survey'),
-                                                               'image'         
=> array('property', 'condition_survey')
+                                                               'image'         
=> array('property', 'condition_survey'),
+                                                               'children'      
=> array
+                                                               (
+                                                                       
'summation'     => array
+                                                                       (
+                                                                               
'url'   => $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 
'property.uicondition_survey.summation')),
+                                                                               
'text'  => lang('summation'),
+                                                                               
'image'         => array('property', 'invoice')
+                                                                       )
+                                                               )
                                                        ),
                                                        'request'       => array
                                                        (

Modified: trunk/property/inc/class.socondition_survey.inc.php
===================================================================
--- trunk/property/inc/class.socondition_survey.inc.php 2013-11-26 19:02:08 UTC 
(rev 11491)
+++ trunk/property/inc/class.socondition_survey.inc.php 2013-11-26 19:04:56 UTC 
(rev 11492)
@@ -543,13 +543,25 @@
 
                public function get_summation($id)
                {
+                       $id_filter = '';
+
                        $condition_survey_id            = (int)$id;
-                       $sql = "SELECT left(building_part,1) as building_part_,"
+                       
+                       if($condition_survey_id == -1) // all
+                       {
+                               $id_filter =  "condition_survey_id > 0";
+                       }
+                       else
+                       {
+                               $id_filter = "condition_survey_id = 
{$condition_survey_id}";
+                       }
+
+                       $sql = "SELECT condition_survey_id, 
left(building_part,1) as building_part_,"
                        . " sum(amount_investment) as investment 
,sum(amount_operation) as operation,"
                        . " recommended_year as year"
                        ." FROM fm_request {$this->_join} fm_request_status ON 
fm_request.status = fm_request_status.id"
-                       ." WHERE condition_survey_id={$condition_survey_id} AND 
fm_request_status.closed IS NULL"
-                       ." GROUP BY building_part_ , year ORDER BY 
building_part_";
+                       ." WHERE {$id_filter} AND fm_request_status.closed IS 
NULL"
+                       ." GROUP BY condition_survey_id, building_part_ , year 
ORDER BY building_part_";
 
                        $this->_db->query($sql,__LINE__,__FILE__);
 
@@ -560,10 +572,11 @@
                                
                                $values[] = array
                                (
-                                       'building_part'         => 
$this->_db->f('building_part_'),
-                                       'amount_investment'     => 
$this->_db->f('investment'),
-                                       'amount_operation'      => 
$this->_db->f('operation'),
-                                       'year'                          => 
$this->_db->f('year'),
+                                       'condition_survey_id'   => 
$this->_db->f('condition_survey_id'),
+                                       'building_part'                 => 
$this->_db->f('building_part_'),
+                                       'amount_investment'             => 
$this->_db->f('investment'),
+                                       'amount_operation'              => 
$this->_db->f('operation'),
+                                       'year'                                  
=> $this->_db->f('year'),
                                );
                        }
 
@@ -577,20 +590,22 @@
                                {
                                        $return[] = array
                                        (
-                                               'building_part' => 
$entry['building_part'],
-                                               'amount'                => 
$entry['amount_investment'],
-                                               'year'                  => 
$entry['year'],
-                                               'category'              => 
$lang_investment,
+                                               'condition_survey_id'   => 
$entry['condition_survey_id'],
+                                               'building_part'                 
=> $entry['building_part'],
+                                               'amount'                        
        => $entry['amount_investment'],
+                                               'year'                          
        => $entry['year'],
+                                               'category'                      
        => $lang_investment,
                                        );
                                }
                                if ($entry['amount_operation'])
                                {
                                        $return[] = array
                                        (
-                                               'building_part' => 
$entry['building_part'],
-                                               'amount'                => 
$entry['amount_operation'],
-                                               'year'                  => 
$entry['year'],
-                                               'category'              => 
$lang_operation,
+                                               'condition_survey_id'   => 
$entry['condition_survey_id'],
+                                               'building_part'                 
=> $entry['building_part'],
+                                               'amount'                        
        => $entry['amount_operation'],
+                                               'year'                          
        => $entry['year'],
+                                               'category'                      
        => $lang_operation,
                                        );
                                }
                        }

Modified: trunk/property/inc/class.uicondition_survey.inc.php
===================================================================
--- trunk/property/inc/class.uicondition_survey.inc.php 2013-11-26 19:02:08 UTC 
(rev 11491)
+++ trunk/property/inc/class.uicondition_survey.inc.php 2013-11-26 19:04:56 UTC 
(rev 11492)
@@ -53,7 +53,8 @@
                        'get_summation'                         => true,
                        'view_file'                                     => true,
                        'import'                                        => true,
-                       'download'                                      => true
+                       'download'                                      => true,
+                       'summation'                                     => true
                );
 
                public function __construct()
@@ -713,7 +714,7 @@
                                 'ResultSet' => array(
                                        'totalResultsAvailable' => 
$total_records,
                                        'startIndex' => $start,
-                                       'sortKey' => 'type', 
+                                       'sortKey' => 'building_part', 
                                        'sortDir' => "ASC", 
                                        'Result' => $out,
                                        'pageSize' => $num_rows,
@@ -1341,6 +1342,89 @@
                        return 'Deleted';
                }
 
+
+               /**
+               * Prepare data for summation - single survey or all
+               *
+               * @return void
+               */
+
+               public function summation()
+               {
+                       $GLOBALS['phpgw_info']['flags']['menu_selection'] = 
"property::project::condition_survey::summation";
+
+                       if(!$this->acl_read)
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'property.uicondition_survey.index'));
+                       }
+
+                       $params = array
+                       (
+                               'start'         => 0,
+                               'sort'          => 'id',
+                               'dir'           => 'asc',
+                               'cat_id'        => 0,
+                               'allrows'       => true
+                       );
+
+                       $survey_list = $this->bo->read($params);
+                       
+                       $surveys = array();
+                       $surveys[] = array
+                       (
+                               'id' => 0, 
+                               'name' => lang('select'), 
+                       );
+                       $surveys[] = array
+                       (
+                               'id' => -1, 
+                               'name' => lang('all'), 
+                       );
+
+                       foreach($survey_list as $survey)
+                       {
+                               $surveys[] = array
+                               (
+                                       'id'                    => 
$survey['id'], 
+                                       'name'                  => 
$survey['title'], 
+                                       'description'   => $survey['address'], 
+                               );
+                       
+                       }
+
+                       $summation_def = array
+                       (
+                               array('key' => 
'building_part','label'=>lang('building 
part'),'sortable'=>false,'resizeable'=>true),
+                               array('key' => 
'category','label'=>lang('category'),'sortable'=>false,'resizeable'=>true),
+                               array('key' => 'period_1','label'=>lang('year') 
. ':: < 1' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 'period_2','label'=>lang('year') 
. ':: 1 - 5' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 'period_3','label'=>lang('year') 
. ':: 6 - 10' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 'period_4','label'=>lang('year') 
. ':: 11 - 15' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 'period_5','label'=>lang('year') 
. ':: 16 - 20' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 'period_6','label'=>lang('year') 
. ':: 21 +' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 
'sum','label'=>lang('sum'),'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                       );
+
+                       $datatable_def = array();
+                       $datatable_def[] = array
+                       (
+                               'container'             => 
'datatable-container_0',
+                               'requestUrl'    => 
json_encode(self::link(array('menuaction' => 
'property.uicondition_survey.get_summation', 'id' => 
$id,'phpgw_return_as'=>'json'))),
+                               'ColumnDefs'    => $summation_def
+                       );
+
+                       $data = array
+                       (
+                               'datatable_def'                                 
=> $datatable_def,
+                               'surveys'                                       
=> array('options' => $surveys),
+                       );
+
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('property') . '::' . lang('condition survey');
+
+                       
self::render_template_xsl(array('condition_survey_summation'), $data);
+               }
+
+
                /*
                * Overrides with incoming data from POST
                */

Added: trunk/property/templates/base/condition_survey_summation.xsl
===================================================================
--- trunk/property/templates/base/condition_survey_summation.xsl                
                (rev 0)
+++ trunk/property/templates/base/condition_survey_summation.xsl        
2013-11-26 19:04:56 UTC (rev 11492)
@@ -0,0 +1,168 @@
+<!-- $Id: documents_add.xsl 11483 2013-11-24 19:54:40Z sigurdne $ -->
+
+<func:function name="phpgw:conditional">
+       <xsl:param name="test"/>
+       <xsl:param name="true"/>
+       <xsl:param name="false"/>
+
+       <func:result>
+               <xsl:choose>
+                       <xsl:when test="$test">
+                       <xsl:value-of select="$true"/>
+                       </xsl:when>
+                       <xsl:otherwise>
+                               <xsl:value-of select="$false"/>
+                       </xsl:otherwise>
+               </xsl:choose>
+       </func:result>
+</func:function>
+
+<xsl:template match="data" xmlns:formvalidator="http://www.w3.org/TR/html4/"; 
xmlns:php="http://php.net/xsl";>
+               <xsl:call-template name="yui_phpgw_i18n"/>
+
+               <div class="yui-navset" id="survey_edit_tabview">
+               <h1>
+                       <xsl:value-of select="php:function('lang', 
'summation')" />
+               </h1>
+                       <div class="yui-content">
+
+                               <dl class="proplist-col">
+
+                                       <dt>
+                                               <label 
for="category"><xsl:value-of select="php:function('lang', 'category')" 
/></label>
+                                       </dt>
+                                       <dd>
+                                               <select id="survey_id" 
name="survey_id" onChange="update_summation();" >
+                                                       <xsl:apply-templates 
select="surveys/options"/>
+                                               </select>
+                                       </dd>
+
+                               </dl>
+                       </div>
+                       <xsl:call-template name="datasource-definition" />
+                       <dl class="proplist-col">
+                               <dt>
+                                       <label><xsl:value-of 
select="php:function('lang', 'summation')"/></label>
+                               </dt>
+                               <dd>
+                                       <div style="clear:both;" 
id="datatable-container_0"></div>
+                               </dd>
+                       </dl>
+       </div>
+
+
+       <script>
+       function update_summation()
+       {
+               var survey_id = document.getElementById("survey_id").value;
+               var oArgs = 
{menuaction:'property.uicondition_survey.get_summation', id:survey_id};
+               var strURL = phpGWLink('index.php', oArgs, true);
+               YAHOO.portico.updateinlineTableHelper('datatable-container_0', 
strURL);
+       }
+
+
+       addFooterDatatable0 = function(paginator,datatable)
+       {
+               //call YAHOO.portico.getTotalSum(name of column) in property.js
+               tmp_sum1 = 
YAHOO.portico.getTotalSum('period_1',0,paginator,datatable);
+               tmp_sum2 = 
YAHOO.portico.getTotalSum('period_2',0,paginator,datatable);
+               tmp_sum3 = 
YAHOO.portico.getTotalSum('period_3',0,paginator,datatable);
+               tmp_sum4 = 
YAHOO.portico.getTotalSum('period_4',0,paginator,datatable);
+               tmp_sum5 = 
YAHOO.portico.getTotalSum('period_5',0,paginator,datatable);
+               tmp_sum6 = 
YAHOO.portico.getTotalSum('period_6',0,paginator,datatable);
+               tmp_sum7 = 
YAHOO.portico.getTotalSum('sum',0,paginator,datatable);
+
+               if(typeof(tableYUI0)=='undefined')
+               {
+                       tableYUI0 = 
YAHOO.util.Dom.getElementsByClassName("yui-dt-data","tbody")[0].parentNode;
+                       tableYUI0.setAttribute("id","tableYUI0");
+               }
+               else
+               {
+                       tableYUI0.deleteTFoot();
+               }
+
+               //Create ROW
+               newTR = document.createElement('tr');
+
+               YAHOO.portico.td_empty(1);
+               YAHOO.portico.td_sum('Sum');
+               YAHOO.portico.td_sum(tmp_sum1);
+               YAHOO.portico.td_sum(tmp_sum2);
+               YAHOO.portico.td_sum(tmp_sum3);
+               YAHOO.portico.td_sum(tmp_sum4);
+               YAHOO.portico.td_sum(tmp_sum5);
+               YAHOO.portico.td_sum(tmp_sum6);
+               YAHOO.portico.td_sum(tmp_sum7);
+
+               myfoot = tableYUI0.createTFoot();
+               myfoot.setAttribute("id","myfoot");
+               myfoot.appendChild(newTR);
+       }
+
+
+  </script>
+
+
+       </xsl:template>
+
+<xsl:template name="datasource-definition">
+       <script>
+               var columnDefs = [];
+               YAHOO.util.Event.onDOMReady(function(){
+                       <xsl:for-each select="datatable_def">
+                               columnDefs = [
+                                       <xsl:for-each select="ColumnDefs">
+                                       {
+                                               resizeable: true,
+                                               key: "<xsl:value-of 
select="key"/>",
+                                               <xsl:if test="label">
+                                               label: "<xsl:value-of 
select="label"/>",
+                                               </xsl:if>
+                                               sortable: <xsl:value-of 
select="phpgw:conditional(not(sortable = 0), 'true', 'false')"/>,
+                                               <xsl:if test="hidden">
+                                               hidden: true,
+                                               </xsl:if>
+                                               <xsl:if test="formatter">
+                                               formatter: <xsl:value-of 
select="formatter"/>,
+                                               </xsl:if>
+                                               <xsl:if test="editor">
+                                               editor: <xsl:value-of 
select="editor"/>,
+                                           </xsl:if>
+                                               className: "<xsl:value-of 
select="className"/>"
+                                       }<xsl:value-of 
select="phpgw:conditional(not(position() = last()), ',', '')"/>
+                               </xsl:for-each>
+                               ];
+                       
+                       YAHOO.portico.inlineTableHelper("<xsl:value-of 
select="container"/>", <xsl:value-of select="requestUrl"/>, columnDefs);
+               </xsl:for-each>
+
+               var PaginatorName0 = 'paginator_containerdatatable-container_0';
+               var DatatableName0 = 'datatable_containerdatatable-container_0';
+
+               var  myPaginator_0 = YAHOO.portico.Paginator[PaginatorName0];
+               var  myDataTable_0 = YAHOO.portico.DataTable[DatatableName0];
+
+               myDataTable_0.subscribe("renderEvent", function()
+               {
+                       addFooterDatatable0(myPaginator_0,myDataTable_0);
+               });
+
+       });
+  </script>
+
+</xsl:template>
+
+
+<xsl:template match="options">
+       <option value="{id}">
+               <xsl:if test="selected = 'selected' or selected = 1">
+                       <xsl:attribute name="selected" value="selected" />
+               </xsl:if>
+               <xsl:attribute name="title">
+                       <xsl:value-of disable-output-escaping="yes" 
select="description"/>
+               </xsl:attribute>
+               <xsl:value-of disable-output-escaping="yes" select="name"/>
+       </option>
+</xsl:template>
+




reply via email to

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