fmsystem-commits
[Top][All Lists]
Advanced

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

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


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

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

Added Paths:
-----------
    thirdparty/PE_custom/BK_EBE/property/inc/import/
    thirdparty/PE_custom/BK_EBE/property/inc/import/default/
    
thirdparty/PE_custom/BK_EBE/property/inc/import/default/cvs_import_kunstoversikt_bilde_bkb
    
thirdparty/PE_custom/BK_EBE/property/inc/import/default/cvs_import_kunstoversikt_bkb
    
thirdparty/PE_custom/BK_EBE/property/inc/import/default/cvs_import_romdata_bkb
    thirdparty/PE_custom/NLSH/property/inc/import/
    thirdparty/PE_custom/NLSH/property/inc/import/default/
    
thirdparty/PE_custom/NLSH/property/inc/import/default/cvs_import_fiktiv_faktura_nlsh

Copied: 
thirdparty/PE_custom/BK_EBE/property/inc/import/default/cvs_import_kunstoversikt_bilde_bkb
 (from rev 17261, 
trunk/property/inc/import/default/cvs_import_kunstoversikt_bilde_bkb)
===================================================================
--- 
thirdparty/PE_custom/BK_EBE/property/inc/import/default/cvs_import_kunstoversikt_bilde_bkb
                          (rev 0)
+++ 
thirdparty/PE_custom/BK_EBE/property/inc/import/default/cvs_import_kunstoversikt_bilde_bkb
  2017-11-02 15:01:56 UTC (rev 17263)
@@ -0,0 +1,78 @@
+<?php
+
+       class import_conversion
+       {
+
+               protected $bofiles;
+               protected $db;
+               public $messages = array();
+               public $warnings = array();
+               public $errors = array();
+               protected $dir = '/u01/kunst/001';
+               protected $entity_id = 4;
+               protected $cat_id = 1;
+               public $debug = true;
+
+               public function __construct()
+               {
+                       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->bofiles = CreateObject('property.bofiles');
+                       $this->category_dir = 
"entity_{$this->entity_id}_{$this->cat_id}";
+                       $this->soentity = CreateObject('property.soentity', 
$this->entity_id, $this->cat_id);
+               }
+
+               public function add( $data )
+               {
+                       $error = false;
+//_debug_array($data);
+
+                       $values = $this->soentity->read_single(array('id' => 
$data[0]));
+
+                       if (isset($values['location_code']))
+                       {
+                               $filename = sprintf('%05s', $data[1]);
+                               $from_file = "{$this->dir}/{$filename}.jpg";
+                               if (!is_file($from_file))
+                               {
+                                       $this->errors[] = "'Missing file: 
{$from_file}";
+                               }
+
+                               $location = explode('-', 
$values['location_code']);
+
+                               $to_file = 
"{$this->bofiles->fakebase}/{$this->category_dir}/{$location[0]}/{$data[0]}/{$filename}.jpg";
+
+                               if ($this->bofiles->vfs->file_exists(array
+                                               (
+                                               'string' => $to_file,
+                                               'relatives' => 
Array(RELATIVE_NONE)
+                                       )))
+                               {
+                                       $this->errors[] = "This file already 
exists: {$to_file}";
+                               }
+                               else if (!$this->debug)
+                               {
+                                       
$this->bofiles->create_document_dir("{$this->category_dir}/{$location[0]}/{$data[0]}");
+                                       $this->bofiles->vfs->override_acl = 1;
+
+                                       if (!$this->bofiles->vfs->cp(array(
+                                                       'from' => $from_file,
+                                                       'to' => $to_file,
+                                                       'relatives' => 
array(RELATIVE_NONE | VFS_REAL, RELATIVE_ALL))))
+                                       {
+                                               $this->errors[] = "'Failed to 
upload file: {$to_file}";
+                                       }
+                                       else
+                                       {
+                                               $this->messages[] = 
"Successfully imported file: Title ({$filename}.jpg)";
+                                       }
+                                       $this->bofiles->vfs->override_acl = 0;
+                               }
+
+//                             _debug_array($to_file);
+                       }
+
+                       return true;
+               }
+       }
\ No newline at end of file

Copied: 
thirdparty/PE_custom/BK_EBE/property/inc/import/default/cvs_import_kunstoversikt_bkb
 (from rev 17261, 
trunk/property/inc/import/default/cvs_import_kunstoversikt_bkb)
===================================================================
--- 
thirdparty/PE_custom/BK_EBE/property/inc/import/default/cvs_import_kunstoversikt_bkb
                                (rev 0)
+++ 
thirdparty/PE_custom/BK_EBE/property/inc/import/default/cvs_import_kunstoversikt_bkb
        2017-11-02 15:01:56 UTC (rev 17263)
@@ -0,0 +1,352 @@
+<?php
+
+       class import_conversion
+       {
+
+               protected $db;
+               public $messages = array();
+               public $warnings = array();
+               public $errors = array();
+               public $debug = true;
+               protected $is_eav;
+               protected $location_id;
+               protected $bim_type_id;
+
+               public function __construct()
+               {
+                       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;
+                       $admin_entity = CreateObject('property.soadmin_entity');
+                       $admin_entity->type = 'entity';
+                       $category = $admin_entity->read_single_category(4, 1);
+                       $this->is_eav = !!$category['is_eav'];
+                       $this->location_id = 
$GLOBALS['phpgw']->locations->get_id('property', ".entity.4.1");
+
+                       $sql = "SELECT fm_bim_type.id FROM fm_bim_type WHERE 
location_id = {$this->location_id}";
+                       $this->db->query($sql, __LINE__, __FILE__);
+                       $this->db->next_record();
+                       $this->bim_type_id = $this->db->f('id');
+               }
+
+               public function add( $data )
+               {
+                       /*
+                         [0] => Identifikasjonsnr
+                         [1] => Betegnelse
+                         [2] => Objekt-id
+                         [3] => Fast plassering
+                         [4] => Juridisk person
+                         [5] => Datering
+                         [6] => Tittel
+                         [7] => Avbildet person
+                         [8] => Avbildet sted
+                         [9] => Teknikk
+                         [10] => Mål
+                         [11] => Historikk
+                         [12] => Tilstand
+                        */
+                       $error = false;
+
+                       $plassering = explode('.', $data[3]);
+                       $byggid = $plassering[1];
+                       if (!$byggid)
+                       {
+                               $this->errors[] = "Mangler objekt, hopper over: 
{$data[3]}";
+                               return true;
+                       }
+
+                       $plassering_descr_arr = array();
+                       $count_plassering = count($plassering);
+                       for ($i = 3; $i < $count_plassering; $i++)
+                       {
+                               if ($plassering[$i])
+                               {
+                                       $plassering_descr_arr[] = 
$plassering[$i];
+                               }
+                       }
+
+                       $plassering_descr = implode('.', $plassering_descr_arr);
+//_debug_array($plassering_descr);
+                       /*
+                         if(substr($plassering[0],0,1) == 'B')
+                         {
+                         $this->warnings[] = "BBB-objekt, hopper over: 
{$data[3]}";
+                         return true;
+                         }
+                        */
+
+                       $location_code = substr($byggid, 0, 4) . '-0' . 
substr($byggid, -1);
+//_debug_array($location_code);
+
+                       $location_data = 
execMethod('property.solocation.read_single', $location_code);
+                       if (!$location_data['loc1'])
+                       {
+                               $this->errors[] = "Error importing location: 
{$location_code}";
+                               $error = true;
+                               return true;
+                       }
+
+
+                       if ($location_data['street_name'])
+                       {
+                               $address[] = $location_data['street_name'];
+                               $address[] = $location_data['street_number'];
+                               $address = $this->db->db_addslashes(implode(" 
", $address));
+                       }
+
+                       $loc3_data = explode('.', $data[3]);
+                       $loc3_data2 = explode('.........', $data[3]);
+                       $loc3_data3 = explode('.', $loc3_data2[1]);
+
+                       if (ctype_digit(rtrim($loc3_data[2], '00')))
+                       {
+                               $location_code .= '-' . sprintf("%02s", 
rtrim($loc3_data[2], '00'));
+                       }
+                       else if (ctype_digit($loc3_data3[0]))
+                       {
+                               $location_code .= '-' . sprintf("%02s", 
$loc3_data3[0]);
+                       }
+
+                       $_location_data = 
execMethod('property.solocation.read_single', $location_code);
+
+                       if (!$_location_data['loc1'])
+                       {
+                               $location_code = substr($byggid, 0, 4) . '-0' . 
substr($byggid, -1);
+                       }
+
+                       if (!$address)
+                       {
+                               $address = 
$this->db->db_addslashes($location_data['loc1_name']);
+                       }
+
+                       $address .= $plassering_descr ? ", $plassering_descr" : 
'';
+
+                       $id = (int)$data[2];
+
+
+                       $this->messages[] = "Dagens dato er lagt inn som 
registreringsdato for {$id}  (mangler info)";
+                       $entry_date = time();
+
+//_debug_array($entry_date_info);
+//_debug_array($entry_date);
+                       $value_set = array();
+
+                       $value_set['num'] = sprintf('%04s', $id);
+                       $value_set['loc1'] = $location_data['loc1'];
+                       $value_set['loc2'] = $location_data['loc2'];
+                       $value_set['user_id'] = $this->account;
+                       $value_set['location_code'] = $location_code;
+                       $value_set['address'] = $address;
+                       $value_set['entry_date'] = $entry_date;
+                       $value_set['museumsnr'] = 
$this->db->db_addslashes($data[0]);
+                       $value_set['betegnelse'] = 
$this->db->db_addslashes($data[1]);
+                       $value_set['beskrivelse'] = 
$this->db->db_addslashes(str_replace('"', '', $data[6])); // tittel
+                       $value_set['juridisk_person'] = 
$this->db->db_addslashes($data[4]);
+                       $value_set['datering'] = 
$this->db->db_addslashes($data[5]);
+                       $value_set['avbildet_person'] = 
$this->db->db_addslashes($data[7]);
+                       $value_set['avbildet_sted'] = 
$this->db->db_addslashes($data[8]);
+                       $value_set['teknikk'] = 
$this->db->db_addslashes($data[9]);
+                       $value_set['maal'] = 
$this->db->db_addslashes($data[10]);
+                       $value_set['historikk'] = 
$this->db->db_addslashes($data[11]);
+                       $value_set['tilstand'] = 
$this->db->db_addslashes($data[12]);
+                       $value_set['tilstandsgrad'] = (int)substr($data[12], 0, 
1) + 1;
+                       $value_set['paafort_text'] = 
$this->db->db_addslashes($data[13]);
+
+                       /*
+                        *    [0] => Identifikasjonsnr
+                        *    [1] => Betegnelse
+                        *    [2] => Objekt-id
+                        *    [3] => Fast plassering
+                        *    [4] => Juridisk person
+                        *    [5] => Datering
+                        *    [6] => Tittel
+                        *    [7] => Avbildet person
+                        *    [8] => Avbildet sted
+                        *    [9] => Teknikk
+                        *    [10] => Mål
+                        *    [11] => Historikk
+                        *    [12] => Tilstand
+                        */
+                       if ($this->is_eav)
+                       {
+                               $ok = $this->_add_eav($id, $value_set);
+                       }
+                       else
+                       {
+                               $ok = $this->_add_sql($id, $value_set);
+                       }
+
+                       return true;
+               }
+
+               private function _add_eav( $id, $data )
+               {
+                       $location_id = (int)$this->location_id;
+                       $sql = "SELECT fm_bim_item.id FROM fm_bim_item WHERE 
fm_bim_item.type = {$this->bim_type_id} AND fm_bim_item.id = {$id}";
+                       $this->db->query($sql, __LINE__, __FILE__);
+
+//                     $this->db->query("SELECT id as type FROM fm_bim_type 
WHERE location_id = {$location_id}",__LINE__,__FILE__);
+//                     $this->db->next_record();
+                       $type = (int)$this->bim_type_id;
+
+
+                       $location_name = '_entity_4_1';
+
+                       if ($this->db->next_record())
+                       {
+                               $this->warnings[] = "ID finnes fra før: {$id}, 
oppdaterer";
+
+
+                               phpgw::import_class('phpgwapi.xmlhelper');
+
+                               $xmldata = phpgwapi_xmlhelper::toXML($data, 
$location_name);
+                               $doc = new DOMDocument;
+                               $doc->preserveWhiteSpace = true;
+                               $doc->loadXML($xmldata);
+                               $domElement = 
$doc->getElementsByTagName($location_name)->item(0);
+                               $domAttribute = 
$doc->createAttribute('appname');
+                               $domAttribute->value = 'property';
+
+                               // Don't forget to append it to the element
+                               $domElement->appendChild($domAttribute);
+
+                               // Append it to the document itself
+                               $doc->appendChild($domElement);
+
+                               $doc->formatOutput = true;
+                               $xml = $doc->saveXML();
+
+                               $value_set = array
+                                       (
+                                       'xml_representation' => 
$this->db->db_addslashes($xml),
+                                       'p_location_id' => 
isset($data['p_location_id']) && $data['p_location_id'] ? 
$data['p_location_id'] : '',
+                                       'p_id' => isset($data['p_id']) && 
$data['p_id'] ? $data['p_id'] : '',
+                                       'location_code' => 
$data['location_code'],
+                                       'loc1' => $data['loc1'],
+                                       'address' => $data['address'],
+                               );
+
+                               $value_set = 
$this->db->validate_update($value_set);
+
+                               $sql = "UPDATE fm_bim_item SET $value_set WHERE 
id = $id AND type = {$type}";
+                       }
+                       else
+                       {
+                               $data['id'] = $id;
+                               $this->warnings[] = "Denne er ny: {$id}, legger 
til";
+
+                               phpgw::import_class('phpgwapi.xmlhelper');
+                               $xmldata = phpgwapi_xmlhelper::toXML($data, 
$location_name);
+                               $doc = new DOMDocument;
+                               $doc->preserveWhiteSpace = true;
+                               $doc->loadXML($xmldata);
+                               $domElement = 
$doc->getElementsByTagName($location_name)->item(0);
+                               $domAttribute = 
$doc->createAttribute('appname');
+                               $domAttribute->value = 'property';
+
+                               // Don't forget to append it to the element
+                               $domElement->appendChild($domAttribute);
+
+                               // Append it to the document itself
+                               $doc->appendChild($domElement);
+                               $doc->formatOutput = true;
+
+                               $xml = $doc->saveXML();
+
+                               if (function_exists('com_create_guid') === true)
+                               {
+                                       $guid = trim(com_create_guid(), '{}');
+                               }
+                               else
+                               {
+                                       $guid = 
sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 
65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), 
mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
+                               }
+
+                               $values_insert = array
+                                       (
+                                       'id' => $id,
+                                       'type' => $type,
+                                       'guid' => $guid,
+                                       'xml_representation' => 
$this->db->db_addslashes($xml),
+                                       'model' => 0,
+                                       'p_location_id' => 
isset($data['p_location_id']) && $data['p_location_id'] ? 
$data['p_location_id'] : '',
+                                       'p_id' => isset($data['p_id']) && 
$data['p_id'] ? $data['p_id'] : '',
+                                       'location_code' => 
$data['location_code'],
+                                       'loc1' => $data['loc1'],
+                                       'address' => $data['address'],
+                                       'entry_date' => time(),
+                                       'user_id' => $this->account
+                               );
+
+                               $sql = "INSERT INTO fm_bim_item (" . 
implode(',', array_keys($values_insert)) . ') VALUES ('
+                                       . 
$this->db->validate_insert(array_values($values_insert)) . ')';
+                       }
+
+                       if ($this->debug)
+                       {
+                               _debug_array($sql);
+                       }
+                       else
+                       {
+                               $request_ok = $this->db->query($sql, __LINE__, 
__FILE__);
+                       }
+
+                       if (!$request_ok)
+                       {
+                               $this->messages[] = "Successfully imported 
location: Title ({$data['betegnelse']})";
+                               $ok = true;
+                       }
+                       else
+                       {
+                               $this->errors[] = "Error importing location: 
Title ({$data['betegnelse']})";
+                               $ok = false;
+                       }
+                       return $ok;
+               }
+
+               private function _add_sql( $id, $value_set )
+               {
+                       $request_ok = false;
+                       $table = 'fm_entity_4_1';
+
+                       $this->db->query("SELECT id FROM {$table} WHERE id = 
{$id}", __LINE__, __FILE__);
+                       if ($this->db->next_record())
+                       {
+                               $this->warnings[] = "ID finnes fra før: {$id}, 
oppdaterer";
+                               $value_set = 
$this->db->validate_update($value_set);
+                               $sql = "UPDATE {$table} SET {$value_set} WHERE 
id = {$id}";
+                       }
+                       else
+                       {
+                               $value_set['id'] = $id;
+                               $this->warnings[] = "Denne er ny: {$id}, legger 
til";
+                               $cols = implode(',', array_keys($value_set));
+                               $values = 
$this->db->validate_insert(array_values($value_set));
+
+                               $sql = "INSERT INTO {$table} ({$cols}) VALUES 
({$values})";
+                       }
+
+                       if ($this->debug)
+                       {
+                               _debug_array($sql);
+                       }
+                       else
+                       {
+                               $request_ok = $this->db->query($sql, __LINE__, 
__FILE__);
+                       }
+
+                       if (!$request_ok)
+                       {
+                               $this->messages[] = "Successfully imported 
location: Title ({$data['betegnelse']})";
+                               $ok = true;
+                       }
+                       else
+                       {
+                               $this->errors[] = "Error importing location: 
Title ({$data['betegnelse']})";
+                               $ok = false;
+                       }
+                       return $ok;
+               }
+       }
\ No newline at end of file

Copied: 
thirdparty/PE_custom/BK_EBE/property/inc/import/default/cvs_import_romdata_bkb 
(from rev 17261, trunk/property/inc/import/default/cvs_import_romdata_bkb)
===================================================================
--- 
thirdparty/PE_custom/BK_EBE/property/inc/import/default/cvs_import_romdata_bkb  
                            (rev 0)
+++ 
thirdparty/PE_custom/BK_EBE/property/inc/import/default/cvs_import_romdata_bkb  
    2017-11-02 15:01:56 UTC (rev 17263)
@@ -0,0 +1,206 @@
+<?php
+
+       class import_conversion
+       {
+
+               protected $db;
+               public $messages = array();
+               public $warnings = array();
+               public $errors = array();
+               protected $debug = true;
+
+               public function __construct()
+               {
+                       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->solocation = CreateObject('property.solocation');
+               }
+
+               public function add( $data )
+               {
+                       $location_code = $this->decode($data[0]);
+                       if (!$location_code)
+                       {
+                               $this->errors[] = "Mangler objekt, hopper over: 
{$data[1]}";
+                               return false;
+                       }
+
+                       $location_arr = explode('-', $location_code);
+                       $_test_floor = 
"{$location_arr[0]}-{$location_arr[1]}-{$location_arr[2]}";
+                       $_test_zone = 
"{$location_arr[0]}-{$location_arr[1]}-{$location_arr[2]}-{$location_arr[3]}";
+
+                       $ok = true;
+                       if (!$this->solocation->check_location($_test_floor))
+                       {
+                               $_ok = 
$this->add_location(array('location_code' => $_test_floor, 'name' => "etasje 
{{$location_arr[2]}}",
+                                       'area' => 0));
+                               $ok = $_ok ? $_ok : false;
+                       }
+
+                       if (!$this->solocation->check_location($_test_zone))
+                       {
+                               $_ok = 
$this->add_location(array('location_code' => $_test_zone, 'name' => "sone 
{{$location_arr[3]}}",
+                                       'area' => 0));
+                               $ok = $_ok && $ok ? $_ok : false;
+                       }
+
+                       if (!$this->solocation->check_location($location_code))
+                       {
+                               $_ok = 
$this->add_location(array('location_code' => $location_code, 'name' => 
$this->decode($data[6]),
+                                       'area' => $this->decode($data[7])));
+                               $ok = $_ok && $ok ? $_ok : false;
+                       }
+                       else
+                       {
+                               $this->warnings[] = "location_code finnes fra 
før: {$location_code}, oppdaterer";
+                               $_ok = 
$this->update_location(array('location_code' => $location_code, 'name' => 
$this->decode($data[6]),
+                                       'area' => $this->decode($data[7])));
+                               $ok = $_ok && $ok ? $_ok : false;
+                       }
+
+                       return $ok;
+               }
+
+               protected function add_location( $data )
+               {
+                       $debug = $this->debug;
+                       $error = false;
+                       $ok = true;
+                       $value_set = array();
+
+                       $location_arr = explode('-', $data['location_code']);
+                       $type_id = count($location_arr);
+
+                       $formatting = array
+                               (
+                               '%04s',
+                               '%02s',
+                               '%02s',
+                               '%02s',
+                               '%03s'
+                       );
+
+                       $value_set['location_code'] = $data['location_code'];
+                       foreach ($location_arr as $_key => $_loc)
+                       {
+                               $i = $_key + 1;
+                               $value_set["loc{$i}"] = 
sprintf($formatting[$_key], $location_arr[$_key]);
+                       }
+
+                       $value_set["loc{$type_id}_name"] = 
$this->db->db_addslashes($data['name']);
+                       $value_set['category'] = 1;
+                       $value_set['user_id'] = $this->account;
+                       $value_set['entry_date'] = time();
+                       $value_set['area_net'] = $data['area'] ? 
str_replace(',', '.', $data['area']) : 0;
+                       $value_set['merknader'] = 'Opprettet fra tegning: ' . 
date('d/m/Y');
+
+                       $cols = implode(',', array_keys($value_set));
+                       $values = 
$this->db->validate_insert(array_values($value_set));
+
+                       $table = "fm_location{$type_id}";
+
+                       $sql = "INSERT INTO {$table} ({$cols}) VALUES 
({$values})";
+
+                       $sql2 = "INSERT INTO fm_locations (level, 
location_code) VALUES ({$type_id}, '{$data['location_code']}')";
+
+                       if ($debug)
+                       {
+                               _debug_array($sql);
+                       }
+                       else
+                       {
+                               $_ok = $this->db->query($sql, __LINE__, 
__FILE__);
+                               $ok = $_ok ? $_ok : false;
+                               $_ok = $this->db->query($sql2, __LINE__, 
__FILE__);
+                               $ok = $_ok ? $_ok : false;
+                       }
+
+                       if (!$error && $ok)
+                       {
+                               $this->messages[] = "Successfully imported 
location: {$data['location_code']}";
+                       }
+                       else
+                       {
+                               $this->errors[] = "Error importing location: 
{$data['location_code']}";
+                       }
+                       return $ok;
+               }
+
+               protected function update_location( $data )
+               {
+                       $debug = $this->debug;
+                       $ok = false;
+                       $value_set = array();
+
+                       $location_arr = explode('-', $data['location_code']);
+                       $type_id = count($location_arr);
+                       $table = "fm_location{$type_id}";
+
+                       $value_set["loc{$type_id}_name"] = 
$this->db->db_addslashes($data['name']);
+                       $value_set['area_net'] = $data['area'] ? 
str_replace(',', '.', $data['area']) : 0;
+
+                       $this->db->query("SELECT merknader FROM {$table} WHERE 
location_code = '{$data['location_code']}'", __LINE__, __FILE__);
+                       $this->db->next_record();
+
+                       $merknader = $this->db->f('merknader', true);
+
+                       $value_set['merknader'] = '';
+                       if ($merknader)
+                       {
+                               $value_set['merknader'] = "{$merknader}\n";
+                       }
+                       $value_set['merknader'] .= "Oppdatert fra tegning: " . 
date('d/m/Y');
+
+                       $value_set = $this->db->validate_update($value_set);
+                       $sql = "UPDATE {$table} SET {$value_set} WHERE 
location_code = '{$data['location_code']}'";
+
+                       if ($debug)
+                       {
+                               _debug_array($sql);
+                               $ok = true;
+                       }
+                       else
+                       {
+                               $ok = $this->db->query($sql, __LINE__, 
__FILE__);
+                       }
+
+                       if ($ok)
+                       {
+                               $this->messages[] = "Successfully updated 
location: {$data['location_code']}";
+                       }
+                       else
+                       {
+                               $this->errors[] = "Error update location: 
{$data['location_code']}";
+                       }
+                       return $ok;
+               }
+
+               /**
+                * Convert from the locale encoding to UTF-8 encoding and 
escape single quotes
+                * 
+                * @param string $value The value to convert
+                * @return string
+                */
+               protected function decode( $value )
+               {
+                       $converted = $value;// mb_convert_encoding($value, 
'UTF-8');
+                       if ($this->is_null(trim($converted)))
+                       {
+                               return null;
+                       }
+                       return stripslashes($converted);
+               }
+
+               /**
+                * Test a value for null according to several formats that can 
exist in the export.
+                * Returns true if the value is null according to these rules, 
false otherwise.
+                * 
+                * @param string $value The value to test
+                * @return bool
+                */
+               protected function is_null( $value )
+               {
+                       return ((trim($value) == "") || ($data == "<NULL>") || 
($data == "''"));
+               }
+       }
\ No newline at end of file

Copied: 
thirdparty/PE_custom/NLSH/property/inc/import/default/cvs_import_fiktiv_faktura_nlsh
 (from rev 17261, 
trunk/property/inc/import/default/cvs_import_fiktiv_faktura_nlsh)
===================================================================
--- 
thirdparty/PE_custom/NLSH/property/inc/import/default/cvs_import_fiktiv_faktura_nlsh
                                (rev 0)
+++ 
thirdparty/PE_custom/NLSH/property/inc/import/default/cvs_import_fiktiv_faktura_nlsh
        2017-11-02 15:01:56 UTC (rev 17263)
@@ -0,0 +1,172 @@
+<?php
+
+       class import_conversion
+       {
+
+               protected $db;
+               public $messages = array();
+               public $warnings = array();
+               public $errors = array();
+               public $debug = true;
+               protected $period;
+               protected $year;
+               protected $month;
+               protected $date;
+               public $fields = array('Hovedgruppering', 'Art', 'Hjelpetekst', 
'Koststed', 'Beløp',
+                       'Best.nr');
+               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 = "DTDRIFT rapport til 
Portico " . 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->boinvoice = CreateObject('property.boinvoice');
+                       $this->boinvoice->supertransaction = true;
+                       $this->soinvoice = CreateObject('property.soinvoice');
+                       $this->boworkorder = 
CreateObject('property.boworkorder');
+                       $this->soproject = CreateObject('property.soproject');
+
+                       $this->config = CreateObject('admin.soconfig', 
$GLOBALS['phpgw']->locations->get_id('property', '.invoice'));
+
+                       if ($debug)
+                       {
+                               $this->debug = true;
+                               $this->boinvoice->debug = true;
+                       }
+
+                       $file_info = pathinfo($_FILES['file']['name']);
+                       $this->period = substr($file_info['filename'], -6);
+
+                       if (!ctype_digit($this->period))
+                       {
+                               throw new Exception("Ikke en periode: 
{$this->period}");
+                       }
+
+                       $this->year = substr($this->period, 0, 4);
+                       $this->month = substr($this->period, -2);
+                       $_date = mktime(0, 0, 0, $this->month, 15, $this->year);
+
+                       $this->date = 
$GLOBALS['phpgw']->common->show_date($_date, 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+               }
+
+               public function add( $data )
+               {
+                       /*
+                         [0] => Hovedgruppering
+                         [1] => Art
+                         [2] => Hjelpetekst
+                         [3] => Koststed
+                         [4] => Beløp
+                         [5] => Best.nr
+                        */
+                       $amount = str_replace(array(' ', ','), array('', '.'), 
$data[4]);
+                       $order_id = $data[5];
+                       $error = false;
+
+                       if (!$amount)
+                       {
+                               $this->warnings[] = "Linje mangler Beløp, 
hopper over: {$data[0]}";
+                               return true;
+                       }
+                       if (!$order_id)
+                       {
+                               $this->warnings[] = "Linje mangler 
bestillingsnummer, hopper over: {$data[0]}";
+                               return true;
+                       }
+
+                       if (!execMethod('property.soXport.check_order', 
$order_id))
+                       {
+                               $this->errors[] = "Ikke gyldig 
bestillingsnummer: {$order_id}";
+                               return false;
+                       }
+
+
+//                     $_location_data = 
execMethod('property.solocation.read_single', $location_code );
+
+                       $workorder = $this->boworkorder->read_single($order_id);
+
+                       $project = 
execMethod('property.boproject.read_single_mini', $workorder['project_id']);
+
+                       $values = array();
+
+                       $values['order_id'] = $order_id;
+                       $values['vendor_id'] = 99;
+                       $values['invoice_id'] = 
$this->boinvoice->get_auto_generated_invoice_num($values['vendor_id']);
+                       $values['amount'] = $amount;
+
+                       $order_info['janitor'] = 
$GLOBALS['phpgw']->accounts->get($workorder['user_id'])->lid;
+                       $supervisor_user_id = 
$this->soinvoice->get_default_dimb_role_user(2, $project['ecodimb']);
+                       if ($supervisor_user_id)
+                       {
+                               $values['supervisor'] = 
$GLOBALS['phpgw']->accounts->get($supervisor_user_id)->lid;
+                       }
+
+                       $budget_responsible_user_id = 
$this->soinvoice->get_default_dimb_role_user(3, $project['ecodimb']);
+                       if ($budget_responsible_user_id)
+                       {
+                               $values['budget_responsible'] = 
$GLOBALS['phpgw']->accounts->get($budget_responsible_user_id)->lid;
+                       }
+
+                       if (!$values['budget_responsible'])
+                       {
+                               $values['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';
+                       }
+
+                       $values['project_group'] = $project['project_group'];
+                       $values['dimb'] = $project['ecodimb'];
+
+                       $location_arr = explode('-', 
$workorder['location_code']);
+
+                       $i = 1;
+                       foreach ($location_arr as $_loc)
+                       {
+                               $values['location']["loc{$i}"] = $_loc;
+                               $i++;
+                       }
+
+                       $values['b_account_id'] = $workorder['b_account_id'];
+                       $values['invoice_date'] = $this->date;
+                       $values['payment_date'] = $this->date;
+                       $values['paid_date'] = $this->date;
+
+                       $values['typeid'] = 5; // administrasjon
+                       $values['artid'] = 4; // fiktiv
+
+                       $values['regtid'] = 
date($GLOBALS['phpgw']->db->datetime_format());
+
+                       $receipt = 
$this->boinvoice->add_manual_invoice($values);
+
+                       $ok = false;
+
+                       if (!isset($receipt['error']) || !$receipt['error'])
+                       {
+                               $this->messages[] = "Importerer faktura med 
beløp {$amount} til bestilling {$order_id}";
+                               $data_close = array
+                                       (
+                                       'closed_b_period' => 
array("{$this->year}_{$this->month}")
+                               );
+
+                               
$this->soproject->close_period_from_budget($workorder['project_id'], 
$data_close);
+
+//                             
execMethod('property.soXport.update_actual_cost_from_archive',array($order_id 
=> true));
+
+                               $ok = true;
+                       }
+                       else
+                       {
+                               $this->errors[] = "Noe feilet med bestilling 
{$order_id}";
+                       }
+
+                       return $ok;
+               }
+       }
\ No newline at end of file




reply via email to

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