fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [8871] Merge 8868:8870 from trunk


From: Sigurd Nes
Subject: [Fmsystem-commits] [8871] Merge 8868:8870 from trunk
Date: Tue, 14 Feb 2012 20:18:00 +0000

Revision: 8871
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=8871
Author:   sigurdne
Date:     2012-02-14 20:17:59 +0000 (Tue, 14 Feb 2012)
Log Message:
-----------
Merge 8868:8870 from trunk

Modified Paths:
--------------
    branches/Version-1_0-branch/phpgwapi/inc/class.db_pdo.inc.php
    
branches/Version-1_0-branch/property/inc/cron/default/Import_fra_basware_X205.php

Property Changed:
----------------
    branches/Version-1_0-branch/


Property changes on: branches/Version-1_0-branch
___________________________________________________________________
Modified: svn:mergeinfo
   - 
/trunk:6439-6441,6443,6445-6447,6449-6464,6466-6468,6470-6474,6476-6477,6479-6480,6483-6488,6490-6491,6493-6494,6496-6501,6503-6504,6506,6508,6510-6511,6513,6515-6516,6518,6520-6524,6526-6528,6533-6534,6536-6541,6543-6565,6567,6569,6571-6576,6578,6580-6586,6588-6596,6598-6600,6602-6604,6606-6607,6609-6611,6613-6625,6629-6639,6641-6643,6645-6646,6648,6650-6654,6656-6659,6661-6663,6665-6666,6668-6669,6672-6673,6675,6677-6678,6680,6682-6686,6688-6717,6719,6721-6722,6724-6728,6730,6732-6734,6736-6739,6741,6743,6745-6746,6748-6756,6758-6762,6764,6766-6788,6790,6792-6798,6800-6814,6816-6819,6821-6822,6824-6826,6828-6837,6839,6841,6843-6849,6851,6853-6869,6871-6874,6876-6877,6879,6881,6883,6885-6886,6888-6893,6895-6897,6899-6901,6903,6905-6907,6909,6911-6929,6931-6936,6938-6947,6949,6951,6953,6955-6956,6958-6959,6961-6968,6970-6971,6973-6974,6976-6978,6980,6982-7017,7019-7025,7027-7035,7037-7039,7041-7045,7047-7055,7057,7059-7065,7067-7069,7071,7073,7075-7076,7078,7080-7081,7083,7085,7087,7089-7097,7099-7102,7104-7105,7107-7111,7113-7120,7122-7124,7126-7129,7131,7133-7141,7143,7145-7146,7148-7150,7152-7153,7155-7158,7160-7164,7166-7167,7169-7170,7172,7174,7176,7178,7180-7181,7183,7185,7187-7188,7190,7192-7196,7198-7199,7201-7203,7205,7207,7209-7210,7212,7214,7216-7217,7219-7222,7224-7226,7228-7229,7231,7233-7234,7236-7238,7240-7241,7243-7244,7246,7248,7250,7252-7256,7258-7259,7261-7264,7266-7273,7275-7279,7281-7332,7334-7338,7340-7348,7350,7352-7353,7355-7361,7363-7366,7368-7370,7372,7374,7376,7378,7380-7386,7388-7400,7402,7404-7433,7435-7439,7441-7446,7448-7458,7460-7469,7471-7483,7485-7487,7489-7490,7492,7494,7496-7497,7499,7501-7502,7504,7506-7507,7509-7511,7513-7517,7519-7521,7523,7525,7527-7529,7531,7533,7535-7538,7540-7542,7544-7549,7551-7552,7554-7561,7563,7565,7567-7573,7575-7578,7580-7584,7586-7591,7593-7624,7627-7636,7638-7656,7658-7718,7720-7732,7734,7736,7738-7750,7754-7759,7761-7767,7769-7780,7782,7784-7809,7811-7812,7814-7835,7837-7847,7849-7887,7889-7895,7897,7899,7901,7903-7905,7907-7921,7923-7925,7927-7933,7935,7937-7952,7954-7968,7970-7974,7976,7978-7979,7981-7982,7984-7988,7990-7992,7994-8041,8043-8066,8068-8087,8089,8091-8108,8110-8124,8126-8129,8131,8133-8150,8152-8154,8156-8162,8164-8167,8169-8170,8172-8179,8181,8183-8196,8198-8207,8209-8211,8213-8214,8216-8217,8219-8220,8222,8224-8225,8227-8247,8249,8251,8253-8282,8284-8352,8354-8368,8370-8396,8398-8430,8432,8434-8440,8442-8445,8447-8453,8455-8456,8458,8460,8462-8464,8466-8473,8475-8479,8481,8483-8501,8503-8523,8525,8527-8531,8533,8535-8536,8538-8550,8552-8554,8556-8557,8559-8579,8581-8587,8589,8591-8592,8594-8595,8597-8601,8603-8610,8612-8613,8615,8617,8619-8645,8647-8650,8652-8661,8663-8666,8668-8669,8671-8683,8685-8691,8693-8730,8732-8737,8739,8741-8767,8769,8771-8772,8774,8776-8797,8799-8812,8814-8819,8821,8823-8833,8835-8837,8839,8841,8843-8849,8852-8858,8860-8867
   + 
/trunk:6439-6441,6443,6445-6447,6449-6464,6466-6468,6470-6474,6476-6477,6479-6480,6483-6488,6490-6491,6493-6494,6496-6501,6503-6504,6506,6508,6510-6511,6513,6515-6516,6518,6520-6524,6526-6528,6533-6534,6536-6541,6543-6565,6567,6569,6571-6576,6578,6580-6586,6588-6596,6598-6600,6602-6604,6606-6607,6609-6611,6613-6625,6629-6639,6641-6643,6645-6646,6648,6650-6654,6656-6659,6661-6663,6665-6666,6668-6669,6672-6673,6675,6677-6678,6680,6682-6686,6688-6717,6719,6721-6722,6724-6728,6730,6732-6734,6736-6739,6741,6743,6745-6746,6748-6756,6758-6762,6764,6766-6788,6790,6792-6798,6800-6814,6816-6819,6821-6822,6824-6826,6828-6837,6839,6841,6843-6849,6851,6853-6869,6871-6874,6876-6877,6879,6881,6883,6885-6886,6888-6893,6895-6897,6899-6901,6903,6905-6907,6909,6911-6929,6931-6936,6938-6947,6949,6951,6953,6955-6956,6958-6959,6961-6968,6970-6971,6973-6974,6976-6978,6980,6982-7017,7019-7025,7027-7035,7037-7039,7041-7045,7047-7055,7057,7059-7065,7067-7069,7071,7073,7075-7076,7078,7080-7081,7083,7085,7087,7089-7097,7099-7102,7104-7105,7107-7111,7113-7120,7122-7124,7126-7129,7131,7133-7141,7143,7145-7146,7148-7150,7152-7153,7155-7158,7160-7164,7166-7167,7169-7170,7172,7174,7176,7178,7180-7181,7183,7185,7187-7188,7190,7192-7196,7198-7199,7201-7203,7205,7207,7209-7210,7212,7214,7216-7217,7219-7222,7224-7226,7228-7229,7231,7233-7234,7236-7238,7240-7241,7243-7244,7246,7248,7250,7252-7256,7258-7259,7261-7264,7266-7273,7275-7279,7281-7332,7334-7338,7340-7348,7350,7352-7353,7355-7361,7363-7366,7368-7370,7372,7374,7376,7378,7380-7386,7388-7400,7402,7404-7433,7435-7439,7441-7446,7448-7458,7460-7469,7471-7483,7485-7487,7489-7490,7492,7494,7496-7497,7499,7501-7502,7504,7506-7507,7509-7511,7513-7517,7519-7521,7523,7525,7527-7529,7531,7533,7535-7538,7540-7542,7544-7549,7551-7552,7554-7561,7563,7565,7567-7573,7575-7578,7580-7584,7586-7591,7593-7624,7627-7636,7638-7656,7658-7718,7720-7732,7734,7736,7738-7750,7754-7759,7761-7767,7769-7780,7782,7784-7809,7811-7812,7814-7835,7837-7847,7849-7887,7889-7895,7897,7899,7901,7903-7905,7907-7921,7923-7925,7927-7933,7935,7937-7952,7954-7968,7970-7974,7976,7978-7979,7981-7982,7984-7988,7990-7992,7994-8041,8043-8066,8068-8087,8089,8091-8108,8110-8124,8126-8129,8131,8133-8150,8152-8154,8156-8162,8164-8167,8169-8170,8172-8179,8181,8183-8196,8198-8207,8209-8211,8213-8214,8216-8217,8219-8220,8222,8224-8225,8227-8247,8249,8251,8253-8282,8284-8352,8354-8368,8370-8396,8398-8430,8432,8434-8440,8442-8445,8447-8453,8455-8456,8458,8460,8462-8464,8466-8473,8475-8479,8481,8483-8501,8503-8523,8525,8527-8531,8533,8535-8536,8538-8550,8552-8554,8556-8557,8559-8579,8581-8587,8589,8591-8592,8594-8595,8597-8601,8603-8610,8612-8613,8615,8617,8619-8645,8647-8650,8652-8661,8663-8666,8668-8669,8671-8683,8685-8691,8693-8730,8732-8737,8739,8741-8767,8769,8771-8772,8774,8776-8797,8799-8812,8814-8819,8821,8823-8833,8835-8837,8839,8841,8843-8849,8852-8858,8860-8867,8869-8870

Modified: branches/Version-1_0-branch/phpgwapi/inc/class.db_pdo.inc.php
===================================================================
--- branches/Version-1_0-branch/phpgwapi/inc/class.db_pdo.inc.php       
2012-02-14 20:15:10 UTC (rev 8870)
+++ branches/Version-1_0-branch/phpgwapi/inc/class.db_pdo.inc.php       
2012-02-14 20:17:59 UTC (rev 8871)
@@ -585,6 +585,11 @@
                */
                public function transaction_abort()
                {
+/*
+                       $bt = debug_backtrace();
+                       echo "<b>db::{$bt[0]['function']} Called from file: 
{$bt[0]['file']} line: {$bt[0]['line']}</b><br/>";
+                       unset($bt);
+*/
                        $ret = false;
 
                        if($this->Transaction)

Modified: 
branches/Version-1_0-branch/property/inc/cron/default/Import_fra_basware_X205.php
===================================================================
--- 
branches/Version-1_0-branch/property/inc/cron/default/Import_fra_basware_X205.php
   2012-02-14 20:15:10 UTC (rev 8870)
+++ 
branches/Version-1_0-branch/property/inc/cron/default/Import_fra_basware_X205.php
   2012-02-14 20:17:59 UTC (rev 8871)
@@ -148,9 +148,72 @@
                        $GLOBALS['phpgw']->xslttpl->pp();
                }
 
+
+               protected function check_archive()
+               {
+                       $dirname = 
$this->config->config_data['import']['local_path'];
+
+                       if ( preg_match('/\./', $dirname) 
+                        || !is_dir($dirname) )
+                       {
+                               return array();
+                       }
+
+                       $archive = "{$dirname}/archive";
+                       $file_list = array();
+                       $dir = new DirectoryIterator($archive); 
+                       if ( is_object($dir) )
+                       {
+                               foreach ( $dir as $file )
+                               {
+                                       if ( $file->isDot()
+                                               || !$file->isFile()
+                                               || !$file->isReadable()
+                                               || strcasecmp( end( explode( 
".", $file->getPathname() ) ), 'xml' ) != 0 )
+                                       {
+                                               continue;
+                                       }
+
+                                       $file_list[] = (string) $file;
+                               }
+                       }
+
+                       foreach($file_list as $file)
+                       {
+                               $file_parts = explode('_', basename($file, 
'.xml'));
+                               $external_ref = $file_parts[2];
+
+                               $duplicate = false;
+                               $sql = "SELECT bilagsnr, external_ref FROM 
fm_ecobilag WHERE external_ref = '{$external_ref}'";
+                               $this->db->query($sql,__LINE__,__FILE__);
+                               if($this->db->next_record())
+                               {
+                                       $duplicate = true;
+                               }
+
+                               $sql = "SELECT bilagsnr FROM fm_ecobilagoverf 
WHERE external_ref = '{$external_ref}'";
+                               $this->db->query($sql,__LINE__,__FILE__);
+                               if($this->db->next_record())
+                               {
+                                       $duplicate = true;
+                               }
+
+                               if( !$duplicate )
+                               {
+                                       rename("{$archive}/{$file}", 
"{$dirname}/{$file}");
+                                       $this->receipt['message'][] = 
array('msg' => "fil tilbakeført fra arkiv til importkø: {$external_ref}");
+                               }
+                       }
+               }
+
                public function execute($cron='')
                {
-                       $this->get_files();
+                       
if(isset($this->config->config_data['import']['check_archive']) && 
$this->config->config_data['import']['check_archive'])
+                       {
+                               $this->check_archive();                 
+                       }               
+
+//                     $this->get_files();
                        $dirname = 
$this->config->config_data['import']['local_path'];
                        // prevent path traversal
                        if ( preg_match('/\./', $dirname) 
@@ -181,6 +244,7 @@
                        {
                                foreach($file_list as $file)
                                {
+                                       $this->db->transaction_begin();
                                        $bilagsnr = $this->import($file);
                                        if ($bilagsnr)
                                        {
@@ -189,14 +253,27 @@
                                                $movefrom = 
"{$dirname}/{$_file}";
                                                $moveto = 
"{$dirname}/archive/{$_file}";
 
-                                               @unlink($moveto);//in case of 
duplicates
+                                               if( is_file($moveto) )
+                                               {
+                                                       @unlink($moveto);//in 
case of duplicates
+                                               }
+
                                                $ok = @rename($movefrom, 
$moveto);
                                                if(!$ok) // Should never happen.
                                                {
-                                                       
$this->invoice->delete($bilagsnr);
+                                               //      
$this->invoice->delete($bilagsnr);
+                                                       
$this->db->transaction_abort();
                                                        
$this->receipt['error'][] = array('msg' => "Kunne ikke flytte importfil til 
arkiv, Bilag {$bilagsnr} er slettet");
                                                }
+                                               else
+                                               {
+                                                       
$this->db->transaction_commit();
+                                               }
                                        }
+                                       else
+                                       {
+                                               $this->db->transaction_abort(); 
                                
+                                       }
                                }
                        }
                        else
@@ -337,6 +414,7 @@
 //                     $valid_data= False;
 
                        $buffer = array();
+                       $bilagsnr = false;
 
                        $xmlparse = CreateObject('property.XmlToArray');
                        $xmlparse->setEncoding('UTF-8');
@@ -344,199 +422,193 @@
 
                        set_time_limit(300);
 
-                       if (isset($var_result['INVOICES']) AND 
is_array($var_result['INVOICES']))
+                       if (isset($var_result['INVOICES']) && 
is_array($var_result['INVOICES']))
                        {
                                $transferdate =  str_replace('.', '-', 
$var_result['TRANSACTIONINFORMATION'][0]['TRANSFERDATE']);// 2009.05.28
                                $transfertime =  
$var_result['TRANSACTIONINFORMATION'][0]['TRANSFERTIME'];// 13:10:28
                                $regtid         = 
date($this->datetimeformat,strtotime("{$transferdate} {$transfertime}"));
 
                                $i = 0;
-                               foreach ($var_result['INVOICES'] as $dummy => 
$entry)
-                               {
-                                       $_data = 
$entry['INVOICE'][0]['INVOICEHEADER'][0];
+                               $_data = 
$var_result['INVOICES'][0]['INVOICE'][0]['INVOICEHEADER'][0];
 
 //_debug_array($_data);
 //die();
 
-                                       $_data['KEY']; // => 1400050146
-                                       $_data['ARRIVAL']; // => 2009.05.28
-                                       $_data['CLIENT.CODE']; // => 14
-                                       $_data['EXCHANGERATE']; // => 1
-                                       $_data['LOCALAMOUNT']; // => 312500
-                                       $_data['LOCALVATAMOUNT']; // => 62500
-                                       $_data['PAYAMOUNT']; // => 0
-                                       $_data['POSTATUSUPDATED']; // => 0
-                                       $_data['PURCHASEORDERSTATUS.CODE']; // 
=> WaitForMatch
-                                       $_data['SUPPLIER.BANKGIRO']; // => 
70580621110
-                                       $_data['VATAMOUNT']; // => 62500
+                               $_data['KEY']; // => 1400050146
+                               $_data['ARRIVAL']; // => 2009.05.28
+                               $_data['CLIENT.CODE']; // => 14
+                               $_data['EXCHANGERATE']; // => 1
+                               $_data['LOCALAMOUNT']; // => 312500
+                               $_data['LOCALVATAMOUNT']; // => 62500
+                               $_data['PAYAMOUNT']; // => 0
+                               $_data['POSTATUSUPDATED']; // => 0
+                               $_data['PURCHASEORDERSTATUS.CODE']; // => 
WaitForMatch
+                               $_data['SUPPLIER.BANKGIRO']; // => 70580621110
+                               $_data['VATAMOUNT']; // => 62500
 
-                                       $bilagsnr_ut = 
isset($_data['VOUCHERID']) ? $_data['VOUCHERID'] : ''; // FIXME: innkommende 
bilagsnummer?
+                               $bilagsnr_ut = isset($_data['VOUCHERID']) ? 
$_data['VOUCHERID'] : ''; // FIXME: innkommende bilagsnummer?
 
-                                       $order_id               = 
$_data['PURCHASEORDERNO'];
-                                       $fakturanr              = 
$_data['SUPPLIERREF'];//$_data['KEY'];
-                                       $fakturadato    = 
date($this->dateformat,strtotime(str_replace('.', '-', $_data['INVOICEDATE'])));
-                                       $forfallsdato   = 
date($this->dateformat,strtotime(str_replace('.', '-', $_data['MATURITY'])));
-                                       $periode                = 
'';//date('Ym',strtotime(str_replace('.', '-', $_data['INVOICEDATE'])));
-                                       $belop                  = 
$_data['AMOUNT']/100;
+                               $order_id               = 
$_data['PURCHASEORDERNO'];
+                               $fakturanr              = 
$_data['SUPPLIERREF'];//$_data['KEY'];
+                               $fakturadato    = 
date($this->dateformat,strtotime(str_replace('.', '-', $_data['INVOICEDATE'])));
+                               $forfallsdato   = 
date($this->dateformat,strtotime(str_replace('.', '-', $_data['MATURITY'])));
+                               $periode                = 
'';//date('Ym',strtotime(str_replace('.', '-', $_data['INVOICEDATE'])));
+                               $belop                  = $_data['AMOUNT']/100;
 
-                                       if( $belop < 0 )
-                                       {
-                                               $buffer[$i]['artid'] = 2;
-                                       }
-                                       else
-                                       {
-                                               $buffer[$i]['artid'] = 1;
-                                       }
+                               if( $belop < 0 )
+                               {
+                                       $buffer[$i]['artid'] = 2;
+                               }
+                               else
+                               {
+                                       $buffer[$i]['artid'] = 1;
+                               }
 
-                                       $kidnr  = $_data['KIDNO'];
+                               $kidnr  = $_data['KIDNO'];
 
-                                       if($order_id)
-                                       {
-                                               $buffer[$i]['project_id'] = 
$this->soXport->get_project($order_id);
-                                       }
+                               if($order_id)
+                               {
+                                       $buffer[$i]['project_id'] = 
$this->soXport->get_project($order_id);
+                               }
 
-                                       $buffer[$i]['external_ref']             
= $_data['SCANNINGNO'];
-                                       $buffer[$i]['pmwrkord_code']    = 
$order_id;
-                                       $buffer[$i]['fakturanr']                
= $fakturanr;
-                                       $buffer[$i]['periode']                  
= $periode;
-                                       $buffer[$i]['forfallsdato']             
= $forfallsdato;
-                                       $buffer[$i]['fakturadato']              
= $fakturadato;
-                                       $buffer[$i]['belop']                    
= $belop;
-                                       $buffer[$i]['currency']                 
= $_data['CURRENCY.CURRENCYID'];
-                                       $buffer[$i]['godkjentbelop']    = 
$belop;
+                               $buffer[$i]['external_ref']             = 
$_data['SCANNINGNO'];
+                               $buffer[$i]['pmwrkord_code']    = $order_id;
+                               $buffer[$i]['fakturanr']                = 
$fakturanr;
+                               $buffer[$i]['periode']                  = 
$periode;
+                               $buffer[$i]['forfallsdato']             = 
$forfallsdato;
+                               $buffer[$i]['fakturadato']              = 
$fakturadato;
+                               $buffer[$i]['belop']                    = 
$belop;
+                               $buffer[$i]['currency']                 = 
$_data['CURRENCY.CURRENCYID'];
+                               $buffer[$i]['godkjentbelop']    = $belop;
 
-                                       $buffer[$i]['kidnr']                    
= $kidnr;
-                                       $buffer[$i]['bilagsnr_ut']              
= $bilagsnr_ut;
-                                       $buffer[$i]['referanse']                
= "ordre: {$order_id}";
+                               $buffer[$i]['kidnr']                    = 
$kidnr;
+                               $buffer[$i]['bilagsnr_ut']              = 
$bilagsnr_ut;
+                               $buffer[$i]['referanse']                = 
"ordre: {$order_id}";
 
-                                       $order_info = 
$this->get_order_info($order_id);
+                               $order_info = $this->get_order_info($order_id);
 
-                                       $buffer[$i]['dimb'] = 
$order_info['dimb'];
-                                       $buffer[$i]['dima'] = 
$order_info['dima'];
-                                       $buffer[$i]['loc1'] = 
$order_info['loc1'];
+                               $buffer[$i]['dimb'] = $order_info['dimb'];
+                               $buffer[$i]['dima'] = $order_info['dima'];
+                               $buffer[$i]['loc1'] = $order_info['loc1'];
 
-                                       $buffer[$i]['mvakode'] = $this->mvakode;
+                               $buffer[$i]['mvakode'] = $this->mvakode;
 
-                                       if($buffer[$i]['loc1'] && 
$this->auto_tax)
+                               if($buffer[$i]['loc1'] && $this->auto_tax)
+                               {
+                                       $mvakode = 
$this->soXport->auto_tax($buffer[$i]['loc1']);
+
+                                       if($mvakode)
                                        {
-                                               $mvakode = 
$this->soXport->auto_tax($buffer[$i]['loc1']);
-
-                                               if($mvakode)
-                                               {
-                                                       $buffer[$i]['mvakode'] 
= $mvakode;
-                                               }
+                                               $buffer[$i]['mvakode'] = 
$mvakode;
                                        }
+                               }
 
-                                       $duplicate = false;
-                                       $sql = "SELECT bilagsnr, external_ref 
FROM fm_ecobilag WHERE external_ref = '{$_data['SCANNINGNO']}'";
-                                       
$this->db->query($sql,__LINE__,__FILE__);
-                                       if($this->db->next_record())
+                               $duplicate = false;
+                               $sql = "SELECT bilagsnr, external_ref FROM 
fm_ecobilag WHERE external_ref = '{$_data['SCANNINGNO']}'";
+                               $this->db->query($sql,__LINE__,__FILE__);
+                               if($this->db->next_record())
+                               {
+                                       $duplicate = true;
+                                       $bilagsnr = $this->db->f('bilagsnr');
+                                       $this->receipt['message'][] = 
array('msg' => "Ikke importert duplikat til arbeidsregister: 
{$_data['SCANNINGNO']}");
+                               }
+
+                               $sql = "SELECT bilagsnr, bilagsnr_ut FROM 
fm_ecobilagoverf WHERE external_ref = '{$_data['SCANNINGNO']}'";
+                               $this->db->query($sql,__LINE__,__FILE__);
+                               if($this->db->next_record())
+                               {
+                                       $duplicate = true;
+                                       $_bilagsnr_ut = 
$this->db->f('bilagsnr_ut');
+                                       $bilagsnr = $this->db->f('bilagsnr');
+                                       $receipt = 
$this->export->RullTilbake(false,false,$_bilagsnr_ut);
+
+                                       if( isset($receipt['message']) )
                                        {
-                                               $duplicate = true;
-                                               $bilagsnr = 
$this->db->f('bilagsnr');
-                                               $this->receipt['message'][] = 
array('msg' => "Ikke importert duplikat til arbeidsregister: 
{$_data['SCANNINGNO']}");
+                                               $this->receipt['message'][] = 
array('msg' => "Bilag rullet tilbake fra historikk : {$_bilagsnr_ut}");
                                        }
-
-                                       $sql = "SELECT bilagsnr, bilagsnr_ut 
FROM fm_ecobilagoverf WHERE external_ref = '{$_data['SCANNINGNO']}'";
-                                       
$this->db->query($sql,__LINE__,__FILE__);
-                                       if($this->db->next_record())
+                                       else
                                        {
-                                               $duplicate = true;
-                                               $_bilagsnr_ut = 
$this->db->f('bilagsnr_ut');
-                                               $bilagsnr = 
$this->db->f('bilagsnr');
-                                               $receipt = 
$this->export->RullTilbake(false,false,$_bilagsnr_ut);
-
-                                               if( isset($receipt['message']) )
-                                               {
-                                                       
$this->receipt['message'][] = array('msg' => "Bilag rullet tilbake fra 
historikk : {$_bilagsnr_ut}");
-                                               }
-                                               else
-                                               {
-                                                       
$this->receipt['error'][] = array('msg' => "Bilag ikke rullet tilbake fra 
historikk : {$_bilagsnr_ut}, extern ref: {$_data['SCANNINGNO']}");
-                                               }
-                                               unset($_bilagsnr_ut);
+                                               $this->receipt['error'][] = 
array('msg' => "Bilag ikke rullet tilbake fra historikk : {$_bilagsnr_ut}, 
extern ref: {$_data['SCANNINGNO']}");
                                        }
+                                       unset($_bilagsnr_ut);
+                               }
 
-                                       $vendor_id = $_data['SUPPLIER.CODE'];
+                               $vendor_id = $_data['SUPPLIER.CODE'];
 
-                                       $sql = 'SELECT id FROM fm_vendor WHERE 
id = ' . (int) $vendor_id;
-                                       
$this->db->query($sql,__LINE__,__FILE__);
+                               $sql = 'SELECT id FROM fm_vendor WHERE id = ' . 
(int) $vendor_id;
+                               $this->db->query($sql,__LINE__,__FILE__);
+                                       
+                               if(!$_data['SUPPLIER.CODE'])
+                               {
+                                       $this->receipt['error'][] = array('msg' 
=> "LeverandørId ikke angitt for faktura: {$_data['SCANNINGNO']}");
+                                       $this->skip_import = true;
+                               }
+                               else if(!$this->db->next_record())
+                               {
+                                       $this->receipt['error'][] = array('msg' 
=> "Ikke gyldig LeverandørId: {$_data['SUPPLIER.CODE']}, Faktura: 
{$_data['SCANNINGNO']}");
+                                       $this->skip_import = true;
 
-                                       
-                                       if(!$_data['SUPPLIER.CODE'])
+                                       $to = 
isset($this->config->config_data['import']['email_on_error']) && 
$this->config->config_data['import']['email_on_error'] ? 
$this->config->config_data['import']['email_on_error'] : '';
+
+                                       if($to)
                                        {
-                                               $this->receipt['error'][] = 
array('msg' => "LeverandørId ikke angitt for faktura: {$_data['SCANNINGNO']}");
-                                               $this->skip_import = true;
-                                       }
-                                       else if(!$this->db->next_record())
-                                       {
-                                               $this->receipt['error'][] = 
array('msg' => "Ikke gyldig LeverandørId: {$_data['SUPPLIER.CODE']}, Faktura: 
{$_data['SCANNINGNO']}");
-                                               $this->skip_import = true;
+                                               $body = "Ikke gyldig 
leverandør, id: {$_data['SUPPLIER.CODE']}</br>";
+                                               $body .= '<a href ="' . 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'property.uigeneric.edit', 'appname' => 'property', 'type' => 
'vendor'),false,true).'">Link til å legge inn ny leverandør</a>';
 
-                                               $to = 
isset($this->config->config_data['import']['email_on_error']) && 
$this->config->config_data['import']['email_on_error'] ? 
$this->config->config_data['import']['email_on_error'] : '';
-
-                                               if($to)
+                                               try
                                                {
-                                                       $body = "Ikke gyldig 
leverandør, id: {$_data['SUPPLIER.CODE']}</br>";
-                                                       $body .= '<a href ="' . 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'property.uigeneric.edit', 'appname' => 'property', 'type' => 
'vendor'),false,true).'">Link til å legge inn ny leverandør</a>';
-
-                                                       try
+                                                       $rc = 
$this->send->msg('email', $to, 'Ikke gyldig leverandør ved import av faktura 
til Portico', $body, '', '', '','','','html');
+                                                       if($rc)
                                                        {
-                                                               $rc = 
$this->send->msg('email', $to, 'Ikke gyldig leverandør ved import av faktura 
til Portico', $body, '', '', '','','','html');
-                                                               if($rc)
-                                                               {
-                                                                       
$this->receipt['message'][] = array('msg'=> "epost sendt til {$to}");           
                                        
-                                                               }
+                                                               
$this->receipt['message'][] = array('msg'=> "epost sendt til {$to}");           
                                        
                                                        }
-                                                       catch 
(phpmailerException $e)
-                                                       {
-                                                               
$this->receipt['error'][] = array('msg' => $e->getMessage());
-                                                       }
                                                }
-                                       }
-                                       else
-                                       {
-                                               if ($order_info['vendor_id'] != 
$vendor_id)
+                                               catch (phpmailerException $e)
                                                {
-                                                       
$this->receipt['message'][] = array('msg' => 'Ikke samsvar med leverandør på 
bestilling og mottatt faktura');
+                                                       
$this->receipt['error'][] = array('msg' => $e->getMessage());
                                                }
                                        }
-
-                                       if($this->auto_tax)
+                               }
+                               else
+                               {
+                                       if ($order_info['vendor_id'] != 
$vendor_id)
                                        {
-                                               $buffer[$i]['mvakode'] = 
$this->soXport->tax_b_account_override($buffer[$i]['mvakode'], 
$order_info['spbudact_code']);
-                                               $buffer[$i]['mvakode'] = 
$this->soXport->tax_vendor_override($buffer[$i]['mvakode'], $vendor_id);
+                                               $this->receipt['message'][] = 
array('msg' => 'Ikke samsvar med leverandør på bestilling og mottatt faktura');
                                        }
+                               }
 
-                                       $buffer[$i]['kostra_id'] = 
$this->default_kostra_id;//$this->soXport->get_kostra_id($buffer[$i]['loc1']);
+                               if($this->auto_tax)
+                               {
+                                       $buffer[$i]['mvakode'] = 
$this->soXport->tax_b_account_override($buffer[$i]['mvakode'], 
$order_info['spbudact_code']);
+                                       $buffer[$i]['mvakode'] = 
$this->soXport->tax_vendor_override($buffer[$i]['mvakode'], $vendor_id);
+                               }
 
-                                       $merknad = '';
+                               $buffer[$i]['kostra_id'] = 
$this->default_kostra_id;//$this->soXport->get_kostra_id($buffer[$i]['loc1']);
 
-                                       $buffer[$i]['merknad'] = $merknad;
-                                       $buffer[$i]['splitt'] = $this->splitt;
-                                       $buffer[$i]['kildeid'] = $this->kildeid;
-                                       $buffer[$i]['spbudact_code'] = 
$order_info['spbudact_code'];
-                                       $buffer[$i]['typeid'] = 
isset($invoice_common['type']) && $invoice_common['type'] ? 
$invoice_common['type'] : 1;
-                                       $buffer[$i]['regtid'] = $regtid;
+                               $merknad = '';
 
-                                       $buffer[$i]['spvend_code'] = $vendor_id;
+                               $buffer[$i]['merknad'] = $merknad;
+                               $buffer[$i]['splitt'] = $this->splitt;
+                               $buffer[$i]['kildeid'] = $this->kildeid;
+                               $buffer[$i]['spbudact_code'] = 
$order_info['spbudact_code'];
+                               $buffer[$i]['typeid'] = 
isset($invoice_common['type']) && $invoice_common['type'] ? 
$invoice_common['type'] : 1;
+                               $buffer[$i]['regtid'] = $regtid;
 
-                                       if(isset($order_info['janitor']) && 
$order_info['janitor'])
-                                       {
-                                               $buffer[$i]['oppsynsmannid'] = 
$order_info['janitor'];
-                                       }
+                               $buffer[$i]['spvend_code'] = $vendor_id;
 
-                                       if(isset($order_info['supervisor']) && 
$order_info['supervisor'])
-                                       {
-                                               $buffer[$i]['saksbehandlerid']  
        = $order_info['supervisor'];
-                                       }
+                               if(isset($order_info['janitor']) && 
$order_info['janitor'])
+                               {
+                                       $buffer[$i]['oppsynsmannid'] = 
$order_info['janitor'];
+                               }
 
-                                       
if(isset($order_info['budget_responsible']) && 
$order_info['budget_responsible'])
-                                       {
-                                               
$buffer[$i]['budsjettansvarligid']      = $order_info['budget_responsible'];
-                                       }
+                               if(isset($order_info['supervisor']) && 
$order_info['supervisor'])
+                               {
+                               $buffer[$i]['saksbehandlerid']          = 
$order_info['supervisor'];
+                               }
 
-                                       $i++;
+                               if(isset($order_info['budget_responsible']) && 
$order_info['budget_responsible'])
+                               {
+                                       $buffer[$i]['budsjettansvarligid']      
= $order_info['budget_responsible'];
                                }
                        }
 
@@ -581,7 +653,30 @@
 
                                if(!$duplicate)
                                {
-                                       return $this->import_end_file($buffer);
+                                       
$GLOBALS['phpgw']->db->Exception_On_Error = true;
+                                       try
+                                       {
+                                               $bilagsnr = 
$this->import_end_file($buffer);
+                                       }
+                                       catch (Exception $e)
+                                       {
+                                               if($e)
+                                               {
+                                                       
$GLOBALS['phpgw']->log->error(array(
+                                                               'text'  => 
'import_fra_basware_X205::import() : error when trying to execute 
import_end_file(): %1',
+                                                               'p1'    => 
$e->getMessage(),
+                                                               'p2'    => '',
+                                                               'line'  => 
__LINE__,
+                                                               'file'  => 
__FILE__
+                                                       ));
+
+                                                       
$this->receipt['error'][] = array('msg'=> $e->getMessage());
+                                               }
+                                               return false;
+                                       }
+                                       
+                                       
$GLOBALS['phpgw']->db->Exception_On_Error = false;
+                                       return $bilagsnr;
                                }
                                else
                                {
@@ -629,11 +724,13 @@
                                $supervisor_user_id                             
        = $this->responsible->get_contact_user_id($supervisor_contact_id);
                                $order_info['supervisor']                       
= $GLOBALS['phpgw']->accounts->get($supervisor_user_id)->lid;
 
+/*
                                $prefs = 
$this->bocommon->create_preferences('property', $supervisor_user_id);
                                if($prefs['email'])
                                {
                                        $toarray[] = $prefs['email'];
                                }
+*/
                        }
 
                        $criteria_budget_responsible            = 
array('ecodimb' => $order_info['dimb'], 'cat_id' => $this->budsjettansvarlig); 
//anviser
@@ -669,7 +766,7 @@
                        $num = $this->soXport->add($buffer);
                        if($num > 0)
                        {
-                               $this->receipt['message'][]= array('msg' => 
lang('Successfully imported %1 records into your invoice register.',$num).' 
'.lang('ID').': '. $buffer[0]['bilagsnr']);
+                               $this->receipt['message'][]= array('msg' => 
"Importert {$num} poster til bilag {$buffer[0]['bilagsnr']}, ref: 
{$buffer[0]['external_ref']}");
                                return $buffer[0]['bilagsnr'];
                        }
                        return false;




reply via email to

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