[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [11855] property: autosplit of vouchers based on down
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [11855] property: autosplit of vouchers based on downloaded templates |
Date: |
Sun, 23 Mar 2014 20:04:56 +0000 |
Revision: 11855
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11855
Author: sigurdne
Date: 2014-03-23 20:04:55 +0000 (Sun, 23 Mar 2014)
Log Message:
-----------
property: autosplit of vouchers based on downloaded templates
Modified Paths:
--------------
trunk/property/inc/class.boinvoice.inc.php
trunk/property/inc/class.soinvoice.inc.php
trunk/property/inc/class.uiinvoice2.inc.php
trunk/property/js/portico/ajax_invoice.js
trunk/property/templates/base/invoice2.xsl
Modified: trunk/property/inc/class.boinvoice.inc.php
===================================================================
--- trunk/property/inc/class.boinvoice.inc.php 2014-03-22 15:25:05 UTC (rev
11854)
+++ trunk/property/inc/class.boinvoice.inc.php 2014-03-23 20:04:55 UTC (rev
11855)
@@ -991,4 +991,27 @@
{
return $this->so->check_valid_b_account($b_account_id);
}
+
+ /**
+ *
+ * @param array $data
+ * @param integer $voucher_id
+ * @return integer $line_id
+ */
+ function perform_bulk_split($data, $voucher_id)
+ {
+ $line_id = 0;
+ try
+ {
+ $line_id = $this->so->perform_bulk_split($data,
$voucher_id);
+ }
+ catch (Exception $e)
+ {
+ if($e)
+ {
+ throw $e;
+ }
+ }
+ return $line_id;
+ }
}
Modified: trunk/property/inc/class.soinvoice.inc.php
===================================================================
--- trunk/property/inc/class.soinvoice.inc.php 2014-03-22 15:25:05 UTC (rev
11854)
+++ trunk/property/inc/class.soinvoice.inc.php 2014-03-23 20:04:55 UTC (rev
11855)
@@ -1587,6 +1587,10 @@
'periodization' =>
$this->db->f('periodization'),
'periodization_start' =>
$this->db->f('periodization_start'),
'continuous' =>
$this->db->f('continuous'),
+ 'regtid'
=> $this->db->f('regtid'),
+ 'item_type'
=> $this->db->f('item_type'),
+ 'item_id'
=> $this->db->f('item_id'),
+ 'external_voucher_id' =>
$this->db->f('external_voucher_id'),
);
}
@@ -2629,12 +2633,6 @@
phpgwapi_cache::message_set(lang('Project is
closed'), 'error');
return false;
}
- else if (!ctype_digit($order_id))
- {
- $remark = "bestillingsnummeret er på feil
format: {$order_id}";
- phpgwapi_cache::message_set($remark, 'error');
- return false;
- }
else if (!$order_info['order_exist'])
{
$remark = 'bestillingsnummeret ikke gyldig: ' .
$order_id;
@@ -2683,4 +2681,100 @@
$this->db->next_record();
return !!$this->db->f('active');
}
- }
+
+ /**
+ *
+ * @param array $data
+ * @return boolean true on ok, false on error
+ */
+ function perform_bulk_split($data, $voucher_id)
+ {
+ if(!is_array($data))
+ {
+ throw new
Exception('soinvoice::perform_bulk_split() - Not a valid input');
+ }
+ $voucher_id = (int) $voucher_id;
+ $voucher = $this->read_single_voucher($voucher_id);
+ $voucher_line = $voucher[0];
+
+ $amount = 0;
+ foreach($voucher as $entry)
+ {
+ $amount += $entry['amount'];
+ }
+ unset($entry);
+
+ $split_amount = 0;
+ foreach($data as $entry)
+ {
+ $split_amount += (float)$entry[2];
+ if(!$entry[0] || !$entry[0] || !$entry[0])
+ {
+ throw new
Exception('soinvoice::perform_bulk_split() - incomplete dataset in input');
+ }
+ }
+
+ if($split_amount != $amount)
+ {
+ throw new
Exception('soinvoice::perform_bulk_split() - amount does not add up');
+ }
+
+ $this->db->transaction_begin();
+
+ $this->db->query("DELETE FROM fm_ecobilag WHERE
bilagsnr='{$voucher_id}'", __LINE__, __FILE__);
+
+ $_last_line_id = 0;
+
+ foreach($data as $entry)
+ {
+ $value_set = array
+ (
+ 'bilagsnr'
=> $voucher_line['voucher_id'],
+ 'bilagsnr_ut' =>
$voucher_line['voucher_out_id'],
+ 'typeid'
=> $voucher_line['type'],
+ 'kildeid'
=> 1,
+ 'belop'
=> $entry[2],
+ 'fakturadato' =>
$voucher_line['invoice_date'],
+ 'merknad'
=> $voucher_line['merknad'],
+ 'periode'
=> $voucher_line['period'],
+ 'forfallsdato' =>
$voucher_line['payment_date'],
+ 'fakturanr'
=> $voucher_line['invoice_id'],
+ 'regtid'
=> $voucher_line['regtid'],
+ 'artid'
=> $voucher_line['art'],
+ 'godkjentbelop' =>
$entry[2],
+ 'budsjettansvarligid' =>
$voucher_line['budget_responsible'],
+ 'splitt'
=> $_last_line_id,
+ 'kreditnota' =>
$voucher_line['parked'],
+ 'item_type'
=> $voucher_line['item_type'],
+ 'item_id'
=> $voucher_line['item_id'],
+ 'spvend_code' =>
$voucher_line['vendor_id'],
+ 'external_ref' =>
$voucher_line['external_ref'],
+ 'external_voucher_id' =>
$voucher_line['external_voucher_id'],
+ 'currency'
=> $voucher_line['currency'],
+ 'process_log' =>
$voucher_line['process_log'],
+ 'process_code' =>
$voucher_line['process_code'],
+ 'periodization' =>
$voucher_line['periodization'],
+ 'periodization_start' =>
$voucher_line['periodization_start'],
+ 'line_text'
=> $voucher_line['line_text'],
+ 'external_voucher_id' =>
$voucher_line['external_voucher_id'],
+ 'spbudact_code' =>
$voucher_line['b_account_id'],
+ 'kostra_id'
=> $voucher_line['kostra_id'],
+ 'mvakode'
=> $voucher_line['tax_code'],
+ );
+ $cols = implode(',', array_keys($value_set));
+ $values =
$this->db->validate_insert(array_values($value_set));
+
+ $this->db->query("INSERT INTO fm_ecobilag
({$cols}) VALUES ({$values})", __LINE__, __FILE__);
+ $_last_line_id =
$this->db->get_last_insert_id('fm_ecobilag', 'id');
+
+ if(!$this->reassign_order($_last_line_id,
$entry[1]))
+ {
+ $this->db->transaction_abort();
+ throw new
Exception("soinvoice::perform_bulk_split() - assigning order {$entry[1]}
failed");
+ }
+ }
+
+ $this->db->transaction_commit();
+ return $_last_line_id;
+ }
+ }
\ No newline at end of file
Modified: trunk/property/inc/class.uiinvoice2.inc.php
===================================================================
--- trunk/property/inc/class.uiinvoice2.inc.php 2014-03-22 15:25:05 UTC (rev
11854)
+++ trunk/property/inc/class.uiinvoice2.inc.php 2014-03-23 20:04:55 UTC (rev
11855)
@@ -56,7 +56,8 @@
'get_single_voucher' => true,
'get_single_line'
=> true,
'update_voucher'
=> true,
- 'get_first_line'
=> true
+ 'get_first_line'
=> true,
+ 'get_split_template' => true
);
function __construct()
@@ -163,6 +164,123 @@
}
}
+ function get_split_template()
+ {
+ $voucher_id = phpgw::get_var('voucher_id', 'int');
+ $filename = '0000_split';
+ $data = array();
+
+ if($voucher_id)
+ {
+ $filename = "{$voucher_id}_split";
+ $voucher =
$this->bo->read_invoice_sub($voucher_id);
+ foreach($voucher as $line)
+ {
+ $data[] = array
+ (
+ 'voucher_id' => $voucher_id,
+ 'order_id' =>
$line['order_id'],
+ 'amount' =>
$line['amount'],
+ );
+ }
+ }
+
+ $cols = array
+ (
+ 'voucher_id',
+ 'order_id',
+ 'amount'
+ );
+ $names = array
+ (
+ 'BilagsNr',
+ 'BestillingsNr',
+ 'Beløp'
+ );
+ $bocommon = CreateObject('property.bocommon');
+ $bocommon->download($data, $cols,
$names,array(),$_identificator,$filename);
+ $GLOBALS['phpgw']->common->phpgw_exit();
+
+ }
+
+ function split_voucher($voucher_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 file er
valgt', 'error');
+ }
+
+ 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;
+ case 'text/csv':
+ case 'text/comma-separated-values':
+ $data =
$this->getcsvdata($file['name']);
+ break;
+ default:
+ phpgwapi_cache::message_set("Not a
valid filetype: {$file['type']}", 'error');
+ $error = true;
+ }
+
+ if($data)
+ {
+ if($data[0][0] != $voucher_id)
+ {
+ phpgwapi_cache::message_set("Feil
bilag", 'error');
+ $error = true;
+ }
+ else
+ {
+ try
+ {
+ $line_id =
$this->bo->perform_bulk_split($data, $voucher_id);
+
+ }
+ catch (Exception $e)
+ {
+ if($e)
+ {
+
phpgwapi_cache::message_set($e->getMessage(), 'error');
+ $error = true;
+ }
+ }
+ }
+ }
+
+ if(!$error)
+ {
+ phpgwapi_cache::message_set(lang('voucher is
updated'), 'message');
+ }
+
+ $result = array
+ (
+ 'status' => $error ? 'error' : 'updated',
+ 'line_id' => $line_id
+ );
+
+ if( $receipt = phpgwapi_cache::session_get('phpgwapi',
'phpgw_messages'))
+ {
+ phpgwapi_cache::session_clear('phpgwapi',
'phpgw_messages');
+ $result['receipt'] = $receipt;
+ }
+ return $result;
+ }
+
function update_voucher()
{
$receipt = array();
@@ -172,6 +290,11 @@
if($values = phpgw::get_var('values'))
{
+ if($_FILES)
+ {
+ return
$this->split_voucher($voucher_id);
+ }
+
if($values['order_id'] !=
$values['order_id_orig'])
{
return $this->reassign_order($line_id,
$values['order_id'], $voucher_id);
@@ -829,4 +952,77 @@
return $voucher_info;
}
+
+ protected function getcsvdata($path)
+ {
+ // Open the csv file
+ $handle = fopen($path, "r");
+
+ // Read the first line to get the headers out of the way
+ $this->fields = $this->getcsv($handle);
+
+ $result = array();
+
+ while(($data = $this->getcsv($handle)) !== false)
+ {
+ $result[] = $data;
+ }
+
+ fclose($handle);
+
+ return $result;
+ }
+
+
+ protected function getexceldata($path)
+ {
+ phpgw::import_class('phpgwapi.phpexcel');
+
+ $objPHPExcel = PHPExcel_IOFactory::load($path);
+ $objPHPExcel->setActiveSheetIndex(0);
+
+ $result = array();
+
+ $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++ )
+ {
+ $_result = array();
+
+ for ($j=0; $j < $highestColumnIndex; $j++ )
+ {
+ $_result[] =
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,$row)->getCalculatedValue();
+ }
+
+ $result[] = $_result;
+ }
+
+ return $result;
+ }
+
+
+ /**
+ * Read the next line from the given file handle and parse it
to CSV according to the rules set up
+ * in the class constants DELIMITER and ENCLOSING. Returns
FALSE like getcsv on EOF.
+ *
+ * @param file-handle $handle
+ * @return array of values from the parsed csv line
+ */
+ protected function getcsv($handle)
+ {
+ return fgetcsv($handle, 1000, self::DELIMITER,
self::ENCLOSING);
+ }
+
}
Modified: trunk/property/js/portico/ajax_invoice.js
===================================================================
--- trunk/property/js/portico/ajax_invoice.js 2014-03-22 15:25:05 UTC (rev
11854)
+++ trunk/property/js/portico/ajax_invoice.js 2014-03-23 20:04:55 UTC (rev
11855)
@@ -17,6 +17,12 @@
update_voucher_filter();
});
+ $("#template").click(function(e){
+ var oArgs_template =
{menuaction:'property.uiinvoice2.get_split_template', voucher_id:
$("#voucher_id").val()};
+ var requestUrl_template = phpGWLink('index.php',
oArgs_template);
+ window.open(requestUrl_template);
+ });
+
$("#voucher_id_filter").change(function () {
$("#voucher_id").val( '' );
@@ -155,9 +161,19 @@
var thisForm = $(this);
var submitBnt = $(thisForm).find("input[type='submit']");
var requestUrl = $(thisForm).attr("action");
+
+ var fileInput = document.getElementById('file');
+ var file = fileInput.files[0];
+ var formData = new FormData();
+ formData.append('file', file);
+ document.getElementsByName("file")[0].value = "";
+
$.ajax({
type: 'POST',
url: requestUrl + "&phpgw_return_as=json&" +
$(thisForm).serialize(),
+ data: formData,
+ processData: false,
+ contentType: false,
success: function(data) {
if(data)
{
@@ -168,17 +184,18 @@
}
var obj = data;
-
+ if(typeof(obj.line_id) != 'undefined')
+ {
+ if(obj.line_id > 0 &&
obj.line_id != line_id)
+ {
+ line_id = obj.line_id;
+ }
+ }
+
var submitBnt =
$(thisForm).find("input[type='submit']");
if(obj.status == "updated")
{
$(submitBnt).val("Lagret");
- /*
- var oArgs =
{menuaction:'property.uiinvoice2.get_vouchers'};
- var requestUrl =
phpGWLink('index.php', oArgs, true);
- requestUrl = requestUrl +
"&voucher_id_filter=" + $("#voucher_id").val();
-
execute_async(myDataTable_0,requestUrl);
- */
base_java_url['voucher_id_filter'] = $("#voucher_id").val();
base_java_url['line_id'] =
line_id;
Modified: trunk/property/templates/base/invoice2.xsl
===================================================================
--- trunk/property/templates/base/invoice2.xsl 2014-03-22 15:25:05 UTC (rev
11854)
+++ trunk/property/templates/base/invoice2.xsl 2014-03-23 20:04:55 UTC (rev
11855)
@@ -105,7 +105,7 @@
<xsl:apply-templates
select="filter_form" />
<xsl:apply-templates
select="filter_invoice" />
</table>
- <form action="{update_action}"
name="voucher_form" id="voucher_form" method="post">
+ <form action="{update_action}"
name="voucher_form" id="voucher_form" method="post"
ENCTYPE="multipart/form-data">
<table align = "center"
width="95%">
<tr>
<td
colspan = '6'>
@@ -113,7 +113,27 @@
<xsl:apply-templates select="datatable"/>
</td>
</tr>
-
<xsl:call-template name="voucher_fields" />
+ <tr>
+ <td
valign="top">
+
<xsl:value-of select="php:function('lang', 'upload file')"/>
+ </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 = "template" name="template" value="{$lang_template}"
title = "{$lang_template}" />
+ </td>
+ </tr>
+ <tr>
+ <td
colspan = '6'>
+
<xsl:variable name="label_submit"><xsl:value-of select="php:function('lang',
'save')" /></xsl:variable>
+
<div class="row_on"><input type="submit" name="values[update_voucher]"
id="frm_update_voucher" value="{$label_submit}"/></div>
+ </td>
+ </tr>
+
<xsl:call-template name="voucher_fields" />
<xsl:call-template name="approve"/>
</table>
</form>
@@ -569,8 +589,6 @@
<xsl:call-template name="datasource-definition" />
<div id="receipt"></div>
- <xsl:variable name="label_submit"><xsl:value-of
select="php:function('lang', 'save')" /></xsl:variable>
- <div class="row_on"><input type="submit" name="values[update_voucher]"
id="frm_update_voucher" value="{$label_submit}"/></div>
</xsl:template>
<xsl:template name="datasource-definition" xmlns:php="http://php.net/xsl">
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [11855] property: autosplit of vouchers based on downloaded templates,
Sigurd Nes <=