Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9d3c499e

Von Holger Lindemann vor mehr als 12 Jahren hinzugefügt

  • ID 9d3c499e4fccf77b2bd0a221dd4dc56053e56d2f
  • Vorgänger e3329d46
  • Nachfolger c068de1b

Neue xtComm Shopschnittstelle.

Weitestgehend mit der PepperShop identisch.
Sollte auch möglichst so bleiben!! Wenn möglich Änderungen am File erplib.php für beide/alle Shop anpassen.
Mehrwert: Artikel aus dem Shop in LxO importieren.

Unterschiede anzeigen:

shopxtc/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
    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
include_once("PictureXTC.php");
34

  
35

  
36
//Bilder
37
$pict = new picture($ERPftphost,$ERPftpuser,$ERPftppwd,$ERPimgdir,$SHOPftphost,$SHOPftpuser,$SHOPftppwd,$SHOPimgdir,$err);
38
//$pict->original = false;
39

  
40
//ERP-Instanz
41
$erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err,$debug);
42
if ($erpdb->db->connected_database_name == $ERPdbname) {
43
    $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstLX,$OEinsPart,$lager,$pricegroup,$ERPusrID);
44
} else {
45
    $err->out('Keine Verbindung zur ERP',true);
46
    exit();
47
}
48
//Shop-Instanz
49
$shopdb = new mydb($SHOPhost,$SHOPdbname,$SHOPuser,$SHOPpass,$SHOPport,'mysql',$err,$debug);
50
if ($shopdb->db->connected_database_name == $SHOPdbname) {
51
     $shop = new xtc($shopdb,$err,$SHOPdbname,$divStd,$divVerm,$minder,$nachn,$versandS,$versandV,$paypal,$treuhand,$mwstLX,$mwstS,$variantnr,$unit,$pict,$nopic,$nopicerr,$nofiles);
52
} else {
53
    $err->out('Keine Verbindung zum Shop',true);
54
    exit();
55
}
56
$artikel = $erp->getParts($pricegroup);
57
$cnt = 0;
58
$errors = 0;
59
if ( $api != 'cli' ) ob_start();
60

  
61
$err->out("Artikelexport für Shop $shopnr",true);
62

  
63
if ($artikel) foreach ($artikel as $row) {
64
    $rc = $shop->saveArtikel($row,"de");
65
    if ($rc) { 
66
       $cnt++;
67
       if ( $cnt % 10 == 0 ) $err->out(".");  
68
    } else {
69
       $errors++;
70
    }
71
}
72
$err->out('',true);
73
$err->out("$cnt Artikel übertragen, $errors Artikel nicht",true);
74
if ( $api != "cli" ) {
75
    echo "</body>\n</html>\n";
76
}
77
?>
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
?>
shopxtc/BestellungShopToErp.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
include_once("dblib.php");
30
include_once("xtc.php");
31
include_once("erplib.php");
32

  
33
$err->out("Shop $shopnr, Bestellimport",true);
34

  
35
//ERP-Instanz
36
$erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err,$debug);
37
if ($erpdb->db->connected_database_name == $ERPdbname) {
38
    $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstLX,$OEinsPart,$lager,$pricegroup,$ERPusrID);
39
} else {
40
    $err->out('Keine Verbindung zur ERP',true);
41
    exit();
42
}
43

  
44
//Shop-Instanz
45
$shopdb = new mydb($SHOPhost,$SHOPdbname,$SHOPuser,$SHOPpass,$SHOPport,'mysql',$err,$debug);
46
if ($shopdb->db->connected_database_name == $SHOPdbname) {
47
     $shop = new xtc($shopdb,$err,$SHOPdbname,$divStd,$divVerm,$minder,$nachn,$versandS,$versandV,$paypal,$mwstLX,$mwstS,$variantnr,$unit);
48
} else {
49
    $err->out('Keine Verbindung zum Shop',true);
50
    exit();
51
}
52

  
53
$bestellungen = $shop->getBestellung($ERPusrID);
54
$cnt = 0;
55
$errors = 0;
56

  
57
$err->out("Bestellimport vom Shop $shopnr",true);
58

  
59
if ($bestellungen) foreach ($bestellungen as $row) {
60
    $rc = $erp->mkAuftrag($row,$shopnr,$longtxt);
61
    echo "!$rc!";
62
    if ($rc>0) {
63
        $rc = $shop->setKundenNr($row['customer']['shopid'],$rc);
64
        if ($rc>0) {
65
           $shop->setAbgeholt($row['cusordnumber']); 
66
           $cnt++;
67
           $err->out("ok",true);
68
        } else {
69
           $errors++;
70
           $err->out("Fehler setKdNr ".$row['customer']['shopid'],true);
71
        }
72
    } else if ($rc == -1) {
73
           $errors++;
74
           $err->out("Fehler mkAuftrag ".$row['cusordnumber'],true);
75
    } else {
76
        $err->out("Fehler Kunde zuordnen ".$row['customer']['shopid'].":".$row['cusordnumber'],true);
77
        $errors++;
78
    } 
79
}
80
$err->out('Von '.count($bestellungen)." Bestellungen $cnt übertragen, $errors nicht",true);
81
if ( $api != "cli" ) {
82
    echo "<br /><a href='../oe.pl?vc=customer&type=sales_order&nextsub=orders&action=Weiter&open=1&notdelivered=1&delivered=1&l_ordnumber=Y&l_transdate=Y&l_reqdate=1&l_name=Y&l_employee=Y&l_amount=Y'>Auftragsliste</a>";
83
    echo "</body>\n</html>\n";
84
}
85

  
86
?>
shopxtc/LiesMich.txt
1
Varianten können in LxO eigene Artikelnummern haben.
2
Die Artikelnummer wird dann automatisch ergänzt um "-" und die Variarions-ID.
3
Aus "A1001" wird z.B. "A1001-1" für die erste (Standard) Variante.
4
Variations-IDs MÜSSEN!! Lückenlos bei 1 beginnen, da sonst der Shop ins Schleudern kommt!!!!!
5

  
6
Preise werden berechnet: Grundpreis + Preis für die Variante
7
Text wird ergänzt: Standardtext + ", Variantengruppe: Variante"
8

  
9
Ein beschreibbares Verzeichnis "tmp" wird als Unterverzeichnis erwartet. 
10
z.B.:
11
ln -s /tmp
12

  
13
Wenn ein Platzhalterbild eingesetzt werden soll, so muß das Bild zuerst auf 
14
den Shopserver übertragen werden.
15
<bildname>.jpg 
16

  
17
Dann den Namen <bildname> in der Maske eintragen. Man kann bestimmen, ob
18
das Bild immer genommen wird, wenn kein Bild angegeben wird oder nur wenn
19
der Upload schief gegangen ist.
20

  
21
Artikelexport (Lx -> Shop) kann ohne Bilderupload durchgeführt werden.
22
Spart Bandbreite und Zeit, wenn nur Updates gemacht werden.
23
Parameterübergabe:  nofiles=1
24
[Shop--Warenexport]
25
module=shopxtc/ArtikelErpToShop.php
26
nofiles=1
27

  
28
Shop ist Mehrshopfähig. Shopnummer muß beim Aufruf übergeben werden:
29
Shop=1
30

  
31
Die Im-/Exportmodule lassen sich auch auf der Konsole oder per Cron-Job aufrufen:
32

  
33
php ArtikelShopToErp.php shop=1 > /tmp/export.log
shopxtc/PictureXTC.php
1
<?php
2

  
3

  
4
class picture {
5

  
6
    var $popupwidth = 800;
7
    var $infowidth = 150;
8
    var $thumbwidth = 80;
9
    var $err = false;
10

  
11
    function picture($ERPhost,$ERPuser,$ERPpass,$ERPimgdir,$SHOPhost,$SHOPuser,$SHOPpass,$SHOPimgdir,$err) {
12
        $this->ERPftphost = $ERPhost;
13
        $this->ERPftpuser = $ERPuser;
14
        $this->ERPftppwd = $ERPpass;
15
        $this->ERPimgdir = $ERPimgdir;
16
        $this->SHOPftphost = $SHOPhost;
17
        $this->SHOPftpuser = $SHOPuser;
18
        $this->SHOPftppwd = $SHOPpass;
19
        $this->SHOPimgdir = $SHOPimgdir;
20
        $this->err = $err;
21
    }
22

  
23
    function copyImage($id,$image,$typ) {
24
        if ( !$this->fromERP($image) ) return false;
25
        if ( !$this->mkbilder() ) return false;
26
        return $this->toShop($id,$typ);
27
    }
28

  
29
    function mkbilder() {
30
        if ( !class_exists("Imagick") ) { $this->err->out("Imagick-Extention nicht installiert",true); return false; };
31
        $handle = new Imagick();
32
        if ( !$handle->readImage("./tmp/tmp.file_org") ) return false;
33
        $d = $handle->getImageGeometry();
34
        if ( $d["width"]<$d["height"] ) {
35
            $faktor = $d["height"]/$d["width"];
36
        } else {
37
            $faktor = $d["width"]/$d["height"];
38
        }
39

  
40
        $thumbheight = floor($this->thumbwidth*$faktor);
41
        $handle->thumbnailImage($this->thumbwidth, $thumbheight);
42
        $rc = $handle->writeImage( "./tmp/tmp.file_thumb");
43

  
44
        $handle->readImage("./tmp/tmp.file_org");
45
        $popupheight = floor($this->popupwidth * $faktor);
46
        $handle->thumbnailImage( $this->popupwidth, $popupheight);
47
        $rc = $handle->writeImage( "./tmp/tmp.file_popup");
48

  
49
        $handle->readImage("./tmp/tmp.file_org");
50
        $infoheight = floor($this->infowidth * $faktor);
51
        $handle->thumbnailImage( $this->infowidth, $infoheight);
52
        $rc = $handle->writeImage( "./tmp/tmp.file_info");
53
        return $rc;
54
    }
55

  
56
    function fromERP($image) {
57
        if ( $this->ERPftphost == 'localhost' ) {
58
            exec("cp $this->ERPimgdir/$image ./tmp/tmp.file_org",$aus,$rc2);
59
            if ( $rc2>0 ) { $this->err->out("[Downloadfehler: $image]",true); return false; };
60
        } else {
61
            $conn_id = ftp_connect($this->ERPftphost);
62
            $rc = @ftp_login($conn_id,$this->ERPftpuser,$this->ERPftppwd);
63
            $src = $this->ERPimgdir."/".$image;
64
            $upload = @ftp_get($conn_id,"tmp/tmp.file_org","$src",FTP_BINARY);
65
            if ( !$upload ) { $this->err->out("[Ftp Downloadfehler! $image]",true); return false; };
66
            ftp_quit($conn_id);
67
        }
68
        $this->image = $image;
69
        return true;
70
    }
71

  
72
    function toShop($id,$typ) {
73
        $picname = $id."_0.".$typ;
74
        if ( $this->SHOPftphost == 'localhost' ) {
75
            exec("cp ./tmp/tmp.file_org   $this->SHOPimgdir/original_images/$picname",$aus,$rc1);
76
            exec("cp ./tmp/tmp.file_info  $this->SHOPimgdir/info_images/$picname",$aus,$rc2);
77
            exec("cp ./tmp/tmp.file_popup $this->SHOPimgdir/popup_images/$picname",$aus,$rc3);
78
            exec("cp ./tmp/tmp.file_thumb $this->SHOPimgdir/thumbnail_images/$picname",$aus,$rc4);
79
            if ( $rc1>0 || $rc2>0 || $rc3>0 || $rc4>0 ) { $this->err->out("[Uploadfehler: $this->image / $picname]",true); return false; };
80
        } else {
81
            $conn_id = ftp_connect($this->SHOPftphost);
82
            @ftp_login($conn_id,$this->SHOPftpuser,$this->SHOPftppwd);
83
            @ftp_chdir($conn_id,$this->SHOPimgdir);
84
            $upload = @ftp_put($conn_id,$this->SHOPimgdir."/original_images/$picname","tmp/tmp.file_org",FTP_BINARY);
85
            if ( !$upload ) { $this->err->out("[Ftp Uploadfehler! original_images/$picname]",true); return false; };
86
            $upload = @ftp_put($conn_id,$this->SHOPimgdir."/info_images/$picname","tmp/tmp.file_info",FTP_BINARY);
87
            if ( !$upload ) { $this->err->out("[Ftp Uploadfehler! info_images/$picname]",true); return false; };
88
            $upload = @ftp_put($conn_id,$this->SHOPimgdir."/popup_images/$picname","tmp/tmp.file_popup",FTP_BINARY);
89
            if ( !$upload ) { $this->err->out("[Ftp Uploadfehler! popup_images/$picname]",true); return false; };
90
            $upload = @ftp_put($conn_id,$this->SHOPimgdir."/thumbnail_images/$picname","tmp/tmp.file_thumb",FTP_BINARY);
91
            if ( !$upload ) { $this->err->out("[Ftp Uploadfehler! thumb_images/$picname]",true); return false; };
92
            @ftp_quit($conn_id);
93
        }
94
        return true;
95
    }
96

  
97

  
98
}
99
?>
shopxtc/conf.php.default
1
<?php
2
// Verbindung zur ERP-db
3
$ERPuser='lxoffice';
4
$ERPpass='lxgeheim';
5
$ERPhost='localhost';
6
$ERPdbname='demo';
7
$codeLX='UTF-8';
8
$mwstLX='1';
9
$ERPusrName='demo';
10
$ERPusrID='';
11
$ERPimgdir='/var/www/lx-office-erp';
12
$maxSize='';
13
$ERPftphost='localhost';
14
$ERPftpuser='pepper';
15
$ERPftppwd='pepper';
16
//Verbindung zur osCommerce-db
17
$SHOPuser='pepper';
18
$SHOPpass='sehrgeheim';
19
$SHOPhost='localhost';
20
$SHOPdbname='Pepper';
21
$codeS='UTF-8';
22
$mwstS='1';
23
$SHOPimgdir='/var/www/Pepper/shop/ProdukteBilder';
24
$SHOPftphost='localhost';
25
$SHOPftpuser='pepper';
26
$SHOPftppwd='pepper';
27
$nopic='nopic';
28
$nopicerr='1';
29
$divStd["ID"]='';
30
$divStd["NR"]='divStd';
31
$divStd["Unit"]='';
32
$divStd["TXT"]='';
33
$divStd["BUGRU"]='';
34
$divStd["TAX"]='';
35
$divVerm["ID"]='';
36
$divVerm["NR"]='divVerm';
37
$divVerm["Unit"]='';
38
$divVerm["TXT"]='';
39
$divVerm["BUGRU"]='';
40
$divVerm["TAX"]='';
41
$versandS["ID"]='';
42
$versandS["NR"]='divStd';
43
$versandS["Unit"]='';
44
$versandS["TXT"]='Versandkosten';
45
$versandS["BUGRU"]='';
46
$versandS["TAX"]='';
47
$versandV["ID"]='';
48
$versandV["NR"]='divVerm';
49
$versandV["Unit"]='';
50
$versandV["TXT"]='Versandkosten';
51
$versandV["BUGRU"]='';
52
$versandV["TAX"]='';
53
$minder["ID"]='';
54
$minder["NR"]='divStd';
55
$minder["Unit"]='';
56
$minder["TXT"]='Mindermengenzuschlag';
57
$minder["BUGRU"]='';
58
$minder["TAX"]='';
59
$nachn["ID"]='';
60
$nachn["NR"]='';
61
$nachn["Unit"]='';
62
$nachn["TXT"]='';
63
$nachn["BUGRU"]='';
64
$nachn["TAX"]='';
65
$treuh["ID"]='';
66
$treuh["NR"]='';
67
$treuh["Unit"]='';
68
$treuh["TXT"]='Treuhandkosten';
69
$treuh["BUGRU"]='';
70
$treuh["TAX"]='';
71
$paypal["ID"]='';
72
$paypal["NR"]='divStd';
73
$paypal["Unit"]='';
74
$paypal["TXT"]='Paypalkosten';
75
$paypal["BUGRU"]='';
76
$paypal["TAX"]='';
77
$bgcol[1]='#ddddff';
78
$bgcol[2]='#ddffdd';
79
$preA='G_';
80
$preK='';
81
$auftrnr='1';
82
$kdnum='1';
83
$pricegroup='';
84
$unit='Stck';
85
$longtxt='2';
86
$invbrne='2';
87
$variantnr='1';
88
$OEinsPart='1';
89
$lager='';
90
?>
shopxtc/confedit.php
1
<?
2
// $Id: confedit.php 2009/02/10 14:41:30 hli Exp $
3
if (!isset($_SERVER['PHP_AUTH_USER'])) {
4
       Header("WWW-Authenticate: Basic realm='Configurations-Editor'");
5
       Header("HTTP/1.0 401 Unauthorized");
6
       echo "Sie m&uuml;ssen sich autentifizieren\n";
7
       exit;
8
} else {
9
        if (!$_POST) {
10
        	//Je Shop ein Conf-File == Multishop
11
		$Shop=$_GET["Shop"];
12
		if ($Shop != "" and file_exists ("conf$Shop.php")) {
13
			require "conf$Shop.php";
14
                        $out = "Konfiguration für Shop $Shop gelesen";
15
		} else {
16
                        //Singleshop oder noch kein Shop definiert
17
			require "conf.php";
18
                        $out = "Standard-Konfiguration gelesen";
19
		}
20
		if ($_SERVER['PHP_AUTH_USER']<>$ERPftpuser || $_SERVER['PHP_AUTH_PW']<>$ERPftppwd) {
21
			Header("WWW-Authenticate: Basic realm='My Realm'");
22
			Header("HTTP/1.0 401 Unauthorized");
23
			echo "Sie m&uuml;ssen sich autentifizieren\n";
24
			exit;
25
		}
26
                echo $out;
27
	}
28
}
29
$debug = true;
30

  
31
include_once("error.php");
32
include_once("dblib.php");
33
$api = php_sapi_name();
34
if ( $api == 'cli' ) {
35
    echo "Nur im Browser benutzen\n";
36
    exit(-1);
37
};
38
$err = new error($api);
39

  
40
$zeichen = array("","UTF-8","ISO-8859-1","ISO-8859-15","Windows-1252","ASCII");
41
function lager($sel,$db) {
42
        if (!$db) return '';
43
        $sql  = "select w.description as lager,b.description as platz,b.id from ";
44
        $sql .= "bin b left join warehouse w on w.id=b.warehouse_id ";
45
        $sql .= "order by b.warehouse_id,b.id";
46
	$bin=$db->getall($sql);
47
        echo "\t<option value=-1 ".(($sel==-1)?'selected':'').">kein Lagerbestand\n";
48
        echo "\t<option value=1 ".(($sel==1)?'selected':'').">Gesamtbestand\n";
49
        if ($bin) foreach ($bin as $row) {
50
		echo "\t<option value=".$row['id'];
51
		if ($sel==$row['id']) echo " selected";
52
		echo ">".$row['lager']." ".$row['platz']."\n";
53
        }
54
}
55
function unit($sel,$db) {
56
        if (!$db) return '';
57
	$sql="select name from units order by sortkey";
58
	$pgs=$db->getall($sql);
59
	if ($sel=='') $sel=$pgs[0]['name'];
60
	if ($pgs) foreach ($pgs as $row) {
61
		echo "\t<option value=".$row['name'];
62
		if ($sel==$row['name']) echo " selected";
63
		echo ">".$row['name']."\n";
64
	}
65
}
66
function pg($sel,$db) {
67
        if (!$db) return '';
68
	$sql="select id,pricegroup from pricegroup";
69
	$pgs=$db->getall($sql);
70
	echo "\t<option value=0";
71
	if ($sel==0) echo " selected";
72
	echo ">Standard VK\n";
73
	if ($pgs) foreach ($pgs as $row) {
74
		echo "\t<option value=".$row['id'];
75
		if ($sel==$row['id']) echo " selected";
76
		echo ">".$row['pricegroup']."\n";
77
	}
78
}
79
function getTax($db) {
80
    $sql  = "SELECT  BG.id AS bugru,T.rate,TK.startdate,C.taxkey_id, ";
81
    $sql .= "(SELECT id FROM chart WHERE accno = T.taxnumber) AS tax_id, ";
82
    $sql .= "BG.income_accno_id_0,BG.expense_accno_id_0 ";
83
    $sql .= "FROM buchungsgruppen BG LEFT JOIN chart C ON BG.income_accno_id_0=C.id ";
84
    $sql .= "LEFT JOIN taxkeys TK ON TK.chart_id=C.id ";
85
    $sql .= "LEFT JOIN tax T ON T.id=TK.tax_id WHERE TK.startdate <= now()";
86
    $rs = $db->getAll($sql);
87
    if ($rs) foreach ($rs as $row) {
88
        $nr = $row['bugru'];
89
        if (!$TAX[$nr]) {
90
            $data = array();
91
            $data['startdate'] =    $row['startdate'];
92
            $data['rate'] = 	    $row['rate']*100.0;
93
            $TAX[$nr] = $data;
94
        } else if ($TAX[$nr]['startdate'] < $row['startdate']) {
95
            $TAX[$nr]["startdate"] = 	$row['startdate'];
96
            $TAX[$nr]["rate"] = 	$row['rate']*100.0;
97
        }
98
    }
99
    return $TAX;
100
}
101
function fputsA($f,$key,$var,$bg=false) {
102
    $lf="\n";
103
    fputs($f,'$'.$key.'["ID"]=\''. $var['ID'].'\';'.$lf);
104
    fputs($f,'$'.$key.'["NR"]=\''. $var['NR'].'\';'.$lf);
105
    fputs($f,'$'.$key.'["Unit"]=\''. $var['Unit'].'\';'.$lf);
106
    fputs($f,'$'.$key.'["TXT"]=\''. $var['TXT'].'\';'.$lf);
107
    if ($bg) fputs($f,'$'.$key.'["BUGRU"]=\''. $var['BUGRU'].'\';'.$lf);
108
    if ($bg) fputs($f,'$'.$key.'["TAX"]=\''. $var['TAX'].'\';'.$lf);
109
}
110
if ($_POST["ok"]=="sichern") {
111
	foreach ($_POST as $key=>$val) {
112
		${$key} = $val;
113
	}
114
};
115
	$ok=true;
116
	$dbP = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err,$debug);
117
	if (!$dbP->db) {
118
		$ok=false;
119
		echo "Keine Verbindung zur ERP<br>";
120
		$dbP=false;		
121
		unset($divStd['ID']);
122
                unset($divVerm['ID']);
123
                unset($minder['ID']);
124
                unset($versand['ID']);
125
                unset($nachn['ID']);
126
                unset($paypal['ID']);
127
		unset($ERPusr['ID']);
128
	} else {
129
                $tax = getTax($dbP);
130
		$sql="SELECT id,description,unit,buchungsgruppen_id FROM parts where partnumber = '%s'";
131
		$rs=$dbP->getOne(sprintf($sql,$divStd['NR']));
132
		$divStd['ID']=$rs['id'];
133
		$divStd['Unit']=$rs['unit'];
134
		$divStd['BUGRU']=$rs['buchungsgruppen_id'];
135
		$divStd['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
136
		$divStd['TXT']=addslashes($rs['description']);
137
	        $rs=$dbP->getOne(sprintf($sql,$divVerm['NR']));
138
		$divVerm['ID']=$rs['id'];
139
		$divVerm['Unit']=$rs['unit'];
140
		$divVerm['BUGRU']=$rs['buchungsgruppen_id'];
141
		$divVerm['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
142
		$divVerm['TXT']=addslashes($rs['description']);
143
		$rs=$dbP->getOne(sprintf($sql,$versandS['NR']));
144
		$versandS['ID']=$rs['id'];
145
		$versandS['Unit']=$rs['unit'];
146
		$versandS['BUGRU']=$rs['buchungsgruppen_id'];
147
		$versandS['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
148
                if ($versandS['TXT'] == '') $versandS['TXT']=addslashes($rs['description']);
149
		$rs=$dbP->getOne(sprintf($sql,$versandV['NR']));
150
		$versandV['ID']=$rs['id'];
151
		$versandV['Unit']=$rs['unit'];
152
		$versandV['BUGRU']=$rs['buchungsgruppen_id'];
153
		$versandV['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
154
                if ($versandV['TXT'] == '') $versandV['TXT']=addslashes($rs['description']);
155
		$rs=$dbP->getOne(sprintf($sql,$nachn['NR']));
156
		$nachn['ID']=$rs['id'];
157
		$nachn['Unit']=$rs['unit'];
158
		$nachn['BUGRU']=$rs['buchungsgruppen_id'];
159
		$nachn['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
160
                if ($nachn['TXT'] == '') $nachn['TXT']=addslashes($rs['description']);
161
		$rs=$dbP->getOne(sprintf($sql,$minder['NR']));
162
		$minder['ID']=$rs['id'];
163
		$minder['Unit']=$rs['unit'];
164
		$minder['BUGRU']=$rs['buchungsgruppen_id'];
165
		$minder['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
166
		if ($minder['TXT'] == '') $minder['TXT']=addslashes($rs['description']);
167
		$rs=$dbP->getOne(sprintf($sql,$paypal['NR']));
168
		$paypal['ID']=$rs['id'];
169
		$paypal['Unit']=$rs['unit'];
170
		$paypal['BUGRU']=$rs['buchungsgruppen_id'];
171
		$paypal['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
172
		if ($paypal['TXT'] == '') $paypal['TXT']=addslashes($rs['description']);
173
		$rs=$dbP->getOne("select id from employee where login = '".$ERPusrName."'");
174
		$ERPusrID=$rs['id'];
175
	}
176
        $dbM = new mydb($SHOPhost,$SHOPdbname,$SHOPuser,$SHOPpass,$SHOPport,'mysql',$err,$debug);
177
	if (!$dbM->db) {
178
		$ok=false;
179
		echo "Keine Verbindung zum Shop<br>";
180
		$dbM=false;
181
	};		
182
if ($_POST["ok"]=="sichern") {
183
        $lf="\n";
184
	$f=@fopen("conf$Shop.php","w");
185
        if ($f) {
186
	$v="1.5";
187
	$d=date("Y/m/d H:i:s");
188
	fputs($f,"<?php$lf// Verbindung zur ERP-db$lf");
189
	fputs($f,'$ERPuser=\''.$ERPuser.'\';'.$lf);
190
	fputs($f,'$ERPpass=\''.$ERPpass.'\';'.$lf);
191
	fputs($f,'$ERPhost=\''.$ERPhost.'\';'.$lf);
192
	fputs($f,'$ERPport=\''.$ERPport.'\';'.$lf);
193
	fputs($f,'$ERPdbname=\''.$ERPdbname.'\';'.$lf);
194
	fputs($f,'$codeLX=\''.$codeLX.'\';'.$lf);
195
	fputs($f,'$mwstLX=\''.$mwstLX.'\';'.$lf);
196
	fputs($f,'$ERPusrName=\''.$ERPusrName.'\';'.$lf);
197
	fputs($f,'$ERPusrID=\''.$ERPusrID.'\';'.$lf);
198
	fputs($f,'$ERPimgdir=\''.$ERPimgdir.'\';'.$lf);
199
	fputs($f,'$maxSize=\''.$maxSize.'\';'.$lf);
200
	fputs($f,'$ERPftphost=\''.$ERPftphost.'\';'.$lf);
201
	fputs($f,'$ERPftpuser=\''.$ERPftpuser.'\';'.$lf);
202
	fputs($f,'$ERPftppwd=\''.$ERPftppwd.'\';'.$lf);
203
	fputs($f,'//Verbindung zur osCommerce-db'.$lf);
204
	fputs($f,'$SHOPuser=\''.$SHOPuser.'\';'.$lf);
205
	fputs($f,'$SHOPpass=\''.$SHOPpass.'\';'.$lf);
206
	fputs($f,'$SHOPhost=\''.$SHOPhost.'\';'.$lf);
207
	fputs($f,'$SHOPport=\''.$SHOPport.'\';'.$lf);
208
	fputs($f,'$SHOPdbname=\''.$SHOPdbname.'\';'.$lf);
209
	fputs($f,'$codeS=\''.$codeS.'\';'.$lf);
210
	fputs($f,'$mwstS=\''.$mwstS.'\';'.$lf);
211
	fputs($f,'$SHOPimgdir=\''.$SHOPimgdir.'\';'.$lf);
212
	fputs($f,'$SHOPftphost=\''.$SHOPftphost.'\';'.$lf);
213
	fputs($f,'$SHOPftpuser=\''.$SHOPftpuser.'\';'.$lf);
214
	fputs($f,'$SHOPftppwd=\''.$SHOPftppwd.'\';'.$lf);
215
	fputs($f,'$nopic=\''.$nopic.'\';'.$lf);
216
	fputs($f,'$nopicerr=\''.$nopicerr.'\';'.$lf);
217
	fputs($f,'$nofiles=\''.$nofiles.'\';'.$lf);
218
        fputsA($f,'divStd',$divStd,true);
219
        fputsA($f,'divVerm',$divVerm,true);
220
        fputsA($f,'versandS',$versandS,true);
221
        fputsA($f,'versandV',$versandV,true);
222
        fputsA($f,'minder',$minder,true);
223
        fputsA($f,'nachn',$nachn,true);
224
        fputsA($f,'paypal',$paypal,true);
225
	fputs($f,'$bgcol[1]=\'#ddddff\';'.$lf);
226
	fputs($f,'$bgcol[2]=\'#ddffdd\';'.$lf);
227
	fputs($f,'$preA=\''.$preA.'\';'.$lf);
228
	fputs($f,'$preK=\''.$preK.'\';'.$lf);
229
	fputs($f,'$auftrnr=\''.$auftrnr.'\';'.$lf);
230
	//fputs($f,'$utftrans=\''.$utftrans.'\';'.$lf);
231
	fputs($f,'$kdnum=\''.$kdnum.'\';'.$lf);
232
	fputs($f,'$pricegroup=\''.$pricegroup.'\';'.$lf);
233
	fputs($f,'$unit=\''.$unit.'\';'.$lf);
234
	fputs($f,'$longtxt=\''.$longtxt.'\';'.$lf);
235
	fputs($f,'$invbrne=\''.$invbrne.'\';'.$lf);
236
	fputs($f,'$variantnr=\''.$variantnr.'\';'.$lf);
237
	fputs($f,'$OEinsPart=\''.$OEinsPart.'\';'.$lf);
238
	fputs($f,'$lager=\''.$lager.'\';'.$lf);
239
	//fputs($f,'$showErr=true;'.$lf);
240
	fputs($f,"?>");
241
	fclose($f);
242
        echo "Konfiguration conf$Shop.php gesichert.";
243
        } else {
244
             echo "Konfigurationsdatei (conf$Shop.php) konnte nicht geschrieben werden";
245
        }
246
} 
247
?>
248
<html>
249
<body>
250
<center>
251
<table style="background-color:#cccccc" border="0">
252
<form name="ConfEdit" method="post" action="confedit.php">
253
<input type="hidden" name="Shop" value="<?= $Shop ?>">
254
<input type="hidden" name="divStd[ID]" value="<?= $divStd['ID'] ?>">
255
<input type="hidden" name="divVerm[ID]" value="<?= $divVerm['ID'] ?>">
256
<input type="hidden" name="minder[ID]" value="<?= $minder['ID'] ?>">
257
<input type="hidden" name="versandS[ID]" value="<?= $versandS['ID'] ?>">
258
<input type="hidden" name="versandV[ID]" value="<?= $versandV['ID'] ?>">
259
<input type="hidden" name="nachn[ID]" value="<?= $nachn['ID'] ?>">
260
<input type="hidden" name="paypal[ID]" value="<?= $paypal['ID'] ?>">
261
<input type="hidden" name="ERPusr[ID]" value="<?= $ERPusr['ID'] ?>">
262

  
263
<tr><th>Daten</th><th>Lx-ERP</th><th><?php echo $Shop ?></th><th>Shop</th></tr>
264
<tr>
265
	<td>db-Host</td>
266
	<td colspan="2"><input type="text" name="ERPhost" size="25" value="<?= $ERPhost ?>"></td>
267
	<td><input type="text" name="SHOPhost" size="25" value="<?= $SHOPhost ?>"></td>
268
</tr>
269
<tr>
270
	<td>Database</td>
271
	<td colspan="2"><input type="text" name="ERPdbname" size="20" value="<?= $ERPdbname ?>"></td>
272
	<td><input type="text" name="SHOPdbname" size="20" value="<?= $SHOPdbname ?>"></td>
273
</tr>
274
<tr>
275
        <td>db-Port</td>
276
        <td colspan="2"><input type="text" name="ERPport" size="25" value="<?= $ERPport ?>"></td>
277
        <td><input type="text" name="SHOPport" size="25" value="<?= $SHOPport ?>"></td>
278
</tr>
279
<tr>
280
	<td>db-User Name</td>
281
	<td colspan="2"><input type="text" name="ERPuser" size="15" value="<?= $ERPuser ?>"></td>
282
	<td><input type="text" name="SHOPuser" size="15" value="<?= $SHOPuser ?>"></td>
283
</tr>
284
<tr>
285
	<td>db-User PWD</td>
286
	<td colspan="2"><input type="text" name="ERPpass" size="15" value="<?= $ERPpass ?>"></td>
287
	<td><input type="text" name="SHOPpass" size="15" value="<?= $SHOPpass ?>"></td>
288
</tr>
289
</tr>
290
	<td>Zeichensatz</td>
291
	<td colspan="2"><select name="codeLX">
292
<?php   foreach($zeichen as $code) {
293
             echo "<option value='".$code."'";
294
             if ($code == $codeLX) echo " selected";
295
             echo ">".$code."\n"; };
296
?>
297
	</select></td>
298
	<td ><select name="codeS">
299
<?php   foreach($zeichen as $code) {
300
             echo "<option value='".$code."'";
301
             if ($code == $codeS) echo " selected";
302
             echo ">".$code."\n"; };
303
?>
304
	</select></td>
305
</tr>
306
<tr>
307
	<td>Preise </td>
308
        <td colspan="2"> <input type="radio" name="mwstLX" value="1" <?= ($mwstLX==1)?"checked":'' ?>> incl.
309
	    <input type="radio" name="mwstLX" value="0" <?= ($mwstLX<>1)?"checked":'' ?>> excl. MwSt</td>
310
	<td><input type="radio" name="mwstS" value="1" <?= ($mwstS==1)?"checked":'' ?>> incl.
311
	    <input type="radio" name="mwstS" value="0" <?= ($mwstS<>1)?"checked":'' ?>> excl. MwSt</td>
312
</tr>
313
<tr>
314
	<td>User-ID</td>
315
	<td colspan="2"><input type="text" name="ERPusrName" size="10" value="<?= $ERPusrName ?>">
316
		<input type="checkbox" name="a1" <?= (empty($ERPusrID)?'':"checked") ?>></td>
317
	<td></td>
318
</tr>
319
<tr>
320
	<td>Image-Dir</td>
321
	<td colspan="2"><input type="text" name="ERPimgdir" size="30" value="<?= $ERPimgdir ?>"></td>
322
	<td><input type="text" name="SHOPimgdir" size="30" value="<?= $SHOPimgdir ?>"></td>
323
</tr>
324
<tr>
325
	<td>Platzhalterbild</td>
326
	<td colspan="2"><input type="text" name="nopic" size="20" value="<?php echo $nopic; ?>"></td>
327
	<td colspan="2"><input type="checkbox" value="1" name="nopicerr" <?= (empty($nopicerr)?'':"checked") ?>>nur bei fehlerhaftem Upload verwenden</td>
328
</tr>
329
<tr>
330
	<td>Bildupload</td>
331
	<td colspan="2"><input type="checkbox" value="1" name="nofiles" <?= (empty($nofiles)?'':"checked") ?>>nur bei neuen Artikeln</td>
332
	<td colspan="2"></td>
333
</tr>
334
<tr>
335
	<td>FTP-Host</td>
336
	<td colspan="2"><input type="text" name="ERPftphost" size="20" value="<?= $ERPftphost ?>"></td>
337
	<td><input type="text" name="SHOPftphost" size="20" value="<?= $SHOPftphost ?>"></td>
338
</tr>
339
<tr>
340
	<td>FTP-User</td>
341
	<td colspan="2"><input type="text" name="ERPftpuser" size="15" value="<?= $ERPftpuser ?>"></td>
342
	<td><input type="text" name="SHOPftpuser" size="15" value="<?= $SHOPftpuser ?>"></td>
343
</tr>
344
<tr>
345
	<td>FTP-User PWD</td>
346
	<td colspan="2"><input type="text" name="ERPftppwd" size="15" value="<?= $ERPftppwd ?>"></td>
347
	<td><input type="text" name="SHOPftppwd" size="15" value="<?= $SHOPftppwd ?>"></td>
348
</tr>
349
<tr>
350
	<td>Nr Diverse Std-MwSt</td>
351
	<td><input type="text" name="divStd[NR]" size="10" value="<?= $divStd['NR'] ?>">
352
		<input type="checkbox" name="a1" <?= (empty($divStd['ID'])?'':"checked") ?>></td>
353
	<td>Nr Diverse Verm-MwSt</td>
354
	<td><input type="text" name="divVerm[NR]" size="10" value="<?= $divVerm['NR'] ?>">
355
		<input type="checkbox" name="a1" <?= (empty($divVerm['ID'])?'':"checked") ?>></td>
356
</tr>
357
<tr>
358
	<td>Nr Versand Std-MwSt</td>
359
	<td><input type="text" name="versandS[NR]" size="10" value="<?= $versandS['NR'] ?>">
360
		<input type="checkbox" name="a1" <?= (empty($versandS['ID'])?'':"checked") ?>></td>
361
	<td>Text:</td>
362
	<td><input type="text" name="versandS[TXT]" size="20" value="<?= $versandS['TXT'] ?>"><?= $versandS['TAX'] ?></td>
363
<tr>
364
	<td>Nr Versand Verm-MwSt</td>
365
	<td><input type="text" name="versandV[NR]" size="10" value="<?= $versandV['NR'] ?>">
366
		<input type="checkbox" name="a1" <?= (empty($versandV['ID'])?'':"checked") ?>></td>
367
	<td>Text:</td>
368
	<td><input type="text" name="versandV[TXT]" size="20" value="<?= $versandV['TXT'] ?>"><?= $versandV['TAX'] ?></td>
369
</tr>
370
<tr>
371
	<td>Nr Paypal</td>
372
	<td><input type="text" name="paypal[NR]" size="10" value="<?= $paypal['NR'] ?>">
373
		<input type="checkbox" name="a1" <?= (empty($paypal['ID'])?'':"checked") ?>></td>
374
	<td>Text:</td>
375
	<td><input type="text" name="paypal[TXT]" size="20" value="<?= $paypal['TXT'] ?>"></td>
376
</tr>
377
<tr>
378
	<td>Nr Mindermenge</td>
379
	<td><input type="text" name="minder[NR]" size="10" value="<?= $minder['NR'] ?>">
380
		<input type="checkbox" name="a1" <?= (empty($minder['ID'])?'':"checked") ?>></td>
381
	<td>Text:</td>
382
	<td><input type="text" name="minder[TXT]" size="20" value="<?= $minder['TXT'] ?>"></td>
383
</tr>
384
<tr>
385
	<td>Nr Nachname</td>
386
	<td><input type="text" name="nachn[NR]" size="10" value="<?= $nachn['NR'] ?>">
387
		<input type="checkbox" name="a1" <?= (empty($nachn['ID'])?'':"checked") ?>></td>
388
	<td>Text:</td>
389
	<td><input type="text" name="nachn[TXT]" size="20" value="<?= $nachn['TXT'] ?>"></td>
390
</tr>
391
<tr>
392
	<td>Std-Einheit</td>
393
	<td><select name="unit">
394
<? unit($unit,$dbP); ?>
395
	    </select></td>
396
	<td>Preisgruppe</td>
397
	<td><select name="pricegroup">
398
<? pg($pricegroup,$dbP); ?>
399
	    </select></td>
400
<tr>
401
	<td colspan="2">Auftragsnummern durch</td>
402
	<td><input type="radio" name="auftrnr" value="1" <?= ($auftrnr==1)?"checked":'' ?>> LxO</td>
403
	<td><input type="radio" name="auftrnr" value="0" <?= ($auftrnr<>1)?"checked":'' ?>> Shop</td>
404
</tr>
405
<tr>
406
	<td colspan="2">Kundennummern durch</td>
407
	<td><input type="radio" name="kdnum" value="1" <?= ($kdnum==1)?"checked":'' ?>> LxO</td>
408
	<td><input type="radio" name="kdnum" value="0" <?= ($kdnum<>1)?"checked":'' ?>> Shop</td>
409
</tr>
410
<tr>
411
	<td colspan="2">Nummernerweiterung</td>
412
	<td>Auftrag<input type="text" name="preA" size="5" value="<?= $preA ?>"></td>
413
	<td>Kunde<input type="text" name="preK" size="5" value="<?= $preK ?>"></td>
414
</tr>
415
<tr>
416
	<td>Lagerbestand aus</td>
417
	<td><select name="lager">
418
<? lager($lager,$dbP); ?>
419
	    </select></td>
420
	<td></td>
421
	<td></td>
422
<tr>
423
<tr>
424
	<td colspan="3">Langbeschreibung aus Shop &uuml;bernehmen</td>
425
	<td><input type="radio" name="longtxt"  value="1" <?= ($longtxt<>2)?"checked":'' ?>>Ja
426
	<input type="radio" name="longtxt"  value="2" <?= ($longtxt==2)?"checked":'' ?>>Nein</td>
427

  
428
</tr>
429
<tr>
430
	<td colspan="3">LxO-Rechnungen sind Netto</td>
431
	<td><input type="radio" name="invbrne"  value="1" <?= ($invbrne<>2)?"checked":'' ?>>Ja
432
	<input type="radio" name="invbrne"  value="2" <?= ($invbrne==2)?"checked":'' ?>>Nein</td>
433
</tr>
434
<tr>
435
	<td >Variantentext</td>
436
	<td colspan="3"><input type="radio" name="variantnr"  value="1" <?= ($variantnr<>2)?"checked":'' ?>>Artikelbezeichnung anhängen
437
	<input type="radio" name="variantnr"  value="2" <?= ($variantnr==2)?"checked":'' ?>>Langebeschreibung voranstellen</td>
438
</tr>
439
<tr>
440
	<td colspan="3">Unbekannte Artikel beim Bestellimport anlegen</td>
441
	<td><input type="radio" name="OEinsPart"  value="1" <?= ($OEinsPart<>2)?"checked":'' ?>>Ja
442
	<input type="radio" name="OEinsPart"  value="2" <?= ($OEinsPart==2)?"checked":'' ?>>Nein</td>
443
</tr>
444

  
445
<!--tr>
446
	<td>Bildergr&ouml;sse (byte)</td>
447
	<td><input type="text" name="maxSize" size="10" value="<?= $maxSize ?>"></td>
448
	<td></td>
449
</tr-->
450

  
451

  
452
<tr><td colspan="4" align="center"><input type="submit" name="ok" value="sichern"></td></tr>
453
</form>
454
</table>
455
</center>
456
</body>
457
</html>
shopxtc/dblib.php
1
<?php
2

  
3
include_once("MDB2.php");
4

  
5
class mydb {
6

  
7
   var $db = false;
8
   var $error = false;
9
   var $debug = true;
10
   var $dbf = false;
11
   var $database = false;
12

  
13
   function mydb($host,$db,$user,$pass,$port,$proto,$error,$debug) {
14
       $this->error = $error;
15
       $dsn = array('phptype'  => $proto,
16
               'username' => $user,
17
               'password' => $pass,
18
               'hostspec' => $host,
19
               'database' => $db,
20
               'port'     => $port);
21
       $this->debug = $debug;
22
       $this->database = "-< $db >-";
23
       $this->connect($dsn);
24
    }
25

  
26
    function connect($dsn) {
27
       $options = array('result_buffering' => false,);
28
       $this->db = MDB2::connect($dsn,$options);
29
       if ( $this->debug ) $this->error->write('dblib->connect '.$this->database,'Connect:');
30
       if (PEAR::isError($this->db)) {
31
           $this->error->write('dblib->connect '.$this->database,$this->db->getMessage());
32
           $this->error->write('dblib->connect '.$this->database,print_r($dsn,true));
33
           $this->db = false;
34
           return false;
35
       }
36
       $this->db->setFetchMode(MDB2_FETCHMODE_ASSOC);
37
    }
38
    function Begin() {
39
        return $this->db->beginTransaction();
40
    }
41
    function Commit() {
42
        return $this->db->commit();
43
    }
44
    function Rollback() {
45
        return $this->db->rollback();
46
    }
47

  
48
    function getAll($sql) {
49
        $rs = $this->db->queryAll($sql);
50
        if ( $this->debug ) $this->error->write('dblib->getAll '.$this->database,$sql);
51
        if (PEAR::isError($rs)) {
52
            $this->error->write('dblib->getAll '.$this->database,$rs->getUserinfo());
53
            return false;
54
        }
55
        return $rs;
56
    } 
57
 
58
    function getOne($sql) {
59
        $rs = $this->db->queryRow($sql);
60
        if ( $this->debug ) $this->error->write('dblib->getOne '.$this->database,$sql);
61
        if (PEAR::isError($rs)) {
62
            $this->error->write('dblib->getOne '.$this->database,$rs->getUserinfo());
63
            return false;
64
        }
65
        return $rs;
66
    }
67
    function query($sql) {
68
        $rc = $this->db->query($sql);
69
        if ( $this->debug ) $this->error->write('dblib->query '.$this->database,$sql);
70
        if (PEAR::isError($rc)) {
71
            $this->error->write('dblib->query '.$this->database,$rc->getUserinfo());
72
            return false;
73
        }
74
        return $rc;
75
    } 
76
    function insert($statement,$data) {
77
        if ( $this->debug ) $this->error->write("dblib->insert ".$this->database,$statement);
78
        $sth = $this->db->prepare($statement);                      //Prepare
79
        if (PEAR::isError($sth)) {
80
            $this->error->write('dblib->insert 1 '.$this->database,$sth->getMessage());
81
            $this->error->write('dblib->insert 2',$sth->getUserinfo());
82
            $this->rollback();
83
            return false;
84
        }
85
        if ( $this->debug ) $this->error->write('dblib->insert',print_r($data,true));
86
        $rc =& $sth->execute($data);
87
        if (PEAR::isError($rc)) {
88
            $this->error->write('dblib->insert 3 '.$this->database,$rc->getUserinfo());
89
            $this->error->write('SQL ',$statement);
90
            $this->error->write('Data ',print_r($data,true));
91
            return false;
92
        }//else{
93
        //    $rc = $this->commit();
94
        //}
95
        return $rc;
96
    }
97
    function update($statement,$data) {  
98
        if ( $this->debug ) $this->error->write("dblib->update ".$this->database,$statement);
99
        $sth = $this->db->prepare($statement);                      //Prepare
100
        if (PEAR::isError($sth)) {
101
            $this->error->write('dblib->update 1 '.$this->database,$sth->getMessage());
102
            $this->error->write('dblib->update 2',$sth->getUserinfo());
103
            $this->rollback();
104
            return false;
105
        }
106
        if ( $this->debug ) $this->error->write('dblib->insert',print_r($data,true));
107
        $rc =& $sth->execute($data);
108
        if (PEAR::isError($rc)) {
109
            $this->error->write('dblib->update 3 '.$this->database,$rc->getUserinfo());
110
            return false;
111
        }//else{
112
        //    $rc = $this->commit();
113
        //}
114
        return $rc;
115
    }
116
    function insertMultipe($statement,$data) {
117
        $this->db->loadModule('Extended');
118
        if (!$this->db->supports('transactions')){
119
            return false;
120
        }
121
        $sth = $this->db->prepare($statement);                      //Prepare
122
        if (PEAR::isError($sth)) {
123
            $this->error->write('dblib->insertMultiple '.$this->database,$sth->getMessage());
124
            $this->rollback();
125
            return false;
126
        }
127
        $rc =& $this->db->beginTransaction();
128
        $rc =& $this->db->extended->executeMultiple($sth, $data);
129
        if (PEAR::isError($rc)) {
130
            $this->error->write('dblib->insertMultiple '.$this->database,$rc->getUserinfo());
131
            $this->rollback();
132
            return false;
133
        }else{
134
                $rc = $this->commit();
135
        }
136
        return $rc;
137
    }
138
}
139

  
140
?>
shopxtc/erplib.php
1
<?php
2
/*
3

  
4
shop muß gesetzt sein, obsolet nicht
5

  
6
Multishop: Hierfür müssen benutzerdefinierte Variablen angelegt werden.
7
Typ:checkbox,  Name=shop[0-9A-Z]+, Bearbeitbar=nein 
8

  
9

  
10
*/
11

  
12
class erp {
13

  
14
    var $db = false;
15
    var $error = false;
16
    var $pricegroup = 0;
17
    var $TAX = false;
18
    var $mkPart = true;
19
    var $divStd = false;
20
    var $divVerm = false;
21
    var $doordnr = false;
22
    var $docustnr = false;
23
    var $lager = 1;
24
    var $warehouse_id = 0;
25
    var $transtype = 0;
26
    var $preordnr = '';
27
    var $precustnr = '';
28
    var $OEinsPart = false;
29
    var $INVnetto = true; //Rechnungen mit Nettopreisen
30
    var $ERPincl = false; //ERP-Preise sind Netto
31

  
32
    function erp($db,$error,$divStd,$divVerm,$doordnr,$docustnr,$preordnr,$precustnr,$INVnetto,$ERPincl,$OEinsPart,$lager,$pricegroup,$ERPusrID) {
33
        $this->db = $db;
34
        $this->pricegroup = $pricegroup;
35
        $this->employee_id = $ERPusrID;
36
        $this->error = $error;
37
        $this->divStd  = $divStd;
38
        $this->divVerm = $divVerm;
39
        $this->doordnr = $doordnr;
40
        $this->preordnr = $preordnr;
41
        $this->docustnr = $docustnr;
42
        $this->precustnr = $precustnr;
43
        $this->INVnetto = ($INVnetto == 1)?true:false;
44
        $this->ERPincl = ($ERPincl == 1)?true:false;
45
        $this->OEinsPart = ($OEinsPart == 1)?true:false;
46
        $this->lager = ($lager)?$lager:1;
47
        $this->getTax();
48
        if ( $lager > 1 ) {
49
            $sql  = "SELECT warehouse_id from bin where id = ".$this->lager;
50
            $rs = $this->db->getOne($sql);
51
            if ( $rs['warehouse_id'] > 0 ) {
52
		        $this->warehouse_id = $rs['warehouse_id'];
53
                $sql = "SELECT id from transfer_type WHERE direction = 'in' and description = 'stock'";
54
                $rs = $this->db->getOne($sql);
55
                $this->transtype = $rs['id'];
56
            } else {
57
                $this->lager = 1;
58
            }
59
        }
60
    }
61

  
62
    function getTax() {
63
        $sql  = "SELECT  BG.id AS bugru,T.rate,TK.startdate,C.taxkey_id, ";
64
        $sql .= "(SELECT id FROM chart WHERE accno = T.taxnumber) AS tax_id, ";
65
        $sql .= "BG.income_accno_id_0,BG.expense_accno_id_0 ";
66
        $sql .= "FROM buchungsgruppen BG LEFT JOIN chart C ON BG.income_accno_id_0=C.id ";
67
        $sql .= "LEFT JOIN taxkeys TK ON TK.chart_id=C.id ";
68
        $sql .= "LEFT JOIN tax T ON T.id=TK.tax_id WHERE TK.startdate <= now()";
69
        $rs = $this->db->getAll($sql);
70
        if ($rs) foreach ($rs as $row) {
71
            $nr = $row['bugru'];
72
            if (!$this->TAX[$nr]) {
73
                $data = array();
74
                $data['startdate'] =     $row['startdate'];
75
                $data['rate'] =     $row['rate'];
76
                $data['taxkey'] =     $row['taxkey_id'];
77
                $data['taxid'] =     $row['tax_id'];
78
                $data['income'] =     $row['income_accno_id_0'];
79
                $data['expense'] =     $row['expense_accno_id_0'];
80
                $this->TAX[$nr] = $data;
81
            } else if ($this->TAX[$nr]['startdate'] < $row['startdate']) {
82
                $this->TAX[$nr]["startdate"] =     $row['startdate'];
83
                $this->TAX[$nr]["rate"] =     $row['rate'];
84
                $this->TAX[$nr]["taxkey"] =     $row['taxkey_id'];
85
                $this->TAX[$nr]["taxid"] =     $row['tax_id'];
86
                $this->TAX[$nr]["income"] =     $row['income_accno_id_0'];
87
                $this->TAX[$nr]["expense"] =     $row['expense_accno_id_0'];
88
            }
89
        }
90
    }
91

  
92
    function getParts($stdprice=0,$shop=0) {
93
        $where = "WHERE 1=1 ";
94
        if ($stdprice>0) {
95
             $sql  = "SELECT P.partnumber,P.description,P.notes,P.weight,G.price as sellprice,P.sellprice as stdprice,";
96
             $sql .= "PG.partsgroup,P.image,P.buchungsgruppen_id as bugru,P.unit,P.ean ";
97
             if ($this->lager>1) {
98
                   $sql .= ",(select sum(qty) from inventory where bin_id = ".$this->lager." and parts_id = P.id) as onhand ";
99
             } else {
100
                   $sql .= ",P.onhand ";
101
             }
102
             $sql .= "FROM parts P ";
103
             $sql .= "LEFT JOIN partsgroup PG on PG.id=P.partsgroup_id ";
104
             $sql .= "LEFT JOIN prices G on G.parts_id=P.id ";
105
             $where .= "AND (G.pricegroup_id=$stdprice ";
106
             $where .= "or G.pricegroup_id is null) ";
107
        } else {
108
             $sql  = "SELECT P.partnumber,P.description,P.notes,P.weight,P.sellprice,";
109
             $sql .= "PG.partsgroup,P.image,P.buchungsgruppen_id as bugru,P.unit,P.ean ";
110
             if ($this->lager>1) {
111
                   $sql .= ",(select sum(qty) from inventory where bin_id = ".$this->lager." and parts_id = P.id) as onhand ";
112
             } else {
113
                   $sql .= ",P.onhand ";
114
             }
115
             $sql .= "FROM parts P left join partsgroup PG on PG.id=P.partsgroup_id ";
116
        }
117
        if ($shop>0) {  
118
            $sql .= "LEFT JOIN custom_variables CV on CV.trans_id=P.id ";
119
            $where .= "AND (CV.config_id = $shop AND bool_value = 't')";
120
        }
121
        $where .= "AND shop = 't' ";
122
        $where .= "AND obsolete = 'f' ORDER BY P.partnumber";
123
        $rs = $this->db->getAll($sql.$where);
124
        if ($rs) for($i = 0; $i < count($rs); $i++) {
125
           $rs[$i]['tax'] = $this->TAX[$rs[$i]['bugru']]['rate'];
126
        }
127
        return $rs;
128
    }
129

  
130
    function getPartsLang($lang,$alle) {
131
        $sql  = "SELECT P.partnumber,L.translation,P.description,L.longdescription,P.notes,PG.partsgroup ";
132
        $sql .= "FROM parts P left join translation L on L.parts_id=P.id left join partsgroup PG on PG.id=P.partsgroup_id ";
133
        $sql .= "WHERE P.shop='t' and (L.language_id = $lang";
134
        if ($alle) {
135
            $sql .= " or L.language_id is Null)";
136
        } else { 
137
            $sql.=")"; 
138
        };
139
        $rs = $this->getAll($sql);
140
        $data=array();
141
        if ($rs) foreach ($rs as $row) {
142
            if (!$data[$row["partnumber"]]) $data[$row["partnumber"]]=$row;
143
        }
144
        return $data;
145
    }
146
    function getNewNr($typ) {
147
        /*
148
          so = Auftragsnummer
149
          customer = Kundennummer 
150
        */
151
        $typ .= "number";
152
        $sql = "SELECT $typ FROM defaults";
153
        $rs = $this->db->getOne($sql);
154
        $i=strlen($rs["$typ"])-1;
155
        //Nummern können Buchstaben, Zeichen und Zahlen enthalten
156
        //nur die Zahlen von rechts werden aber inkrementiert.
157
        while($i>=0) {
158
            if ($rs["$typ"][$i] >= "0" and $rs["$typ"][$i]<="9") {
159
                $n=$rs["$typ"][$i].$n;
160
                $i--;
161
            } else {
162
                $pre = substr($rs["$typ"],0,$i+1);
163
                $i=-1;
164
            }
165
        };
166
        $nr = (int)$n + 1;
167
        $sonr = $pre.$nr;
168
        $sql = "UPDATE defaults SET $typ = '$sonr'";
169
        $rc = $this->db->query($sql);
170
        if (!$rc) {
171
            $this->error->write('erplib','Neue Nummer ($typ) nicht gesichert: '.$sonr);
172
        }
173
        return $sonr;
174
    }
175
    function newOrder($data) {
176
        /*Einen neuen Auftrag anlegen. Folgendes Array muß übergeben werden:
177
        $data = array(ordnumber,customer_id,employee_id,taxzone_id,amount,netamount,transdate,notes,intnotes,shipvia)
178
        Rückgabe oe.id */
179
        $this->db->begin();
180
        $incltax = ($this->INVnetto)?'f':'t';
181
        $sql  = "INSERT INTO oe (ordnumber,customer_id,employee_id,taxzone_id,taxincluded,curr,amount,netamount,transdate,notes,intnotes,shipvia,cusordnumber) ";
182
        $sql .= "values (:ordnumber,:customer_id,:employee_id,:taxzone_id,'$incltax',:curr,:amount,:netamount,:transdate,:notes,:intnotes,:shipvia,:cusordnumber)";
183
        $rc = $this->db->insert($sql,$data);
184
        $sql = "SELECT * FROM oe where ordnumber = '".$data["ordnumber"]."'";
185
        $rs = $this->db->getOne($sql);
186
        if (!$rs['id']) {
187
            $this->error->write('erplib','Auftrag erzeugen: '.$data["ordnumber"]);
188
            $this->db->rollback();
189
            return false;
190
        } else {
191
            $this->error->out(" Auftrag: ".$data["ordnumber"]." ");
192
            return $rs['id'];
193
        }
194
    }
195
    function insParts($trans_id,$data,$longtxt) {
196
        /*Artikel in die orderitem einfügen. Folgende Daten müssen übergeben werden:
197
        $trans_id = (int) oe.id
198
        $data = array(trans_id,partnumber,description,longdescription,qty,sellprice,unit)*/
199
        foreach ($data as $row) {
200
             $row['trans_id'] = $trans_id;
201
             //$sql = "SELECT id FROM parts WHERE partnumber = '".$row['partnumber']."'";
202
             //$tmp = $this->db->getOne($sql);
203
             $tmp = $this->chkPartnumber($row,$this->OEinsPart,true,true);
204
             if ($tmp) {
205
                 $row['parts_id'] = $tmp['id'];
206
             } else {
207
                 if ($this->TAX[$this->divStd['BUGRU']]['rate'] == $row['mwst']/100) {
208
                      $row['parts_id'] = $this->divStd['ID'];
209
                 } else if ($this->TAX[$this->divVerm['BUGRU']]['rate'] == $row['mwst']/100) {
210
                      $row['parts_id'] = $this->divVerm['ID'];
211
                 } else {
212
                      $row['parts_id'] = $this->divStd['ID'];
213
                 }
214
             }
215
             //Shop soll immer Nettopreise liefern!
216
             if (!$this->INVnetto) {
217
                     $row['sellprice'] = round($row['sellprice'] * (100 + $row['taxrate']) / 100,2);
218
             }
219
             $row['unit'] = $this->chkUnit($row['unit']);
220
             if ($longtxt == 1) {
221
                 //$row['longdescription'] = addslashes($row['longdescription']);
222
                 $row['longdescription'] = $row['longdescription'];
223
             } else {
224
                 //$row['longdescription'] = addslashes($tmp['longdescription']);
225
                 $row['longdescription'] = $tmp['longdescription'];
226
             }
227
             //$row['description'] = addslashes($row['description']);
228
             $sql  = "INSERT INTO orderitems (trans_id,parts_id,description,longdescription,qty,sellprice,unit,pricegroup_id,discount) ";
229
             $sql .= "VALUES (:trans_id,:parts_id,:description,:longdescription,:qty,:sellprice,:unit,0,0)";
230
             $row["trans_id"]=$trans_id;
231
             $rc = $this->db->insert($sql,$row);
232
             if (!$rc) {
233
                 $this->db->rollback();
234
                 return false;
235
             };
236
        };
237
        $this->db->commit();
238
        return true;
239
    }
240
    function insCustomer($data) {
241
        $this->error->out('Insert:'.$data["name"].' ');
242
        if ($this->docustnr == 1) {
243
            $data['customernumber'] = $this->getNewNr('customer');
244
        } else {
245
            $data['customernumber'] = $data['shopid'];
246
        }
247
        $data['customernumber'] = $this->precustnr.$data['customernumber'];
248
            if ($data['customernumber']>0) {
249
                if (!$data['greeting']) $data['greeting'] = '';
250
                $sql  = "INSERT INTO customer (greeting,name,street,city,zipcode,country,contact,phone,email,customernumber)";
251
                $sql .= " VALUES (:greeting,:name,:street,:city,:zipcode,:country,:contact,:phone,:email,:customernumber)";
252
                $rc =  $this->db->insert($sql,$data);
253
                $sql = "SELECT id FROM customer WHERE customernumber = '".$data['customernumber']."'";
254
                $rs = $this->db->getOne($sql);
255
                $rc = $rs['id'];
256
                $this->error->out("Kd-Nr: ".$data['customernumber'].":".$rs['id']);
257
            } else {
258
                $this->error->write('erplib','Kunde anlegen: '.$data["name"]);
259
                $this->db->rollback();
260
                return false;
261
            }
262
            return $rc;
263
    }
264
    function chkCustomer($data) {
265
        if ($data['customer_id']>0) {
266
            $sql = "SELECT * FROM customer WHERE id = ".$data['customer_id'];
267
            $rs = $this->db->getOne($sql);
268
            if ($rs['id'] == $data['customer_id']) {
269
                 $this->error->out('Update:'.$data['customer_id'].' ');
270
                 $sql  = "UPDATE customer SET greeting = :greeting,name = :name,street = :street,city = :city,country = :country,";
271
                 $sql .= "zipcode = :zipcode,contact = :contact,phone = :phone,email = :email WHERE id = :customer_id";
272
                 $rc =  $this->db->update($sql,$data);
273
                 if ($rc) $rc = $data['customer_id'];
274
            } else {
275
                $rc = $this->insCustomer($data);
276
            }
277
        } else {
278
            $rc = $this->insCustomer($data);
279
        }
280
        return $rc;
281
    }
282
    function mkAuftrag($data,$shop,$longtxt) {
283
        $this->db->Begin();
284
        $data["notes"] .= "\nBezahlung:".$data['bezahlung']."\n";
285
        if ($data['bezahlung'] == "Kreditkarte")   $data["notes"] .= $data['kreditkarte']."\n"; 
286
        if ($shop) { 
287
           $data["intnotes"] = "Shop: $shop";
288
        } else {
289
           $data["intnotes"] = "";
290
        };
291
        $data["customer_id"] = $this->chkCustomer($data["customer"]);
292
        $parts = $data['parts'];
293
        unset($data['parts']);
294
        unset($data['customer']);
295
        if ($this->doordnr == 1) {
296
            $data["ordnumber"] = $this->getNewNr('so');
297
        } else {
298
            $data["ordnumber"] = $data['cusordnumber'];
299
        }
300
        $data["ordnumber"] = $this->preordnr.$data["ordnumber"];
301
        $tid = $this->newOrder($data);
302
        if ($tid) {
303
            $rc = $this->insParts($tid,$parts,$longtxt);  
304
            if (!$rc) {
305
                 $this->error->write('erplib','Artikel zu Auftrag');
306
                 return -1;
307
            }
308
        } else {
309
            $this->error->write('erplib','Auftrag anlegen');
310
            return -1;
311
        }
312
        $this->error->out($data["customer"]["firma"]." ".$data["shopid"]);
313
        $rc = $this->db->Commit();
314
        return $data["customer_id"];
315
    }
316
    function chkPartsgroup($pg,$new=True) {
317
       /*gibt es die Warengruppe?
318
       Rückgabe nichts oder die partsgroup.id
319
       ggf neu anlegen*/
320
       $sql = "SELECT * FROM partsgroup WHERE partsgroup = '".$pg."'";
321
       $rs = $this->db->getOne($sql);
322
       if ($rs) {
323
           return $rs['id'];
324
       } else if ($this->mkPart and $new) {
325
           return $this->mkNewPartsgroup($pg);
326
       } else {
327
           return '';
328
       };
329
    }
330
    function mkNewPartsgroup($name) {
331
       $sql = "INSERT INTO partsgroup (partsgroup) VALUES ('".$name."')";
332
       $rc = $this->db->query($sql);
333
       if ($rc) {
334
           return $this->chkPartsgroup($name,False);
335
       } else {
336
           return '';
337
       }
338
    }
339
    function chkUnit($unit) {
340
       /*Prüfen ob es die Unit gibt.
341
         wenn nicht, die Standardunit zurückgeben*/
342
       if ($unit == '') {
343
           return $this->stdUnit();
344
       } else {
345
           $sql = "SELECT * FROM units WHERE name ilike '".$unit."'";
346
           $rs = $this->db->getOne($sql);
347
           if ($rs) {
348
              return $rs["name"];
349
           } else {
350
               return $this->stdUnit();
351
           }
352
       }
353
    }
354
    function stdUnit() {
355
       $sql = "SELECT * FROM units WHERE type = 'dimension' ORDER BY sortkey LIMIT 1";
356
       $rs = $this->db->getOne($sql);
357
       return $rs["name"];
358
    }
359
    function chkPartnumber($data,$new=True,$long=false,$bestellung=false) {
360
       $sql = "SELECT * FROM parts WHERE partnumber = '".$data["partnumber"]."'";
361
       $rs = $this->db->getOne($sql);
362
       if ($rs) {
363
           if ($long) {
364
               return $rs;
365
           } else {
366
               return $rs['id'];
367
           }
368
       } else if ($new and $this->mkPart) {
369
           $data['id'] = $this->mkNewPart($data,$bestellung);
370
           if ($long) {
371
               return $data;
372
           } else {
373
               return $data['id'];
374
           }
375
       } else {
376
           return '';
377
       };
... Dieser Diff wurde abgeschnitten, weil er die maximale Anzahl anzuzeigender Zeilen überschreitet.

Auch abrufbar als: Unified diff