phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] CVS: property/inc/import Import_fra_BKK,NONE,1.1 Impo


From: Sigurd Nes <address@hidden>
Subject: [Phpgroupware-cvs] CVS: property/inc/import Import_fra_BKK,NONE,1.1 Import_fra_Kemner,NONE,1.1 Import_fra_Service,NONE,1.1
Date: Wed, 16 Oct 2002 11:32:52 -0400

Update of /cvsroot/phpgroupware/property/inc/import
In directory subversions:/tmp/cvs-serv9701/inc/import

Added Files:
        Import_fra_BKK Import_fra_Kemner Import_fra_Service 
Log Message:
no message

--- NEW FILE ---
<?php
// This file defines a set of functions and an associative array.
// The key of the array corresponds to a header in the source
// import file and the value of the array item will be used in
// the creation of the output file.
//
// An exported Outlook file looks like this:
//
// Title<tab>First Name<tab>Middle Name<tab>Last Name<tab>...
// <tab>Patrick<tab><tab>Walsh<tab>...
//
// Where the first line explains each optional field.  This is what
// will be looked up in the key.
//
// The array need not be in any order and any fields not defined will
// not be transferred.  If the val='+', the value will be appended to
// the previous field and any text after the '+' will be appended 
// before the value.  For example, the following would add a comma and
// a space between LastName and FirstName and store it in FullName:
//
//      array('LastName' => 'FullName','FirstName' => '+, ');
//
// Also start with a '#' symbol and a comma separated list will be
// turned into a number of the same entries.

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

                var $import = array(
                        'Bestilling' => 'pmwrkord_code', 
                        'Fakt. Nr' => 'fakturanr',
                        'Måler nr' => 'maalernr',
                        'Konto' => 'spbudact_code',
                        'Objekt' => 'dima',
                        'Omr' => 'omraade',
                        'Adresse' => 'merknad',
                        'MVA' => 'mvakode',
                        'Beløp [kr]' => 'belop'
                        );

                var $header = array('Fakt. Nr','Måler 
nr','Konto','Objekt','MVA','Beløp [kr]','Omr','Adresse');

                var $import_bkk = 
array('boligbyggelag','dato','kundenr','lopenr', 'maalernr' , 
'installasjonsnr', 
                        
'anleggsid','stedsnavn','kunde_navn','navn','netto','mva');
                        
                var $import_bkk_offset = array(
                        'boligbyggelag' => '0', 
                        'dato' => '5', 
                        'kundenr' => '16', 
                        'lopenr' => '25', 
                        'maalernr' => '30', 
                        'installasjonsnr' => '43', 
                        'anleggsid' => '54', 
                        'stedsnavn' => '59',
                        'kunde_navn' => '95',
                        'navn' => '126',
                        'netto' => '157',
                        'mva' => '172'
                        );

                var $import_bkk_len = array(
                        'boligbyggelag' => '5', 
                        'dato' => '10', 
                        'kundenr' => '8', 
                        'lopenr' => '4', 
                        'maalernr' => '8', 
                        'installasjonsnr' => '9', 
                        'anleggsid' => '4', 
                        'stedsnavn' => '35',
                        'kunde_navn' => '30',
                        'navn' => '30',
                        'netto' => '14',
                        'mva' => '14'
                        );




                function import_conv()
                {

                        $this->soXport = CreateObject('property.soXport');      
                        $this->invoice = CreateObject('property.invoice');      
                }

                function 
import($tsvfile,$conv_type,$private,$fcat_id,$invoice_common,$download)
                {

                        if ($private == '') { $private = 'public'; }
                        $valid_data= False;
                        $buffer = array();
                        $buffer = $this->import_start_file($buffer);
                        $fp = fopen($tsvfile,'rb');
//print_r($buffer);

//print_r($header);
//echo '<br>';
                        for ($i = 0; $i < $this->header_count && 
fgets($fp,8000); ++$i);

                        while ($data = fgets($fp,8000))
                        {
//print_r($data);
                                $num = count($this->import_bkk);
//echo 'data :'.$data.'<br>';
                                $buffer = $this->import_start_record($buffer);
//print_r($buffer);
                                for ($c=0; $c<$num; $c++ )
                                {
                                        //Send name/value pairs along with the 
buffer
                                        if ($this->import_bkk[$c] != '' && 
substr($data,5,10) !='')
                                        {
//echo 'len :'.$this->import_bkk_len[$this->import_bkk[$c]].'<br>';
//print_r(fread($data,$this->import_bkk_len[$this->import_bkk[$c]]));
//print_r($this->import_bkk[$c]);
                                                
$value=substr($data,$this->import_bkk_offset[$this->import_bkk[$c]],$this->import_bkk_len[$this->import_bkk[$c]]);
                                                $name=$this->import_bkk[$c];
                                                if ($name=='installasjonsnr')
                                                {
                                                        $name='anleggsnr';
                                                        
$value=substr($data,43,9)." ".substr($data,54,4);
                                                }
                                                if ($name=='netto')
                                                {
                                                        $name='belop';
                                                        
$value=(floatval(substr($data,157,14)) + floatval(substr($data,172,14)))/100;
                                                        $valid_data= True;      
                        
                                                }
//echo 'name :'.$name;
//echo '  value :'.$value.'<br>';
//print_r($buffer);

                                                $buffer = 
$this->import_new_attrib($buffer,$name,$value,$invoice_common);
                                        }
                                }
                                if ($valid_data)
                                {
                                        $buffer = 
$this->import_end_record($buffer,$invoice_common,$private);
                                        $valid_data= False;
                                }
                        }
                        fclose($fp);
//print_r($buffer);


//echo 'download'.$download.'<br>';

                        if(!$download)
                        {
                                $buffer = 
$this->import_end_file($buffer,$private,$fcat_id,$invoice_common['bilagsnr']);
                                $this->invoice->increment_bilagsnr();
                        }

                        return $buffer;
                }
                

                function import_start_file($buffer)
                {
                        return $buffer;
                }

                function import_start_record($buffer)
                {
//print_r($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);
//print_r($buffer);
                        return $buffer;
                }

                function import_end_record($buffer,$invoice_common)
                {
                        $buffer[$this->id]='';
                        while ( list($name, $value) = 
each($this->currentrecord))
                        {
                                $invoice_date = date("M d 
Y",mktime(2,0,0,$invoice_common['invoice_month'],$invoice_common['invoice_day'],$invoice_common['invoice_year']));

                                if($invoice_common['num_days'])
                                {
                                        $payment_date = date("M d 
Y",mktime(2,0,0,$invoice_common['invoice_month'],$invoice_common['invoice_day'],$invoice_common['invoice_year'])+(86400*$invoice_common['num_days']));
                                }
                                else
                                {
                                        $payment_date = date("M d 
Y",mktime(2,0,0,$invoice_common['payment_month'],$invoice_common['payment_day'],$invoice_common['payment_year']));
                    
                                }

                                if($name=='belop')
                                {
                                        $value = str_replace('kr','',$value);
                                        $value = str_replace(' ','',$value);
                                        $value = str_replace(',','.',$value);
                                        $godkjentbelop=$value;
                                }

                                if($name=='anleggsnr')
                                {
                                        
$maalerinfo=$this->soXport->anleggsnr_to_objekt($value);
                                        $dima=$maalerinfo['dima'];
//                                      $maalernr=$maalerinfo['maalernr'];
                                        $omraade=$maalerinfo['omraade'];
                                }
                                if($name=='stedsnavn')
                                {
                                        $buffer[$this->id]['merknad'] = $value;
                                }


                                $buffer[$this->id][$name] = $value;
                                $buffer[$this->id]['bilagsnr'] = 
$this->invoice->next_bilagsnr();
                                $buffer[$this->id]['fakturanr'] = 
$invoice_common['invoice_num'];
                                $buffer[$this->id]['dima'] = $dima;
                                $buffer[$this->id]['omraade'] = $omraade;
//                              $buffer[$this->id]['maalernr'] = $maalernr;
                                $buffer[$this->id]['splitt'] = $this->splitt;
                                $buffer[$this->id]['kildeid'] = $this->kildeid;
                                $buffer[$this->id]['mvakode'] = $this->mvakode;
                                $buffer[$this->id]['spbudact_code'] = 
$this->spbudact_code;
                                $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['invoice_month'];
                                $buffer[$this->id]['regtid'] = date("M d Y 
g:iA");
                                $buffer[$this->id]['artid'] = 
$invoice_common['art'];
                                $buffer[$this->id]['godkjentbelop'] = 
$godkjentbelop;
                                $buffer[$this->id]['spvend_code'] = 
$invoice_common['abid'];
                                $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'];

//                              echo '<br>'.$name.' => '.$value;
                        }
//print_r($buffer);
                        return $buffer;
                }

                function 
import_end_file($buffer,$access='private',$cat_id=0,$bilagsnr)
                {
//print_r($buffer);
                        //echo '<br>'; 
                        for ($i=1;$i<=count($buffer);$i++)
                        {
                                while ( list($name,$value) = @each($buffer[$i]) 
)
                                {
//echo '<br>'.$i.': '.$name.' => '.$value;
                                        $entry[$i][$name] = $value;
                                }
//print_r($buffer);
//print_r($entry[$i]);
//                              echo '<br>';
                                
$this->soXport->add($GLOBALS['phpgw_info']['user']['account_id'],$entry[$i],$access,$cat_id);
                        }
                        $num = $i - 1;
                        return lang('Successfully imported x records into your 
invoice register.',$num).'<br>'.lang('ID').': '. $bilagsnr;
                }
        }
?>

--- NEW FILE ---
<?php
// This file defines a set of functions and an associative array.
// The key of the array corresponds to a header in the source
// import file and the value of the array item will be used in
// the creation of the output file.
//
// An exported Outlook file looks like this:
//
// Title<tab>First Name<tab>Middle Name<tab>Last Name<tab>...
// <tab>Patrick<tab><tab>Walsh<tab>...
//
// Where the first line explains each optional field.  This is what
// will be looked up in the key.
//
// The array need not be in any order and any fields not defined will
// not be transferred.  If the val='+', the value will be appended to
// the previous field and any text after the '+' will be appended 
// before the value.  For example, the following would add a comma and
// a space between LastName and FirstName and store it in FullName:
//
//      array('LastName' => 'FullName','FirstName' => '+, ');
//
// Also start with a '#' symbol and a comma separated list will be
// turned into a number of the same entries.

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

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

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

                function import_conv()
                {
                        $this->soXport = CreateObject('property.soXport');      
                        $this->invoice = CreateObject('property.invoice');      
                }

                function 
import($tsvfile,$conv_type,$private,$fcat_id,$invoice_common,$download)
                {
                        $Ingen = 0;
                        $FilGodkjent = 1;
                        $Betalingskrav = 2;
                        $Beløpspost1 = 3;
                        $Beløpspost2 = 4;
                        $Spesifikasjon = 5;
                        $LinjeNr = 0;
                        $ePostNivå = $Ingen;
                        $errorcount = 0;
                        $last_case_merknad='';
                        $bilagsnr = $this->invoice->next_bilagsnr();
                        if ($private == '') { $private = 'public'; }
                        $buffer = array();
                        $buffer = $this->import_start_file($buffer);
                        $fp = fopen($tsvfile,'r');

                        while ($data = fgets($fp,8000))
                        {
//-----------------------------
//print_r($buffer);
                                
                                $LinjeNr = $LinjeNr + 1;
                                if (strlen($data) >= 80)
                                {
                                        if ($last_case_merknad && 
substr($data,0,8)!=$last_case_merknad)
                                        {
                                                if ($Merknad)
                                                {
                                                        $buffer = 
$this->import_new_attrib($buffer,merknad,$Merknad,$invoice_common);
                                                }
                                                $Merknad='';
                                                $buffer = 
$this->import_end_record($buffer,$invoice_common,$private);
                                                $last_case_merknad='';
                                        }
                                    switch(substr($data,0,8))
                                    {
                                        Case 'NY000010':
                                            //Start forsendelse
                                            if (($LinjeNr == 1) && ($ePostNivå 
== $Ingen))
                                            {
                                                $ePostNivå = $FilGodkjent;
                                            }
                                            else
                                            {
                                                echo lang('Importer_BBS') . 
lang('Filen inneholder flere start poster på linje nr:') . $LinjeNr . 
lang('Importen kan ikke fortsette');
                                                break 2;
                                            }
                        
                                        break;
                                        
                                        Case 'NY210020':
                                            //Start betalingskrav
                                            if ($ePostNivå == $FilGodkjent)
                                            {
                                                $ePostNivå = $Betalingskrav;
                                            }
                                            else
                                            {
                                                echo lang('Importer_BBS') 
.lang('Formatfeil på fil på linjenr:') . $LinjeNr . lang('Importen kan ikke 
fortsette');
                                                break 2;
                                            }
                        
                                            $OppdragsNr = substr($data,17,7);
                                            $OppdragsKonto = substr($data, 24, 
11);
                                        break;
                                        
                                        Case 'NY210230':
                                        break;
                                        
                                        Case 'NY212130':
                                        $buffer = 
$this->import_start_record($buffer);

             
                                            //Beløpspost 1
                                            if ($ePostNivå == $Betalingskrav Or 
$ePostNivå >= $Beløpspost2)
                                            {
                                                $ePostNivå = $Beløpspost1;
                                            }
                                            else
                                            {
                                                echo lang('Importer_BBS') 
.lang('Formatfeil på fil på linjenr:') . $LinjeNr . lang('Importen kan ikke 
fortsette');
                                                break 2;
                                            }
                        
                                            //Lagre eksisterende post
                                            if (!oRsTmp.EOF && !oRsTmp.BOF)
                                            {
                                                if (oRsTmp.EditMode == 
adEditAdd)
                                                {
                                                    oRsTmp.Update;
                                                }
                                            }
                        
                                            //Opprett post
                                                $TransaksjonsNr = substr($data, 
8, 7);
                                                $Gnr = substr($data, 56, 5);
                                                $Bnr = substr($data, 61, 4);
                                                $sekjonnr = substr($data, 69, 
3);
                        
                                                $forfall_day = substr($data, 
15, 2);
                                                $forfall_month = substr($data, 
17, 2);
                                                $forfall_year = substr($data, 
19, 2);

                                                $forfallsdato = date("M d 
Y",mktime(2,0,0,$forfall_month,$forfall_day,$forfall_year));
                                                $fakturadato= date("M d 
Y",mktime(2,0,0,$forfall_month,$forfall_day,$forfall_year)-(86400*30));

                                                $belop = 
intval(substr($data,32,17))/100;
                                                $kidnr = substr($data, 49, 25);
                                                $gid = 
$Gnr.'/'.$Bnr.'-'.$sekjonnr;
                        
                                                $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
                                                $sql = "select 
boei_gabnr.objekt_id, boei_gabnr.bygg_id, boei_gabnr.seksjons_id from 
boei_gabnr, boei_objekt, boei_eier "
                                                       . "where 
substring(boei_gabnr.gabnr,5,5)='$Gnr' and "
                                                       . "      
substring(boei_gabnr.gabnr,10,4)='$Bnr' and "
                                                       . "      
boei_gabnr.objekt_id=boei_objekt.objekt_id and "
                                                       . "      
boei_objekt.eier_id=boei_eier.eier_id and "
                                                       . "      
boei_eier.eiertype_id=0";

                                                
$GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
                                                
$GLOBALS['phpgw']->db->next_record();
                        
                                                if ($GLOBALS['phpgw']->db->f(0))
                                                {
                                                        
$dima=$GLOBALS['phpgw']->db->f('objekt_id').$GLOBALS['phpgw']->db->f('bygg_id').$GLOBALS['phpgw']->db->f('seksjons_id');
                                                }
                                                else
                                                {
                                                        $dima='';
                                                }
                                                $buffer = 
$this->import_new_attrib($buffer,dima,$dima,$invoice_common);
                                        break;
                                        
                                        Case 'NY210231':
                                        break;
                                        
                                        Case 'NY212131':
                                            //Beløpspost 2
                                            if ($ePostNivå == $Beløpspost1)
                                            {
                                                $ePostNivå = $Beløpspost2;
                                            }
                                            else
                                            {
                                                echo lang('Importer_BBS') 
.lang('Formatfeil på fil på linjenr:') . $LinjeNr . lang('Importen kan ikke 
fortsette');
                                                break 2;
                                            }
                        
                                            //Sjekk transaksjonsnr
                                            if ((intval(substr($data, 8, 7))) 
<> $TransaksjonsNr)
                                            {
                                                echo lang('Importer_BBS') 
.lang('Transaksjonsnr på beløpspost 2 stemmer ikke med nr på beløpspost 1. 
Linjenr:') . $LinjeNr . lang('Importen kan ikke fortsette');
                                                break 2;
                                            }
                        
                                            $Navn = substr($data, 15, 10);
                                            $Referanse = substr($data, 50, 25);
                        
                                        $Merknad = '';
                                        break;
                                        
                                        Case 'NY212149':
                                            //Spesifikasjonsrecord
                                            if ($ePostNivå >= $Beløpspost2)
                                            {
                                                $ePostNivå = $Spesifikasjon;
                                            }
                                            else
                                            {
                                                echo lang('Importer_BBS') 
.lang('Formatfeil på fil på linjenr:') . $LinjeNr . lang('Importen kan ikke 
fortsette');
                                                break 2;
                                            }
                        
                                            //Hent merknad
                                        $Merknad.=strval(substr($data, 20, 
40))."\r\n";
                                        $last_case_merknad=substr($data,0,8);
                        
                                        break;
                                        
                                        Case 'NY210088':
                                            //Slutt betalingskrav
                                            if ($ePostNivå >= $Betalingskrav && 
$ePostNivå <> $Beløpspost1)
                                            {
                                                $ePostNivå = $FilGodkjent;
                                            }
                                            else
                                            {
                                                echo lang('Importer_BBS') 
.lang('Formatfeil på fil på linjenr:') . $LinjeNr . lang('Importen kan ikke 
fortsette');
                                                break 2;
                                            }
                        
                                        break;
                                        
                                        Case 'NY000089':
                                            //Slutt forsendelse
                                            if ($ePostNivå == $FilGodkjent)
                                            {
                                                $ePostNivå = $Ingen;
                                            }
                                            else
                                            {
                                                echo lang('Importer_BBS') 
.lang('Formatfeil på fil på linjenr:') . $LinjeNr . lang('Importen kan ikke 
fortsette');
                                                break 2;
                                            }
                                        
                                        break;
                                    }
                        
                                    //Filen må altid begynne med en gyldig 
start record
                                    if ($LinjeNr == 1 && $ePostNivå == $Ingen)
                                    {
                                        echo lang('Importer_BBS') . lang('Filen 
starter ikke med riktig recordtype. Importen kan ikke fortsette');
                                        break;
                                    }
                                }
//-----------------------------
                        }
                        fclose($fp);

                        if(!$download)
                        {
                                $buffer = 
$this->import_end_file($buffer,$private,$fcat_id,$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);
//echo '<br> '.$name.': => '.$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;
                                }

                                $buffer[$this->id][$name] = $value;
                                $buffer[$this->id]['fakturanr'] = 
$invoice_common['invoice_num'];
                                $buffer[$this->id]['splitt'] = $this->splitt;
                                $buffer[$this->id]['kildeid'] = $this->kildeid;
                                $buffer[$this->id]['mvakode'] = $this->mvakode;
                                $buffer[$this->id]['spbudact_code'] = 
$this->spbudact_code;
                                $buffer[$this->id]['typeid'] = 
$invoice_common['type'];
                                $buffer[$this->id]['periode'] = 
$invoice_common['invoice_month'];
                                $buffer[$this->id]['regtid'] = date("M d Y 
g:iA");
                                $buffer[$this->id]['artid'] = 
$invoice_common['art'];
                                $buffer[$this->id]['godkjentbelop'] = 
$godkjentbelop;
                                $buffer[$this->id]['spvend_code'] = 
$invoice_common['abid'];
//                              $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'];

//                              echo '<br>'.$name.' => '.$value;
                        }
//print_r($buffer);
                        return $buffer;
                }

                function 
import_end_file($buffer,$access='private',$cat_id=0,$bilagsnr)
                {

//echo 'count(buffer) '.count($buffer) .'<br>';
                        for ($i=1;$i<=count($buffer);$i++)
                        {
                                while ( list($name,$value) = @each($buffer[$i]) 
)
                                {
//                                      echo '<br>'.$i.': '.$name.' => '.$value;
                                        $entry[$i][$name] = $value;
                                }
//print_r($buffer);
//print_r($entry[$i]);
                                
$this->soXport->add($GLOBALS['phpgw_info']['user']['account_id'],$entry[$i],$access,$cat_id);
                                $bilagsnr_end = 
$this->invoice->increment_bilagsnr();
                        }
                        $num = $i - 1;
                        return lang('Successfully imported x records into your 
invoice register.',$num).'<br>'.lang('ID').': '. $bilagsnr .' - ' . 
$bilagsnr_end;
                }
        }
?>

--- NEW FILE ---
<?php
// This file defines a set of functions and an associative array.
// The key of the array corresponds to a header in the source
// import file and the value of the array item will be used in
// the creation of the output file.
//
// An exported Outlook file looks like this:
//
// Title<tab>First Name<tab>Middle Name<tab>Last Name<tab>...
// <tab>Patrick<tab><tab>Walsh<tab>...
//
// Where the first line explains each optional field.  This is what
// will be looked up in the key.
//
// The array need not be in any order and any fields not defined will
// not be transferred.  If the val='+', the value will be appended to
// the previous field and any text after the '+' will be appended 
// before the value.  For example, the following would add a comma and
// a space between LastName and FirstName and store it in FullName:
//
//      array('LastName' => 'FullName','FirstName' => '+, ');
//
// Also start with a '#' symbol and a comma separated list will be
// turned into a number of the same entries.

        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 = 18;
                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->soXport = CreateObject('property.soXport');      
                        $this->invoice = CreateObject('property.invoice');      
                }

                function 
import($tsvfile,$conv_type,$private,$fcat_id,$invoice_common,$download)
                {

                        if ($private == '') { $private = 'public'; }
                        $row = 0;
                        $valid_data= False;
                        $buffer = array();
                        $buffer = $this->import_start_file($buffer);
                        $fp = fopen($tsvfile,'r');
//print_r($header);
//echo '<br>';
                        for ($i = 1; $i < $this->header_count && 
fgetcsv($fp,8000,';'); ++$i);

                        while ($data = fgetcsv($fp,8000,';'))
                        {
                                $num = count($data);
                                $row++;
                                $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] != '')
                                        {

//echo 'data'.$data[$c].'<br>';
//echo '<br>'.$c.': '.$this->import[$this->header[$c]].' => '.$data[$c];
                                                $buffer = 
$this->import_new_attrib($buffer, 
$this->import[$this->header[$c]],$data[$c],$invoice_common);
                                                $valid_data= True;
                                        }
                                }
                                if ($valid_data)
                                {
                                        $buffer = 
$this->import_end_record($buffer,$invoice_common,$private);
                                        $valid_data= False;
                                }
                        }
                        fclose($fp);


//echo 'download'.$download.'<br>';

                        if(!$download)
                        {
                                $buffer = 
$this->import_end_file($buffer,$private,$fcat_id,$invoice_common['bilagsnr']);
                                $this->invoice->increment_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("M d 
Y",mktime(2,0,0,$invoice_common['invoice_month'],$invoice_common['invoice_day'],$invoice_common['invoice_year']));

                                if($invoice_common['num_days'])
                                {
                                        $payment_date = date("M d 
Y",mktime(2,0,0,$invoice_common['invoice_month'],$invoice_common['invoice_day'],$invoice_common['invoice_year'])+(86400*$invoice_common['num_days']));
                                }
                                else
                                {
                                        $payment_date = date("M d 
Y",mktime(2,0,0,$invoice_common['payment_month'],$invoice_common['payment_day'],$invoice_common['payment_year']));
                    
                                }

                                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='';
                                        }
                                }

                                $buffer[$this->id][$name] = $value;
                                $buffer[$this->id]['bilagsnr'] = 
$this->invoice->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['invoice_month'];
                                $buffer[$this->id]['regtid'] = date("M d Y 
g:iA");
                                $buffer[$this->id]['artid'] = 
$invoice_common['art'];
                                $buffer[$this->id]['godkjentbelop'] = 
$godkjentbelop;
                                $buffer[$this->id]['spvend_code'] = 
$invoice_common['abid'];
                                $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'];

        //                      echo '<br>'.$name.' => '.$value;
                        }
//print_r($buffer);
                        return $buffer;
                }

                function 
import_end_file($buffer,$access='private',$cat_id=0,$bilagsnr)
                {
//print_r($buffer);
//echo '<br>'; 
                        for ($i=1;$i<=count($buffer);$i++)
                        {
                                while ( list($name,$value) = @each($buffer[$i]) 
)
                                {
//echo '<br>'.$i.': '.$name.' => '.$value;
                                        $entry[$i][$name] = $value;
                                }
//print_r($buffer);
//print_r($entry[$i]);
//                              echo '<br>';
                                
$this->soXport->add($GLOBALS['phpgw_info']['user']['account_id'],$entry[$i],$access,$cat_id);
                        }
                        $num = $i - 1;
                        return lang('Successfully imported x records into your 
invoice register.',$num).'<br>'.lang('ID').': '. $bilagsnr;
                }
        }
?>





reply via email to

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