Überflüssige "jquery-ui"-Einbindungen gelöscht
[kivitendo-erp.git] / shopxtc / xtc.php
1 <?php
2 /*
3 Funktionen für den Zugriff auf den xtc 3.04 newxtc 1.05
4 */
5
6
7 class xtc {
8
9     var $db = false;
10     var $error = false;
11     var $divStd = false;
12     var $divVerm = false;
13     var $minder = false;
14     var $paypal = false;
15     var $nachn = false;
16     var $shopcode = 'ISO-8859-1';
17     var $erpcode = 'UTF-8';
18     var $VariantNr = 1;
19     var $EU = array('AT','BE','BG','CZ','DK','EE','ES','FI','FR','GB','GR','HR','HU','IE','IT','LU','LV','MT','NL','PL','PT','RO','SE','SI','SK');
20     var $Kategorien = False;
21     var $dezimal = 2;
22     var $tax_zone = 5;
23     var $language = 2;
24     var $geozone = 5;
25
26     var $tableerp  = array("partnumber"=>"products_model","description"=>"products_name","notes"=>"products_description","ean"=>"products_ean",
27                            "unit"=>"products_vpe","weight"=>"products_weight","sellprice"=>"products_price","partsgroup"=>"products_partsgroup",
28                            "tax"=>"products_tax","image"=>"products_image","onhand"=>"products_quantity");
29     var $custshop   = array("kontakt"=>"contact","ort"=>"city","plz"=>"zipcode","land"=>"country","tel"=>"phone",
30                             "fax"=>"fax","email"=>"email","beschreibung"=>"notes","strasse"=>"street","firma"=>"name",
31                             "kunden_nr"=>"customer_id","anrede"=>"greeting","k_id"=>"shopid",
32                             "bankname"=>"bank","blz"=>"bank_code","kontonummer"=>"account_number",
33                             "iban"=>"iban","bic"=>"bic","attributwert1"=>"ustid");
34     var $ordershop  = array("datum"=>"transdate","rechnungsbetrag"=>"amount","rechnungs_nr"=>"",
35                             "waehrung"=>"currency","beschreibung"=>"notes",
36                             "mwst"=>"mwst","versandart"=>"shipvia");
37     var $orderparts = array("products_name"=>"description","products_description"=>"longdescription","products_price"=>"sellprice",
38                             "products_quantity"=>"qty","products_model"=>"partnumber",
39                             "partsgroup"=>"partsgroup","products_weight"=>"weight","products_ean"=>"ean",
40                             "products_tax"=>"taxrate","products_image"=>"image","products_vpe_name"=>"unit");
41
42     function xtc($db,$error,$dbname,$divStd,$divVerm,$minder,$nachn,$versandS,$versandV,$paypal,$mwstLX,$mwstS,$variantnr,$unit,
43                  $pic=false,$nopic=false,$nopicerr=false,$nofiles=false,
44                  $erpcode='UTF-8',$shopcode='ISO-8859-1') {
45         $this->db       = $db;
46         $this->error    = $error;
47         $this->divStd   = $divStd  ;
48         $this->divVerm  = $divVerm ;
49         $this->minder   = $minder  ;
50         $this->nachn    = $nachn   ;
51         $this->versandS = $versandS ;
52         $this->versandV = $versandV ;
53         $this->paypal   = $paypal  ;
54         $this->erpcode  = $erpcode;
55         $this->mwstLX   = $mwstLX;
56         $this->mwstS    = $mwstS;
57         $this->unit     = $unit;
58         $this->VariantNr = $variantnr;
59         $this->language  = $this->defaultLang();        
60         $this->geozone   = $this->getDefaultGZ();
61         $this->pic       = $pic;
62         $this->nopic     = ( $nopic != '' )?$nopic:false;
63         $this->nopicerr  = ( $nopicerr != '' )?true:false;
64         $this->nofiles     = $nofiles;
65         if ($shopcode == 'AUTO') {
66             $sql = "SELECT TABLE_COLLATION FROM information_schema.TABLES WHERE table_schema = '$dbname' AND table_name = 'customers'";
67             $rs = $this->db->getOne($sql);
68             if ($rs) {
69                 preg_match('/([^_]+)/',$rs['table_collation'],$hits);
70                 if (count($hits)>0) {
71                     $this->shopcode = $hits[1];
72                 } else {
73                     $this->shopcode =  'ISO-8859-1';
74                 }
75             }
76         } else {
77             $this->shopcode = $shopcode;
78         }
79     }
80     function getDefaultGZ() {
81         $sql  = "SELECT geo_zone_id FROM  zones_to_geo_zones Z ";
82         $sql .= "LEFT JOIN countries CO ON Z.zone_country_id=CO.countries_id ";
83         $sql .= "LEFT JOIN configuration CF ON CO.countries_iso_code_2=CF.configuration_value ";
84         $sql .= "WHERE configuration_key = 'DEFAULT_LANGUAGE'";
85         $rs = $this->db->getOne($sql);
86         return $rs['geo_zone_id'];
87     }
88     function defaultLang() {
89         $sql  = "SELECT languages_id FROM languages L LEFT JOIN configuration C ON L.code = C.configuration_value ";
90         $sql .= "WHERE C.configuration_key = 'DEFAULT_LANGUAGE'";
91         $rs = $this->db->getOne($sql);
92         return $rs['languages_id'];
93     }
94     function _toERP($txt) {
95         return mb_convert_encoding($txt,$this->erpcode,$this->shopcode);
96     }
97     function _toShop($txt) {
98         return mb_convert_encoding($txt,$this->shopcode,$this->erpcode);
99     }
100     function translateTable($data,$table) {
101         $newdata = array();
102         foreach ($data as $key=>$val) {
103              if ($this->{$table}[$key]) 
104                  $newdata[$this->{$table}[$key]] = $val;
105         }
106         return $newdata;
107     }
108     function getCategoryID($name) {
109         if (empty($name)) {
110               $name = "Default";
111         } else {
112               $name = $this->_toShop($name);
113         }
114         //Kategorien werden durch die ERP mit "!" getrennt
115         preg_match_all("/([^!]+)!?/",$name,$kat);
116         if (count($kat)>0) {
117             $kat = $kat[1];
118         } else {
119             return false;
120         };
121         $parent = 0;
122         $sql="select D.*,C.parent_id from categories C left join categories_description D on C.categories_id=D.categories_id ";
123         $sql.="where categories_name = '%s' and ";
124         $sql.="C.parent_id=%d and language_id=".$this->language;
125         if (count($kat)>0) foreach ($kat as $wg) {
126             $sql_ = sprintf($sql,$wg,$parent);
127             $rs=$this->db->getOne($sql_);
128             if ($rs["categories_id"]) {                   // gefunden
129                 $parent=$rs["categories_id"];
130             } else {                    // nicht gefunden, anlegen
131                 $parent=$this->createCategory($wg,$parent);
132             }
133         }
134         return $parent;
135     }
136     function createCategory($name,$parent) {
137         echo "Kategorie: $name<br>";
138         //Kategorie nicht vorhanden, anlegen
139         $newID = uniqid(rand());
140         $sql = "INSERT INTO categories (categories_image,parent_id,date_added) VALUES  ('$newID',$parent,now())";
141         $rc = $this->db->query($sql);
142         if ( !$rc ) return false;
143         $sql = "SELECT * FROM categories WHERE categories_image = '$newID'";
144         $rs = $this->db->getOne($sql);
145         $id = $rs["categories_id"];
146         $sql = "UPDATE categories SET categories_image = null WHERE categories_id=$id";
147         $rc = $this->db->query($sql);
148         if ( !$rc ) return false;
149         $rc = $this->createCategoryLang($id,$name);
150         return $id;
151     }
152     /*******************************************
153     * createCategoryLang($id,$lang,$name)
154     * Kategorie für eine Sprache anlegen. Ist immer
155     * in der gleichen Sprache, da ERP nur eine hat.
156     *******************************************/
157     function createCategoryLang($id,$name) {
158         $sql  = "INSERT INTO categories_description (categories_id,language_id,categories_name,categories_meta_title) ";
159         $sql .= "VALUES ($id,".$this->language.",'$name','$name')";
160         $rc = $this->db->query($sql);
161         return $rc;
162     }
163     function getTax($tax) {
164         $sql = "SELECT * FROM tax_rates WHERE tax_rate = $tax and tax_zone_id =".$this->geozone;
165         $rs = $this->db->getOne($sql);
166         return $rs['tax_class_id'];
167     }
168     function getVPE($vpe) {
169         $sql  = "SELECT products_vpe_id FROM products_vpe WHERE products_vpe_name = '$vpe' AND language_id = ".$this->language;
170         $rs = $this->db->getOne($sql);
171         return $rs['products_vpe_id'];
172     }
173     function saveArtikel($data,$lang) {
174          $values = $this->translateTable($data,"tableerp"); //$this->tableerp);
175          if ($this->mwstLX) { //ERP-Bruttopreis
176               $values['products_price'] = round($values['products_price'] / (1 + $values["products_tax"]),2);
177          }
178          $values["products_name"] = $this->_toShop($values["products_name"]);
179          $values["products_description"] = $this->_toShop($values["products_description"]);
180          $values["products_tax_class_id"] = $this->getTax($values["products_tax"]*100);
181          $values["categories_id"] = $this->getCategoryID($values["products_partsgroup"]);
182          $values["products_vpe"] = $this->getVPE($values["products_vpe"]);
183          $values["products_id"] = $this->checkArtikelOK($values["products_model"]);  
184          if ($values["products_id"]>0)  {
185              $rc = $this->updateArtikel($values);
186          } else {
187              $rc = $this->insertArtikel($values);
188          };
189          return $rc;
190     }
191     function checkArtikelOK($nr) {
192         $sql = "SELECT * FROM products WHERE products_model = '".$nr."'";
193         $rs = $this->db->getOne($sql);
194         return $rs["products_id"];
195     }
196     function insertArtikel($data) {
197         $newID = uniqid(rand());
198         $this->db->Begin();
199         $sql = "INSERT INTO products (products_model,products_image,products_status) VALUES ('".$data["products_model"]."','$newID',1)";
200             $rc = $this->db->query($sql);
201         $sql = "SELECT * FROM products WHERE products_image='$newID'";
202             $rs = $this->db->getOne($sql);
203         $sql = "INSERT INTO products_description (products_id,products_name,language_id) VALUES (".$rs['products_id'].",'".$data['products_name']."',".$this->language.")";
204             $rc = $this->db->query($sql);
205             if ($rs['products_image'] == $newID) {
206             $data["products_id"] = $rs["products_id"];
207                 $statement = "INSERT INTO products_to_categories (products_id,categories_id) VALUES (?,?)";
208             $values = array($rs["products_id"],$data["categories_id"]);
209                 $rc = $this->db->insert($statement,$values);
210             if (!$rc) {
211                  echo $data['products_model'].' konnte nicht zur Gruppe '.$data['categories_id'].' zugef&uuml;gt werden.';
212                  $this->error->write('xtc',$data['products_model'].' konnte nicht zur Gruppe '.$data['categories_id'].' zugefügt werden.');
213                  $this->db->Rollback();
214                  return false;
215             }
216             $this->db->Commit();
217             echo " insert ";
218             $rc = $this->updateArtikel($data,true);
219         } else { return false; }
220         return $rc;
221     }
222     function updateArtikel($values,$insert=false) {
223         if ($this->mwstLX) $values['products_price'] = round($values['products_price'] / (100+$values['products_tax'])*100,2);
224         $sql  = "UPDATE products SET products_price = :products_price, products_weight = :products_weight, ";
225         if ( !$this->nofiles || $insert) {
226              //vorhandene Bilder übertragen
227              $sql .= "products_image = :products_image,  ";
228              if ( $values['products_image'] != '' ) {
229                  preg_match("/(.+)\.(jpg|png|jpeg|gif)/i",$values['products_image'],$tmp);
230                  $sql .= "products_image = :products_image,  ";
231                  if ( count($tmp) == 3 ) {
232                      if ( $this->pic &&  $this->pic->copyImage($values['products_id'],$values['products_image'],$tmp[2]) ) {
233                          $values['products_image'] = $values['products_id']."_0.".$tmp[2];
234                      } else if ( $this->nopic ){
235                          $values['products_image'] = $this->nopic;
236                      }
237                  } 
238              } else if ( $this->nopic && !$this->nopicerr ){
239                  $values['products_image'] = $this->nopic;
240              }
241         }
242         $sql .= "products_tax_class_id = :products_tax_class_id, products_vpe = :products_vpe, products_ean = :products_ean ";
243         //Kein Lagerbestand übergeben, also nichts ändern
244         if ($values['products_quantity'] != '') $sql .= ",products_quantity = :products_quantity ";
245         $sql .= "WHERE products_id = :products_id ";
246         $rc = $this->db->update($sql,$values);
247         $sql  = "UPDATE products_description SET products_name = :products_name, products_description = :products_description ";
248         #products_short_description products_keywords <== aus CVars
249         $sql .= "WHERE products_id = :products_id AND language_id = ".$this->language;
250         $rc = $this->db->update($sql,$values);
251         if ($rc) { 
252             return $values["products_id"];
253         } else {
254             return false;
255         }
256     }
257     function getVersand($class,$orderid,$country) {
258         $tmp = explode("_",$class);
259         if ( $tmp[1] == "" ) $tmp[1] = "dp";
260         $sql  = "SELECT geo_zone_id FROM zones_to_geo_zones WHERE zone_country_id = (";
261         $sql .= "SELECT countries_id FROM countries WHERE countries_name = '$country')";
262         $rs = $this->db->getOne($sql);
263         $sql  = "SELECT tax_rate FROM tax_rates WHERE tax_zone_id = ".$rs['geo_zone_id']." AND tax_class_id = (";
264         $sql .= "SELECT configuration_value FROM  configuration WHERE configuration_key = 'MODULE_SHIPPING_".strtoupper($tmp[1])."_TAX_CLASS') ";
265         $rs = $this->db->getOne($sql);
266         $preis = $this->getTotal($orderid,'ot_shipping');
267         if ( $preis > 0 ) {
268             if ($this->mwstS) {
269                 $preis = round($preis/(100+$rs['tax_rate'])*100,2);
270             } 
271             if ($rs['tax_rate'] ==  $this->versandV['TAX']) {
272                      $artikel  = array("partnumber"=>$this->versandV['NR'],"description"=>$this->versandV['TXT'],
273                                        "qty"=>1,"unit"=>$this->versandV['Unit'],"sellprice"=>$preis);
274             } else {
275                      $artikel  = array("partnumber"=>$this->versandS['NR'],"description"=>$this->versandS['TXT'],"taxrate"=>$this->versandS['TAX'],
276                                        "qty"=>1,"unit"=>$this->versandS['Unit'],"sellprice"=>$preis);
277             }
278             return $artikel;
279         }
280         return false;
281     }
282     function getKosten($kosten,$orderid,$country) {
283         $sql  = "SELECT geo_zone_id FROM zones_to_geo_zones WHERE zone_country_id = (";
284         $sql .= "SELECT countries_id FROM countries WHERE countries_name = '$country')";
285         $rs = $this->db->getOne($sql);
286         $sql  = "SELECT tax_rate FROM tax_rates WHERE tax_zone_id = ".$rs['geo_zone_id']." AND tax_class_id = (";
287         $sql .= "SELECT configuration_value FROM  configuration WHERE configuration_key = 'MODULE_SHIPPING_".strtoupper($kosten)."_TAX_CLASS') ";
288         $rs = $this->db->getOne($sql);
289         $preis = $this->getTotal($orderid,'ot_'.$kosten);
290         if ( $preis > 0 ) {
291             //Shop muß immer Nettopreise liefern.
292             if ( $this->mwstS ) {
293                 $preis = round($preis / (100+$rs['tax_rate'])*100,2);
294             } 
295                  if ( $kosten == 'cod_fee' )     { $erp = $this->nachn; }
296             else if ( $kosten == 'loworderfee' ) { $erp = $this->minder; }
297             else if ( $kosten == 'paypal_fee' )      { $erp = $this->paypal; }
298             $artikel  = array("partnumber"=>$erp['NR'],"description"=>$erp['TXT'],
299                                "qty"=>1,"unit"=>$erp['Unit'],"sellprice"=>$preis);
300             return $artikel;
301         }
302         return false;
303     }
304     function getTotal($orderid,$type) {
305         $sql = "SELECT value FROM orders_total WHERE orders_id = $orderid AND class = '$type'";
306         $rs = $this->db->getOne($sql);
307         return $rs['value'];
308     }
309     function getBestellung($employee_id) {
310         $sql = "SELECT * FROM orders WHERE orders_status=1 order by orders_id limit 1";
311         $rs=$this->db->getAll($sql);
312         if (!$rs) return array(); 
313         $data = false; 
314         foreach ($rs as $row) {
315              $artikel = $this->getBestellArtikel($row["orders_id"]);
316              $versand = $this->getVersand($row["shipping_class"],$row['orders_id'],$row['delivery_country']);
317              if ($versand) $artikel[] = $versand;
318              $nachn = $this->getKosten('cod_fee',$row['orders_id'],$row['delivery_country']);
319              if ($nachn) $artikel[] = $nachn;
320              $minder = $this->getKosten('loworderfee',$row['orders_id'],$row['delivery_country']);
321              if ($minder) $artikel[] = $minder;
322              $paypal = $this->getKosten('paypal',$row['orders_id'],$row['delivery_country']);
323              if ($paypal) $artikel[] = $paypal;
324              if ($row["delivery_country_iso_code_2"] == "DE") {
325                  $rowdata['taxzone_id'] = 0;
326              } else if (in_array($this->EU,$row["delivery_country_iso_code_2"])) {
327                  if (preg_match('/^[^0-9]{2,3}[ 0-9]+$/',$row["customers_vat_id"])) {
328                      $rowdata['taxzone_id'] = 1;
329                  } else {
330                      $rowdata['taxzone_id'] = 2;
331                  }
332              } else {
333                  $rowdata['taxzone_id'] = 3;
334              }
335              if ($rowdata["cc_number"]) {
336                  $rowdata["kreditkarte"] = $row['cc_type']."\n";
337                  $rowdata["kreditkarte"] = $row['cc_number']." ID:".$row['cc_cvv']."\n";
338                  $rowdata["kreditkarte"] = $row['cc_expires']."\n";
339                  $rowdata["kreditkarte"] = $row['cc_owner']."\n";
340              }
341              $rowdata['cusordnumber']   = $row['orders_id'];
342              $rowdata["versandart"] = $this->_toERP($row["shipping_method"]);
343              $rowdata["notes"] = $this->_toERP($row["comments"]);
344              $rowdata["curr"] = $this->_toERP($row["currency"]);
345              $rowdata["transdate"] = substr($row["date_purchased"],0,10);
346              $rowdata["shipvia"] = $this->_toERP($row["shipping_method"]);
347              $rowdata["employee_id"] = $employee_id;
348              $rowdata["parts"] = $artikel;
349              $rowdata["mwst"] = $this->getTotal($row['orders_id'],'ot_tax');
350              $rowdata["amount"]= $this->getTotal($row['orders_id'],'ot_total');
351              $rowdata["netamount"] = $this->getTotal($row['orders_id'],'ot_subtotal');
352              if ($row['delivery_company']) {
353                  $delivery['name']    = $row['delivery_company'];
354                  $delivery['contact'] = $row['delivery_firstname']." ".$row['delivery_lastname'];
355              } else {
356                  $delivery['name']  = $row['delivery_lastname'].', '.$row['delivery_firstname'];
357              }
358              $delivery['street']    = $row['delivery_street_address'];
359              $delivery['city']      = $row['delivery_city'];
360              $delivery['zipcode']   = $row['delivery_postcode'];
361              $delivery['country']   = $row['delivery_country'];
362              $delivery['phone']     = $row['delivery_telephone'];
363              $delivery['email']     = $row['delivery_email_address'];
364              if ($row['customers_company']) {
365                  $customer['name']    = $row['customers_company'];
366                  $customer['contact'] = $row['customers_firstname']." ".$row['customers_lastname'];
367                  $customer['greeting']  = 'Firma';
368              } else {
369                  $customer['name']  = $row['customers_lastname'].', '.$row['customers_firstname'];
370                  $customer['greeting']  = ($row['customers_gender'] == 'm')?'Herr':'Frau';
371              }
372              $customer['shopid']    = $row['customers_id'];
373              $customer['street']    = $row['customers_street_address'];
374              $customer['city']      = $row['customers_city'];
375              $customer['zipcode']   = $row['customers_postcode'];
376              $customer['country']   = $row['customers_country'];
377              $customer['phone']     = $row['customers_telephone'];
378              $customer['email']     = $row['customers_email_address'];
379              $customer['contact']   = $row['customers_name'];
380              $customer['customer_id']   = $row['customers_cid'];
381              $rowdata['customer']   = $customer;
382              if ( $customer != $delivery ) $rowdata['delivery'] = $delivery;
383              $rowdata["customer"]['customernumber'] = $row['customers_cid'];
384              $data[] = $rowdata;
385         }
386         return $data;
387     }
388     function getBestellArtikel($bestellung) {
389         if (!$this->kategorien) $this->getKategorien();
390         $sql  = "SELECT OP.*,D.products_description,PC.categories_id as katid,PV.products_vpe_name,P.products_ean,P.products_image,P.products_weight ";
391         $sql .= "FROM orders_products OP ";
392         $sql .= "LEFT JOIN products_description D on OP.products_id=D.products_id ";
393         $sql .= "LEFT JOIN products P on OP.products_id=P.products_id ";
394         $sql .= "LEFT JOIN products_to_categories PC on OP.products_id = PC.products_id ";
395         $sql .= "LEFT JOIN products_vpe PV ON PV.products_vpe_id = P.products_vpe ";
396         $sql .= "WHERE (PV.language_id = ".$this->language." OR PV.language_id is Null) AND D.language_id = ".$this->language;
397         $sql .= " AND OP.orders_id = $bestellung";
398         $rs=$this->db->getAll($sql);
399         if (!$rs) {
400              $this->error->write("xtc","Die Artikel der Bestellung $bestellung konnte nicht gelesen werden");
401              return false;
402         }
403         foreach ($rs as $row) {
404             $row['partsgroup'] = $this->_toERP($this->Kategorien[$row['katid']]);
405             $variant = $this->getVariant($row['orders_id'],$row['orders_products_id']);
406             if ( $this->variantnr == 1 ) {
407                 $row['products_name'] = $this->_toERP($row['products_name'].$variant);
408                 $row['products_description'] = $this->_toERP($row['products_description']);
409             } else {
410                 $row['products_name'] = $this->_toERP($row['products_name']);
411                 $row['products_description'] = $this->_toERP($variant.$row['products_description']);
412             }
413             //Shop muß immer Nettopreise liefern.
414             if ($this->mwstS) {
415                 $row['products_price'] = round($row['products_price'] / (100+$row['products_tax'])*100,2);
416             }
417             $row['products_vpe_name'] = ( $row['products_vpe_name'] )?$this->_toERP($row['products_vpe_name']):$this->unit;
418             $row['partsgroup'] = $this->_toERP($this->Kategorien[$row['katid']]);
419             $data[] = $this->translateTable($row,"orderparts");
420         }
421         return $data;
422     }
423     function getVariant($oid,$aid) {
424         $sql  = "SELECT * FROM orders_products_attributes WHERE orders_id = $oid AND orders_products_id = $aid";
425         $rs = $this->db->getAll($sql);
426         if ( $this->variantnr == 1 ) { $start = "\n"; $end = ""; }
427         else { $start = ""; $end = "\n"; }
428         $txt = '';
429         if ($rs) foreach ($rs as $row) {
430             $txt .= $start.sprintf('%s: %s %s%0.2f',$row['products_options'],$row['products_options_values'],$row['price_prefix'],$row['options_values_price']).$end;
431         };
432         return $txt;
433     }
434     function setAbgeholt($bestellung) {
435         $sql = "UPDATE orders SET orders_status ='3' WHERE orders_id = $bestellung"; // in ($bestellungen)";
436         $rc = $this->db->query($sql);
437         if (!$rc) {
438             $this->error->write("xtc","Die Bestellung $bestellung konnten nicht als abgeholt markiert werden");
439             return false;
440         } else {
441             return true;
442         }
443     }
444     function setKundenNr($id,$nr) {
445         $sql = "UPDATE customers SET customers_cid = '$nr' WHERE customers_id = $id";
446         $rc = $this->db->query($sql);
447         if (!$rc) {
448             $this->error->write("xtc","Die Kundennummer $nr konnte nicht dem Kunden $id zugeordnet werden");
449             return false;
450         } else {
451             return true;
452         }
453     }
454     function getAllArtikel() {
455         if (!$this->Kategorien) $this->getKategorien();
456         $sql  = "SELECT P.*,D.*,PC.categories_id as katid,T.tax_rate as products_tax,PV.products_vpe_name FROM products P ";
457         $sql .= "LEFT JOIN products_description D on P.products_id=D.products_id ";
458         $sql .= "LEFT JOIN products_to_categories PC on P.products_id = PC.products_id ";
459         $sql .= "LEFT JOIN tax_rates T ON T.tax_class_id = P.products_tax_class_id ";
460         $sql .= "LEFT JOIN products_vpe PV ON PV.products_vpe_id = P.products_vpe ";
461         $sql .= "WHERE T.tax_zone_id = ".$this->tax_zone." AND ";
462         $sql .= "PV.language_id = ".$this->language." AND D.language_id = ".$this->language;
463         $rs = $this->db->getAll($sql);
464         if ($rs) foreach ($rs as $row) {
465             $row['partsgroup'] = $this->_toERP($this->Kategorien[$row['katid']]);
466             $row['name'] = $this->_toERP($row['products_name']);
467             $row['beschreibung'] = $this->_toERP($row['products_description']);
468             //if (!$this->mwstLX) $row['products_price'] = round(($row['products_price'] / (100 + $row['mwst_satz']) * 100),$this->dezimal);
469             $data[] = $this->translateTable($row,"orderparts");
470         }
471         return $data;
472     }
473     function getKategorien() {
474         $sql  = "SELECT C.categories_id,D.categories_name,C.parent_id ";
475         $sql .= "FROM categories C LEFT JOIN categories_description D ON C.categories_id=D.categories_id ";
476         $sql .= "WHERE C.parent_id >= 0 order by C.parent_id AND D.language_id = ".$this->language;
477         $rs = $this->db->getAll($sql);
478         if ($rs) {
479             foreach($rs as $row) { $this->katrs[$row['categories_id']] = $row;};
480             foreach($this->katrs as $row) {
481             if ($row['parent_id'] == '0') {
482                 $name = $row['categories_name'];
483             } else {
484                 $name = $this->mkKategorien($row['categories_id'],'');
485             }
486             $this->Kategorien[$row['categories_id']] = $name;
487             }
488         }
489     }
490     function mkKategorien($id,$name) {
491         if ($this->katrs[$id]['parent_id'] == '0') {
492            if ($name) {
493                 return $this->katrs[$id]['categories_name'].'!'.$name;
494             } else {
495                 return $this->katrs[$id]['categories_name']."#";
496             }
497         } else {
498            if (!$name) {
499                $name = $this->katrs[$id]['categories_name'];
500            } else {
501                $name = $this->katrs[$id]['categories_name'].'!'.$name;
502            }
503                $name = $this->mkKategorien($this->katrs[$id]['parent_id'],$name);
504         }
505         return $name;
506     }
507 }
508 ?>