[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/import/Import_fra_Service_xml, 1.1.2.1
From: |
nomail |
Subject: |
[Phpgroupware-cvs] property/import/Import_fra_Service_xml, 1.1.2.1 |
Date: |
Sun, 23 May 2004 17:01:58 -0000 |
Update of /property/import
Added Files:
Branch: proposal-branch
Import_fra_Service_xml
date: 2004/05/05 07:13:28; author: sigurdne; state: Exp; lines: +208 -0
Log Message:
no message
=====================================================================
<?php
class import_conv
{
var $currentrecord = array(); //used for buffering to allow uid
lines to go first
var $id;
var $kildeid=1;
var $splitt=0;
var $type = 'csv';
var $header_count = 17;
var $soXport;
var $invoice;
var $import = array(
'Bestilling' => 'pmwrkord_code',
'Fakt. Nr' => 'fakturanr',
'Konto' => 'spbudact_code',
'Objekt' => 'dima',
'Fag/Timer/Matr' => 'dimd',
'MVA' => 'mvakode',
'Beløp [kr]' => 'belop'
);
var $header = array('Bestilling','Fakt.
Nr','Konto','Objekt','Fag/Timer/Matr','MVA','Beløp [kr]');
function import_conv()
{
$this->currentapp = 'property';
//$GLOBALS['phpgw_data']['flags']['req_app'];
$this->soXport =
CreateObject($this->currentapp.'_soXport');
$this->invoice =
CreateObject($this->currentapp.'_boinvoice');
$this->bocommon =
CreateObject($this->currentapp.'_bocommon');
$this->dateformat = $this->bocommon->dateformat;
$this->datetimeformat =
$this->bocommon->datetimeformat;
$this->next_bilagsnr =
$this->invoice->next_bilagsnr();
$this->xmltool =
CreateObject('phpgwapi.xmltool');
}
function import($invoice_common,$download)
{
$tsvfile = $invoice_common['tsvfile'];
$conv_type = $invoice_common['conv_type'];
$valid_data= False;
$buffer = array();
$buffer = $this->import_start_file($buffer);
$xmldata=file_get_contents($tsvfile);
$this->xmltool->import_xml($xmldata);
$var_result = $this->xmltool->export_var();
if(is_array($var_result['Worksheet']['Table']['Row']))
{
$data_temp=$var_result['Worksheet']['Table']['Row'];
}
else
{
$data_temp=$var_result['Worksheet'][0]['Table']['Row'];
}
$rows = count($data_temp);
//_debug_array($data_temp);
// _debug_array($var_result['Worksheet'][0]['Table']['Row']);
//_debug_array($var_result['Worksheet']['Table']['Row']);
if (isset($data_temp) AND is_array($data_temp))
{
for ($i = $this->header_count; $i < $rows; ++$i)
{
$data=$data_temp[$i]['Cell'];
$num = count($data);
$buffer =
$this->import_start_record($buffer);
for ($c=0; $c<$num; $c++ )
{
//Send name/value pairs along
with the buffer
if
($this->import[$this->header[$c]] != '' && $data[$c]['Data'] != '')
{
//echo 'data'.$data[$c].'<br>';
//echo '<br>'.$c.': '.$this->import[$this->header[$c]].' => '.$data[$c]['Data'];
$buffer =
$this->import_new_attrib($buffer,
$this->import[$this->header[$c]],$data[$c]['Data'],$invoice_common);
$valid_data= True;
}
}
if ($valid_data)
{
$buffer =
$this->import_end_record($buffer,$invoice_common);
$valid_data= False;
}
}
}
if(!$download)
{
$buffer =
$this->import_end_file($buffer,$invoice_common['bilagsnr']);
}
//print_r($buffer);
return $buffer;
}
function import_start_file($buffer)
{
return $buffer;
}
function import_start_record($buffer)
{
$top=array();
++$this->id;
$this->currentrecord = $top;
return $buffer;
}
function import_new_attrib($buffer,$name,$value,$invoice_common)
{
$value = trim($value);
$value = str_replace('\n','<BR>',$value);
$value = str_replace('\r','',$value);
$this->currentrecord += array($name => $value);
return $buffer;
}
function import_end_record($buffer,$invoice_common)
{
$buffer[$this->id]='';
while ( list($name, $value) =
each($this->currentrecord))
{
$invoice_date =
date($this->dateformat,mktime(2,0,0,$invoice_common['smonth'],$invoice_common['sday'],$invoice_common['syear']));
if($invoice_common['num_days'])
{
$payment_date =
date($this->dateformat,mktime(2,0,0,$invoice_common['smonth'],$invoice_common['sday'],$invoice_common['syear'])+(86400*$invoice_common['num_days']));
}
else
{
$payment_date =
date($this->dateformat,mktime(2,0,0,$invoice_common['emonth'],$invoice_common['eday'],$invoice_common['eyear']));
}
if($name=='belop')
{
$value = str_replace('kr','',$value);
$value = str_replace(' ','',$value);
$value = str_replace(',','.',$value);
$godkjentbelop=$value;
}
if($name=='pmwrkord_code')
{
if(!$this->soXport->check_pmwrkord_code(intval($value)))
{
$value='';
}
}
if($name=='spbudact_code')
{
if(!$this->soXport->check_spbudact_code(intval($value)))
{
$value='';
}
}
if($name=='fakturanr')
{
if($invoice_common['invoice_num'])
{
$value=$invoice_common['invoice_num'];
}
}
if($name=='mvakode' &&
$invoice_common['auto_tax'])
{
$value =
$this->soXport->auto_tax($buffer[$this->id]['dima']);
}
$buffer[$this->id][$name] = $value;
$buffer[$this->id]['bilagsnr'] =
$this->next_bilagsnr;
$buffer[$this->id]['splitt'] = $this->splitt;
$buffer[$this->id]['kildeid'] = $this->kildeid;
$buffer[$this->id]['kidnr'] =
$invoice_common['kid_nr'];
$buffer[$this->id]['typeid'] =
$invoice_common['type'];
$buffer[$this->id]['fakturadato'] =
$invoice_date;
$buffer[$this->id]['forfallsdato'] =
$payment_date;
$buffer[$this->id]['periode'] =
$invoice_common['smonth'];
$buffer[$this->id]['regtid'] =
date($this->datetimeformat);
$buffer[$this->id]['artid'] =
$invoice_common['art'];
$buffer[$this->id]['godkjentbelop'] =
$godkjentbelop;
$buffer[$this->id]['spvend_code'] =
$invoice_common['vendor_id'];
$buffer[$this->id]['dimb'] =
$invoice_common['dim_b'];
$buffer[$this->id]['oppsynsmannid'] =
$invoice_common['janitor'];
$buffer[$this->id]['saksbehandlerid'] =
$invoice_common['supervisor'];
$buffer[$this->id]['budsjettansvarligid'] =
$invoice_common['budget_responsible'];
}
return $buffer;
}
function import_end_file($buffer,$bilagsnr)
{
$num = $this->soXport->add($buffer);
$receipt['message'][]= array('msg' =>
lang('Successfully imported %1 records into your invoice register.',$num).'
'.lang('ID').': '. $bilagsnr);
return $receipt;
}
}
?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] property/import/Import_fra_Service_xml, 1.1.2.1,
nomail <=