[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [12017] property: import calculation from spreadsheet
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [12017] property: import calculation from spreadsheet |
Date: |
Sun, 22 Jun 2014 14:53:31 +0000 |
Revision: 12017
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=12017
Author: sigurdne
Date: 2014-06-22 14:53:30 +0000 (Sun, 22 Jun 2014)
Log Message:
-----------
property: import calculation from spreadsheet
Modified Paths:
--------------
trunk/property/inc/class.bowo_hour.inc.php
trunk/property/inc/class.sowo_hour.inc.php
trunk/property/inc/class.uiwo_hour.inc.php
trunk/property/js/yahoo/wo_hour.index.js
trunk/property/setup/phpgw_no.lang
trunk/property/templates/base/wo_hour.xsl
Modified: trunk/property/inc/class.bowo_hour.inc.php
===================================================================
--- trunk/property/inc/class.bowo_hour.inc.php 2014-06-17 15:31:50 UTC (rev
12016)
+++ trunk/property/inc/class.bowo_hour.inc.php 2014-06-22 14:53:30 UTC (rev
12017)
@@ -408,6 +408,51 @@
return $receipt;
}
+ /**
+ *
+ * @param type $data
+ * @param type $workorder_id
+ */
+ function import_calculation($data, $workorder_id)
+ {
+ $GLOBALS['phpgw']->db->transaction_begin();
+ foreach($data as $section => $valueset)
+ {
+ $section_name = $valueset['name'];
+ foreach($valueset['data'] as $entry)
+ {
+ if((int)$entry[4] > 0)
+ {
+ //_debug_array($entry[5]);
+ //_debug_array($entry[4]);
+ $values = array
+ (
+ 'descr'
=> $entry[1],
+ 'unit'
=> 8, // FIXME
+ 'cost'
=> $entry[5],
+ 'quantity'
=> $entry[4],
+ 'billperae'
=> $entry[3],
+ 'ns3420_id'
=> '',
+ 'dim_d'
=> '',
+ 'new_grouping'
=> $section_name,
+ 'building_part_id'
=> '',
+ 'tolerance_id'
=> '',
+ );
+ try
+ {
+
$this->so->add_custom_hour($values,$workorder_id);
+ }
+ catch(Exception $exc)
+ {
+ throw
$exc->getTraceAsString();
+ }
+ }
+ }
+
+ }
+ $GLOBALS['phpgw']->db->transaction_commit();
+ }
+
function get_email($selected, $vendor_id)
{
$email_list = $this->so->get_email($vendor_id);
Modified: trunk/property/inc/class.sowo_hour.inc.php
===================================================================
--- trunk/property/inc/class.sowo_hour.inc.php 2014-06-17 15:31:50 UTC (rev
12016)
+++ trunk/property/inc/class.sowo_hour.inc.php 2014-06-22 14:53:30 UTC (rev
12017)
@@ -471,10 +471,9 @@
if($hour['grouping_id'])
{
- $this->db->query("SELECT grouping_descr ,
max(record) as record FROM fm_wo_hours where grouping_id='"
.$hour['grouping_id'] . "' and workorder_id= '$workorder_id' GROUP by
grouping_descr",__LINE__,__FILE__);
+ $this->db->query("SELECT grouping_descr FROM
fm_wo_hours where grouping_id='" .$hour['grouping_id'] . "' and workorder_id=
'$workorder_id' GROUP by grouping_descr",__LINE__,__FILE__);
$this->db->next_record();
$hour['grouping_descr'] =
$this->db->f('grouping_descr');
-// $hour['record'] = $this->db->f('record')+1;
}
if($hour['new_grouping'])
@@ -490,7 +489,6 @@
$this->db->query("SELECT
max(grouping_id) as grouping_id FROM fm_wo_hours where workorder_id=
'$workorder_id'",__LINE__,__FILE__);
$this->db->next_record();
$hour['grouping_id'] =
$this->db->f('grouping_id')+1;
-// $hour['record'] = 1;
}
$hour['grouping_descr'] = $hour['new_grouping'];
@@ -524,7 +522,7 @@
$values = $this->db->validate_insert($values);
- $this->db->query("insert into fm_wo_hours
(owner,hours_descr,unit,cost,quantity,billperae,ns3420_id,dim_d,"
+ $this->db->query("INSERT INTO fm_wo_hours
(owner,hours_descr,unit,cost,quantity,billperae,ns3420_id,dim_d,"
. "
grouping_id,grouping_descr,record,building_part,tolerance,remark,entry_date,workorder_id,category,cat_per_cent)
"
. "VALUES ( $values )",__LINE__,__FILE__);
Modified: trunk/property/inc/class.uiwo_hour.inc.php
===================================================================
--- trunk/property/inc/class.uiwo_hour.inc.php 2014-06-17 15:31:50 UTC (rev
12016)
+++ trunk/property/inc/class.uiwo_hour.inc.php 2014-06-22 14:53:30 UTC (rev
12017)
@@ -46,18 +46,19 @@
var $public_functions = array
(
- 'index' => true,
- 'tender' => true,
- 'view' => true,
- 'template' => true,
+ 'index' => true,
+ 'tender' => true,
+ 'view' => true,
+ 'template' => true,
'save_template' => true,
- 'prizebook' => true,
- 'add' => true,
- 'edit' => true,
- 'delete' => true,
- 'deviation' => true,
- 'edit_deviation'=> true,
- 'pdf_order' => true
+ 'prizebook' => true,
+ 'add' => true,
+ 'edit' => true,
+ 'delete' => true,
+ 'deviation' => true,
+ 'edit_deviation' => true,
+ 'pdf_order' => true,
+ 'import_calculation'=> true,
);
function property_uiwo_hour()
@@ -753,12 +754,19 @@
'value'
=> lang('Add from template')
),
array
- (
+ (
'type'
=> 'button',
'id'
=> 'btn_add_prizebook',
'tab_index' => 1,
'value'
=> lang('Add from prizebook')
- )
+ ),
+ array
+ (
+ 'type'
=> 'button',
+ 'id'
=> 'btn_import_calculation',
+
'tab_index' => 1,
+ 'value'
=> lang('import calculation')
+ )
),
'hidden_value' => array
(
@@ -971,6 +979,16 @@
$datatable['rowactions']['action_form'][] = array
(
+ 'my_name' =>
'import_calculation',
+ 'action' =>
$GLOBALS['phpgw']->link('/index.php',array
+ (
+ 'menuaction' =>
'property.uiwo_hour.import_calculation',
+ 'workorder_id' => $workorder_id
+ ))
+ );
+
+ $datatable['rowactions']['action_form'][] = array
+ (
'my_name' =>
'add_prizebook',
'action' =>
$GLOBALS['phpgw']->link('/index.php',array
(
@@ -1195,6 +1213,9 @@
// Prepare YUI Library
$GLOBALS['phpgw']->js->validate_file( 'yahoo',
'wo_hour.index', 'property' );
+ $GLOBALS['phpgw']->js->validate_file( 'tinybox2',
'packed', 'phpgwapi' );
+
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/tinybox2/style.css');
+
$this->save_sessiondata();
}
@@ -3478,4 +3499,136 @@
$GLOBALS['phpgw_info']['flags']['app_header'] =
lang('property') . ' - ' . $appname . ': ' . $function_msg;
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('delete' => $data));
}
+
+ function import_calculation()
+ {
+ $GLOBALS['phpgw_info']['flags']['noframework'] = true;
+ $workorder_id = phpgw::get_var('workorder_id');
+ if($_FILES)
+ {
+ $this->_import_calculation($workorder_id);
+ }
+
+ if( $receipt = phpgwapi_cache::session_get('phpgwapi',
'phpgw_messages'))
+ {
+ phpgwapi_cache::session_clear('phpgwapi',
'phpgw_messages');
+ }
+
+ $data = array
+ (
+ 'redirect'
=> $redirect ? $GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'property.uiinvoice.list_sub', 'user_lid' => $user_lid, 'voucher_id' =>
$voucher_id, 'paid' => $paid)) : null,
+ 'msgbox_data' =>
$GLOBALS['phpgw']->common->msgbox($GLOBALS['phpgw']->common->msgbox_data($receipt)),
+ 'form_action' =>
$GLOBALS['phpgw']->link('/index.php',array('menuaction' =>
'property.uiwo_hour.import_calculation')),
+ 'workorder_id' =>
$workorder_id
+ );
+
+ $GLOBALS['phpgw']->xslttpl->add_file('wo_hour');
+ $GLOBALS['phpgw']->xslttpl->set_var('phpgw',
array('import_calculation' => $data));
+ }
+
+ private function _import_calculation($workorder_id)
+ {
+ $error = false;
+
+ $data = array();
+ if(isset($_FILES['file']['tmp_name']) &&
$_FILES['file']['tmp_name'])
+ {
+ $file = array
+ (
+ 'name' => $_FILES['file']['tmp_name'],
+ 'type' => $_FILES['file']['type']
+ );
+ }
+ else
+ {
+ phpgwapi_cache::message_set('Ingen fil er
valgt', 'error');
+ return;
+ }
+
+ switch ($file['type'])
+ {
+ case
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
+ case
'application/vnd.oasis.opendocument.spreadsheet':
+ case 'application/vnd.ms-excel':
+ $data =
$this->getexceldata($file['name']);
+ break;
+ default:
+ phpgwapi_cache::message_set("Not a
valid filetype: {$file['type']}", 'error');
+ $error = true;
+ }
+
+ if($data)
+ {
+ try
+ {
+ //Import
+ $this->bo->import_calculation($data,
$workorder_id);
+
+ }
+ catch (Exception $e)
+ {
+ if($e)
+ {
+
phpgwapi_cache::message_set($e->getMessage(), 'error');
+ $error = true;
+ }
+ }
+ }
+
+ if(!$error)
+ {
+ phpgwapi_cache::message_set(lang('workorder is
updated'), 'message');
+ }
+ }
+
+ protected function getexceldata($path)
+ {
+ phpgw::import_class('phpgwapi.phpexcel');
+
+ $inputFileType = PHPExcel_IOFactory::identify($path);
// Identify the type of file.
+ $objReader =
PHPExcel_IOFactory::createReader($inputFileType); // Create a reader of the
identified file type.
+ $worksheetNames = $objReader->listWorksheetNames($path);
+// _debug_array($worksheetNames);
+
+ $objPHPExcel = PHPExcel_IOFactory::load($path);
+
+ $result = array();
+
+ foreach($worksheetNames as $_index => $sheet_name)
+ {
+ $result[$_index]['name'] = $sheet_name;
+ $objPHPExcel->setActiveSheetIndex($_index);
+
+// $objWorksheet = $objPHPExcel->getActiveSheet();
+// _debug_array($objWorksheet->getTitle());
+
+ $highestColumm =
$objPHPExcel->getActiveSheet()->getHighestDataColumn();
+
+ $highestColumnIndex =
PHPExcel_Cell::columnIndexFromString($highestColumm);
+
+ $rows =
$objPHPExcel->getActiveSheet()->getHighestDataRow();
+
+ $start = 2; // Read the first line to get the
headers out of the way
+
+ for ($j=0; $j < $highestColumnIndex; $j++ )
+ {
+ $this->fields[] =
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,1)->getCalculatedValue();
+ }
+
+ $rows = $rows ? $rows +1 : 0;
+ for ($row=$start; $row < $rows; $row++ )
+ {
+ $_data = array();
+
+ for ($j=0; $j < $highestColumnIndex;
$j++ )
+ {
+ $_data[] =
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,$row)->getCalculatedValue();
+ }
+
+ $result[$_index]['data'][] = $_data;
+ }
+ }
+ return $result;
+ }
+
}
Modified: trunk/property/js/yahoo/wo_hour.index.js
===================================================================
--- trunk/property/js/yahoo/wo_hour.index.js 2014-06-17 15:31:50 UTC (rev
12016)
+++ trunk/property/js/yahoo/wo_hour.index.js 2014-06-22 14:53:30 UTC (rev
12017)
@@ -16,14 +16,16 @@
]
// define buttons
- var
oNormalButton_0,oNormalButton_1,oNormalButton_2,oNormalButton_3,oNormalButton_4,oNormalButton_5;
+ var
oNormalButton_0,oNormalButton_1,oNormalButton_2,oNormalButton_3,oNormalButton_4,oNormalButton_5,oNormalButton_6;
var normalButtons = [
- {order:0, name:'btn_add_prizebook', funct:"onAddPrizebookClick"},
- {order:1, name:'btn_add_template', funct:"onAddTemplate"},
- {order:2, name:'btn_add_custom', funct:"onAddCustom"},
- {order:3, name:'btn_save_template', funct:"onSaveTemplate"},
- {order:4, name:'btn_print_preview', funct:"onPrintPreview"},
- {order:5, name:'btn_view_tender', funct:"onViewTender"}
+
+ {order:0, name:'btn_import_calculation',
funct:"onImportCalculationClick"},
+ {order:1, name:'btn_add_prizebook', funct:"onAddPrizebookClick"},
+ {order:2, name:'btn_add_template', funct:"onAddTemplate"},
+ {order:3, name:'btn_add_custom', funct:"onAddCustom"},
+ {order:4, name:'btn_save_template', funct:"onSaveTemplate"},
+ {order:5, name:'btn_print_preview', funct:"onPrintPreview"},
+ {order:6, name:'btn_view_tender', funct:"onViewTender"}
]
// define Text buttons
@@ -38,6 +40,24 @@
var div_footer, table, tableYUI ;
/****************************************************************************************/
+this.onImportCalculationClick = function()
+{
+ for(i=0;i<values_ds.rights_form.length;i++)
+ {
+ if(values_ds.rights_form[i].my_name ==
'import_calculation')
+ {
+ //NEW is always the last options in arrays
RIGHTS
+ sUrl = values_ds.rights_form[i].action;
+ //Convert all HTML entities to their applicable
characters
+ sUrl=html_entity_decode(sUrl);
+ TINY.box.show({iframe:sUrl,
boxid:'frameless',width:750,height:450,fixed:false,maskid:'darkmask',maskopacity:40,
mask:true, animate:true, close:
true,closejs:function(){parent.location.reload();}});
+ }
+ }
+}
+
+
+
+
this.onAddPrizebookClick = function()
{
for(i=0;i<values_ds.rights_form.length;i++)
@@ -539,9 +559,3 @@
}
});
-
-
-
-
-
-
Modified: trunk/property/setup/phpgw_no.lang
===================================================================
--- trunk/property/setup/phpgw_no.lang 2014-06-17 15:31:50 UTC (rev 12016)
+++ trunk/property/setup/phpgw_no.lang 2014-06-22 14:53:30 UTC (rev 12017)
@@ -894,6 +894,7 @@
if this entity type is to be linked to a location property no
Om denne entitetstypen skal linkes til en lokalisering
if this entity type is to be linked to documents property no
Om denne entitetstypen skal linkes til dokumentasjon
if this entity type is to look up tenants property no Om
denne entiteten skal gjøre oppslag på leietakere
+import calculation property no Importer kalkulasjon
import property no Import
importance property no Viktighet
import detail property no Importer detalj
Modified: trunk/property/templates/base/wo_hour.xsl
===================================================================
--- trunk/property/templates/base/wo_hour.xsl 2014-06-17 15:31:50 UTC (rev
12016)
+++ trunk/property/templates/base/wo_hour.xsl 2014-06-22 14:53:30 UTC (rev
12017)
@@ -28,6 +28,9 @@
<xsl:when test="edit_deviation">
<xsl:apply-templates select="edit_deviation"/>
</xsl:when>
+ <xsl:when test="import_calculation">
+ <xsl:apply-templates
select="import_calculation"/>
+ </xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="list_hour"/>
</xsl:otherwise>
@@ -2690,3 +2693,53 @@
<xsl:value-of disable-output-escaping="yes"
select="name"/>
</option>
</xsl:template>
+
+ <!-- Import calculation -->
+
+ <xsl:template match="import_calculation" xmlns:php="http://php.net/xsl">
+ <h2>
+ <xsl:value-of select="php:function('lang', 'upload file')"/>
+ </h2>
+ <form action="{form_action}" name="import_calculation_form"
id="split_voucher_form" method="post" ENCTYPE="multipart/form-data">
+ <br/>
+ <br/>
+ <input type="hidden" name="workorder_id" id="workorder_id"
value="{workorder_id}"/>
+
+ <table align = "center" valign = "center" width="95%">
+ <xsl:choose>
+ <xsl:when test="msgbox_data != ''">
+ <tr>
+ <td align="left"
colspan="2">
+
<xsl:call-template name="msgbox"/>
+ </td>
+ </tr>
+ </xsl:when>
+ </xsl:choose>
+
+ <tr>
+ <td >
+ <xsl:variable name="lang_submit">
+ <xsl:value-of
select="php:function('lang', 'upload file')"/>
+ </xsl:variable>
+ <input type="submit" name="submit"
value="{$lang_submit}">
+ <xsl:attribute name="title">
+ <xsl:value-of
select="$lang_submit"/>
+ </xsl:attribute>
+ </input>
+ </td>
+ <td>
+ <input type="file" id="file"
name="file" size="40">
+ <xsl:attribute name="title">
+ <xsl:value-of
select="php:function('lang', 'Select file to upload')"/>
+ </xsl:attribute>
+ </input>
+ <!--
+ <xsl:variable
name="lang_template"><xsl:value-of select="php:function('lang', 'template')"
/></xsl:variable>
+ <input type="button" id =
"get_template" name="get_template" value="{$lang_template}" title =
"{$lang_template}" />
+ -->
+ </td>
+ </tr>
+ </table>
+ </form>
+
+</xsl:template>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [12017] property: import calculation from spreadsheet,
Sigurd Nes <=