fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [11587] property:improve excel import, budget


From: Sigurd Nes
Subject: [Fmsystem-commits] [11587] property:improve excel import, budget
Date: Wed, 08 Jan 2014 13:36:46 +0000

Revision: 11587
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11587
Author:   sigurdne
Date:     2014-01-08 13:36:42 +0000 (Wed, 08 Jan 2014)
Log Message:
-----------
property:improve excel import, budget

Modified Paths:
--------------
    trunk/property/inc/class.uicondition_survey.inc.php
    trunk/property/inc/class.uiimport.inc.php
    trunk/property/inc/import/import_update_generic.php
    trunk/property/setup/setup.inc.php
    trunk/property/setup/tables_update.inc.php

Modified: trunk/property/inc/class.uicondition_survey.inc.php
===================================================================
--- trunk/property/inc/class.uicondition_survey.inc.php 2014-01-06 14:32:39 UTC 
(rev 11586)
+++ trunk/property/inc/class.uicondition_survey.inc.php 2014-01-08 13:36:42 UTC 
(rev 11587)
@@ -992,7 +992,6 @@
 
 //-----------
 
-                       $data = array();
                        if(!$step )
                        {
                                phpgwapi_cache::session_clear('property', 
'condition_survey_import_file');
@@ -1020,11 +1019,6 @@
                                        }
 
                                        
$objPHPExcel->setActiveSheetIndex((int)$sheet_id);
-                                       $data = 
$objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
-
-       //                              $format = 
$objPHPExcel->getActiveSheet()->getStyle('R13')->getNumberFormat()->getFormatCode();
-       //                              $value = 
$objPHPExcel->getActiveSheet()->getCell('R13')->getCalculatedValue();
-
                                }
                                catch(Exception $e)
                                {
@@ -1039,18 +1033,31 @@
 
                        $survey = $this->bo->read_single( array('id' => $id,  
'view' => $mode == 'view') );
 
+                       $rows = 
$objPHPExcel->getActiveSheet()->getHighestDataRow();
+                       $highestColumm = 
$objPHPExcel->getActiveSheet()->getHighestDataColumn();
+               $highestColumnIndex = 
PHPExcel_Cell::columnIndexFromString($highestColumm);
+
+                       $i = 0;
                        $html_table = '<table border="1">';
-                       if($data && $step == 2)
+                       if($rows > 1 && $step == 2)
                        {
-                               $i = 0;
-                               $html_table .= "<tr><th align = 'center'>". 
lang('start'). "</th><th align='center'>" . implode("</th><th align='center'>", 
array_keys($data[1])) . '</th></tr>';
-                               foreach($data as $row_key => $row)
+
+                               $cols = array();
+                               for ($j=0; $j < $highestColumnIndex; $j++ )
                                {
+                                       $cols[] = $this->getexcelcolumnname($j);
+                               }
+
+                               $html_table .= "<tr><th align = 'center'>". 
lang('start'). "</th><th align='center'>" . implode("</th><th align='center'>", 
$cols) . '</th></tr>';
+                               foreach 
($objPHPExcel->getActiveSheet()->getRowIterator() as $row)
+                               {
                                        if($i>20)
                                        {
                                                break;
                                        }
+                                       $i++;
 
+                                       $row_key = $i;
                                        $_checked = '';
                                        if($start_line == $row_key)
                                        {
@@ -1059,11 +1066,22 @@
 
                                        $_radio = "[{$row_key}]<input 
id=\"start_line\" type =\"radio\" {$_checked} name=\"start_line\" 
value=\"{$row_key}\">";
 
-                                       $html_table .= 
"<tr><td><pre>{$_radio}</pre></td><td>" . implode('</td><td>', 
array_values($row)) . '</td></tr>';
-                                       $i++;
+                                       $cellIterator = $row->getCellIterator();
+                                       
$cellIterator->setIterateOnlyExistingCells(false);
+
+                                       $row_values = array();
+                                       foreach ($cellIterator as $cell)
+                                       {
+                                               if (!is_null($cell))
+                                               {
+                                                       $row_values[] = 
$cell->getCalculatedValue();
+                                               }
+                                       }
+                                       $html_table .= 
"<tr><td><pre>{$_radio}</pre></td><td>" . implode('</td><td>',$row_values) . 
'</td></tr>';
                                }
+                               echo '</table>';
                        }
-                       else if($data && $step == 3)
+                       else if($rows > 1 && $step == 3)
                        {
                                $_options = array
                                (
@@ -1092,18 +1110,21 @@
 
                                phpgw::import_class('phpgwapi.sbox');
 
-                               foreach($data[$start_line] as $_column => 
$_value)
+                               for ($j=0; $j < $highestColumnIndex; $j++ )
                                {
+                                       $_column = 
$this->getexcelcolumnname($j);
+                                       $_value = 
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,$start_line)->getCalculatedValue();
                                        $selected = isset($columns[$_column]) 
&& $columns[$_column] ? $columns[$_column] : '';
 
                                        $_listbox = 
phpgwapi_sbox::getArrayItem("columns[{$_column}]", $selected, $_options, true );
                                        $html_table .= "<tr><td>[{$_column}] 
{$_value}</td><td>{$_listbox}</td><tr>";
                                }
                        }
-                       else if($data && $step == 4)
+                       else if($rows > 1 && $step == 4)
                        {
 
-                               $rows = count($data)+1;
+                               $rows = 
$objPHPExcel->getActiveSheet()->getHighestDataRow();
+                               $rows = $rows ? $rows +1 : 0;
 
                                $import_data = array();
 
@@ -1185,6 +1206,27 @@
 
 
                /**
+                * Get excel column name
+                * @param index : a column index we want to get the value in 
excel column format
+                * @return (string) : excel column format
+                */
+               private function getexcelcolumnname($index)
+               {
+                       //Get the quotient : if the index superior to base 26 
max ?
+                       $quotient = $index / 26;
+                       if ($quotient >= 1)
+                       {
+                               //If yes, get top level column + the current 
column code
+                               return getexcelcolumnname($quotient-1). 
chr(($index % 26)+65);
+                       }
+                       else
+                       {
+                               //If no just return the current column code
+                               return chr(65 + $index);
+                       }
+               }
+
+               /**
                * Gets user candidates to be used as coordinator - called as 
ajax from edit form
                *
                * @param string  $query

Modified: trunk/property/inc/class.uiimport.inc.php
===================================================================
--- trunk/property/inc/class.uiimport.inc.php   2014-01-06 14:32:39 UTC (rev 
11586)
+++ trunk/property/inc/class.uiimport.inc.php   2014-01-08 13:36:42 UTC (rev 
11587)
@@ -613,28 +613,36 @@
                        phpgw::import_class('phpgwapi.phpexcel');
 
                        $objPHPExcel = PHPExcel_IOFactory::load($path);
-                       $data = 
$objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
+                       $objPHPExcel->setActiveSheetIndex(0);
 
                        $result = array();
 
+                       $highestColumm = 
$objPHPExcel->getActiveSheet()->getHighestDataColumn();
+
+               $highestColumnIndex = 
PHPExcel_Cell::columnIndexFromString($highestColumm);
+
+                       $rows = 
$objPHPExcel->getActiveSheet()->getHighestDataRow();
+
                        $start = $skipfirstline ? 2 : 1; // Read the first line 
to get the headers out of the way
 
                        if ($skipfirstline)
                        {
-                               $this->fields = array_values($data[1]);
+                               for ($j=0; $j < $highestColumnIndex; $j++ )
+                               {
+                                       $this->fields[] = 
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,1)->getCalculatedValue();
+                               }
                        }
 
-                       $rows = count($data)+1;
-
-                       for ($row=$start; $row<$rows; $row++ )
+                       $rows = $rows ? $rows +1 : 0;
+                       for ($row=$start; $row < $rows; $row++ )
                        {
                                $_result = array();
-                               $j=0;
-                               foreach($data[$row] as $key => $value)
+
+                               for ($j=0; $j < $highestColumnIndex; $j++ )
                                {
                                        $_result[] = 
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,$row)->getCalculatedValue();
-                                       $j++;
                                }
+
                                $result[] = $_result;
                        }
 

Modified: trunk/property/inc/import/import_update_generic.php
===================================================================
--- trunk/property/inc/import/import_update_generic.php 2014-01-06 14:32:39 UTC 
(rev 11586)
+++ trunk/property/inc/import/import_update_generic.php 2014-01-08 13:36:42 UTC 
(rev 11587)
@@ -345,6 +345,7 @@
                                $this->warnings[] = "ID finnes fra før: 
{$filtermethod}, oppdaterer";
                                $value_set      = 
$this->db->validate_update($value_set);
                                $sql = "UPDATE {$table} SET {$value_set} WHERE 
{$filtermethod}";
+                               $action = 'updated';
                        }
                        else
                        {
@@ -353,6 +354,8 @@
                                $cols = implode(',', array_keys($value_set));
                                $values = 
$this->db->validate_insert(array_values($value_set));
                                $sql = "INSERT INTO {$table} ({$cols}) VALUES 
({$values})";
+
+                               $action = 'inserted';
                        }
 
                        if($this->debug)
@@ -366,11 +369,11 @@
 
                        if($ok)
                        {
-                               $this->messages[] = "Successfully imported 
record: id ({$id})";
+                               $this->messages[] = "Successfully {$action} 
record: " . implode(', ', $primary_key);
                        }
                        else
                        {
-                               $this->errors[] = "Error importing record: id 
({$id})";
+                               $this->errors[] = "Error importing record: " . 
implode(', ', $primary_key);
                        }
                        return $ok;
                }

Modified: trunk/property/setup/setup.inc.php
===================================================================
--- trunk/property/setup/setup.inc.php  2014-01-06 14:32:39 UTC (rev 11586)
+++ trunk/property/setup/setup.inc.php  2014-01-08 13:36:42 UTC (rev 11587)
@@ -12,7 +12,7 @@
        */
 
        $setup_info['property']['name']                 = 'property';
-       $setup_info['property']['version']              = '0.9.17.675';
+       $setup_info['property']['version']              = '0.9.17.676';
        $setup_info['property']['app_order']    = 8;
        $setup_info['property']['enable']               = 1;
        $setup_info['property']['app_group']    = 'office';

Modified: trunk/property/setup/tables_update.inc.php
===================================================================
--- trunk/property/setup/tables_update.inc.php  2014-01-06 14:32:39 UTC (rev 
11586)
+++ trunk/property/setup/tables_update.inc.php  2014-01-08 13:36:42 UTC (rev 
11587)
@@ -7841,3 +7841,23 @@
                }
        }
 
+
+       /**
+       * Update property version from 0.9.17.675 to 0.9.17.676
+       * Add multiplier to condition survey
+       */
+
+       $test[] = '0.9.17.675';
+       function property_upgrade0_9_17_675()
+       {
+               $GLOBALS['phpgw_setup']->oProc->m_odb->transaction_begin();
+
+               $GLOBALS['phpgw_setup']->oProc->query("ALTER TABLE fm_budget 
DROP CONSTRAINT fm_budget_year_key");
+               $GLOBALS['phpgw_setup']->oProc->query("ALTER TABLE fm_budget 
ADD CONSTRAINT fm_budget_year_key UNIQUE(year , b_account_id , district_id , 
revision, ecodimb ,category)");
+
+               if($GLOBALS['phpgw_setup']->oProc->m_odb->transaction_commit())
+               {
+                       $GLOBALS['setup_info']['property']['currentver'] = 
'0.9.17.676';
+                       return $GLOBALS['setup_info']['property']['currentver'];
+               }
+       }




reply via email to

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