phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] property/inc/import/Import_fra_Kemner_xml, 1.1


From: nomail
Subject: [Phpgroupware-cvs] property/inc/import/Import_fra_Kemner_xml, 1.1
Date: Thu, 30 Sep 2004 14:25:41 +0200

Update of /property/inc/import
Added Files:
        Branch: 
          Import_fra_Kemner_xml

date: 2004/09/30 12:25:41;  author: sigurdne;  state: Exp;

Log Message:
no message
=====================================================================
<?php

        class import_conv
        {
                var $currentrecord = array(); //used for buffering to allow uid 
lines to go first
                var $spbudact_code=4111;
                var $dimb=40;
                var $mvakode=0;
                var $kildeid=1;
                var $splitt=0;
                var $type = 'fixed';
                var $soXport;
                var $invoice;

                var $import = array(
                        'Bilagsnr' => 'bilagsnr', 
                        'Fakturanr' => 'fakturanr', 
                        'Gnr/Bnr-seksjon' => 'gid',
                        'Konto' => 'spbudact_code',
                        'Objekt' => 'dima', //objectclass: organizationalPerson
                        'DimB' => 'dimb',
                        'KID' => 'kidnr',
                        'MVA' => 'mvakode',
                        'Tjeneste'=> 'kostra_id',
                        'Beløp [kr]' => 'belop',
                        'Referanse' => 'referanse',
                        'BOEI Gateadresse' => 'boei_gateadresse',
                        );

                var $header = 
array('Bilagsnr','Fakturanr','Gnr/Bnr-seksjon','Konto','Objekt','DimB','KID','MVA','Tjeneste','Beløp
 [kr]','Referanse');

                function import_conv()
                {
                        $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
                        $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;
                        $bilagsnr = $this->invoice->next_bilagsnr();

                        $buffer = array();
                        $buffer = $this->import_start_file($buffer);

                        $xmldata=file_get_contents($tsvfile);
                        $this->xmltool->import_xml($xmldata);
                        $var_result = $this->xmltool->export_var();
//_debug_array($var_result);

                        if(is_array($var_result['Invoice'][0]))
                        {
                                $data=$var_result['Invoice'];
                        }
                        else
                        {
                                $data[0]=$var_result['Invoice'];
                        }

//_debug_array($data);

                        if (isset($data) AND is_array($data))
                        {
                                $num = count($data);

                                for ($i = 0; $i < $num; ++$i)
                                {
                        
                                        $buffer = 
$this->import_start_record($buffer);


                                        $Gnr            = 
$data[$i]['Header']['Text1'];
                                        $Bnr            = 
$data[$i]['Header']['Text2'];
                                        $sekjonnr       = 
$data[$i]['Header']['Text4'];

                                        $fakturanr      = 
$data[$i]['InvoiceNo'];
                                        $fakturadato    = 
date($this->dateformat,strtotime($data[$i]['Header']['InvoiceDate'][0]));
                                        $forfallsdato   = 
date($this->dateformat,strtotime($data[$i]['Header']['DueDate'][0]));

                                        $periode = 
date(n,strtotime($data[$i]['Header']['InvoiceDate'][0]));
                                        
                                        $belop  = 
$data[$i]['Summary']['TotalInclTax'];
                                        $kidnr  = 
$data[$i]['Header']['PaymentInfo']['0']['BacsId'];

                                        $gid = $Gnr.'/'.$Bnr.'-'.$sekjonnr;
                        
                                        $buffer = 
$this->import_new_attrib($buffer,'fakturanr',$fakturanr,$invoice_common);
                                        $buffer = 
$this->import_new_attrib($buffer,periode,$periode,$invoice_common);
                                        $buffer = 
$this->import_new_attrib($buffer,forfallsdato,$forfallsdato,$invoice_common);
                                        $buffer = 
$this->import_new_attrib($buffer,fakturadato,$fakturadato,$invoice_common);
                                        $buffer = 
$this->import_new_attrib($buffer,belop,$belop,$invoice_common);
                                        $buffer = 
$this->import_new_attrib($buffer,kidnr,$kidnr,$invoice_common);
                                        $buffer = 
$this->import_new_attrib($buffer,gid,$gid,$invoice_common);
                                        $buffer = 
$this->import_new_attrib($buffer,bilagsnr,$bilagsnr,$invoice_common);
                                        $buffer = 
$this->import_new_attrib($buffer,dimb,$this->dimb,$invoice_common);
                                        $bilagsnr++;

                                        //Finn dima fra Boei
                                        $gabinfo = 
$this->soXport->gabnr_to_objekt($Gnr,$Bnr,$sekjonnr);
                                        $buffer = 
$this->import_new_attrib($buffer,dima,$gabinfo['dima'],$invoice_common);
                                        $buffer = 
$this->import_new_attrib($buffer,loc1,$gabinfo['loc1'],$invoice_common);
                                        //finn boei gateadresse for kongroll
                                        
$boei_gateadresse=$this->soXport->dima_to_address($gabinfo['dima']);
                                        $buffer = 
$this->import_new_attrib($buffer,boei_gateadresse,$boei_gateadresse,$invoice_common);

                                        $referanse = 
$data[$i]['Header']['Buyer'][0]['Accountable'];
                                        
                                        $buffer = 
$this->import_new_attrib($buffer,referanse,$referanse,$invoice_common);         
       

                                        $merknad = '';

                                        $merknad = 'Kemner adr: 
'.$referanse."\r\n".'BOEI adr: '.$boei_gateadresse."\r\n";

                                        foreach ($data[$i]['Details']['Detail'] 
as $detail)
                                        {
                                                if 
(is_array($detail['Products']['SellerProductDescr']))
                                                {
                                                        $merknad .= 
implode("",$detail['Products']['SellerProductDescr']) . "\t";
                                                }
                                                else
                                                {
                                                        $merknad .= 
$detail['Products']['SellerProductDescr'] . "\t";
                                                }
                                                

                                                if 
(is_array($detail['Products']['UnitCode']))
                                                {
                                                        $merknad .= 
implode("",$detail['Products']['UnitCode']) . "\t";
                                                }
                                                else
                                                {
                                                        $merknad .= 
$detail['Products']['UnitCode'] . "\t";
                                                }
                                                
                                                if 
(is_array($detail['Products']['Quantity']))
                                                {
                                                        $merknad .= 
implode("",$detail['Products']['Quantity']) . "\t";
                                                }
                                                else
                                                {
                                                        $merknad .= 
$detail['Products']['Quantity'] . "\t";
                                                }
                                                
                                                if 
(is_array($detail['Products']['Price']))
                                                {
                                                        $merknad .= 
implode("",$detail['Products']['Price'])."\r\n";
                                                }
                                                else
                                                {
                                                        $merknad .= 
$detail['Products']['Price']."\r\n";
                                                }

                                        }
                                        
                                        $buffer = 
$this->import_new_attrib($buffer,'merknad',$merknad,$invoice_common);


                                        $buffer = 
$this->import_end_record($buffer,$invoice_common);
                                }
                        }


                        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))
                        {
                                if($name=='belop')
                                {
                                        $godkjentbelop=$value;
                                }


                                if($name=='dima' && 
$invoice_common['auto_tax']):
                                {
                                        
$mvakode=$this->soXport->auto_tax($value);
                                        
                                        if($mvakode)
                                        {
                                                $buffer[$this->id]['mvakode'] = 
$mvakode;
                                        }
                                        else
                                        {
                                                $buffer[$this->id]['mvakode'] = 
$this->mvakode;
                                        }
                                }
                                elseif($name=='dima' && 
!$invoice_common['auto_tax']):
                                {
                                        $buffer[$this->id]['mvakode'] = 
$this->mvakode;
                                }
                                endif;

                                $buffer[$this->id][$name] = $value;
                                $buffer[$this->id]['splitt'] = $this->splitt;
                                $buffer[$this->id]['kildeid'] = $this->kildeid;

                                $buffer[$this->id]['spbudact_code'] = 
$this->spbudact_code;
                                $buffer[$this->id]['typeid'] = 
$invoice_common['type'];
                                $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'];

                                if($invoice_common['auto_tax'])
                                {
                                        $buffer[$this->id]['mvakode'] = 
$this->soXport->tax_b_account_override($buffer[$this->id]['mvakode'] 
,$buffer[$this->id]['spbudact_code']);
                                        $buffer[$this->id]['mvakode'] = 
$this->soXport->tax_vendor_override($buffer[$this->id]['mvakode'] 
,$buffer[$this->id]['spvend_code']);
                                        $buffer[$this->id]['kostra_id'] = 
$this->soXport->get_kostra_id($buffer[$this->id]['dima']);
                                }
                        }
                        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;
                }
        }
?>




reply via email to

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