Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
[kivitendo-erp.git] / shopxtc / ArtikelShopToErp.php
1 <?php
2
3 $debug = true;
4
5 $api = php_sapi_name();
6 if ( $api != "cli" ) {
7     echo "<html>\n<head>\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n</head>\n<body>\n";
8     @apache_setenv('no-gzip', 1);
9     @ini_set('zlib.output_compression', 0);
10     @ini_set('implicit_flush', 1);
11     $shopnr = $_GET["Shop"];
12     $nofiles = ( $_GET["nofiles"] == '1' )?true:false;
13 } else {
14     if ( $argc > 1 ) {
15         $tmp = explode("=",trim($argv[1]));
16         if ( count($tmp) != 2 ) {
17              echo "Falscher Aufruf: php <scriptname.php> shop=1\n";
18              exit (-1);
19          } else {
20               $shopnr = $tmp[1];
21          }
22     }
23 }
24
25 include_once("conf$shopnr.php");
26 include_once("error.php");
27 //Fehlerinstanz
28 $err = new error($api);
29
30 include_once("dblib.php");
31 include_once("xtc.php");
32 include_once("erplib.php");
33
34
35
36 //ERP-Instanz
37 $erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err,$debug);
38 if ($erpdb->db->connected_database_name == $ERPdbname) {
39     $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstLX,$OEinsPart,$lager,$pricegroup,$ERPusrID);
40 } else {
41     $err->out('Keine Verbindung zur ERP',true);
42     exit();
43 }
44
45 //Shop-Instanz
46 $shopdb = new mydb($SHOPhost,$SHOPdbname,$SHOPuser,$SHOPpass,$SHOPport,'mysql',$err,$debug);
47 if ($shopdb->db->connected_database_name == $SHOPdbname) {
48      $shop = new xtc($shopdb,$err,$SHOPdbname,$divStd,$divVerm,$minder,$nachn,$versandS,$versandV,$paypal,$treuhand,$mwstLX,$mwstS,$variantnr,$unit);
49 } else {
50     $err->out('Keine Verbindung zum Shop',true);
51     exit();
52 }
53
54 $artikel = $shop->getAllArtikel();
55 echo "<pre>"; print_r($artikel); echo "</pre>";
56 $cnt = 0;
57 $errors = 0;
58 //Artikel die mehreren Warengruppen zugeordnet sind, werden nur einmal importiert.
59 //Es wird dann auch nur die erste Warengruppe angelegt.
60 if ( $api != 'cli' ) ob_start();
61
62 $err->out("Artikelimport von Shop $shopnr",true);
63
64 if ($artikel) foreach ($artikel as $row) {
65      $rc = $erp->chkPartnumber($row,true);
66      if ($rc) { 
67         $cnt++;
68      } else { 
69         $err->out('Fehler: '.$row['partnumber'],true);
70         $errors++;
71      }
72 }
73 $err->out('',true);
74 $err->out("$cnt Artikel geprüft bzw. übertragen, $errors Artikel nicht",true);
75 if ( $api != "cli" ) {
76     echo "</body>\n</html>\n";
77 }
78 ?>