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