3 Funktionsbibliothek für den Datenimport in Lx-Office ERP
6 Author: Holger Lindemann
7 Email: hli@lx-system.de
8 Web: http://lx-system.de
12 require_once "DB.php";
15 "name" => "Firmenname",
16 "department_1" => "Abteilung",
17 "department_2" => "Abteilung",
18 "street" => "Strasse + Nr",
22 "contact" => "Ansprechpartner",
25 "homepage" => "Homepage",
27 "notes" => "Bemerkungen",
28 "discount" => "Rabatt (nn.nn)",
29 "taxincluded" => "incl. Steuer? (t/f)",
30 "terms" => "Zahlungsziel (Tage)",
31 "customernumber" => "Kundennummer",
32 "vendornumber" => "Lieferantennummer",
33 "taxnumber" => "Steuernummer",
34 "ustid" => "Umsatzsteuer-ID",
35 "account_number" => "Kontonummer",
36 "bank_code" => "Bankleitzahl",
38 "branche" => "Branche",
39 //"language" => "Sprache (de,en,fr)",
41 "creditlimit" => "Kreditlimit (nnnnnn.nn)"); /*,
42 "hierarchie" => "Hierarchie",
43 "potenzial" => "Potenzial",
44 "ar" => "Debitorenkonto",
45 "ap" => "Kreditorenkonto",
46 "matchcode" => "Matchcode",
47 "customernumber2" => "Kundennummer 2");
51 "shiptoname" => "Firmenname",
52 "shiptodepartment_1" => "Abteilung",
53 "shiptodepartment_2" => "Abteilung",
54 "shiptostreet" => "Strasse + Nr",
55 "shiptozipcode" => "Plz",
56 "shiptocity" => "Ort",
57 "shiptocountry" => "Land",
58 "shiptocontact" => "Ansprechpartner",
59 "shiptophone" => "Telefon",
61 "shiptoemail" => "eMail",
62 "customernumber" => "Kundennummer",
63 "vendornumber" => "Lieferantennummer");
66 "partnumber" => "Artikelnummer",
67 "description" => "Artikeltext",
69 "weight" => "Gewicht in Benutzerdefinition",
70 "onhand" => "Lagerbestand",
71 "notes" => "Beschreibung",
72 "makemodel" => "Hersteller",
73 "model" => "Modellbezeichnung",
75 "image" => "Pfad/Dateiname",
76 "drawing" => "Pfad/Dateiname",
77 "microfiche" => "Pfad/Dateiname",
78 "listprice" => "Listenpreis",
79 "sellprice" => "Verkaufspreis",
80 "lastcost" => "letzter EK",
81 "art" => "Ware/Dienstleistung (*/d), muß vor den Konten kommen",
82 "inventory_accno" => "Bestandskonto",
83 "income_accno" => "Erlöskonto",
84 "expense_accno" => "Konto Umsatzkosten",
85 "obsolete" => "Gesperrt (Y/N)",
86 "lastcost" => "letzer EK-Preis",
87 "rop" => "Mindestbestand",
88 "shop" => "Shopartikel (Y/N)",
89 "assembly" => "Stückliste (Y/N); wird noch nicht unterstützt",
90 "partsgroup" => "Warengruppenbezeichnung",
91 //"income_accno_0" => "?Nummer? für Erlöse Inland",
92 //"income_accno_1" => "?Nummer? für Erlöse EG",
93 //"income_accno_3" => "?Nummer? für Erlöse Ausland",
97 "customernumber" => "Kundennummer",
98 "vendornumber" => "Lieferantennummer",
99 "cp_cv_id" => "FirmenID in der db",
100 "firma" => "Firmenname",
101 "cp_abteilung" => "Abteilung",
102 "cp_position" => "Position/Hierarchie",
103 "cp_greeting" => "Anrede",
104 "cp_title" => "Titel",
105 "cp_givenname" => "Vorname",
106 "cp_name" => "Nachname",
107 "cp_email" => "eMail",
108 "cp_phone1" => "Telefon 1",
109 "cp_phone2" => "Telefon 2",
110 "cp_mobile1" => "Mobiltelefon 1",
111 "cp_mobile2" => "Mobiltelefon 2",
112 "cp_homepage" => "Homepage",
113 "cp_street" => "Strasse",
114 "cp_country" => "Land",
115 "cp_zipcode" => "PLZ",
117 "cp_privatphone" => "Privattelefon",
118 "cp_privatemail" => "private eMail",
119 "cp_notes" => "Bemerkungen",
120 "cp_stichwort1" => "Stichwort(e)",
121 "katalog" => "Katalog",
122 "inhaber" => "Inhaber",
123 "contact_id" => "Kontakt ID"
127 "customernumber" => "Kundennummer",
128 "vendornumber" => "Lieferantennummer",
129 "cp_cv_id" => "FirmenID in der db",
130 "firma" => "Firmenname",
131 "cp_greeting" => "Anrede",
132 "cp_title" => "Titel",
133 "cp_givenname" => "Vorname",
134 "cp_greeting" => "Anrede",
135 "cp_name" => "Nachname",
136 "cp_email" => "eMail",
137 "cp_phone1" => "Telefon 1",
138 "cp_phone2" => "Telefon 2",
139 "cp_mobile1" => "Mobiltelefon 1",
140 "cp_mobile2" => "Mobiltelefon 2",
141 "cp_privatphone" => "Privattelefon",
142 "cp_privatemail" => "private eMail",
143 "cp_homepage" => "Homepage",
144 "katalog" => "Katalog",
145 "inhaber" => "Inhaber",
146 "contact_id" => "Kontakt ID"
149 function checkCRM() {
151 $sql="select * from crm";
152 $rs=$db->getAll($sql);
160 function chkUsr($usr) {
161 // ist es ein gültiger ERP-Benutzer? Er muß mindestens 1 x angemeldet gewesen sein.
163 $sql="select * from employee where login = '$usr'";
164 $rs=$db->getAll($sql);
165 if ($rs[0]["id"]) { return $rs[0]["id"]; }
166 else { return false; };
170 // die nächste freie Kunden-/Lieferantennummer holen
171 global $db,$file,$test;
172 if ($test) { return "#####"; }
173 $sql1="select * from defaults";
174 $sql2="update defaults set ".$file."number = '%s'";
176 $rs=$db->getAll($sql1);
177 $nr=$rs[0][$file."number"];
178 preg_match("/^([^0-9]*)([0-9]+)/",$nr,$hits);
179 if ($hits[2]) { $nr=$hits[2]+1; $nnr=$hits[1].$nr; }
180 else { $nr=$hits[1]+1; $nnr=$nr; };
181 $rc=$db->query(sprintf($sql2,$nnr));
191 function chkKdId($data) {
192 // gibt es die Nummer schon?
193 global $db,$file,$test;
194 $sql="select * from $file where ".$file."number = '$data'";
195 $rs=$db->getAll($sql);
196 if ($rs[0][$file."number"]==$data) {
197 // ja, eine neue holen
204 function getKdRefId($data) {
205 // gibt es die Nummer schon?
206 global $db,$file,$test;
207 if (empty($data) or !$data) {
210 $sql="select * from $file where ".$file."number = '$data'";
211 $rs=$db->getAll($sql);
215 function suchFirma($tab,$data) {
218 if (empty($data) or !$data) {
221 $data=strtoupper($data);
222 $sql="select * from $tab where upper(name) like '%$data%'";
223 $rs=$db->getAll($sql);
226 while(strpos($data," ")>0) {
227 $data=ereg_replace(" "," ",$data);
229 $data=preg_replace("/[^A-Z0-9]/ ",".*",trim($data));
230 $sql="select * from $tab where upper(name) ~ '$data'";
231 $rs=$db->getAll($sql);
233 return array("cp_cv_id"=>$rs[0]["id"],"Firma"=>$rs[0]["name"]);
237 return array("cp_cv_id"=>$rs[0]["id"],"Firma"=>$rs[0]["name"]);
241 $land=array("DEUTSC"=>"D","FRANKR"=>"F","SPANIE"=>"ES","ITALIE"=>"I","HOLLAN"=>"NL","NIEDER"=>"NL",
242 "BELGIE"=>"B","LUXEMB"=>"L","NORWEG"=>"N","FINNLA"=>"","GRIECH"=>"GR","OESTER"=>"A",
243 "SCHWEI"=>"CH","SCHWED"=>"S","AUSTRI"=>"A");
245 function mkland($data) {
247 $data=strtr($data,array("Ö"=>"OE","Ä"=>"AE","Ü"=>"UE","ö"=>"OE","ä"=>"AE","ü"=>"UE","ß"=>"SS"));
248 $data=strtoupper(substr($data,0,6));
250 return (strlen($cntr)>0)?$cntr:substr($data,0,3);
253 //Suche Nach Kunden-/Lieferantenummer
254 function getFirma($nummer,$tabelle) {
256 $nummer=strtoupper($nummer);
257 $sql="select id from $tabelle where upper(".$tabelle."number) = '$nummer'";
258 $rs=$db->getAll($sql);
260 $nr=ereg_replace(" ","%",$nummer);
261 $sql="select id,".$tabelle."number from $tabelle where upper(".$tabelle."number) like '$nr'";
262 $rs=$db->getAll($sql);
264 $nr=ereg_replace(" ","",$nummer);
265 foreach ($rs as $row) {
266 $tmp=ereg_replace(" ","",$row[$tabelle."number"]);
267 if ($tmp==$nr) return $row["id"];
277 function getAllBG($db) {
278 $sql = "select * from buchungsgruppen order by description";
279 $rs=$db->getAll($sql);
283 class myDB extends DB {
287 var $showErr = false;
291 /****************************************************
295 * dekodiert Perl-UU-kodierte Passwort-Strings
296 * http://de3.php.net/base64_decode (bug #171)
297 *****************************************************/
298 function uudecode($encode) {
299 $b64chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
301 $encode = preg_replace("/^./m","",$encode);
302 $encode = preg_replace("/\n/m","",$encode);
303 for($i=0; $i<strlen($encode); $i++) {
304 if ($encode[$i] == '')
306 $encode[$i] = $b64chars[ord($encode[$i])-32];
309 while(strlen($encode) % 4)
312 return base64_decode($encode);
315 function dbFehler($sql,$err) {
317 echo "$sql : $err\n";
320 function showDebug($sql) {
322 if ($this->debug==2) {
327 function myDB($usr) {
328 // Datenbankparameter des ERP-Users benutzen.
329 $tmp = file_get_contents("../users/$usr.conf");
330 preg_match("/dbname => '(.+)'/",$tmp,$hits);
332 preg_match("/dbpasswd => '(.+)'/",$tmp,$hits);
334 $dbpasswd=$this->uudecode($hits[1]);
338 preg_match("/dbuser => '(.+)'/",$tmp,$hits);
340 preg_match("/dbhost => '(.+)'/",$tmp,$hits);
342 if (!$dbhost) $dbhost="localhost";
344 $dns=$dbuser.":".$dbpasswd."@".$dbhost."/".$dbname;
346 $dns=$dbuser."@".$dbhost."/".$dbname;
348 $dns="pgsql://".$dns;
349 $this->db=DB::connect($dns);
350 if (!$this->db) DB::dbFehler("oh oh oh",$this->db->getDebugInfo());
351 if (DB::isError($this->db)) {
352 $this->dbFehler("Connect",$this->db->getDebugInfo());
353 die ($this->db->getDebugInfo());
358 function query($sql) {
359 $this->rc=@$this->db->query($sql);
360 if ($this->debug) $this->showDebug($sql);
361 if(DB::isError($this->rc)) {
362 $this->dbFehler($sql,$this->rc->getMessage());
368 function getAll($sql) {
369 $this->rc=@$this->db->getAll($sql,DB_FETCHMODE_ASSOC);
370 if ($this->debug) $this->showDebug($sql);
371 if(DB::isError($this->rc)) {
372 $this->dbFehler($sql,$this->rc->getMessage());
380 $this->query("BEGIN");
383 $this->query("COMMIT");
385 function rollback() {
386 $this->query("ROLLBACK");
388 function chkcol($tbl) {
389 // gibt es die Spalte import schon?
390 $rc=$this->db->query("select import from $tbl limit 1");
391 if(DB::isError($rc)) {
392 $rc=$this->db->query("alter table $tbl add column import int4");
393 if(DB::isError($rc)) { return false; }
394 else { return true; }
396 } else { return true; };