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_Service_xls


From: Sigurd Nes
Subject: [Phpgroupware-cvs] property/inc/import import_fra_Service_xls
Date: Mon, 03 Sep 2007 13:24:39 +0000

CVSROOT:        /sources/phpgroupware
Module name:    property
Changes by:     Sigurd Nes <sigurdne>   07/09/03 13:24:39

Added files:
        inc/import     : import_fra_Service_xls 

Log message:
        import from xls

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/property/inc/import/import_fra_Service_xls?cvsroot=phpgroupware&rev=1.1

Patches:
Index: import_fra_Service_xls
===================================================================
RCS file: import_fra_Service_xls
diff -N import_fra_Service_xls
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ import_fra_Service_xls      3 Sep 2007 13:24:39 -0000       1.1
@@ -0,0 +1,275 @@
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003,2004,2005,2006,2007 Free Software 
Foundation, Inc. http://www.fsf.org/
+       * This file is part of phpGroupWare.
+       *
+       * phpGroupWare is free software; you can redistribute it and/or modify
+       * it under the terms of the GNU General Public License as published by
+       * the Free Software Foundation; either version 2 of the License, or
+       * (at your option) any later version.
+       *
+       * phpGroupWare is distributed in the hope that it will be useful,
+       * but WITHOUT ANY WARRANTY; without even the implied warranty of
+       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       * GNU General Public License for more details.
+       *
+       * You should have received a copy of the GNU General Public License
+       * along with phpGroupWare; if not, write to the Free Software
+       * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 
 USA
+       *
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage import
+       * @version $Id: import_fra_Service_xls,v 1.1 2007/09/03 13:24:39 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class import_conv
+       {
+               var $currentrecord = array(); //used for buffering to allow uid 
lines to go first
+               var $id = -1;
+               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',
+                       'Tjeneste'=> 'kostra_id',
+                       'Belop [kr]' => 'belop'
+                       );
+
+               var $header = array('Bestilling','Fakt. 
Nr','Konto','Objekt','Fag/Timer/Matr','MVA','Belop [kr]');
+
+               function import_conv()
+               {
+       //              $this->db               = $GLOBALS['phpgw']->db;
+                       $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->db               = $this->bocommon->new_db();
+                       $this->dateformat       = $this->bocommon->dateformat;
+                       $this->datetimeformat   = 
$this->bocommon->datetimeformat;
+                       $this->next_bilagsnr    = 
$this->invoice->next_bilagsnr();
+               }
+
+               function import($invoice_common,$download)
+               {
+
+                       $tsvfile        = $invoice_common['tsvfile'];
+                       $conv_type      = $invoice_common['conv_type'];
+                       $valid_data= False;
+                       $buffer = array();
+                       $data = CreateObject('phpgwapi.excelreader');
+                       
+                       $data->setOutputEncoding('CP1251');
+                       $data->read($tsvfile);
+
+//_debug_array($data->sheets[0]['numRows']);
+//_debug_array($data->sheets[0]['cells']);
+
+//die();
+                       $this->id = 0;
+                       $num = count($this->header)+1;
+                       for ($i=18; $c<$data->sheets[0]['numRows']+1; $i++ ) 
//First data entry on row 18
+                       {
+                               $this->currentrecord = array();
+                               
+                               $valid_data=0;
+                               for ($c=1; $c<$num; $c++ )
+                               {
+                                       //Send name/value pairs along with the 
buffer
+                                       if ($data->sheets[0]['cells'][$i][$c] 
!= '')
+                                       {
+                                               
$this->import_new_attrib($this->import[$this->header[$c-1]],$data->sheets[0]['cells'][$i][$c],$invoice_common);
+                                               
if($data->sheets[0]['cells'][$i][$c])
+                                               {
+                                                       $valid_data++;
+                                               }
+                                       }
+                               }
+                               if ($valid_data > 0)
+                               {
+                                       $buffer = 
$this->import_end_record($invoice_common);
+                                       $valid_data= False;
+                               }
+                               $this->id++;
+                       }
+
+                       if(!$download)
+                       {
+                               $buffer = 
$this->import_end_file($buffer,$invoice_common['bilagsnr']);
+                       }
+
+                       $this->header = array('Bestilling','Fakt. 
Nr','Konto','Objekt','Fag/Timer/Matr','MVA','Tjeneste','Belop [kr]');
+
+                       return $buffer;
+               }
+
+               function import_new_attrib($name,$value,$invoice_common)
+               {
+                       $value = $this->bocommon->ascii2utf(trim($value));
+                       $value = str_replace('\n','<BR>',$value);
+                       $value = str_replace('\r','',$value);
+
+                       $this->currentrecord += array($name => $value);
+               }
+
+               function import_end_record($invoice_common)
+               {
+                       $buffer = array();
+                       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_order(intval($value)))
+                                       {
+                                               $value='';
+                                       }
+                                       else
+                                       {
+                                               
$buffer[$this->id]['project_id'] = $this->soXport->get_project(intval($value)); 
+                                       }
+                               }
+                               if($name=='spbudact_code')
+                               {
+                                       $value = 
$this->check_spbudact_code($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']);
+                               }
+
+                               if($name=='dima')
+                               {
+                                       $value = $this->check_dima($value);
+                                       $buffer[$this->id]['loc1'] = 
$loc1=substr($value,0,4);
+                               }
+
+                               $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'];
+
+                               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 check_spbudact_code($id)
+               {
+                       $b_account='';
+                       $this->db->query("select id from fm_b_account where 
id='$id'");
+                       $this->db->next_record();
+                       if ($this->db->f('id'))
+                       { 
+                               $b_account = $this->db->f('id');
+                       }
+                       else
+                       {
+                               $this->db->query("select id from 
fm_b_account_convert where old_id='$id'");
+                               $this->db->next_record();
+                               $b_account = $this->db->f('id');
+                       }
+                       
+                       return $b_account;
+               }
+
+               function check_dima($id)
+               {
+                       $loc1=substr($id,0,4);
+                       $loc2=substr($id,4,2);
+                       
+                       $this->db->query("select loc1 from fm_location1 where 
loc1='$loc1' AND ((fm_location1.category <> 99) OR (fm_location1.category IS 
NULL))");
+                       $this->db->next_record();
+                       if ($this->db->f('loc1'))
+                       { 
+                               $dima = $this->db->f('loc1');
+                               
+                               if ($loc2)
+                               {
+                                       $this->db->query("select location_code 
from fm_location2 where loc1='$loc1' AND loc2='$loc2'  AND 
((fm_location2.category <> 99) OR (fm_location2.category IS NULL))");
+                                       $this->db->next_record();
+                                       if ($this->db->f('location_code'))
+                                       { 
+                                               $dima = 
str_replace('-','',$this->db->f('location_code'));
+                                       }
+                                       else
+                                       {
+                                               unset($dima);
+                                       }
+                               }
+                       }
+                       
+                       return $dima;
+               }
+
+               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]