fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [16140] more on integration


From: sigurdne
Subject: [Fmsystem-commits] [16140] more on integration
Date: Wed, 4 Jan 2017 13:41:49 +0000 (UTC)

Revision: 16140
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=16140
Author:   sigurdne
Date:     2017-01-04 13:41:49 +0000 (Wed, 04 Jan 2017)
Log Message:
-----------
more on integration

Modified Paths:
--------------
    trunk/property/inc/class.uiwo_hour.inc.php
    trunk/property/inc/custom/default/BkBygg_exporter_data_til_Agresso.php
    trunk/property/inc/custom/default/BkBygg_lag_Agresso_ordre_fra_workorder.php

Modified: trunk/property/inc/class.uiwo_hour.inc.php
===================================================================
--- trunk/property/inc/class.uiwo_hour.inc.php  2017-01-04 12:16:21 UTC (rev 
16139)
+++ trunk/property/inc/class.uiwo_hour.inc.php  2017-01-04 13:41:49 UTC (rev 
16140)
@@ -59,6 +59,7 @@
                        'edit_deviation' => true,
                        'pdf_order' => true,
                        'import_calculation' => true,
+                       'send_all_orders'       => true
                );
 
                function __construct()
@@ -3341,12 +3342,76 @@
                        return $result;
                }
 
+
+               function send_all_orders( )
+               {
+                       if(!$this->acl->check('.admin', PHPGW_ACL_ADD, 
'property'))
+                       {
+                               phpgw::no_access();
+                       }
+
+                       $start_from = 45000000;
+                       $sql = "SELECT id FROM fm_workorder WHERE id >= 
$start_from";
+                       $db = & $GLOBALS['phpgw']->db;
+                       $db->query($sql, __LINE__, __FILE__);
+                       $ids = array();
+                       while ($db->next_record())
+                       {
+                               $ids[] = $db->f('id');
+                       }
+
+                       foreach ($ids as $workorder_id)
+                       {
+                               try
+                               {
+                                       $this->send_order( $workorder_id );
+                               }
+                               catch (Exception $e)
+                               {
+                                       
phpgwapi_cache::message_set($e->getMessage(), 'error');
+                               }
+                       }
+               }
+
                function send_order( $workorder_id )
                {
                        $workorder = 
$this->boworkorder->read_single($workorder_id);
                        $show_cost = false;
                        $email_receipt = true;
-                       $pdfcode = $this->pdf_order($workorder_id, $show_cost);
+
+                       try
+                       {
+                               $pdfcode = $this->pdf_order($workorder_id, 
$show_cost);
+                       }
+                       catch (Exception $e)
+                       {
+                               phpgwapi_cache::message_set($e->getMessage(), 
'error');
+                       }
+
+                       $criteria = array
+                       (
+                               'appname' => 'property',
+                               'location' => '.project.workorder.transfer',
+                               'allrows' => true
+                       );
+
+                       $custom_functions = 
$GLOBALS['phpgw']->custom_functions->find($criteria);
+
+                       foreach ($custom_functions as $entry)
+                       {
+                               // prevent path traversal
+                               if (preg_match('/\.\./', $entry['file_name']))
+                               {
+                                       continue;
+                               }
+
+                               $file = PHPGW_SERVER_ROOT . 
"/property/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}";
+                               if ($entry['active'] && is_file($file) && 
!$entry['client_side'] && !$entry['pre_commit'])
+                               {
+                                       require $file;
+                               }
+                       }
+
                        $dir = 
"{$GLOBALS['phpgw_info']['server']['temp_dir']}/pdf_files";
                        $attachments = array();
 

Modified: trunk/property/inc/custom/default/BkBygg_exporter_data_til_Agresso.php
===================================================================
--- trunk/property/inc/custom/default/BkBygg_exporter_data_til_Agresso.php      
2017-01-04 12:16:21 UTC (rev 16139)
+++ trunk/property/inc/custom/default/BkBygg_exporter_data_til_Agresso.php      
2017-01-04 13:41:49 UTC (rev 16140)
@@ -37,434 +37,440 @@
         *
         * @author Sigurd Nes
         */
-       class BkBygg_exporter_data_til_Agresso
+       if (!class_exists("BkBygg_exporter_data_til_Agresso"))
        {
+               class BkBygg_exporter_data_til_Agresso
+               {
 
-               var $dim0; // Art
-               var $dim1; // Ansvar
-               var $dim2; // Tjeneste
-               var $dim3; // Objekt
-               var $dim4; // Kontrakt - frivillig
-               var $dim5; // Prosjekt
-               var $dim6; // Aktivitet - frivillig
-               var $transfer_xml;
-               var $connection;
-               var $order_id;
-               var $voucher_type;
-               var $batchid;
+                       var $dim0; // Art
+                       var $dim1; // Ansvar
+                       var $dim2; // Tjeneste
+                       var $dim3; // Objekt
+                       var $dim4; // Kontrakt - frivillig
+                       var $dim5; // Prosjekt
+                       var $dim6; // Aktivitet - frivillig
+                       var $transfer_xml;
+                       var $connection;
+                       var $order_id;
+                       var $voucher_type;
+                       var $batchid;
 
 
-               public function __construct( $param )
-               {
-                       $this->db = & $GLOBALS['phpgw']->db;
-                       $this->soXport = CreateObject('property.soXport');
-                       $this->config = CreateObject('admin.soconfig', 
$GLOBALS['phpgw']->locations->get_id('property', '.invoice'));
-                       $this->order_id = $param['order_id'];
-                       $this->voucher_type = $param['voucher_type'];
-               }
+                       public function __construct( $param )
+                       {
+                               $this->db = & $GLOBALS['phpgw']->db;
+                               $this->soXport = 
CreateObject('property.soXport');
+                               $this->config = CreateObject('admin.soconfig', 
$GLOBALS['phpgw']->locations->get_id('property', '.invoice'));
+                               $this->order_id = $param['order_id'];
+                               $this->voucher_type = $param['voucher_type'];
+                       }
 
-               public function create_transfer_xml( $param )
-               {
-                       $Orders = array();
-                       /*
-                         UN-kodene i Agresso ligger med prefiks UN- foran 
koden.
-                         Eks: UN-70111601: Plantetjenester
-                        */
+                       public function create_transfer_xml( $param )
+                       {
+                               $Orders = array();
+                               /*
+                                 UN-kodene i Agresso ligger med prefiks UN- 
foran koden.
+                                 Eks: UN-70111601: Plantetjenester
+                                */
 
-                       $Seller = array(
-                               'Name' => $param['vendor_name'],
-                               'AddressInfo' => array(
-                                       array(
-                                               'Address' => 
$param['vendor_address']
-                                       )
-                               ),
-                               'SellerNo' => $param['vendor_id'],
-//                             'SellerReferences' => array(
-//                                     array(
-//                                             'SalesMan' => 12573,
-//                                     )
-//                             )
-                       );
+                               $Seller = array(
+                                       'Name' => $param['vendor_name'],
+                                       'AddressInfo' => array(
+                                               array(
+                                                       'Address' => 
$param['vendor_address']
+                                               )
+                                       ),
+                                       'SellerNo' => $param['vendor_id'],
+       //                              'SellerReferences' => array(
+       //                                      array(
+       //                                              'SalesMan' => 12573,
+       //                                      )
+       //                              )
+                               );
 
 
-                       $DetailInfo = array();
-                       $DetailInfo[] = array(
-                               'TaxCode' => $param['tax_code'] // Moms kode
-                       );
-                       $DetailInfo[] = array(
-                               'ReferenceCode' => array(
-                                       'Code' => 'A0',
-                                       'Value' => $param['dim0'] // Art
-                               )
-                       );
-                       $DetailInfo[] = array(
-                               'ReferenceCode' => array(
-                                       'Code' => 'C1',
-                                       'Value' => sprintf("%06s", 
$param['dim1']) // Ansvar
-                               )
-                       );
-                       $DetailInfo[] = array(
-                               'ReferenceCode' => array(
-                                       'Code' => 'Q0',
-                                       'Value' => $param['dim2'] // Tjeneste
-                               )
-                       );
-                       $DetailInfo[] = array(
-                               'ReferenceCode' => array(
-                                       'Code' => 'F0',
-                                       'Value' => $param['dim3'] // Objekt
-                               )
-                       );
-                       $DetailInfo[] = array(
-                               'ReferenceCode' => array(
-                                       'Code' => 'A7',
-                                       'Value' => $param['dim4'] // Kontrakt
-                               )
-                       );
-                       $DetailInfo[] = array(
-                               'ReferenceCode' => array(
-                                       'Code' => 'B0',
-                                       'Value' => $param['dim5'] ? 
$param['dim5'] : 9 // Prosjekt
-                               )
-                       );
-                       $DetailInfo[] = array(
-                               'ReferenceCode' => array(
-                                       'Code' => 'B1',
-                                       'Value' => $param['dim6'] // Aktivitet
-                               )
-                       );
+                               $DetailInfo = array();
+                               $DetailInfo[] = array(
+                                       'TaxCode' => $param['tax_code'] // Moms 
kode
+                               );
+                               $DetailInfo[] = array(
+                                       'ReferenceCode' => array(
+                                               'Code' => 'A0',
+                                               'Value' => $param['dim0'] // Art
+                                       )
+                               );
+                               $DetailInfo[] = array(
+                                       'ReferenceCode' => array(
+                                               'Code' => 'C1',
+                                               'Value' => sprintf("%06s", 
$param['dim1']) // Ansvar
+                                       )
+                               );
+                               $DetailInfo[] = array(
+                                       'ReferenceCode' => array(
+                                               'Code' => 'Q0',
+                                               'Value' => $param['dim2'] // 
Tjeneste
+                                       )
+                               );
+                               $DetailInfo[] = array(
+                                       'ReferenceCode' => array(
+                                               'Code' => 'F0',
+                                               'Value' => $param['dim3'] // 
Objekt
+                                       )
+                               );
+                               $DetailInfo[] = array(
+                                       'ReferenceCode' => array(
+                                               'Code' => 'A7',
+                                               'Value' => $param['dim4'] // 
Kontrakt
+                                       )
+                               );
+                               $DetailInfo[] = array(
+                                       'ReferenceCode' => array(
+                                               'Code' => 'B0',
+                                               'Value' => $param['dim5'] ? 
$param['dim5'] : 9 // Prosjekt
+                                       )
+                               );
+                               $DetailInfo[] = array(
+                                       'ReferenceCode' => array(
+                                               'Code' => 'B1',
+                                               'Value' => $param['dim6'] // 
Aktivitet
+                                       )
+                               );
 
-                       $DetailInfo[] = array(
-                               'ReferenceCode' => array(
-                                       'Code' => 'A1',
-                                       'Value' => $param['tax_code'] // Moms 
kode
-                               )
-                       );
+                               $DetailInfo[] = array(
+                                       'ReferenceCode' => array(
+                                               'Code' => 'A1',
+                                               'Value' => $param['tax_code'] 
// Moms kode
+                                       )
+                               );
 
-                       $Header = array(
-                               'AcceptFlag' => 1,
-                               'OrderType]' => 'WB',
-                               'Status' => 'N',
-                               'OrderDate' => date('Y-m-d'),
-                               'Currency' => 'NOK',
-                               'Seller' => array($Seller),
-                               'Buyer' => array($param['buyer']),
-                               $DetailInfo
-                       );
-
-                       $Detail = array();
-                       $i = 1;
-                       foreach ($param['lines'] as $line)
-                       {
-
-                               $Detail[] = array(
-                                       'LineNo' => $i,
+                               $Header = array(
+                                       'AcceptFlag' => 1,
+                                       'OrderType]' => 'WB',
                                        'Status' => 'N',
-                                       'BuyerProductCode' => 
$line['unspsc_code'], //74000176, //UN-kode
-                                       'BuyerProductDescr' => $line['descr'], 
//'Kopipapir',
-                                       'UnitCode' => 'STK',
-                                       'Quantity' => 1,
-                                       'Price' => 
number_format($line['price'], 2, '.', ''),
-                                       'LineTotal'=> 
number_format($line['price'], 2, '.', ''),
-                                       'DetailInfo' => $DetailInfo
+                                       'OrderDate' => date('Y-m-d'),
+                                       'Currency' => 'NOK',
+                                       'Seller' => array($Seller),
+                                       'Buyer' => array($param['buyer']),
+                                       $DetailInfo
                                );
 
-                               $i++;
-                       }
+                               $Detail = array();
+                               $i = 1;
+                               foreach ($param['lines'] as $line)
+                               {
 
+                                       $Detail[] = array(
+                                               'LineNo' => $i,
+                                               'Status' => 'N',
+                                               'BuyerProductCode' => 
$line['unspsc_code'], //74000176, //UN-kode
+                                               'BuyerProductDescr' => 
$line['descr'], //'Kopipapir',
+                                               'UnitCode' => 'STK',
+                                               'Quantity' => 1,
+                                               'Price' => 
number_format($line['price'], 2, '.', ''),
+                                               'LineTotal'=> 
number_format($line['price'], 2, '.', ''),
+                                               'DetailInfo' => $DetailInfo
+                                       );
 
-                       $Orders['Order'][] = array(
-                               'OrderNo' => $param['order_id'],
-                               'VoucherType' => $this->voucher_type,
-                               'TransType' => 41,
-                               'Header' => array($Header),
-                               'Details' => array('Detail' => $Detail)
-                       );
+                                       $i++;
+                               }
 
-//                     _debug_array($Orders);
-//                     die();
 
-                       $root_attributes = array(
-                               'Version' => "542",
-                               'xmlns:xsi' => 
"http://www.w3.org/2001/XMLSchema-instance";,
-                               'xsi:noNamespaceSchemaLocation' => 
"http://services.agresso.com/schema/ABWOrder/2004/07/02/ABWOrder.xsd";
-                       );
-                       $xml_creator = new xml_creator('ABWOrder', 
$root_attributes);
-                       $xml_creator->fromArray($Orders);
-                       $this->transfer_xml = $xml_creator->getDocument();
-                       return $this->transfer_xml;
-       //              $xml_creator->output();
-       //              die();
-               }
+                               $Orders['Order'][] = array(
+                                       'OrderNo' => $param['order_id'],
+                                       'VoucherType' => $this->voucher_type,
+                                       'TransType' => 41,
+                                       'Header' => array($Header),
+                                       'Details' => array('Detail' => $Detail)
+                               );
 
-               /**
-                * Output the content of a current xml document.
-                * @access public
-                * @param null
-                */
-               public function output()
-               {
-                       header('Content-type: text/xml');
-                       echo $this->transfer_xml;
-               }
+       //                      _debug_array($Orders);
+       //                      die();
 
-
-               protected function create_file_name( $ref = '' )
-               {
-                       if (!$ref)
-                       {
-                               throw new 
Exception('BkBygg_exporter_data_til_Agresso::create_file_name() Mangler 
referanse');
+                               $root_attributes = array(
+                                       'Version' => "542",
+                                       'xmlns:xsi' => 
"http://www.w3.org/2001/XMLSchema-instance";,
+                                       'xsi:noNamespaceSchemaLocation' => 
"http://services.agresso.com/schema/ABWOrder/2004/07/02/ABWOrder.xsd";
+                               );
+                               $xml_creator = new xml_creator('ABWOrder', 
$root_attributes);
+                               $xml_creator->fromArray($Orders);
+                               $this->transfer_xml = 
$xml_creator->getDocument();
+                               return $this->transfer_xml;
+               //              $xml_creator->output();
+               //              die();
                        }
-                       $voucher_type = $this->voucher_type;
-                       if (!$voucher_type)
-                       {
-                               throw new 
Exception('BkBygg_exporter_data_til_Agresso::create_file_name() Mangler 
bilagstype');
-                       }
-                       $fil_katalog = 
$this->config->config_data['export']['path'];
 
-                       $filename = 
"{$fil_katalog}/{$voucher_type}_ordre_{$ref}.xml";
-
-                       //Sjekk om filen eksisterer
-                       if (file_exists($filename))
+                       /**
+                        * Output the content of a current xml document.
+                        * @access public
+                        * @param null
+                        */
+                       public function output()
                        {
-                               unlink($filename);
+                               header('Content-type: text/xml');
+                               echo $this->transfer_xml;
                        }
 
-                       return $filename;
-               }
 
-               public function transfer( )
-               {
-                       $batchid = $this->soXport->increment_batchid();
-                       $this->batchid = $batchid;
-                       $filename = $this->create_file_name($this->order_id);
-                       $content = $this->transfer_xml;
-                       $debug = 
empty($this->config->config_data['export']['activate_transfer']) ? true : false;
-
-                       if(!empty($this->config->config_data['export']['path']) 
&& is_dir($this->config->config_data['export']['path'])) // keep a copy
+                       protected function create_file_name( $ref = '' )
                        {
-                               $file_written = false;
-                               $fp = fopen($filename, "wb");
-                               fwrite($fp, $content);
-
-                               if (fclose($fp))
+                               if (!$ref)
                                {
-                                       $file_written = true;
+                                       throw new 
Exception('BkBygg_exporter_data_til_Agresso::create_file_name() Mangler 
referanse');
                                }
-                               else
+                               $voucher_type = $this->voucher_type;
+                               if (!$voucher_type)
                                {
-                                       phpgwapi_cache::message_set("$filename 
feilet", 'error');
+                                       throw new 
Exception('BkBygg_exporter_data_til_Agresso::create_file_name() Mangler 
bilagstype');
                                }
+                               $fil_katalog = 
$this->config->config_data['export']['path'];
+
+                               $filename = 
"{$fil_katalog}/{$voucher_type}_ordre_{$ref}.xml";
+
+                               //Sjekk om filen eksisterer
+                               if (file_exists($filename))
+                               {
+                                       unlink($filename);
+                               }
+
+                               return $filename;
                        }
 
-                       $transfer_ok = false;
-                       if (!$debug && 
($this->config->config_data['common']['method'] == 'ftp' || 
$this->config->config_data['common']['method'] == 'ssh'))
+                       public function transfer( )
                        {
-                               $this->db->transaction_begin();
+                               $batchid = $this->soXport->increment_batchid();
+                               $this->batchid = $batchid;
+                               $filename = 
$this->create_file_name($this->order_id);
+                               $content = $this->transfer_xml;
+                               $debug = 
empty($this->config->config_data['export']['activate_transfer']) ? true : false;
 
-                               if (!$connection = $this->connection)
+                               
if(!empty($this->config->config_data['export']['path']) && 
is_dir($this->config->config_data['export']['path'])) // keep a copy
                                {
-                                       $connection = $this->phpftp_connect();
-                               }
+                                       $file_written = false;
+                                       $fp = fopen($filename, "wb");
+                                       fwrite($fp, $content);
 
-                               $basedir = 
$this->config->config_data['export']['remote_basedir'];
-                               if ($basedir)
-                               {
-                                       $remote_file = $basedir . '/' . 
basename($filename);
+                                       if (fclose($fp))
+                                       {
+                                               $file_written = true;
+                                       }
+                                       else
+                                       {
+                                               
phpgwapi_cache::message_set("$filename feilet", 'error');
+                                       }
                                }
-                               else
-                               {
-                                       $remote_file = basename($filename);
-                               }
 
-                               switch 
($this->config->config_data['common']['method'])
+                               $transfer_ok = false;
+                               if (!$debug && 
($this->config->config_data['common']['method'] == 'ftp' || 
$this->config->config_data['common']['method'] == 'ssh'))
                                {
-                                       case 'ftp';
-                                               $tmp = tmpfile();
-                                               fwrite($tmp, $content);
-                                               rewind($tmp);
-                                               $transfer_ok = 
ftp_fput($connection, $remote_file, $tmp, FTP_BINARY);
-                                               fclose($tmp);
-                                       //      $transfer_ok = 
ftp_put($connection, $remote_file, $filename, FTP_BINARY);
-                                               break;
-                                       case 'ssh';
-                                               $sftp = ssh2_sftp($connection);
-                                               $stream = 
@fopen("ssh2.sftp://$sftp$remote_file";, 'w');
-                                               fwrite($stream, $content);
-                                               $transfer_ok = @fclose($stream);
-                                               break;
-                                       default:
-                                               $transfer_ok = false;
-                               }
-                               if ($transfer_ok)
-                               {
-                                       
$this->soXport->log_transaction($batchid, $this->order_id, lang('transferred 
Order %1 to Agresso', basename($filename)));
-                                       $this->db->transaction_commit(); // 
Reverse the batch_id - increment
-                               }
-                               else
-                               {
-                                       $this->db->transaction_abort();
-                                       
$this->soXport->log_transaction($batchid, $this->order_id, lang('Failed to 
transfere Order %1 to Agresso', basename($filename)));
-                       //              @unlink($filename);
-                               }
-                       }
-                       else
-                       {
-                               $transfer_ok = true;
+                                       $this->db->transaction_begin();
 
-//                             $GLOBALS['phpgw_info']['flags']['noheader'] = 
true;
-//                             $GLOBALS['phpgw_info']['flags']['nofooter'] = 
true;
-//                             $GLOBALS['phpgw_info']['flags']['xslt_app'] = 
false;
-//                             $size = strlen($content);
-//                             $browser = CreateObject('phpgwapi.browser');
-//                             $browser->content_header(basename($filename), 
'', $size);
-//                             echo $content;
-                       }
-                       return $transfer_ok;
-               }
+                                       if (!$connection = $this->connection)
+                                       {
+                                               $connection = 
$this->phpftp_connect();
+                                       }
 
-               function phpftp_connect()
-               {
-                       $server = $this->config->config_data['common']['host'];
-                       $user = $this->config->config_data['common']['user'];
-                       $password = 
$this->config->config_data['common']['password'];
-                       $port = 22;
-
-                       switch ($this->config->config_data['common']['method'])
-                       {
-                               case 'ftp';
-                                       if ($connection = ftp_connect($server))
+                                       $basedir = 
$this->config->config_data['export']['remote_basedir'];
+                                       if ($basedir)
                                        {
-                                               ftp_login($connection, $user, 
$password);
+                                               $remote_file = $basedir . '/' . 
basename($filename);
                                        }
-                                       break;
-                               case 'ssh';
-                                       if (!function_exists("ssh2_connect"))
+                                       else
                                        {
-                                               die("function ssh2_connect 
doesn't exist");
+                                               $remote_file = 
basename($filename);
                                        }
-                                       if (!($connection = 
ssh2_connect("$server", $port)))
+
+                                       switch 
($this->config->config_data['common']['method'])
                                        {
-                                               $message = "fail: unable to 
establish connection";
-                                               _debug_array($message);
-                                               //$receipt['error'][]= 
array('msg' => $message);
+                                               case 'ftp';
+                                                       $tmp = tmpfile();
+                                                       fwrite($tmp, $content);
+                                                       rewind($tmp);
+                                                       $transfer_ok = 
ftp_fput($connection, $remote_file, $tmp, FTP_BINARY);
+                                                       fclose($tmp);
+                                               //      $transfer_ok = 
ftp_put($connection, $remote_file, $filename, FTP_BINARY);
+                                                       break;
+                                               case 'ssh';
+                                                       $sftp = 
ssh2_sftp($connection);
+                                                       $stream = 
@fopen("ssh2.sftp://$sftp$remote_file";, 'w');
+                                                       fwrite($stream, 
$content);
+                                                       $transfer_ok = 
@fclose($stream);
+                                                       break;
+                                               default:
+                                                       $transfer_ok = false;
                                        }
+                                       if ($transfer_ok)
+                                       {
+                                               
$this->soXport->log_transaction($batchid, $this->order_id, lang('transferred 
Order %1 to Agresso', basename($filename)));
+                                               
$this->db->transaction_commit(); // Reverse the batch_id - increment
+                                       }
                                        else
                                        {
-                                               // try to authenticate with 
username root, password secretpassword
-                                               if 
(!ssh2_auth_password($connection, $user, $password))
+                                               $this->db->transaction_abort();
+                                               
$this->soXport->log_transaction($batchid, $this->order_id, lang('Failed to 
transfere Order %1 to Agresso', basename($filename)));
+                               //              @unlink($filename);
+                                       }
+                               }
+                               else
+                               {
+                                       $transfer_ok = true;
+
+       //                              
$GLOBALS['phpgw_info']['flags']['noheader'] = true;
+       //                              
$GLOBALS['phpgw_info']['flags']['nofooter'] = true;
+       //                              
$GLOBALS['phpgw_info']['flags']['xslt_app'] = false;
+       //                              $size = strlen($content);
+       //                              $browser = 
CreateObject('phpgwapi.browser');
+       //                              
$browser->content_header(basename($filename), '', $size);
+       //                              echo $content;
+                               }
+                               return $transfer_ok;
+                       }
+
+                       function phpftp_connect()
+                       {
+                               $server = 
$this->config->config_data['common']['host'];
+                               $user = 
$this->config->config_data['common']['user'];
+                               $password = 
$this->config->config_data['common']['password'];
+                               $port = 22;
+
+                               switch 
($this->config->config_data['common']['method'])
+                               {
+                                       case 'ftp';
+                                               if ($connection = 
ftp_connect($server))
                                                {
-                                                       $message = "fail: 
unable to authenticate";
+                                                       ftp_login($connection, 
$user, $password);
+                                               }
+                                               break;
+                                       case 'ssh';
+                                               if 
(!function_exists("ssh2_connect"))
+                                               {
+                                                       die("function 
ssh2_connect doesn't exist");
+                                               }
+                                               if (!($connection = 
ssh2_connect("$server", $port)))
+                                               {
+                                                       $message = "fail: 
unable to establish connection";
                                                        _debug_array($message);
                                                        //$receipt['error'][]= 
array('msg' => $message);
                                                }
-                                       }
-                                       break;
+                                               else
+                                               {
+                                                       // try to authenticate 
with username root, password secretpassword
+                                                       if 
(!ssh2_auth_password($connection, $user, $password))
+                                                       {
+                                                               $message = 
"fail: unable to authenticate";
+                                                               
_debug_array($message);
+                                                               
//$receipt['error'][]= array('msg' => $message);
+                                                       }
+                                               }
+                                               break;
+                               }
+                               $this->connection = $connection;
+                               return $connection;
                        }
-                       $this->connection = $connection;
-                       return $connection;
                }
        }
 
-       class xml_creator extends XMLWriter
+       if (!class_exists("xml_creator"))
        {
-
-               /**
-                * Constructor.
-                * @param string $prm_rootElementName A root element's name of 
a current xml document
-                * @param ARRAY $root_attributtes array of root attributes.
-                * @param string $prm_xsltFilePath Path of a XSLT file.
-                * @access public
-                * @param null
-                */
-               public function __construct( $prm_rootElementName, 
$root_attributes = array(), $prm_xsltFilePath = '' )
+               class xml_creator extends XMLWriter
                {
-                       $this->openMemory();
-                       $this->setIndent(true);
-                       $this->setIndentString(' ');
-                       $this->startDocument('1.0', 'UTF-8');
 
-                       if ($prm_xsltFilePath)
+                       /**
+                        * Constructor.
+                        * @param string $prm_rootElementName A root element's 
name of a current xml document
+                        * @param ARRAY $root_attributtes array of root 
attributes.
+                        * @param string $prm_xsltFilePath Path of a XSLT file.
+                        * @access public
+                        * @param null
+                        */
+                       public function __construct( $prm_rootElementName, 
$root_attributes = array(), $prm_xsltFilePath = '' )
                        {
-                               $this->writePi('xml-stylesheet', 
'type="text/xsl" href="' . $prm_xsltFilePath . '"');
+                               $this->openMemory();
+                               $this->setIndent(true);
+                               $this->setIndentString(' ');
+                               $this->startDocument('1.0', 'UTF-8');
+
+                               if ($prm_xsltFilePath)
+                               {
+                                       $this->writePi('xml-stylesheet', 
'type="text/xsl" href="' . $prm_xsltFilePath . '"');
+                               }
+
+                               $this->startElement($prm_rootElementName);
+
+                               foreach ($root_attributes as $key => $value)
+                               {
+                                       $this->writeAttribute($key, $value);
+                               }
                        }
 
-                       $this->startElement($prm_rootElementName);
-
-                       foreach ($root_attributes as $key => $value)
+                       /**
+                        * Set an element with a text to a current xml document.
+                        * @access public
+                        * @param string $prm_elementName An element's name
+                        * @param string $prm_ElementText An element's text
+                        * @return null
+                        */
+                       public function setElement( $prm_elementName, 
$prm_ElementText )
                        {
-                               $this->writeAttribute($key, $value);
+                               $this->startElement($prm_elementName);
+                               $this->text($prm_ElementText);
+                               $this->endElement();
                        }
-               }
 
-               /**
-                * Set an element with a text to a current xml document.
-                * @access public
-                * @param string $prm_elementName An element's name
-                * @param string $prm_ElementText An element's text
-                * @return null
-                */
-               public function setElement( $prm_elementName, $prm_ElementText )
-               {
-                       $this->startElement($prm_elementName);
-                       $this->text($prm_ElementText);
-                       $this->endElement();
-               }
-
-               /**
-                * Construct elements and texts from an array.
-                * The array should contain an attribute's name in index part
-                * and a attribute's text in value part.
-                * @access public
-                * @param array $prm_array Contains attributes and texts
-                * @return null
-                */
-               public function fromArray( array $array )
-               {
-                       foreach ($array as $key => $val)
+                       /**
+                        * Construct elements and texts from an array.
+                        * The array should contain an attribute's name in 
index part
+                        * and a attribute's text in value part.
+                        * @access public
+                        * @param array $prm_array Contains attributes and texts
+                        * @return null
+                        */
+                       public function fromArray( array $array )
                        {
-                               if (is_array($val))
+                               foreach ($array as $key => $val)
                                {
-                                       if (is_numeric($key))
+                                       if (is_array($val))
                                        {
-                                               // numeric keys aren't allowed 
so we'll skip the key
-                                               $this->fromArray($val);
+                                               if (is_numeric($key))
+                                               {
+                                                       // numeric keys aren't 
allowed so we'll skip the key
+                                                       $this->fromArray($val);
+                                               }
+                                               else
+                                               {
+                                                       
$this->startElement($key);
+                                                       $this->fromArray($val);
+                                                       $this->endElement();
+                                               }
                                        }
                                        else
                                        {
-                                               $this->startElement($key);
-                                               $this->fromArray($val);
-                                               $this->endElement();
+                                               $this->writeElement($key, $val);
                                        }
                                }
-                               else
-                               {
-                                       $this->writeElement($key, $val);
-                               }
                        }
-               }
 
-               /**
-                * Return the content of a current xml document.
-                * @access public
-                * @param null
-                * @return string Xml document
-                */
-               public function getDocument()
-               {
-                       $this->endElement();
-                       $this->endDocument();
-                       return $this->outputMemory();
-               }
+                       /**
+                        * Return the content of a current xml document.
+                        * @access public
+                        * @param null
+                        * @return string Xml document
+                        */
+                       public function getDocument()
+                       {
+                               $this->endElement();
+                               $this->endDocument();
+                               return $this->outputMemory();
+                       }
 
-               /**
-                * Output the content of a current xml document.
-                * @access public
-                * @param null
-                */
-               public function output()
-               {
-                       header('Content-type: text/xml');
-                       echo $this->getDocument();
+                       /**
+                        * Output the content of a current xml document.
+                        * @access public
+                        * @param null
+                        */
+                       public function output()
+                       {
+                               header('Content-type: text/xml');
+                               echo $this->getDocument();
+                       }
                }
        }
\ No newline at end of file

Modified: 
trunk/property/inc/custom/default/BkBygg_lag_Agresso_ordre_fra_workorder.php
===================================================================
--- 
trunk/property/inc/custom/default/BkBygg_lag_Agresso_ordre_fra_workorder.php    
    2017-01-04 12:16:21 UTC (rev 16139)
+++ 
trunk/property/inc/custom/default/BkBygg_lag_Agresso_ordre_fra_workorder.php    
    2017-01-04 13:41:49 UTC (rev 16140)
@@ -31,308 +31,312 @@
         * @package property
         */
        
-//     if (!$workorder['order_sent'])
+       if (!class_exists("lag_agresso_ordre_fra_workorder"))
        {
-               $exporter_ordre = new lag_agresso_ordre_fra_workorder();
-               try
+               class lag_agresso_ordre_fra_workorder
                {
-                       $exporter_ordre->transfer($project, $workorder);
-               }
-               catch (Exception $exc)
-               {
-                       phpgwapi_cache::message_set($exc->getMessage(), 
'error');
-               }
+                       var $debug = false;
 
-       }
-       class lag_agresso_ordre_fra_workorder
-       {
-               var $debug = false;
-
-               public function __construct()
-               {
-                       $this->cats = CreateObject('phpgwapi.categories', -1, 
'property', '.project');
-                       $this->cats->supress_info = true;
-                       $config = CreateObject('admin.soconfig', 
$GLOBALS['phpgw']->locations->get_id('property', '.invoice'));
-                       $this->debug = 
empty($config->config_data['export']['activate_transfer']) ? true : false;
-               }
-
-               public function transfer( $project, $workorder )
-               {
-//     _debug_array($workorder);die();
-                       if (!$this->debug && $workorder['order_sent'])
+                       public function __construct()
                        {
-                               $transfer_time = 
$GLOBALS['phpgw']->common->show_date($workorder['order_sent']);
-                               phpgwapi_cache::message_set("Info: Ordre 
#{$workorder['id']} er allerede overført til Agresso {$transfer_time}");
-                               return 2;
+                               $this->cats = 
CreateObject('phpgwapi.categories', -1, 'property', '.project');
+                               $this->cats->supress_info = true;
+                               $config = CreateObject('admin.soconfig', 
$GLOBALS['phpgw']->locations->get_id('property', '.invoice'));
+                               $this->debug = 
empty($config->config_data['export']['activate_transfer']) ? true : false;
                        }
 
-                       $config = CreateObject('phpgwapi.config', 'property');
-                       $config->read();
-                       $approval_level = 
!empty($config->config_data['approval_level']) ? 
$config->config_data['approval_level'] : 'order';
-
-                       $approval_amount = 0;
-                       $price = 0;
-                       if($approval_level == 'project')
+                       public function transfer( $workorder )
                        {
-                               $approval_amount = 
ExecMethod('property.boworkorder.get_accumulated_budget_amount', 
$workorder['project_id']);
-                               $price = (float) 
ExecMethod('property.boworkorder.get_budget_amount', $workorder['id']);
-                       }
-                       else
-                       {
-                               $approval_amount = 
ExecMethod('property.boworkorder.get_budget_amount', $workorder['id']);
-                               $price = (float) $approval_amount;
+                               $project = 
createObject('property.boproject')->read_single($workorder['project_id'], 
array(), true);
 
-                       }
+                               if (!$this->debug && $workorder['order_sent'])
+                               {
+                                       $transfer_time = 
$GLOBALS['phpgw']->common->show_date($workorder['order_sent']);
+                                       phpgwapi_cache::message_set("Info: 
Ordre #{$workorder['id']} er allerede overført til Agresso {$transfer_time}");
+                                       return 2;
+                               }
 
-                       try
-                       {
-                               $purchase_grant_ok = 
CreateObject('property.botts')->validate_purchase_grant( $workorder['ecodimb'], 
$approval_amount, $workorder['id']);
-                       }
-                       catch (Exception $ex)
-                       {
-                               throw $ex;
-                       }
+                               $config = CreateObject('phpgwapi.config', 
'property');
+                               $config->read();
+                               $approval_level = 
!empty($config->config_data['approval_level']) ? 
$config->config_data['approval_level'] : 'order';
 
-                       if (!$this->debug && !$purchase_grant_ok)
-                       {
-                               return 3;
-                       }
+                               $approval_amount = 0;
+                               $price = 0;
+                               if($approval_level == 'project')
+                               {
+                                       $approval_amount = 
ExecMethod('property.boworkorder.get_accumulated_budget_amount', 
$workorder['project_id']);
+                                       $price = (float) 
ExecMethod('property.boworkorder.get_budget_amount', $workorder['id']);
+                               }
+                               else
+                               {
+                                       $approval_amount = 
ExecMethod('property.boworkorder.get_budget_amount', $workorder['id']);
+                                       $price = (float) $approval_amount;
 
-                       $contacts = CreateObject('property.sogeneric');
-                       $contacts->get_location_info('vendor', false);
+                               }
 
-                       $custom = createObject('property.custom_fields');
-                       $vendor_data['attributes'] = $custom->find('property', 
'.vendor', 0, '', 'ASC', 'attrib_sort', true, true);
+                               try
+                               {
+                                       $purchase_grant_ok = 
CreateObject('property.botts')->validate_purchase_grant( $workorder['ecodimb'], 
$approval_amount, $workorder['id']);
+                               }
+                               catch (Exception $ex)
+                               {
+                                       throw $ex;
+                               }
 
-                       $vendor_data = $contacts->read_single(array('id' => 
$workorder['vendor_id']), $vendor_data);
-                       if (is_array($vendor_data))
-                       {
-                               foreach ($vendor_data['attributes'] as 
$attribute)
+                               if (!$this->debug && !$purchase_grant_ok)
                                {
-                                       if ($attribute['name'] == 'adresse')
+                                       return 3;
+                               }
+
+                               $contacts = CreateObject('property.sogeneric');
+                               $contacts->get_location_info('vendor', false);
+
+                               $custom = 
createObject('property.custom_fields');
+                               $vendor_data['attributes'] = 
$custom->find('property', '.vendor', 0, '', 'ASC', 'attrib_sort', true, true);
+
+                               $vendor_data = 
$contacts->read_single(array('id' => $workorder['vendor_id']), $vendor_data);
+                               if (is_array($vendor_data))
+                               {
+                                       foreach ($vendor_data['attributes'] as 
$attribute)
                                        {
-                                               $vendor['address'] = 
$attribute['value'];
+                                               if ($attribute['name'] == 
'adresse')
+                                               {
+                                                       $vendor['address'] = 
$attribute['value'];
+                                               }
+                                               if ($attribute['name'] == 
'org_name')
+                                               {
+                                                       $vendor['name'] = 
$attribute['value'];
+                                               }
                                        }
-                                       if ($attribute['name'] == 'org_name')
-                                       {
-                                               $vendor['name'] = 
$attribute['value'];
-                                       }
                                }
-                       }
-                       unset($contacts);
+                               unset($contacts);
 
-                       
$GLOBALS['phpgw']->preferences->set_account_id($workorder['user_id'], true);
+                               
$GLOBALS['phpgw']->preferences->set_account_id($workorder['user_id'], true);
 
-                       $user_name = 
$GLOBALS['phpgw']->accounts->get($workorder['user_id'])->__toString();
-                       $account_lid = 
$GLOBALS['phpgw']->accounts->id2lid($workorder['user_id']);
+                               $user_name = 
$GLOBALS['phpgw']->accounts->get($workorder['user_id'])->__toString();
+                               $account_lid = 
$GLOBALS['phpgw']->accounts->id2lid($workorder['user_id']);
 
 
-                       if ($workorder['ecodimb'])
-                       {
-                               $dim1 = $workorder['ecodimb'];
-                       }
-                       else if ($project['ecodimb'])
-                       {
-                               $dim1 = $project['ecodimb'];
-                       }
-                       else
-                       {
-                               throw new Exception('Dimensjonen "Ansvar" 
mangler');
-                       }
+                               if ($workorder['ecodimb'])
+                               {
+                                       $dim1 = $workorder['ecodimb'];
+                               }
+                               else if ($project['ecodimb'])
+                               {
+                                       $dim1 = $project['ecodimb'];
+                               }
+                               else
+                               {
+                                       throw new Exception('Dimensjonen 
"Ansvar" mangler');
+                               }
 
-                       if ($workorder['location_code'])
-                       {
-                               $location_code = $workorder['location_code'];
-                               $location = explode('-', $location_code);
-//                             $dim3 = isset($location[1]) && $location[1] ? 
"{$location[0]}{$location[1]}" : "{$location[0]}01";
-                               $dim3 = $location[0];
+                               if ($workorder['location_code'])
+                               {
+                                       $location_code = 
$workorder['location_code'];
+                                       $location = explode('-', 
$location_code);
+       //                              $dim3 = isset($location[1]) && 
$location[1] ? "{$location[0]}{$location[1]}" : "{$location[0]}01";
+                                       $dim3 = $location[0];
 
-                       }
-                       else if ($project['location_code'])
-                       {
-                               $location_code = $project['location_code'];
-                               $location = explode('-', $location_code);
-//                             $dim3 = isset($location[1]) && $location[1] ? 
"{$location[0]}{$location[1]}" : "{$location[0]}01";
-                               $dim3 = $location[0];
-                       }
-                       else
-                       {
-                               $dim3 = 9;
-                       }
+                               }
+                               else if ($project['location_code'])
+                               {
+                                       $location_code = 
$project['location_code'];
+                                       $location = explode('-', 
$location_code);
+       //                              $dim3 = isset($location[1]) && 
$location[1] ? "{$location[0]}{$location[1]}" : "{$location[0]}01";
+                                       $dim3 = $location[0];
+                               }
+                               else
+                               {
+                                       $dim3 = 9;
+                               }
 
-                       $address_element = 
execMethod('property.botts.get_address_element', $location_code);
-                       $_address = array();
-                       foreach ($address_element as $entry)
-                       {
-                               $_address[] = "{$entry['text']}: 
{$entry['value']}";
-                       }
+                               $address_element = 
execMethod('property.botts.get_address_element', $location_code);
+                               $_address = array();
+                               foreach ($address_element as $entry)
+                               {
+                                       $_address[] = "{$entry['text']}: 
{$entry['value']}";
+                               }
 
-                       $address = '';
-                       if ($_address)
-                       {
-                               $address = implode(', ', $_address);
-                       }
+                               $address = '';
+                               if ($_address)
+                               {
+                                       $address = implode(', ', $_address);
+                               }
 
-                       $buyer = array(
-                               'Name' => $user_name,
-                               'AddressInfo' => array(
-                                       array(
-                                               'Address' => $address
+                               $buyer = array(
+                                       'Name' => $user_name,
+                                       'AddressInfo' => array(
+                                               array(
+                                                       'Address' => $address
+                                               )
+                                       ),
+                                       'BuyerReferences' => array(
+                                               array(
+                                                       'Responsible' => 
strtoupper($account_lid),
+                                                       'RequestedBy' => 
strtoupper($account_lid),
+                                                       'Accountable' => 
strtoupper($account_lid),
+                                               )
                                        )
-                               ),
-                               'BuyerReferences' => array(
-                                       array(
-                                               'Responsible' => 
strtoupper($account_lid),
-                                               'RequestedBy' => 
strtoupper($account_lid),
-                                               'Accountable' => 
strtoupper($account_lid),
-                                       )
-                               )
-                       );
+                               );
 
 
-                       //EBF...
+                               //EBF...
 
-                       $location_info = 
execMethod('property.bolocation.read_single', $location[0]);
+                               $location_info = 
execMethod('property.bolocation.read_single', $location[0]);
 
-                       $tax_code = 0;
-                       $tjeneste = 9;
-                       if ($location_info['attributes'])
-                       {
-                               $_found = 0;
-                               foreach ($location_info['attributes'] as $key 
=> $attribute)
+                               $tax_code = 0;
+                               $tjeneste = 9;
+                               if ($location_info['attributes'])
                                {
-                                       if ($attribute['name'] == 'mva')
+                                       $_found = 0;
+                                       foreach ($location_info['attributes'] 
as $key => $attribute)
                                        {
-                                               $tax_code = $attribute['value'];
-                                               $_found ++;
+                                               if ($attribute['name'] == 'mva')
+                                               {
+                                                       $tax_code = 
$attribute['value'];
+                                                       $_found ++;
+                                               }
+                                               if ($attribute['name'] == 
'kostra_id')
+                                               {
+                                                       $tjeneste = 
$attribute['value'];
+                                                       $_found ++;
+                                               }
+                                               if ($_found == 2)
+                                               {
+                                                       break;
+                                               }
                                        }
-                                       if ($attribute['name'] == 'kostra_id')
-                                       {
-                                               $tjeneste = $attribute['value'];
-                                               $_found ++;
-                                       }
-                                       if ($_found == 2)
-                                       {
+                               }
+
+                               //Override from workorder
+                               $tax_code = $workorder['tax_code'] ? 
$workorder['tax_code'] : $tax_code;
+                               switch ($tax_code)
+                               {
+                                       case '0':
+                                               $tax_code = '6A';
                                                break;
-                                       }
+                                       case '75':
+                                               $tax_code = '60';
+                                               break;
+                                       default:
+                                               $tax_code = '6A';
+                                               break;
                                }
-                       }
 
-                       //Override from workorder
-                       $tax_code = $workorder['tax_code'] ? 
$workorder['tax_code'] : $tax_code;
-                       switch ($tax_code)
-                       {
-                               case '0':
-                                       $tax_code = '6A';
-                                       break;
-                               case '75':
-                                       $tax_code = '60';
-                                       break;
-                               default:
-                                       $tax_code = '6A';
-                                       break;
-                       }
+                               $tjeneste = $workorder['service_id'] ? 
$workorder['service_id'] : $tjeneste;
 
-                       $tjeneste = $workorder['service_id'] ? 
$workorder['service_id'] : $tjeneste;
+       //                      _debug_array($location_info);die();
 
-//                     _debug_array($location_info);die();
-
-                       $collect_building_part = false;
-                       if 
(isset($config->config_data['workorder_require_building_part']))
-                       {
-                               if 
($config->config_data['workorder_require_building_part'] == 1)
+                               $collect_building_part = false;
+                               if 
(isset($config->config_data['workorder_require_building_part']))
                                {
-                                       $collect_building_part = true;
+                                       if 
($config->config_data['workorder_require_building_part'] == 1)
+                                       {
+                                               $collect_building_part = true;
+                                       }
                                }
-                       }
 
-                       if ($collect_building_part)
-                       {
-                               if ($workorder['order_dim1'])
+                               if ($collect_building_part)
                                {
-                                       $sogeneric = 
CreateObject('property.sogeneric', 'order_dim1');
-                                       $sogeneric_data = 
$sogeneric->read_single(array('id' => $workorder['order_dim1']));
-                                       if ($sogeneric_data)
+                                       if ($workorder['order_dim1'])
                                        {
-                                               $dim6 = 
"{$workorder['building_part']}{$sogeneric_data['num']}";
+                                               $sogeneric = 
CreateObject('property.sogeneric', 'order_dim1');
+                                               $sogeneric_data = 
$sogeneric->read_single(array('id' => $workorder['order_dim1']));
+                                               if ($sogeneric_data)
+                                               {
+                                                       $dim6 = 
"{$workorder['building_part']}{$sogeneric_data['num']}";
+                                               }
                                        }
                                }
-                       }
-                       else
-                       {
-                               $category = 
$this->cats->return_single($workorder['cat_id']);
-                               $category_arr = explode('-', 
$category[0]['name']);
-                               $dim6 = (int)trim($category_arr[0]);
-                       }
+                               else
+                               {
+                                       $category = 
$this->cats->return_single($workorder['cat_id']);
+                                       $category_arr = explode('-', 
$category[0]['name']);
+                                       $dim6 = (int)trim($category_arr[0]);
+                               }
 
-                       /*
-                       P3: EBF Innkjøpsordre Portico : 45000000-45249999
-                       V3: EBF Varemotttak Portico   : 45500000-45749999
-                       P4: EBE Innkjøpsordre Portico : 45250000-45499999
-                       V4: EBE Varemotttak Portico   : 45750000-45999999
-                       */
+                               /*
+                               P3: EBF Innkjøpsordre Portico : 
45000000-45249999
+                               V3: EBF Varemotttak Portico   : 
45500000-45749999
+                               P4: EBE Innkjøpsordre Portico : 
45250000-45499999
+                               V4: EBE Varemotttak Portico   : 
45750000-45999999
+                               */
 
-//                     $voucher_type = 'P4';
+       //                      $voucher_type = 'P4';
 
-                       if($workorder['id'] >= 45000000 && $workorder['id'] <= 
45249999)
-                       {
-                               $voucher_type = 'P3';
-                       }
-                       else if ($workorder['id'] >= 45250000 && 
$workorder['id'] <= 45499999)
-                       {
-                               $voucher_type = 'P4';
-                       }
-                       else
-                       {
-                               throw new Exception("Ordrenummer 
'{$workorder['id']}' er utenfor serien:<br/>" . __FILE__ . '<br/>linje:' . 
__LINE__);
-                       }
+                               if($workorder['id'] >= 45000000 && 
$workorder['id'] <= 45249999)
+                               {
+                                       $voucher_type = 'P3';
+                               }
+                               else if ($workorder['id'] >= 45250000 && 
$workorder['id'] <= 45499999)
+                               {
+                                       $voucher_type = 'P4';
+                               }
+                               else
+                               {
+                                       throw new Exception("Ordrenummer 
'{$workorder['id']}' er utenfor serien:<br/>" . __FILE__ . '<br/>linje:' . 
__LINE__);
+                               }
 
-                       $param = array(
-                               'dim0' => $workorder['b_account_id'], // Art
-                               'dim1' => $dim1, // Ansvar
-                               'dim2' => $tjeneste, // Tjeneste liste 30 stk, 
default 9
-                               'dim3' => $dim3, // Objekt: eiendom + bygg: 6 
siffer
-                               'dim4' => $workorder['contract_id'], // 
Kontrakt - frivillig / 9, 7 tegn - alfanumerisk
-                               'dim5' => $project['external_project_id'], // 
Prosjekt
-                               'dim6' => $dim6, // Aktivitet - frivillig: 
bygningsdel, 3 siffer + bokstavkode
-                               'vendor_id' => $workorder['vendor_id'],
-                               'vendor_name' => $vendor['name'],
-                               'vendor_address' => $vendor['address'],
-                               'order_id' => $workorder['id'],
-                               'tax_code' => $tax_code,
-                               'buyer' => $buyer,
-                               'lines' => array(
-                                       array(
-                                               'unspsc_code' => 
$workorder['unspsc_code'] ? $workorder['unspsc_code'] : 'UN-72000000',
-//                                             'descr' => 
strip_tags($workorder['descr'])
-                                               'descr' => '',
-                                               'price' => $price,
+                               $param = array(
+                                       'dim0' => $workorder['b_account_id'], 
// Art
+                                       'dim1' => $dim1, // Ansvar
+                                       'dim2' => $tjeneste, // Tjeneste liste 
30 stk, default 9
+                                       'dim3' => $dim3, // Objekt: eiendom + 
bygg: 6 siffer
+                                       'dim4' => $workorder['contract_id'], // 
Kontrakt - frivillig / 9, 7 tegn - alfanumerisk
+                                       'dim5' => 
$project['external_project_id'], // Prosjekt
+                                       'dim6' => $dim6, // Aktivitet - 
frivillig: bygningsdel, 3 siffer + bokstavkode
+                                       'vendor_id' => $workorder['vendor_id'],
+                                       'vendor_name' => $vendor['name'],
+                                       'vendor_address' => $vendor['address'],
+                                       'order_id' => $workorder['id'],
+                                       'tax_code' => $tax_code,
+                                       'buyer' => $buyer,
+                                       'lines' => array(
+                                               array(
+                                                       'unspsc_code' => 
$workorder['unspsc_code'] ? $workorder['unspsc_code'] : 'UN-72000000',
+       //                                              'descr' => 
strip_tags($workorder['descr'])
+                                                       'descr' => '',
+                                                       'price' => $price,
+                                               )
                                        )
-                               )
-                       );
+                               );
 
 
-                       $exporter_ordre = new 
BkBygg_exporter_data_til_Agresso(array(
-                               'order_id' => $workorder['id'],
-                               'voucher_type' => $voucher_type
-                               )
-                       );
-                       $exporter_ordre->create_transfer_xml($param);
+                               $exporter_ordre = new 
BkBygg_exporter_data_til_Agresso(array(
+                                       'order_id' => $workorder['id'],
+                                       'voucher_type' => $voucher_type
+                                       )
+                               );
+                               $exporter_ordre->create_transfer_xml($param);
 
-                       $export_ok = $exporter_ordre->transfer($this->debug);
+                               $export_ok = 
$exporter_ordre->transfer($this->debug);
 
-                       if ($export_ok)
+                               if ($export_ok)
+                               {
+                                       phpgwapi_cache::message_set("Ordre 
#{$workorder['id']} er overført");
+                                       $this->log_transfer( $workorder['id'] );
+                               }
+                       }
+
+                       private function log_transfer( $id )
                        {
-                               phpgwapi_cache::message_set("Ordre 
#{$workorder['id']} er overført");
-                               $this->log_transfer( $workorder['id'] );
+                               $historylog = 
CreateObject('property.historylog', 'workorder');
+                               $historylog->add('RM', $id, "Ordre overført til 
agresso");
+                               $now = time();
+                               $GLOBALS['phpgw']->db->query("UPDATE 
fm_workorder SET order_sent = {$now} WHERE id = {$id}");
                        }
                }
-
-               private function log_transfer( $id )
+       }
+//     if (!$workorder['order_sent'])
+       {
+               $exporter_ordre = new lag_agresso_ordre_fra_workorder();
+               try
                {
-                       $historylog = CreateObject('property.historylog', 
'workorder');
-                       $historylog->add('RM', $id, "Ordre overført til 
agresso");
-                       $now = time();
-                       $GLOBALS['phpgw']->db->query("UPDATE fm_workorder SET 
order_sent = {$now} WHERE id = {$id}");
+                       $exporter_ordre->transfer($workorder);
                }
-       }
\ No newline at end of file
+               catch (Exception $exc)
+               {
+                       phpgwapi_cache::message_set($exc->getMessage(), 
'error');
+               }
+
+       }




reply via email to

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