[20957] Fix: tiny fix on integration with external accountingsystem

Sigurd Nes <[email protected]> Wed, 13 Jan 2010 19:13:01 +0000
Newsgroups gmane.comp.web.phpgroupware.cvs
Message-ID <[email protected]>
Revision: 20957
          http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=20957
Author:   sigurdne
Date:     2010-01-13 19:13:01 +0000 (Wed, 13 Jan 2010)
Log Message:
-----------
Fix: tiny fix on integration with external accountingsystem

Modified Paths:
--------------
    people/sigurdne/modules/property/trunk/inc/cron/default/Import_fra_basware_X205.php
    people/sigurdne/modules/property/trunk/inc/export/default/Basware_X114

Modified: people/sigurdne/modules/property/trunk/inc/cron/default/Import_fra_basware_X205.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/cron/default/Import_fra_basware_X205.php	2010-01-13 19:11:38 UTC (rev 20956)
+++ people/sigurdne/modules/property/trunk/inc/cron/default/Import_fra_basware_X205.php	2010-01-13 19:13:01 UTC (rev 20957)
@@ -24,7 +24,7 @@
 	* @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/
 	* @package property
 	* @subpackage import
- 	* @version $Id: Import_fra_basware_X205.php 4418 2009-12-25 19:30:58Z sigurd $
+ 	* @version $Id: Import_fra_basware_X205.php 4446 2010-01-06 13:59:32Z sigurd $
 	*/
 
 	/**
@@ -337,7 +337,7 @@
 
 					$buffer[$i]['kostra_id'] = $this->default_kostra_id;//$this->soXport->get_kostra_id($buffer[$i]['loc1']);
 					
-					$merknad = "lag meg ein link til bilde av faktura - ref: {$_data['SCANNINGNO']}";
+					$merknad = '';
 					
 					$buffer[$i]['merknad'] = $merknad;
 					$buffer[$i]['splitt'] = $this->splitt;

Modified: people/sigurdne/modules/property/trunk/inc/export/default/Basware_X114
===================================================================
--- people/sigurdne/modules/property/trunk/inc/export/default/Basware_X114	2010-01-13 19:11:38 UTC (rev 20956)
+++ people/sigurdne/modules/property/trunk/inc/export/default/Basware_X114	2010-01-13 19:13:01 UTC (rev 20957)
@@ -24,7 +24,7 @@
 	* @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/
 	* @package property
 	* @subpackage export
- 	* @version $Id: Basware_X114 3375 2009-08-14 11:56:22Z sigurd $
+ 	* @version $Id: Basware_X114 4446 2010-01-06 13:59:32Z sigurd $
 	*/
 
 	/**
@@ -55,7 +55,14 @@
 
 		protected function select_vouchers_to_transfer()
 		{
-			$sql= "SELECT DISTINCT bilagsnr from fm_ecobilag WHERE budsjettsigndato IS NOT NULL AND (saksigndato IS NOT NULL OR oppsynsigndato IS NOT NULL) AND utbetalingsigndato IS NOT NULL";
+			if(isset($this->config->config_data['invoice_approval']) && $this->config->config_data['invoice_approval']== 1)
+			{
+				$sql= 'SELECT DISTINCT bilagsnr from fm_ecobilag WHERE budsjettsigndato IS NOT NULL AND utbetalingsigndato IS NOT NULL';
+			}
+			else
+			{
+				$sql= 'SELECT DISTINCT bilagsnr from fm_ecobilag WHERE budsjettsigndato IS NOT NULL AND (saksigndato IS NOT NULL OR oppsynsigndato IS NOT NULL) AND utbetalingsigndato IS NOT NULL';
+			}
 			$this->db->query($sql,__LINE__,__FILE__);
 			$vouchers = array();
 			while ($this->db->next_record())
@@ -223,6 +230,7 @@
 					'external_ref'			=> $this->db->f('external_ref'),
 				);
 			}
+
 			return $invoice_rollback;
 		}
 
@@ -264,8 +272,8 @@
 				$BilagOverf['item_type'],
 				$BilagOverf['item_id'],
 				$BilagOverf['external_ref'],
-				$this->db->money_format($BilagOverf['belop']),
-				$this->db->money_format($BilagOverf['godkjentbelop'])
+				$BilagOverf['belop'],
+				$BilagOverf['godkjentbelop']
 			);
 			
 			$values	= $this->db->validate_insert($values);
@@ -286,6 +294,7 @@
 			$this->db->query($sql,__LINE__,__FILE__);
 			$this->db->next_record();
 
+			$table = '';
 			$update_paid = '';
 			switch($this->db->f('type'))
 			{
@@ -307,6 +316,10 @@
 			}
 
 			$Belop = $Belop/100;
+			if(!$table)
+			{
+				throw new Exception('ERROR: the order id seems to not correspond with any order type');
+			}
 
 			$sql="UPDATE $table SET $actual_cost_field=$actual_cost_field $operator $Belop $update_paid WHERE id='$order_id'";
 			$this->db->query($sql,__LINE__,__FILE__);
@@ -316,7 +329,7 @@
 		{
 //			$download = 'on';
 //			$download = False;
-			$this->debug=True;
+//			$this->debug=True;
 
 			//Generer batch ID
 			$batchid = $this->soXport->next_batchid();
@@ -415,14 +428,11 @@
 			return $receipt;
 		}
 				
-		protected function LagFilnavn ($batchid)
+		protected function LagFilnavn ($external_ref)
 		{	
 			$fil_katalog = $this->config->config_data['export_path'];
 			$continue = True;
-			$i = 1;
-			do
-			{
-				$Filnavn = $fil_katalog . '/x114_' . date("dmy") . '_' . sprintf("%02s",$i) . '.TXT';
+			$Filnavn = $fil_katalog . "/x114_14_{$external_ref}.xml";
 
 				//Sjekk om filen eksisterer
 				If (!file_exists($Filnavn))
@@ -430,21 +440,24 @@
 					return $Filnavn;
 				}
 
-				$i++;
-			}
-			while  ($continue);
-			
-			//Ingen l\xF8penr er ledige, gi feilmelding
 			return False;
 		}
 		
 		protected function transfer_voucher($batchid, $voucher_id, $download, $force_period_year = '')
 		{
+			
+			//Velg ut alle hoved bilag som skal overf\xF8res
+
+			$oRsBilag = $this->get_voucher($voucher_id);
+
+			if(isset($oRsBilag[0]['external_ref']) && $oRsBilag[0]['external_ref'])
+			{
 			//Bestem filnavn
-			$Filnavn = $this->LagFilnavn($batchid);
+				$Filnavn = $this->LagFilnavn($oRsBilag[0]['external_ref']);
+
 			if (!$Filnavn)
 			{
-				$message='LagFilnavn: Alle loepenr for filnavn er i bruk';
+					$message='LagFilnavn: Filnavn er i bruk';
 				$this->errorhandler($batchid,$message);
 				return $message;
 			}
@@ -466,14 +479,12 @@
 					return $message;
 				}
 			}
+			}
 			
-			//Velg ut alle hoved bilag som skal overf\xF8res
+			$antall = count($oRsBilag);
 
 			$this->db->transaction_begin();
 
-			$oRsBilag = $this->get_voucher($voucher_id);
-			$antall = count($oRsBilag);
-
 			$tranfser_bilag = array($oRsBilag[0]['bilagsnr']);
 			$localtime = phpgwapi_datetime::user_localtime();
 
@@ -585,6 +596,7 @@
 				$oRsOverfBilag				= $line;
 				$oRsOverfBilag['filnavn']	= basename($Filnavn);
 				$oRsOverfBilag['ordrebelop']= $line[$BelopFelt];
+				$oRsOverfBilag['pmwrkord_code'] = $line['order_id'];
 
 				//Kopier verdier  til fm_ecobilagoverf
 				if ($download=='on' && !$this->debug)
@@ -696,8 +708,7 @@
 			$buffer = $xmltool->import_var('INVOICEIMPORT', $export_data,true, true);
 			$buffer = str_replace('<INVOICEIMPORT>', '<INVOICEIMPORT TYPE="INVOICE">', $buffer);
 			
-_debug_array(date('H:i:s', phpgwapi_datetime::user_localtime()));
-			echo $buffer; die();
+//			echo $buffer; 
 //-- fortsett her....									
 
 			//Slett bilaget i fm_ecobilag
@@ -709,25 +720,25 @@
 			}
 				
 			//Fullf\xF8r transaksjon
-			if ($download=='on' && !$this->debug):
+			if ($download=='on' && !$this->debug)
 			{
+				$file_written = false;
 				$fp = fopen($Filnavn, "wb");
 				fwrite($fp,$buffer);
 				
 				if(fclose($fp))
 				{
-					$file_written=True;
+					$file_written=true;
 				}
 
-				if($file_written && $this->config->config_data['invoice_export_method']!='ftp'):
+				if( $file_written && $this->config->config_data['invoice_export_method'] != 'ftp' )
 				{
-					$transfer_ok = True;
+					$transfer_ok = true;
 				}
-				elseif($file_written):
+				else if($file_written)
 				{
 					$transfer_ok = $this->transfer($buffer,$Filnavn,$batchid,$tranfser_bilag);
 				}
-				endif;
 
 				if($transfer_ok)
 				{
@@ -740,20 +751,19 @@
 					$message = 'Noe gikk galt med overforing av godkjendte fakturaer!';				
 				}
 			}
-			else:
+			else
 			{
 				$message = $buffer;
 				$this->db->transaction_abort();
 
 			}
-			endif;
 
 			return $message;
 		}
 		
     	protected function get_voucher($bilagsnr)
     	{
-  	  		$bilagsnr = (int)$bilagsnr;
+  	  		$bilagsnr = $bilagsnr;
   	  		$sql= "SELECT fm_ecobilag.*,fm_ecouser.initials as saksbehandler FROM fm_ecobilag $this->join fm_ecouser ON fm_ecobilag.budsjettansvarligid=fm_ecouser.lid WHERE bilagsnr = {$bilagsnr}";
 			$this->db->query($sql,__LINE__,__FILE__);
 
@@ -792,7 +802,9 @@
 					'splitt'				=> $this->db->f('splitt'),
 					'utbetalingid'			=> $this->db->f('utbetalingid'),
 					'utbetalingsigndato'	=> $this->db->f('utbetalingsigndato'),
-					'saksbehandler'			=> $this->db->f('saksbehandler')
+					'saksbehandler'			=> $this->db->f('saksbehandler'),
+					'external_ref'			=> $this->db->f('external_ref'),
+					'kostra_id'				=> $this->db->f('kostra_id')
 				);
 			}