[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [11770] Added excel format export of lg04 agresso fil
From: |
Erik Holm-Larsen |
Subject: |
[Fmsystem-commits] [11770] Added excel format export of lg04 agresso file |
Date: |
Mon, 03 Mar 2014 06:45:52 +0000 |
Revision: 11770
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11770
Author: erikhl
Date: 2014-03-03 06:45:50 +0000 (Mon, 03 Mar 2014)
Log Message:
-----------
Added excel format export of lg04 agresso file
Modified Paths:
--------------
trunk/rental/inc/class.sobilling.inc.php
trunk/rental/inc/class.uibilling.inc.php
trunk/rental/inc/model/class.agresso_lg04.inc.php
trunk/rental/setup/phpgw_no.lang
trunk/rental/templates/base/billing.php
Modified: trunk/rental/inc/class.sobilling.inc.php
===================================================================
--- trunk/rental/inc/class.sobilling.inc.php 2014-02-28 20:46:58 UTC (rev
11769)
+++ trunk/rental/inc/class.sobilling.inc.php 2014-03-03 06:45:50 UTC (rev
11770)
@@ -332,8 +332,9 @@
*
* @param $billing_job
*/
- public function generate_export(&$billing_job)
+ public function generate_export(&$billing_job, $excel_export=false)
{
+ set_time_limit(500);
$exportable = null;
switch($billing_job->get_export_format())
{
@@ -349,6 +350,14 @@
}
if($exportable != null)
{
+ if($excel_export)
+ {
+ $export_data = $exportable->get_contents_excel();
+ //_debug_array($export_data[1]);
+ return $export_data;
+ }
+ else
+ {
//$sql = "UPDATE rental_billing SET export_data =
{$this->marshal(iconv("ISO-8859-1","UTF-8",$exportable->get_contents()),'string')}
WHERE id = {$this->marshal($billing_job->get_id(),'int')}";
//$result = $this->db->query($sql, __LINE__, __FILE__);
@@ -392,6 +401,7 @@
return true;
}
}
+ }
}
return false;
}
Modified: trunk/rental/inc/class.uibilling.inc.php
===================================================================
--- trunk/rental/inc/class.uibilling.inc.php 2014-02-28 20:46:58 UTC (rev
11769)
+++ trunk/rental/inc/class.uibilling.inc.php 2014-03-03 06:45:50 UTC (rev
11770)
@@ -615,8 +615,11 @@
$stop = phpgw::get_var('date');
$cs15 = phpgw::get_var('generate_cs15');
+ $toExcel = phpgw::get_var('toExcel');
if($cs15 == null){
- $export_format =
explode('_',phpgw::get_var('export_format'));
+ if($toExcel == null)
+ {
+ $export_format =
explode('_',phpgw::get_var('export_format'));
$file_ending = $export_format[1];
if($file_ending == 'gl07')
{
@@ -646,6 +649,82 @@
);
//print
rental_sobilling::get_instance()->get_export_data((int)phpgw::get_var('id'));
+ }
+ else
+ {
+ $billing_job =
rental_sobilling::get_instance()->get_single((int)phpgw::get_var('id'));
+ $billing_info_array =
rental_sobilling_info::get_instance()->get(null, null, null, null, null, null,
array('billing_id' => phpgw::get_var('id')));
+
+ if($billing_job == null) // Not found
+ {
+ $errorMsgs[] = lang('Could not find specified
billing job.');
+ }
+ else
+ {
+ //Loop through billing info array to find the
first month
+ $month = 12;
+ foreach($billing_info_array as $billing_info)
+ {
+ $year = $billing_info->get_year();
+ if($month > $billing_info->get_month())
+ {
+ $month =
$billing_info->get_month();
+ }
+ }
+
+ $billing_job->set_year($year);
+ $billing_job->set_month($month);
+
+ $list =
rental_sobilling::get_instance()->generate_export($billing_job, true);
+ //_debug_array($list[0]);
+ /*foreach ($list as $l)
+ {
+ _debug_array($l);
+ }*/
+
+ if(isset($list))
+ {
+ $infoMsgs[] = lang('Export generated.');
+
+ $keys = array();
+
+ if(count($list[0]) > 0) {
+ foreach($list[0] as $key => $value) {
+ if(!is_array($value)) {
+ array_push($keys, $key);
+ }
+ }
+ }
+
+ // Remove newlines from output
+// $count = count($list);
+// for($i = 0; $i < $count; $i++)
+// {
+// foreach ($list[$i] as $key => &$data)
+// {
+// $data =
str_replace(array("\n","\r\n", "<br>"),'',$data);
+// }
+// }
+
+ // Use keys as headings
+ $headings = array();
+ $count_keys = count($keys);
+ for($j=0;$j<$count_keys;$j++)
+ {
+ array_push($headings, lang($keys[$j]));
+ }
+
+// _debug_array($list);
+
+ $property_common =
CreateObject('property.bocommon');
+ $property_common->download($list, $keys,
$headings);
+ }
+ else
+ {
+ $errorMsgs = lang('Export failed.');
+ }
+ }
+ }
}
else{
$file_ending = 'cs15';
Modified: trunk/rental/inc/model/class.agresso_lg04.inc.php
===================================================================
--- trunk/rental/inc/model/class.agresso_lg04.inc.php 2014-02-28 20:46:58 UTC
(rev 11769)
+++ trunk/rental/inc/model/class.agresso_lg04.inc.php 2014-03-03 06:45:50 UTC
(rev 11770)
@@ -44,6 +44,15 @@
}
return $contents;
}
+
+ public function get_contents_excel()
+ {
+ if($this->orders == null) // Data hasn't been created yet
+ {
+ $this->run_excel_export();
+ }
+ return $this->orders;
+ }
public function get_missing_billing_info($contract)
{
@@ -169,6 +178,71 @@
$so_invoice->store($invoice);
}
}
+
+ protected function run_excel_export()
+ {
+ $this->orders = array();
+ $decimal_separator =
isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['decimal_separator'])
? $GLOBALS['phpgw_info']['user']['preferences']['rental']['decimal_separator']
: ',';
+ $thousands_separator =
isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['thousands_separator'])
?
$GLOBALS['phpgw_info']['user']['preferences']['rental']['thousands_separator']
: '.';
+ // We need all invoices for this billing
+ $invoices = rental_soinvoice::get_instance()->get(null, null,
'id', true, null, null, array('billing_id' => $this->billing_job->get_id()));
+
+ foreach($invoices as $invoice) // Runs through all invoices
+ {
+ // We need all price items in the invoice
+ $price_items =
rental_soinvoice_price_item::get_instance()->get(null, null, null, null, null,
null, array('invoice_id' => $invoice->get_id()));
+ $composite_name = '';
+ // We need to get the composites to get a composite
name for the Agresso export
+ $composites =
rental_socomposite::get_instance()->get(null, null, null, null, null, null,
array('contract_id' => $invoice->get_contract_id()));
+ if($composites != null && count($composites) > 0)
+ {
+ $keys = array_keys($composites);
+ $composite_name =
$composites[$keys[0]]->get_name();
+ }
+ // HACK to get the needed location code for the building
+ $building_location_code =
rental_socomposite::get_instance()->get_building_location_code($invoice->get_contract_id());
+
+ $price_item_data = array();
+ $price_item_counter = 0;
+ foreach($price_items as $price_item) // Runs through
all items
+ {
+ $data = array();
+ $data['amount'] =
$price_item->get_total_price();
+ $description = $price_item->get_title();
+ $start = $price_item->get_timestamp_start();
+ $stop = $price_item->get_timestamp_end();
+ if(isset($start) && isset($stop))
+ {
+ $description .= '
'.date('j/n',$start).'-'.date('j/n',$stop);
+ }
+ $data['article_description'] = $description;
+ $data['article_code'] =
$price_item->get_agresso_id();
+ $price_item_data[] = $data;
+
+ $serialized_party = $invoice->get_party()->serialize();
+ $party_name = $serialized_party['name'];
+
+ $this->orders[] = $this->get_order_excel(
+ $invoice->get_header(),
+ $invoice->get_party()->get_identifier(),
+ $party_name,
+ $invoice->get_id(),
+ $this->billing_job->get_year(),
+ $this->billing_job->get_month(),
+ $invoice->get_account_out(),
+ $data,
+ $invoice->get_responsibility_id(),
+ $invoice->get_service_id(),
+ $building_location_code,
+ $invoice->get_project_id(),
+ $composite_name,
+ $invoice->get_reference(),
+ $price_item_counter
+ );
+ $price_item_counter++;
+ }
+ }
+ }
/**
* Builds one single order of the Agresso file.
@@ -352,6 +426,49 @@
}
return str_replace(array("\n", "\r"), '', $order);
}
+
+ /**
+ * Builds one single order of the excel file.
+ *
+ */
+ protected function get_order_excel($header, $party_id, $party_name,
$order_id, $bill_year, $bill_month, $account, $product_item, $responsibility,
$service, $building, $project, $text, $client_ref, $counter)
+ {
+
+ //$order_id = $order_id + 39500000;
+ // XXX: Which charsets do Agresso accept/expect? Do we need to
something regarding padding and UTF-8?
+ //$order = array();
+
+ $item_counter = $counter;
+ $order = array(
+ 'account' => $account,
+ 'client_ref' => $client_ref,
+ 'header' => utf8_decode($header),
+ 'bill_year' => $bill_year,
+ 'bill_month' => $bill_month,
+ 'Ansvar' => 'BKBPE',
+ 'Ansvar2' => 'BKBPE',
+ 'Party' => $party_id,
+ 'name' => $party_name,
+ 'amount' =>
$this->get_formatted_amount_excel($product_item['amount']),
+// 'amount' =>
$this->get_formatted_amount($product_items[0]['amount']),
+ 'article description' =>
utf8_decode($product_item['article_description']),
+ 'article_code' => $product_item['article_code'],
+ 'batch_id' => "BKBPE{$this->date_str}",
+ 'client' => 'BY',
+ 'responsibility' => $responsibility,
+ 'service' => $service,
+ 'project' => $project,
+ 'counter' => ++$item_counter,
+ 'bill_year' => $bill_year,
+ 'bill_month' => $bill_month,
+ 'batch_id' => "BKBPE{$this->date_str}",
+ 'client' => 'BY',
+ 'item_counter' => $item_counter,
+ 'text' => utf8_decode($text)
+ );
+
+ return str_replace(array("\n", "\r"), '', $order);
+ }
protected function get_formatted_amount($amount)
{
@@ -362,6 +479,20 @@
}
return sprintf("%017.17s", $amount);
}
+
+ protected function get_formatted_amount_excel($amount)
+ {
+// var_dump($amount);
+
+// var_dump($belop);
+ $amount = round($amount, 2) * 100;
+ $belop = substr($amount, 0, strlen($amount)-2) . '.' .
substr($amount, -2);
+ if($amount < 0) // Negative number
+ {
+ return '-' . sprintf("%016.16s", abs($belop)); // We
have to have the sign at the start of the string
+ }
+ return sprintf("%017.17s", $belop);
+ }
}
Modified: trunk/rental/setup/phpgw_no.lang
===================================================================
--- trunk/rental/setup/phpgw_no.lang 2014-02-28 20:46:58 UTC (rev 11769)
+++ trunk/rental/setup/phpgw_no.lang 2014-03-03 06:45:50 UTC (rev 11770)
@@ -591,4 +591,5 @@
working_on rental no Kontrakter under arbeid
year rental no År
yes rental no Ja
-your_notifications rental no Dine varsler
\ No newline at end of file
+your_notifications rental no Dine varsler
+Download Excel export rental no Last ned eksportfil i Excel-format
\ No newline at end of file
Modified: trunk/rental/templates/base/billing.php
===================================================================
--- trunk/rental/templates/base/billing.php 2014-02-28 20:46:58 UTC (rev
11769)
+++ trunk/rental/templates/base/billing.php 2014-03-03 06:45:50 UTC (rev
11770)
@@ -106,7 +106,8 @@
if($billing_job->has_generated_export())
{
?>
- <a href="<?php echo $download_link ?>"><?php
echo lang('Download export') ?></a>
+ <a href="<?php echo $download_link ?>"><?php
echo lang('Download export') ?></a><br />
+ <a href="<?php echo $download_link . '&toExcel=true'
?>">Last ned eksportfil i Excel-format</a>
<?php
if(!$billing_job->is_commited())
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [11770] Added excel format export of lg04 agresso file,
Erik Holm-Larsen <=