Mahnprozess um Filter nach (Kunden) Land erweitert
[kivitendo-erp.git] / peppershop / ArtikelErpToShop.php
1 <?php
2
3 $debug = False;
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     $p = array('shopnr','nofiles');
15     if ( $argc > 1 ) {
16         for( $i=1; $i<count($argv); $i++)  {
17                 $tmp = explode("=",trim($argv[$i]));
18                 if ( count($tmp) < 2 ) {
19                     echo "Falscher Aufruf: php ArtikelErpToShop.php shopnr=1 [nofiles=1]\n";
20                     exit (-1);
21                 };
22                 if ( ! in_array(strtolower($tmp[0]),$p) ) {
23                     echo "Falscher Aufruf: php ArtikelErpToShop.php shopnr=1 [nofiles=1]\n";
24                     exit (-1);
25                 };
26                 ${$tmp[0]} = trim($tmp[1]);
27         }
28     } else {
29         $shopnr=false;
30         $nofiles=false;
31     }
32 }
33
34 include_once("conf$shopnr.php");
35 include_once("error.php");
36 //Fehlerinstanz
37 $err = new error($api);
38
39 include_once("dblib.php");
40 include_once("pepper.php");
41 include_once("erplib.php");
42 include_once("Picture.php");
43
44
45 //Bilder
46 $pict = new picture($ERPftphost,$ERPftpuser,$ERPftppwd,$ERPimgdir,$SHOPftphost,$SHOPftpuser,$SHOPftppwd,$SHOPimgdir,$err);
47 //$pict->original = false;
48
49 //ERP-Instanz
50 $erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err,$debug);
51 if ($erpdb->db->connected_database_name == $ERPdbname) {
52     $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstS,$OEinsPart,$lager,$pricegroup,$ERPusrID);
53 } else {
54     $err->out('Keine Verbindung zur ERP',true);
55     exit();
56 }
57 //Shop-Instanz
58 $shopdb = new mydb($SHOPhost,$SHOPdbname,$SHOPuser,$SHOPpass,$SHOPport,'mysql',$err,$debug);
59
60 if ($shopdb->db->connected_database_name == $SHOPdbname) {
61      $shop = new pepper($shopdb,$err,$SHOPdbname,$divStd,$divVerm,$minder,$nachn,$versandS,$versandV,$paypal,$treuhand,$mwstLX,$mwstS,$variantnr,$pict,$nopic,$nopicerr,$nofiles);
62 } else {
63     $err->out('Keine Verbindung zum Shop',true);
64     exit();
65 }
66 $artikel = $erp->getParts($pricegroup);
67 $lang = $shop->getLang("de");
68 $cnt = 0;
69 $errors = 0;
70
71 if ( $api != 'cli' ) ob_start();
72
73 $err->out("Artikelexport für Shop $shopnr",true);
74
75 if ($artikel) foreach ($artikel as $row) {
76     $rc = $shop->saveArtikel($row,"de");
77     if ($rc) { 
78        $cnt++;
79        if ( $cnt % 10 == 0 ) $err->out(".");  
80     } else {
81        $errors++;
82     }
83 }
84 $err->out('',true);
85 $err->out("$cnt Artikel übertragen, $errors Artikel nicht",true);
86 if ( $api != "cli" ) {
87     echo "</body>\n</html>\n";
88 }
89 ?>