fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [17262] prepare for custom code outside tree


From: sigurdne
Subject: [Fmsystem-commits] [17262] prepare for custom code outside tree
Date: Thu, 2 Nov 2017 11:01:01 -0400 (EDT)

Revision: 17262
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=17262
Author:   sigurdne
Date:     2017-11-02 11:01:01 -0400 (Thu, 02 Nov 2017)
Log Message:
-----------
prepare for custom code outside tree

Modified Paths:
--------------
    thirdparty/PE_custom/BK_EBF/svn_full_checkout.php

Added Paths:
-----------
    thirdparty/PE_custom/BK_EBF/property/inc/import/
    thirdparty/PE_custom/BK_EBF/property/inc/import/default/
    
thirdparty/PE_custom/BK_EBF/property/inc/import/default/Import_fra_Service_EBF
    
thirdparty/PE_custom/BK_EBF/property/inc/import/default/import_faktura_LRS_manglende_varemottak

Copied: 
thirdparty/PE_custom/BK_EBF/property/inc/import/default/Import_fra_Service_EBF 
(from rev 17261, trunk/property/inc/import/default/Import_fra_Service_EBF)
===================================================================
--- 
thirdparty/PE_custom/BK_EBF/property/inc/import/default/Import_fra_Service_EBF  
                            (rev 0)
+++ 
thirdparty/PE_custom/BK_EBF/property/inc/import/default/Import_fra_Service_EBF  
    2017-11-02 15:01:01 UTC (rev 17262)
@@ -0,0 +1,411 @@
+<?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,v 1.19 2007/03/18 16:33:16 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',
+                       'DIM 6' => 'dimd', //utgår fra import - kopieres fra 
kategori
+                       'MVA' => 'mvakode',
+                       'Tjeneste' => 'kostra_id',
+                       'Belop [kr]' => 'belop'
+               );
+               var $header = array('Bestilling', 'Fakt. Nr', 'Konto', 
'Objekt', 'DIM 6', 'MVA',
+                       'Belop [kr]');
+
+               function __construct()
+               {
+                       $this->db = clone($GLOBALS['phpgw']->db);
+                       $this->soXport = CreateObject('property.soXport');
+                       $this->invoice = CreateObject('property.boinvoice');
+                       $this->bocommon = CreateObject('property.bocommon');
+                       $this->dateformat = 
$GLOBALS['phpgw']->db->date_format();
+                       $this->datetimeformat = 
$GLOBALS['phpgw']->db->datetime_format();
+                       $this->next_bilagsnr = $this->invoice->next_bilagsnr();
+                       $this->cats = CreateObject('phpgwapi.categories', -1, 
'property', '.project');
+                       $this->cats->supress_info = true;
+               }
+
+               function import( $invoice_common, $download )
+               {
+                       $tsvfile = $invoice_common['tsvfile'];
+
+                       $conv_type = $invoice_common['conv_type'];
+                       $buffer = array();
+
+//-----------
+
+                       phpgw::import_class('phpgwapi.phpexcel');
+
+                       $objPHPExcel = PHPExcel_IOFactory::load($tsvfile);
+
+                       $data = $objPHPExcel->getActiveSheet()->toArray(null, 
true, true, true);
+
+                       $result = array();
+
+                       $rows = count($data) + 1;
+
+                       for ($row = $this->header_count; $row < $rows; $row++)
+                       {
+                               $this->currentrecord = array();
+
+                               $j = 0;
+                               foreach ($data[$row] as $key => $_dummy)
+                               {
+                                       $value = 
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j, 
$row)->getCalculatedValue();
+
+                                       if ($name = 
$this->import[$this->header[$j]])
+                                       {
+
+                                               $value = 
str_replace(array('\n', '\r'), array('<BR>', ''), $value);
+                                               $this->currentrecord += 
array($name => $value);
+                                       }
+                                       $j++;
+                               }
+
+                               if ($this->currentrecord['fakturanr'] && 
$this->currentrecord['belop']) // fakturanr og beløp
+                               {
+                                       ++$this->id;
+                                       $buffer = 
$this->import_end_record($buffer, $invoice_common);
+                               }
+                       }
+
+//----------
+
+                       if (!$download)
+                       {
+                               $buffer = $this->import_end_file($buffer, 
$invoice_common['bilagsnr']);
+                       }
+
+                       return $buffer;
+               }
+
+               function import_end_record( $buffer, $invoice_common )
+               {
+                       static $workorders = array();
+
+                       $buffer[$this->id] = array();
+
+                       foreach ($this->currentrecord as $name => $value)
+                       {
+                               if ($name == 'belop')
+                               {
+                                       $value = str_replace('kr', '', $value);
+                                       $value = str_replace(' ', '', $value);
+                                       $value = str_replace(',', '.', $value);
+
+                                       if ($invoice_common['art'] == 2) // 
kreditnota
+                                       {
+                                               $value = -1 * abs($value);
+                                       }
+
+                                       $buffer[$this->id]['godkjentbelop'] = 
$value;
+                               }
+
+                               if ($name == 'pmwrkord_code')
+                               {
+                                       if (!$workorder = 
$workorders[(int)$value]['order'])
+                                       {
+                                               if 
($this->soXport->check_order((int)$value))
+                                               {
+                                                       $workorder = 
execMethod('property.soworkorder.read_single', (int)$value);
+                                                       
$workorders[(int)$value]['order'] = $workorder;
+                                                       
$workorders[(int)$value]['project_id'] = 
$this->soXport->get_project((int)$value);//Agresso prosjekt
+                                               }
+                                       }
+                                       $buffer[$this->id]['project_id'] = 
$workorders[(int)$value]['project_id'];//Agresso prosjekt
+                                       $buffer[$this->id]['dimb'] = 
$workorders[(int)$value]['order']['ecodimb']; // Ansvarssted
+                               }
+
+                               if ($name == 'spbudact_code')
+                               {
+                                       continue;
+                               }
+
+                               if ($name == 'dima')
+                               {
+                                       $value = $this->check_dima($value);
+                                       $buffer[$this->id]['loc1'] = $loc1 = 
substr($value, 0, 4);
+                               }
+
+                               if ($name == 'mvakode')
+                               {
+                                       if ($invoice_common['auto_tax'])
+                                       {
+                                               $value = 
(int)$this->soXport->auto_tax($buffer[$this->id]['loc1']);
+                                       }
+                                       else
+                                       {
+                                               $value = (int)$value;
+                                       }
+                               }
+
+                               $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]['periode'] = 
$invoice_common['syear'] . sprintf("%02d", $invoice_common['smonth']);
+                       $buffer[$this->id]['regtid'] = 
date($this->datetimeformat);
+                       $buffer[$this->id]['artid'] = $invoice_common['art'];
+                       $buffer[$this->id]['spvend_code'] = 
$invoice_common['vendor_id'];
+                       $buffer[$this->id]['oppsynsmannid'] = 
$invoice_common['janitor'];
+                       $buffer[$this->id]['saksbehandlerid'] = 
$invoice_common['supervisor'];
+                       $buffer[$this->id]['budsjettansvarligid'] = 
$invoice_common['budget_responsible'];
+
+
+                       $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']));
+                       }
+
+                       $buffer[$this->id]['fakturadato'] = $invoice_date;
+                       $buffer[$this->id]['forfallsdato'] = $payment_date;
+
+                       if ($workorder)
+                       {
+                               if 
($this->check_old_spbudact_code($workorder['b_account_id']))
+                               {
+                                       $_accout_class = 
substr(substr($workorder['b_account_id'], -4), 0, 2);
+                                       switch ($_accout_class)
+                                       {
+                                               case '41':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123013';
+                                                       break;
+                                               case '42':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123014';
+                                                       break;
+                                               case '44':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123015';
+                                                       break;
+                                               case '45':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123016';
+                                                       break;
+                                               case '46':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123016';
+                                                       break;
+                                               case '47':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123017';
+                                                       break;
+                                               case '48':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123018';
+                                                       break;
+                                               case '49':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123019';
+                                                       break;
+                                               default:
+                                                       
$buffer[$this->id]['spbudact_code'] = '123014';
+                                                       break;
+                                       }
+
+                                       $buffer[$this->id]['dime'] = 
(int)substr($workorder['b_account_id'], -4); // Dim 6
+                               }
+                               else
+                               {
+                                       $buffer[$this->id]['dime'] = 
strlen($workorder['cat_id']) == 4 ? $workorder['cat_id'] : ''; // Dim 6
+                                       if (strlen($workorder['b_account_id']) 
== 6 && $this->check_spbudact_code($workorder['b_account_id']))
+                                       {
+                                               
$buffer[$this->id]['spbudact_code'] = $workorder['b_account_id'];
+                                       }
+                                       else
+                                       {
+                                               
$buffer[$this->id]['spbudact_code'] = '';
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               $_spbudact_code = 
$this->currentrecord['spbudact_code'];
+                               if 
($this->check_old_spbudact_code($_spbudact_code))
+                               {
+                                       $_accout_class = 
substr(substr($_spbudact_code, -4), 0, 2);
+                                       switch ($_accout_class)
+                                       {
+                                               case '41':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123013';
+                                                       break;
+                                               case '42':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123014';
+                                                       break;
+                                               case '44':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123015';
+                                                       break;
+                                               case '45':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123016';
+                                                       break;
+                                               case '46':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123016';
+                                                       break;
+                                               case '47':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123017';
+                                                       break;
+                                               case '48':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123018';
+                                                       break;
+                                               case '49':
+                                                       
$buffer[$this->id]['spbudact_code'] = '123019';
+                                                       break;
+                                               default:
+                                                       
$buffer[$this->id]['spbudact_code'] = '123014';
+                                                       break;
+                                       }
+
+                                       $buffer[$this->id]['dime'] = 
(int)substr($_spbudact_code, -4); // Dim 6
+                               }
+                               else
+                               {
+                                       $category = 
$this->cats->return_single((int)$this->currentrecord['dimd']);
+                                       if (isset($category[0]) && 
$category[0]['active'] == 1)
+                                       {
+                                               $buffer[$this->id]['dime'] = 
$this->currentrecord['dimd']; // Dim 6
+                                       }
+
+                                       $buffer[$this->id]['spbudact_code'] = 
$_spbudact_code ? $_spbudact_code : '';
+                               }
+                       }
+
+                       if 
(!$this->invoice->check_valid_b_account($buffer[$this->id]['spbudact_code']))
+                       {
+                               $buffer[$this->id]['spbudact_code'] = '';
+                       }
+
+                       $buffer[$this->id]['dimd'] = $buffer[$this->id]['dime'];
+
+                       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]['loc1']);
+
+                       if (!isset($buffer[$this->id]['fakturanr']) || 
!$buffer[$this->id]['fakturanr']) // fakturanr
+                       {
+                               $buffer[$this->id]['fakturanr'] = 
$invoice_common['invoice_num'];
+                       }
+
+                       if (!isset($buffer[$this->id]['dimb']) || 
!$buffer[$this->id]['dimb']) // Ansvarssted
+                       {
+                               $buffer[$this->id]['dimb'] = 
$invoice_common['dim_b'];
+                       }
+
+                       return $buffer;
+               }
+
+               function check_old_spbudact_code( $id )
+               {
+                       $this->db->query("SELECT id FROM fm_b_account_convert 
WHERE id='{$id}'");
+                       $this->db->next_record();
+                       if ($this->db->f('id'))
+                       {
+                               return true;
+                       }
+                       else
+                       {
+                               $this->db->query("SELECT id FROM 
fm_b_account_convert WHERE old_id='{$id}'");
+                               $this->db->next_record();
+                               return !!$this->db->f('id');
+                       }
+
+                       return false;
+               }
+
+               /**
+                * Check for valid budget account
+                * @param integer $id
+                * @return bool true on exist, false on not exist
+                */
+               function check_spbudact_code( $id )
+               {
+                       $this->db->query("SELECT id FROM fm_b_account WHERE 
id='{$id}'");
+                       return !!$this->db->next_record();
+               }
+
+               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 )
+               {
+                       $receipt = array();
+                       $num = $this->soXport->add($buffer);
+                       $receipt['message'][] = array('msg' => 
lang('Successfully imported %1 records into your invoice register.', $num) . ' 
' . lang('ID') . ': ' . $bilagsnr);
+                       return $receipt;
+               }
+       }       
\ No newline at end of file

Copied: 
thirdparty/PE_custom/BK_EBF/property/inc/import/default/import_faktura_LRS_manglende_varemottak
 (from rev 17261, 
trunk/property/inc/import/default/import_faktura_LRS_manglende_varemottak)
===================================================================
--- 
thirdparty/PE_custom/BK_EBF/property/inc/import/default/import_faktura_LRS_manglende_varemottak
                             (rev 0)
+++ 
thirdparty/PE_custom/BK_EBF/property/inc/import/default/import_faktura_LRS_manglende_varemottak
     2017-11-02 15:01:01 UTC (rev 17262)
@@ -0,0 +1,478 @@
+<?php
+
+       class import_conversion
+       {
+
+               protected $db;
+               public $messages = array();
+               public $warnings = array();
+               public $errors = array();
+               public $debug = false;
+
+               protected $period;
+               protected $year;
+               protected $month;
+               protected $date;
+               protected $mvakode = 0;
+               protected $kildeid = 1;
+               protected $splitt = 0;
+               protected $soXport;
+               protected $invoice;
+               protected $default_kostra_id = 9999; //dummy
+               protected $skip_import = false;
+               protected $skip_email = false;
+               protected $export;
+               protected $skip_update_voucher_id = false;
+
+               public $filename_template;
+
+               public function __construct( $location_id, $debug = false, 
$get_template = false )
+               {
+                       /*
+                        * The purpose is to get to the fields definition
+                        */
+                       if ($get_template)
+                       {
+                               $this->filename_template = "Import av manglende 
faktura " . date(Ym);// 201401"
+                               return;
+                       }
+                       set_time_limit(10000); //Set the time limit for this 
request
+                       $this->account = 
(int)$GLOBALS['phpgw_info']['user']['account_id'];
+                       $this->db = & $GLOBALS['phpgw']->db;
+                       $this->join = $this->db->join;
+
+                       $this->soXport = CreateObject('property.soXport');
+                       $this->invoice = CreateObject('property.soinvoice');
+                       $this->responsible = 
CreateObject('property.soresponsible');
+                       $this->bocommon = CreateObject('property.bocommon');
+
+                       $this->dateformat = $this->db->date_format();
+                       $this->datetimeformat = $this->db->datetime_format();
+                       $this->config = CreateObject('admin.soconfig', 
$GLOBALS['phpgw']->locations->get_id('property', '.invoice'));
+               }
+
+               public function add( $data )
+               {
+//                     static $linje = 1;
+//                     _debug_array("Innkommende {$linje}");
+//                     _debug_array($data);
+//                     $linje ++;
+
+                       $type = $data[0];
+                       $bilagsnr = $data[1];
+                       $bilagsdato = $data[2];
+                       $periode = $data[3];
+                       $art = (string)$data[4];
+                       $mva_kode = $data[5];
+                       $amount = round($data[6] / (-1.25), 2);
+                       $fakturanr = $data[7];
+                       $order_id = $data[8];
+
+                       if ($art != '2327010')
+                       {
+                       _debug_array('Hopper over');
+                       _debug_array($data);
+                               return true;
+                       }
+                       $this->db->query("SELECT vendor_id FROM fm_workorder 
WHERE id = $order_id", __LINE__, __FILE__);
+                       $this->db->next_record();
+                       $vendor_id = $this->db->f('vendor_id');
+
+                       $_data = array(
+                               'KEY'=> $bilagsnr,
+                               'AMOUNT'=> $amount,
+                               'CURRENCY.CURRENCYID'=> 'NOK',
+                               'INVOICEDATE'   => '20170207',
+                               'MATURITY'              => '20170306',
+                               'PURCHASEORDERNO'=> $order_id,
+                               'SUPPLIERREF'   => $fakturanr,
+                               'SUPPLIER.CODE' => $vendor_id,
+                               'art'   => $art
+
+                       );
+
+                       $error = false;
+
+                       if (!$amount)
+                       {
+                               $this->warnings[] = "Linje mangler Beløp, 
hopper over: {$bilagsnr}";
+                               return true;
+                       }
+                       if (!$order_id)
+                       {
+                               $this->warnings[] = "Linje mangler 
bestillingsnummer, hopper over: {$bilagsnr}";
+                               return true;
+                       }
+
+                       if (!execMethod('property.soXport.check_order', 
$order_id))
+                       {
+                               $this->errors[] = "Ikke gyldig 
bestillingsnummer: {$order_id}";
+                               return false;
+                       }
+
+                       $this->import($_data);
+
+                       return true;
+               }
+
+               protected function import( $_data )
+               {
+                       $this->skip_update_voucher_id = false;
+                       $this->skip_import = false;
+
+                       $sql = "SELECT bilagsnr, bilagsnr_ut FROM fm_ecobilag 
WHERE external_voucher_id = '{$_data['KEY']}'";
+                       $this->db->query($sql, __LINE__, __FILE__);
+                       if ($this->db->next_record())
+                       {
+                               _debug_array('Finnest frå før:' .$_data['KEY']);
+                               _debug_array($_data);
+                               $this->skip_update_voucher_id = true;
+                               $this->skip_import = true;
+                       }
+
+                       $sql = "SELECT bilagsnr, bilagsnr_ut FROM 
fm_ecobilagoverf WHERE external_voucher_id = '{$_data['KEY']}'";
+                       $this->db->query($sql, __LINE__, __FILE__);
+                       if ($this->db->next_record())
+                       {
+                               _debug_array('Finnest frå før:' .$_data['KEY']);
+                               _debug_array($_data);
+                               $this->skip_update_voucher_id = true;
+                               $this->skip_import = true;
+                       }
+
+                       if(!$this->skip_import)
+                       {
+                               _debug_array('Nye data');
+                               _debug_array($_data);
+                       }
+                       
+                       $buffer = array();
+                       $bilagsnr = false;
+
+                       set_time_limit(300);
+
+                       $regtid = date($this->datetimeformat);
+
+                       $i = 0;
+
+                       $_data['ARRIVAL']; // => 2009.05.28
+                       $_data['CLIENT.CODE']; // => 14
+                       $_data['EXCHANGERATE']; // => 1
+                       $_data['LOCALAMOUNT']; // => 312500
+                       $_data['LOCALVATAMOUNT']; // => 62500
+                       $_data['PAYAMOUNT']; // => 0
+                       $_data['POSTATUSUPDATED']; // => 0
+                       $_data['PURCHASEORDERSTATUS.CODE']; // => WaitForMatch
+                       $_data['SUPPLIER.BANKGIRO']; // => 70580621110
+                       $_data['VATAMOUNT']; // => 62500
+
+                       $bilagsnr_ut = isset($_data['VOUCHERID']) ? 
$_data['VOUCHERID'] : ''; // FIXME: innkommende bilagsnummer?
+
+                       $fakturanr = $_data['SUPPLIERREF'];
+                       $fakturadato = date($this->dateformat, 
strtotime(str_replace('.', '-', $_data['INVOICEDATE'])));
+                       $forfallsdato = date($this->dateformat, 
strtotime(str_replace('.', '-', $_data['MATURITY'])));
+                       $periode = '';
+                       $belop = $_data['AMOUNT'];
+
+                       if (!abs($belop) > 0)
+                       {
+                               $this->receipt['message'][] = array('msg' => 
"Beløpet er 0 for Skanningreferanse: {$_data['SCANNINGNO']}, FakturaNr: 
{$fakturanr}, fil: {$file}");
+                               $belop = (float)0.0001; // imported as 0.00
+                       }
+
+                       if ($belop < 0)
+                       {
+                               $buffer[$i]['artid'] = 2;
+                       }
+                       else
+                       {
+                               $buffer[$i]['artid'] = 1;
+                       }
+
+                       $kidnr = $_data['KIDNO'];
+                       $_order_id = $_data['PURCHASEORDERNO'];
+                       $merknad = '';
+                       $line_text = '';
+
+                       $order_info = $this->get_order_info($_order_id); // 
henter default verdier selv om  $_order_id ikke er gyldig.
+
+                       $buffer[$i]['project_id'] = 
$this->soXport->get_project($_order_id);
+                       $order_id = $_order_id;
+
+                       $buffer[$i]['external_voucher_id'] = $_data['KEY']; // 
=> 1400050146
+                       $buffer[$i]['pmwrkord_code'] = $order_id;
+                       $buffer[$i]['fakturanr'] = $fakturanr;
+                       $buffer[$i]['periode'] = $periode;
+                       $buffer[$i]['forfallsdato'] = $forfallsdato;
+                       $buffer[$i]['fakturadato'] = $fakturadato;
+                       $buffer[$i]['belop'] = $belop;
+                       $buffer[$i]['currency'] = $_data['CURRENCY.CURRENCYID'];
+                       $buffer[$i]['godkjentbelop'] = $belop;
+
+                       $buffer[$i]['kidnr'] = $kidnr;
+                       $buffer[$i]['bilagsnr_ut'] = $bilagsnr_ut;
+                       $buffer[$i]['referanse'] = "ordre: {$order_id}";
+
+                       $buffer[$i]['dima'] = $order_info['dima'];
+                       $buffer[$i]['dimb'] = $order_info['dimb'];
+                       $buffer[$i]['dime'] = $order_info['dime'];
+                       $buffer[$i]['loc1'] = $order_info['loc1'];
+                       $buffer[$i]['line_text'] = $order_info['title'];
+
+                       $buffer[$i]['mvakode'] = $order_info['tax_code'];
+
+                       if ($buffer[$i]['loc1'] && !$buffer[$i]['mvakode'])
+                       {
+                               $mvakode = 
$this->soXport->auto_tax($buffer[$i]['loc1']);
+
+                               if ($mvakode)
+                               {
+                                       $buffer[$i]['mvakode'] = $mvakode;
+                               }
+                       }
+
+                       $update_voucher = false;
+
+                       $vendor_id = $_data['SUPPLIER.CODE'];
+
+                       $sql = 'SELECT id FROM fm_vendor WHERE id = ' . 
(int)$vendor_id;
+                       $this->db->query($sql, __LINE__, __FILE__);
+
+                       if (!$_data['SUPPLIER.CODE'])
+                       {
+                               $this->receipt['error'][] = array('msg' => 
"LeverandørId ikke angitt for faktura: {$_data['SCANNINGNO']}");
+                               $this->skip_import = true;
+                       }
+                       else if (!$this->db->next_record())
+                       {
+                               $this->receipt['error'][] = array('msg' => 
"Importeres ikke: Ikke gyldig LeverandørId: {$_data['SUPPLIER.CODE']}, 
Skanningreferanse: {$_data['SCANNINGNO']}, FakturaNr: {$fakturanr}, fil: 
{$file}");
+                               $this->skip_import = true;
+                       }
+                       else if ($order_info['vendor_id'] != $vendor_id)
+                       {
+                               $this->receipt['message'][] = array('msg' => 
'Ikke samsvar med leverandør på bestilling og mottatt faktura');
+                       }
+
+                       $buffer[$i]['kostra_id'] = $order_info['service_id'];
+
+                       $buffer[$i]['merknad'] = $merknad;
+                       $buffer[$i]['splitt'] = $this->splitt;
+                       $buffer[$i]['kildeid'] = $this->kildeid;
+                       $buffer[$i]['spbudact_code'] = 
$order_info['spbudact_code'];
+                       $buffer[$i]['typeid'] = isset($invoice_common['type']) 
&& $invoice_common['type'] ? $invoice_common['type'] : 1;
+                       $buffer[$i]['regtid'] = $regtid;
+
+                       $buffer[$i]['spvend_code'] = $vendor_id;
+
+                       if (isset($order_info['janitor']) && 
$order_info['janitor'])
+                       {
+                               $buffer[$i]['oppsynsmannid'] = 
$order_info['janitor'];
+                       }
+
+                       if (isset($order_info['supervisor']) && 
$order_info['supervisor'])
+                       {
+                               $buffer[$i]['saksbehandlerid'] = 
$order_info['supervisor'];
+                       }
+
+                       if (isset($order_info['budget_responsible']) && 
$order_info['budget_responsible'])
+                       {
+                               $buffer[$i]['budsjettansvarligid'] = 
$order_info['budget_responsible'];
+                       }
+
+
+//_debug_array($buffer);
+//_debug_array($this->receipt);
+//_debug_array($order_info['toarray']);
+
+
+                       {
+                               if (!$bilagsnr)
+                               {
+                                       $bilagsnr = 
$this->invoice->next_bilagsnr();
+
+                                       foreach ($buffer as &$entry)
+                                       {
+                                               $entry['bilagsnr'] = $bilagsnr;
+                                       }
+                               }
+
+                               $GLOBALS['phpgw']->db->Exception_On_Error = 
true;
+
+                               try
+                               {
+                                       if(!$this->skip_import)
+                                       {
+                                               $bilagsnr = 
$this->import_end_file($buffer);
+                                       }
+
+                                       if 
($this->config->config_data['export']['auto_receive_order'])
+                                       {
+                                               $received_amount = 
$this->get_total_received((int)$order_id);
+                                               $order_type = 
$this->bocommon->socommon->get_order_type($order_id);
+
+                                               switch ($order_type)
+                                               {
+                                                       case 'workorder':
+                                                               $received = 
createObject('property.boworkorder')->receive_order((int)$order_id, 
$received_amount);
+                                                               break;
+                                                       case 'ticket':
+                                                               $received = 
createObject('property.botts')->receive_order((int)$order_id, $received_amount);
+                                                               break;
+                                                       default:
+                                                               throw new 
Exception('Order type not supported');
+                                               }
+                                       }
+                               }
+                               catch (Exception $e)
+                               {
+                                       if ($e)
+                                       {
+                                               
$GLOBALS['phpgw']->log->error(array(
+                                                       'text' => 
'import_fra_agresso_X205::import() : error when trying to execute 
import_end_file(): %1',
+                                                       'p1' => 
$e->getMessage(),
+                                                       'p2' => '',
+                                                       'line' => __LINE__,
+                                                       'file' => __FILE__
+                                               ));
+                                               $this->receipt['error'][] = 
array('msg' => $e->getMessage());
+                                       }
+                                       return false;
+                               }
+
+                               $GLOBALS['phpgw']->db->Exception_On_Error = 
false;
+                               return $bilagsnr;
+                       }
+               }
+
+               function get_total_received( $order_id )
+               {
+                       $amount = 0;
+                       $sql = "SELECT sum(godkjentbelop) AS amount FROM 
fm_ecobilag WHERE pmwrkord_code = {$order_id}";
+                       $this->db->query($sql, __LINE__, __FILE__);
+                       $this->db->next_record();
+                       $amount += (float)$this->db->f('amount');
+                       $sql = "SELECT sum(godkjentbelop) AS amount FROM 
fm_ecobilagoverf WHERE pmwrkord_code = {$order_id}";
+                       $this->db->query($sql, __LINE__, __FILE__);
+                       $this->db->next_record();
+                       $amount += (float)$this->db->f('amount');
+                       return $amount;
+               }
+
+               function get_order_info( $order_id = 0 )
+               {
+                       $order_id = (int)$order_id;
+
+                       $this->db->query("SELECT type FROM fm_orders WHERE id = 
$order_id", __LINE__, __FILE__);
+                       $this->db->next_record();
+                       $order_type = $this->db->f('type');
+
+                       $order_info = array();
+                       $toarray = array();
+
+                       switch ($order_type)
+                       {
+                               case 'ticket':
+                                       $sql = "SELECT 
fm_tts_tickets.location_code,"
+                                               . " fm_tts_tickets.vendor_id,"
+                                               . " fm_tts_tickets.b_account_id 
as account_id,"
+                                               . " fm_tts_tickets.ecodimb,"
+                                               . " fm_tts_tickets.service_id,"
+                                               . " fm_tts_tickets.tax_code,"
+                                               . " fm_tts_tickets.cat_id as 
category,"
+                                               . " fm_tts_tickets.ordered_by 
as user_id,"
+                                               . " fm_tts_tickets.subject as 
title"
+                                               . " FROM fm_tts_tickets"
+                                               . " WHERE 
fm_tts_tickets.order_id = {$order_id}";
+
+                                       break;
+                               case 'workorder':
+                                       $sql = "SELECT 
fm_workorder.location_code,"
+                                               . " fm_workorder.vendor_id,"
+                                               . " fm_workorder.account_id,"
+                                               . " fm_project.ecodimb as 
project_ecodimb,"
+                                               . " fm_workorder.ecodimb,"
+                                               . " fm_workorder.category,"
+                                               . " fm_workorder.user_id,"
+                                               . " fm_workorder.service_id,"
+                                               . " fm_workorder.tax_code,"
+                                               . " fm_workorder.title"
+                                               . " FROM fm_workorder 
{$this->join} fm_project ON fm_workorder.project_id = fm_project.id"
+                                               . " WHERE fm_workorder.id = 
{$order_id}";
+                                       break;
+
+                               default:
+                                       throw new Exception("{$order_type} not 
supported");
+                                       break;
+                       }
+
+                       $this->db->query($sql, __LINE__, __FILE__);
+                       if ($this->db->next_record())
+                       {
+                               $order_info['order_exist'] = true;
+                       }
+                       if ($this->db->f('location_code'))
+                       {
+                               $parts = explode('-', 
$this->db->f('location_code'));
+                               $order_info['dima'] = implode('', $parts);
+                               $order_info['loc1'] = $parts[0];
+                       }
+
+                       $order_info['vendor_id'] = $this->db->f('vendor_id');
+                       $order_info['spbudact_code'] = 
$this->db->f('account_id');
+                       $ecodimb = $this->db->f('ecodimb');
+                       $order_info['dimb'] = $ecodimb ? $ecodimb : 
$this->db->f('project_ecodimb');
+                       $order_info['dime'] = $this->db->f('category');
+                       $order_info['title'] = $this->db->f('title', true);
+                       $order_info['service_id'] = $this->db->f('service_id');
+                       $order_info['tax_code'] = $this->db->f('tax_code');
+
+                       $janitor_user_id = $this->db->f('user_id');
+                       $order_info['janitor'] = 
$GLOBALS['phpgw']->accounts->get($janitor_user_id)->lid;
+                       $supervisor_user_id = 
$this->invoice->get_default_dimb_role_user(2, $order_info['dimb']);
+                       if ($supervisor_user_id)
+                       {
+                               $order_info['supervisor'] = 
$GLOBALS['phpgw']->accounts->get($supervisor_user_id)->lid;
+                       }
+
+                       $budget_responsible_user_id = 
$this->invoice->get_default_dimb_role_user(3, $order_info['dimb']);
+                       if ($budget_responsible_user_id)
+                       {
+                               $order_info['budget_responsible'] = 
$GLOBALS['phpgw']->accounts->get($budget_responsible_user_id)->lid;
+                       }
+
+                       if (!$order_info['budget_responsible'])
+                       {
+                               $order_info['budget_responsible'] = 
isset($this->config->config_data['import']['budget_responsible']) && 
$this->config->config_data['import']['budget_responsible'] ? 
$this->config->config_data['import']['budget_responsible'] : 'karhal';
+                       }
+
+                       $order_info['toarray'] = $toarray;
+                       return $order_info;
+               }
+
+               function import_end_file( $buffer )
+               {
+                       try
+                       {
+                               $num = $this->soXport->add($buffer, 
$this->skip_update_voucher_id);
+                       }
+                       catch (Exception $e)
+                       {
+                               throw $e;
+                       }
+
+                       if ($this->debug)
+                       {
+                               _debug_array("import_end_file() ");
+                               echo 'buffer: ';
+                               _debug_array($buffer);
+                               _debug_array("num: {$num}");
+                       }
+
+                       if ($num > 0)
+                       {
+                               $this->receipt['message'][] = array('msg' => 
"Importert {$num} poster til bilag {$buffer[0]['bilagsnr']}, KEY: 
{$buffer[0]['external_voucher_id']}");
+                               return $buffer[0]['bilagsnr'];
+                       }
+                       return false;
+               }
+       }
\ No newline at end of file

Modified: thirdparty/PE_custom/BK_EBF/svn_full_checkout.php
===================================================================
--- thirdparty/PE_custom/BK_EBF/svn_full_checkout.php   2017-11-02 10:43:08 UTC 
(rev 17261)
+++ thirdparty/PE_custom/BK_EBF/svn_full_checkout.php   2017-11-02 15:01:01 UTC 
(rev 17262)
@@ -18,10 +18,10 @@
        // Config section
        // 
****************************************************************************
 
-        //Example: /usr/local/bin/php -q svn_full_checkout.php user=<username>
+        //Example: /usr/bin/php -q svn_full_checkout.php user=<username>
 
        /**
-       * Repository where you are checking out the code.  NO trailing / - 
example: 'svn.savannah.gnu.org/phpgroupware'
+       * Repository where you are checking out the code.  NO trailing / - 
example: 'svn.savannah.nongnu.org/fmsystem'
        */
 
        $repository = 'svn.savannah.nongnu.org/fmsystem';
@@ -32,10 +32,10 @@
 
        $action = 'co';
 //     $action = 'export';
-       $revision =  '-r 17207';
+       $revision =  '';
 
        /**
-       * Directory that you want the phpgroupware directory to go in.  NO 
trailing /
+       * Directory that you want the portico directory to go in.  NO trailing /
        */
 
        $co_dir = '/var/www/html';
@@ -58,59 +58,66 @@
        $release_info = 'Version-2_0-branch';
 
        /**
-       * Modules you want to checkout, do NOT add the phpgroupware module
+       * Modules you want to checkout
        */
 
        /**
        * Base
        */
-       $co_modules[] = 'admin';
-       $co_modules[] = 'doc';
-       $co_modules[] = 'manual';
-       $co_modules[] = 'phpgwapi';
-       $co_modules[] = 'preferences';
-       $co_modules[] = 'setup';
-       $co_modules[] = 'xmlrpc';
-       $co_modules[] = 'soap';
-       $co_modules[] = 'registration';
-       $co_modules[] = 'addressbook';
+       $co_modules = array();
+       $co_modules[] = array('admin', $revision);
+       $co_modules[] = array('doc', $revision);
+       $co_modules[] = array('manual', $revision);
+       $co_modules[] = array('phpgwapi', $revision);
+       $co_modules[] = array('preferences', $revision);
+       $co_modules[] = array('setup', $revision);
+       $co_modules[] = array('xmlrpc', $revision);
+       $co_modules[] = array('soap', $revision);
+       $co_modules[] = array('registration', $revision);
+       $co_modules[] = array('addressbook', $revision);
 
        /**
        * FM
        */
-       $co_modules[] = 'mobilefrontend';
-       $co_modules[] = 'controller';
-       $co_modules[] = 'hrm';
-       $co_modules[] = 'property';
-       $co_modules[] = 'sms';
-       $co_modules[] = 'bim';
+       $co_modules[] = array('mobilefrontend', $revision);
+       $co_modules[] = array('controller', $revision);
+       $co_modules[] = array('hrm', $revision);
+       $co_modules[] = array('property', $revision);
+       $co_modules[] = array('sms', $revision);
+       $co_modules[] = array('bim', $revision);
 
 
        /*
         * Booking
         */
-       $co_modules[] = 'booking';
-       $co_modules[] = 'bookingfrontend';
-       $co_modules[] = 'activitycalendar';
-       $co_modules[] = 'activitycalendarfrontend';
+       $co_modules[] = array('booking', $revision);
+       $co_modules[] = array('bookingfrontend', $revision);
+       $co_modules[] = array('activitycalendar', $revision);
+       $co_modules[] = array('activitycalendarfrontend', $revision);
 
 
        /*
         * rental
         */
-       $co_modules[] = 'rental';
-       $co_modules[] = 'frontend';
+       $co_modules[] = array('rental', $revision);
+       $co_modules[] = array('frontend', $revision);
 
        /**
        * Some other stuff
        */
-       $co_modules[] = 'catch';
-       $co_modules[] = 'logistic';
-       $co_modules[] = 'helpdesk';
-       $co_modules[] = 'eventplanner';
-       $co_modules[] = 'eventplannerfrontend';
+       $co_modules[] = array('catch', $revision);
+       $co_modules[] = array('logistic', $revision);
+       $co_modules[] = array('helpdesk', $revision);
+       $co_modules[] = array('eventplanner', $revision);
+       $co_modules[] = array('eventplannerfrontend', $revision);
 
 
+       $pe_custom = array();
+       $pe_custom['BK_EBF'] = array
+               (
+                       array('property', '')
+               );
+
        // 
****************************************************************************
        // End config section
        // 
****************************************************************************
@@ -135,26 +142,54 @@
                $branch = 'trunk';
        }
 
+       $_revision = $revision ? "-r $revision" : '';
+
        chdir($co_dir);
+
+       echo "$action {$_revision} {$repository}/{$branch}{$release} to 
{$co_dir}\n";
+
        if ($cvs_anonymous)
        {
-               system("svn {$action} {$revision} 
svn://{$repository}/{$branch}{$release} portico --non-recursive");
+               system("svn {$action} {$_revision} 
svn://{$repository}/{$branch}{$release} portico --non-recursive");
        }
        else
        {
-               system("svn {$action} {$revision} 
svn+ssh://address@hidden/{$branch}{$release}  portico --non-recursive");
+               system("svn {$action} {$_revision} 
svn+ssh://address@hidden/{$branch}{$release} portico --non-recursive");
        }
 
        chdir($co_dir . '/portico');
 
-       foreach($co_modules as $module)
+       foreach($co_modules as $_module)
        {
+               $module = $_module[0];
+               $_revision = !empty($_module[1]) ? "-r {$_module[1]}" : '';
+               echo "$action {$_revision} 
{$repository}/{$branch}{$release}/{$module} to {$co_dir}/portico\n";
                if ($cvs_anonymous)
                {
-                       system("svn {$action} {$revision} 
svn://{$repository}/{$branch}{$release}/{$module}");
+                       system("svn {$action} {$_revision} 
svn://{$repository}/{$branch}{$release}/{$module}");
                }
                else
                {
-                       system("svn {$action} {$revision} 
svn+ssh://address@hidden/{$branch}$release/{$module}");
+                       system("svn {$action} {$_revision} 
svn+ssh://address@hidden/{$branch}$release/{$module}");
                }
        }
+
+       foreach($pe_custom as $section => $modules)
+       {
+               foreach ($modules as $_module)
+               {
+                       $module = $_module[0];
+                       $_revision = !empty($_module[1]) ? "-r {$_module[1]}" : 
'';
+
+                       echo "export {$_revision} 
{$repository}/thirdparty/PE_custom/{$section}/{$module} to {$co_dir}/portico\n";
+
+                       if ($cvs_anonymous)
+                       {
+                               system("svn export {$_revision} 
svn://{$repository}/thirdparty/PE_custom/{$section}/{$module} --force");
+                       }
+                       else
+                       {
+                               system("svn export {$_revision} 
svn+ssh://address@hidden/thirdparty/PE_custom/{$section}/{$module} --force");
+                       }
+               }
+       }




reply via email to

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