fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [15804] more on invoice/order


From: sigurdne
Subject: [Fmsystem-commits] [15804] more on invoice/order
Date: Fri, 7 Oct 2016 13:49:38 +0000 (UTC)

Revision: 15804
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=15804
Author:   sigurdne
Date:     2016-10-07 13:49:38 +0000 (Fri, 07 Oct 2016)
Log Message:
-----------
more on invoice/order

Modified Paths:
--------------
    trunk/property/inc/class.uitts.inc.php
    trunk/property/inc/custom/default/BkBygg_exporter_data_til_Agresso.php
    trunk/property/inc/custom/default/BkBygg_exporter_varemottak_til_Agresso.php
    trunk/property/inc/custom/default/BkBygg_lag_Agresso_ordre_fra_melding.php

Modified: trunk/property/inc/class.uitts.inc.php
===================================================================
--- trunk/property/inc/class.uitts.inc.php      2016-10-07 08:17:07 UTC (rev 
15803)
+++ trunk/property/inc/class.uitts.inc.php      2016-10-07 13:49:38 UTC (rev 
15804)
@@ -2894,9 +2894,8 @@
                        $active_tab = 'general';
 
                        $unspsc_code = $ticket['unspsc_code'] ? 
$ticket['unspsc_code'] : 
$GLOBALS['phpgw_info']['user']['preferences']['property']['unspsc_code'];
-                       $enable_order_service_id = 
isset($config->config_data['enable_order_service_id']) && 
$config->config_data['enable_order_service_id'] ? true : false;
-                       $enable_unspsc = 
isset($config->config_data['enable_unspsc']) && 
$config->config_data['enable_unspsc'] ? true : false;
-
+                       $enable_order_service_id = 
!empty($this->bo->config->config_data['enable_order_service_id']) ? true : 
false;
+                       $enable_unspsc = 
!empty($this->bo->config->config_data['enable_unspsc']) ? true : false;
                        $relation_type_list = array(
                                array(
                                        'id'    => 'property.uirequest.index',

Modified: trunk/property/inc/custom/default/BkBygg_exporter_data_til_Agresso.php
===================================================================
--- trunk/property/inc/custom/default/BkBygg_exporter_data_til_Agresso.php      
2016-10-07 08:17:07 UTC (rev 15803)
+++ trunk/property/inc/custom/default/BkBygg_exporter_data_til_Agresso.php      
2016-10-07 13:49:38 UTC (rev 15804)
@@ -50,6 +50,7 @@
                var $transfer_xml;
                var $connection;
                var $order_id;
+               var $voucher_type;
 
                public function __construct( $param )
                {
@@ -57,6 +58,7 @@
                        $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 )
@@ -105,7 +107,7 @@
                        $DetailInfo[] = array(
                                'ReferenceCode' => array(
                                        'Code' => 'C1',
-                                       'Value' => $param['dim1'] // Ansvar
+                                       'Value' => sprintf("%06s", 
$param['dim1']) // Ansvar
                                )
                        );
                        $DetailInfo[] = array(
@@ -129,7 +131,7 @@
                        $DetailInfo[] = array(
                                'ReferenceCode' => array(
                                        'Code' => 'B0',
-                                       'Value' => $param['dim5'] // Prosjekt
+                                       'Value' => $param['dim5'] ? 
$param['dim5'] : 9 // Prosjekt
                                )
                        );
                        $DetailInfo[] = array(
@@ -157,9 +159,9 @@
                                        'BuyerProductCode' => 
$line['unspsc_code'], //74000176, //UN-kode
                                        'BuyerProductDescr' => $line['descr'], 
//'Kopipapir',
                                        'UnitCode' => 'STK',
-                                       'Quantity' => 100,
-                                       'Price' =>'',
-                                       'Linetotal'=> '',
+                                       'Quantity' => 1,
+                                       'Price' => $line['price'],
+                                       'Linetotal'=> $line['price'],
                                        'DetailInfo' => $DetailInfo
                                );
 
@@ -169,7 +171,7 @@
 
                        $Orders['Order'][] = array(
                                'OrderNo' => $param['order_id'],
-                               'VoucherType' => 'P3',
+                               'VoucherType' => $param['voucher_type'],
                                'TransType' => 41,
                                'Header' => array($Header),
                                'Details' => array('Detail' => $Detail)
@@ -209,9 +211,14 @@
                        {
                                throw new 
Exception('BkBygg_exporter_data_til_Agresso::create_file_name() Mangler 
referanse');
                        }
+                       $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}/FDV_ordre_{$ref}.xml";
+                       $filename = 
"{$fil_katalog}/{$voucher_type}_ordre_{$ref}.xml";
 
                        //Sjekk om filen eksisterer
                        if (file_exists($filename))
@@ -224,17 +231,16 @@
 
                public function transfer( $debug )
                {
-                       $this->db->transaction_begin();
 
                        $filename = $this->create_file_name($this->order_id);
                        $batchid = $this->soXport->increment_batchid();
                        $content = $this->transfer_xml;
 
-                       if(false) // keep a copy?
+                       if($debug) // keep a copy?
                        {
                                $file_written = false;
                                $fp = fopen($filename, "wb");
-                               fwrite($fp, $buffer);
+                               fwrite($fp, $content);
 
                                if (fclose($fp))
                                {
@@ -246,6 +252,8 @@
 //                     if ($this->config->config_data['common']['method'] == 
'ftp' || $this->config->config_data['common']['method'] == 'ssh')
                        if (!$debug)//Not yet...
                        {
+                               $this->db->transaction_begin();
+
                                if (!$connection = $this->connection)
                                {
                                        $connection = $this->phpftp_connect();

Modified: 
trunk/property/inc/custom/default/BkBygg_exporter_varemottak_til_Agresso.php
===================================================================
--- 
trunk/property/inc/custom/default/BkBygg_exporter_varemottak_til_Agresso.php    
    2016-10-07 08:17:07 UTC (rev 15803)
+++ 
trunk/property/inc/custom/default/BkBygg_exporter_varemottak_til_Agresso.php    
    2016-10-07 13:49:38 UTC (rev 15804)
@@ -46,6 +46,7 @@
 
                private $acl_location;
                private $values;
+               var $debug = true;
 
                function __construct( $acl_location, $id )
                {
@@ -68,7 +69,29 @@
                        $values = $this->values;
 //             _debug_array($values);die();
 
+                       /*
+                       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
+                       */
+
+
+                       if($values['order_id'] >= 45000000 && 
$values['order_id'] <= 45249999)
+                       {
+                               $voucher_type = 'V3';
+                       }
+                       else if ($values['order_id'] >= 45250000 && 
$values['order_id'] <= 45499999)
+                       {
+                               $voucher_type = 'V4';
+                       }
+                       else
+                       {
+                               throw new Exception("Ordrenummer 
'{$values['order_id']}' er utenfor serien");
+                       }
+
                        $param = array(
+                               'voucher_type'  => $voucher_type,
                                'order_id' => $values['order_id'],
                                'lines' => array(
                                        array(
@@ -78,12 +101,13 @@
                                )
                        );
 
-                       $exporter_varemottak = new 
BkBygg_exporter_varemottak_til_Agresso(array('order_id' => 
$values['order_id']));
+                       $exporter_varemottak = new 
BkBygg_exporter_varemottak_til_Agresso(array(
+                               'order_id' => $values['order_id'],
+                               'voucher_type' => $voucher_type
+                               ));
                        $exporter_varemottak->create_transfer_xml($param);
-       //              $exporter_varemottak->output();
-                       $export_ok = true;
-       //              die();
-       //              $export_ok = $exporter_varemottak->transfer();
+
+                       $export_ok = 
$exporter_varemottak->transfer($this->debug);
                        if ($export_ok)
                        {
                                $this->log_transfer( $id, $received_amount );
@@ -118,6 +142,7 @@
                var $transfer_xml;
                var $connection;
                var $order_id;
+               var $voucher_type;
 
                public function __construct( $param )
                {
@@ -142,7 +167,7 @@
 
                        $Orders['Order'][] = array(
                                'OrderNo' => $param['order_id'],
-                               'VoucherType' => 'VV',
+                               'VoucherType' => $param['voucher_type'],
                                'TransType' => 51,
                                'Details' => array('Detail' => $Detail)
                        );
@@ -167,9 +192,15 @@
                        {
                                throw new 
Exception('BkBygg_exporter_data_til_Agresso::create_file_name() Mangler 
referanse');
                        }
+                       $voucher_type = $this->voucher_type;
+                       if (!$voucher_type)
+                       {
+                               throw new 
Exception('BkBygg_exporter_varemottak_til_Agresso::create_file_name() Mangler 
bilagstype');
+                       }
+
                        $fil_katalog = 
$this->config->config_data['export']['path'];
 
-                       $filename = "{$fil_katalog}/FDV_varemottak_{$ref}.xml";
+                       $filename = 
"{$fil_katalog}/{$voucher_type}_varemottak_{$ref}.xml";
 
                        //Sjekk om filen eksisterer
                        if (file_exists($filename))

Modified: 
trunk/property/inc/custom/default/BkBygg_lag_Agresso_ordre_fra_melding.php
===================================================================
--- trunk/property/inc/custom/default/BkBygg_lag_Agresso_ordre_fra_melding.php  
2016-10-07 08:17:07 UTC (rev 15803)
+++ trunk/property/inc/custom/default/BkBygg_lag_Agresso_ordre_fra_melding.php  
2016-10-07 13:49:38 UTC (rev 15804)
@@ -54,6 +54,14 @@
                                return 2;
                        }
 
+                       $price = 0;
+                       $budgets = ExecMethod('property.botts.get_budgets',$id);
+                       foreach ($budgets as $budget)
+                       {
+
+                               $price += $budget['amount'];
+                       }
+
 //             _debug_array($_ticket);die();
 
                        $contacts = CreateObject('property.sogeneric');
@@ -103,9 +111,9 @@
                                ),
                                'BuyerReferences' => array(
                                        array(
-                                               'Responsible' => $account_lid,
-                                               'RequestedBy' => $account_lid,
-                                               'Accountable' => $account_lid,
+                                               'Responsible' => 
strtoupper($account_lid),
+                                               'RequestedBy' => 
strtoupper($account_lid),
+                                               'Accountable' => 
strtoupper($account_lid),
                                        )
                                )
                        );
@@ -129,8 +137,30 @@
                                        $dim6 = 
"{$_ticket['building_part']}{$sogeneric_data['num']}";
                                }
                        }
+                       /*
+                       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
+                       */
 
+
+                       if($_ticket['order_id'] >= 45000000 && 
$_ticket['order_id'] <= 45249999)
+                       {
+                               $voucher_type = 'P3';
+                       }
+                       else if ($_ticket['order_id'] >= 45250000 && 
$_ticket['order_id'] <= 45499999)
+                       {
+                               $voucher_type = 'P4';
+                       }
+                       else
+                       {
+                               throw new Exception("Ordrenummer 
'{$_ticket['order_id']}' er utenfor serien");
+                       }
+
+
                        $param = array(
+                               'voucher_type'  => $voucher_type,
                                'dim0' => $_ticket['b_account_id'],             
        // Art
                                'dim1' => $_ticket['ecodimb'],                  
        // Ansvar
                                'dim2' => $_ticket['service_id'] ? 
$_ticket['service_id'] : 9, // Tjeneste liste 30 stk, default 9
@@ -146,13 +176,19 @@
                                'buyer' => $buyer,
                                'lines' => array(
                                        array(
-                                               'unspsc_code' => 
$_ticket['unspsc_code'],
-                                               'descr' => 
strip_tags($_ticket['order_descr'])
+                                               'unspsc_code' => 
$_ticket['unspsc_code'] ? $_ticket['unspsc_code'] : 'UN-72000000',
+//                                             'descr' => 
$_ticket['order_descr'] ? strip_tags($_ticket['order_descr']) : 'Bygnings-, 
konstruksjons- og vedlikeholdstjenester'
+                                               'descr' => 
$_ticket['unspsc_code'] ? $this->get_unspsc_code_descr($_ticket['unspsc_code']) 
: 'Bygnings-, konstruksjons- og vedlikeholdstjenester',
+                                               'price' => $price,
                                        )
                                )
                        );
-
-                       $exporter_ordre = new 
BkBygg_exporter_data_til_Agresso(array('order_id' => $_ticket['order_id']));
+       
+                       $exporter_ordre = new 
BkBygg_exporter_data_til_Agresso(array(
+                               'order_id' => $_ticket['order_id'],
+                               'voucher_type' => $voucher_type
+                               )
+                       );
                        $exporter_ordre->create_transfer_xml($param);
 
                        $export_ok = $exporter_ordre->transfer($this->debug);
@@ -170,4 +206,11 @@
                        $now = time();
                        $GLOBALS['phpgw']->db->query("UPDATE fm_tts_tickets SET 
order_sent = {$now} WHERE id = {$id}");
                }
+
+               private function get_unspsc_code_descr( $unspsc_code )
+               {
+                       $GLOBALS['phpgw']->db->query("SELECT name FROM 
fm_unspsc_code WHERE id = '{$unspsc_code}'");
+                       $GLOBALS['phpgw']->db->next_record();
+                       return $GLOBALS['phpgw']->db->f('name');
+               }
        }
\ No newline at end of file




reply via email to

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