Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 7e28f16e

Von Holger Lindemann vor mehr als 12 Jahren hinzugefügt

  • ID 7e28f16efbb81644815ef06396b1d5c89c8bb5ec
  • Vorgänger b81f2b8f
  • Nachfolger 2d16e7a2

Diverse Verbesserungen u.a. Debugging

Unterschiede anzeigen:

peppershop/ArtikelErpToShop.php
1 1
<?php
2

  
3
$debug = False;
4

  
2 5
$api = php_sapi_name();
3 6
if ( $api != "cli" ) {
4 7
    echo "<html>\n<head>\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n</head>\n<body>\n";
......
21 24

  
22 25
include_once("conf$shopnr.php");
23 26
include_once("error.php");
27
//Fehlerinstanz
28
$err = new error($api);
29

  
24 30
include_once("dblib.php");
25 31
include_once("pepper.php");
26 32
include_once("erplib.php");
27 33
include_once("Picture.php");
28 34

  
29
//Fehlerinstanz
30
$err = new error($api);
31 35

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

  
36 40
//ERP-Instanz
37
$erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err);
41
$erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err,$debug);
38 42
if ($erpdb->db->connected_database_name == $ERPdbname) {
39
    $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstS,$OEinsPart,$lager);
43
    $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstS,$OEinsPart,$lager,$pricegroup,$ERPusrID);
40 44
} else {
41 45
    $err->out('Keine Verbindung zur ERP',true);
42 46
    exit();
peppershop/ArtikelShopToErp.php
1 1
<?php
2

  
3
$debug = False;
4

  
2 5
$api = php_sapi_name();
3 6
if ( $api != "cli" ) {
4 7
    echo "<html>\n<head>\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n</head>\n<body>\n";
......
21 24

  
22 25
include_once("conf$shopnr.php");
23 26
include_once("error.php");
27
//Fehlerinstanz
28
$err = new error($api);
29

  
24 30
include_once("dblib.php");
25 31
include_once("pepper.php");
26 32
include_once("erplib.php");
27 33

  
28
//Fehlerinstanz
29
$err = new error($api);
30 34

  
31 35

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

  
41 45
//Shop-Instanz
42
$shopdb = new mydb($SHOPhost,$SHOPdbname,$SHOPuser,$SHOPpass,$SHOPport,'mysql',$err);
46
$shopdb = new mydb($SHOPhost,$SHOPdbname,$SHOPuser,$SHOPpass,$SHOPport,'mysql',$err,$debug);
43 47
if ($shopdb->db->connected_database_name == $SHOPdbname) {
44 48
     $shop = new pepper($shopdb,$err,$SHOPdbname,$divStd,$divVerm,$minder,$nachn,$versandS,$versandV,$paypal,$treuhand,$mwstLX,$mwstS,$variantnr);
45 49
} else {
peppershop/BestellungShopToErp.php
1 1
<?php
2

  
3
$debug = False;
4

  
2 5
$api = php_sapi_name();
3 6
if ( $api != "cli" ) {
4 7
    echo "<html>\n<head>\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n</head>\n<body>\n";
......
21 24

  
22 25
include_once("conf$shopnr.php");
23 26
include_once("error.php");
27
//Fehlerinstanz
28
$err = new error();
29

  
24 30
include_once("dblib.php");
25 31
include_once("pepper.php");
26 32
include_once("erplib.php");
27
//Fehlerinstanz
28
$err = new error();
29 33

  
30 34
$err->out("Shop $shopnr, Bestellimport",true);
31 35

  
32 36
//ERP-Instanz
33
$erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err);
37
$erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err,$debug);
34 38
if ($erpdb->db->connected_database_name == $ERPdbname) {
35
    $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstS,$OEinsPart,$lager);
39
    $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstS,$OEinsPart,$lager,$pricegroup,$ERPusrID);
36 40
} else {
37 41
    $err->out('Keine Verbindung zur ERP',true);
38 42
    exit();
peppershop/dblib.php
8 8
   var $error = false;
9 9
   var $debug = true;
10 10
   var $dbf = false;
11
   var $database = false;
11 12

  
12
   function mydb($host,$db,$user,$pass,$port,$proto,$error) {
13
   function mydb($host,$db,$user,$pass,$port,$proto,$error,$debug) {
13 14
       $this->error = $error;
14 15
       $dsn = array('phptype'  => $proto,
15 16
               'username' => $user,
......
17 18
               'hostspec' => $host,
18 19
               'database' => $db,
19 20
               'port'     => $port);
20
       if ( $this->debug ) {
21
            $this->dbf = fopen ("tmp/shop.log","w");
22
            if ( !$this->dbf ) $this->debug = false;
23
       }
21
       $this->debug = $debug;
22
       $this->database = "-< $db >-";
24 23
       $this->connect($dsn);
25 24
    }
26 25

  
27
    function log($txt) {
28
       $now = date('Y-m-d H:i:s');
29
       fputs($this->dbf,$now." : ".$txt."\n");
30
    }
31 26
    function connect($dsn) {
32 27
       $options = array('result_buffering' => false,);
33 28
       $this->db = MDB2::connect($dsn,$options);
34
       if ( $this->debug ) $this->log('Connect:');
29
       if ( $this->debug ) $this->error->write('dblib->connect '.$this->database,'Connect:');
35 30
       if (PEAR::isError($this->db)) {
36
           if ( $this->debug ) $this->log($this->db->getMessage());
37
           $this->error->write('dblib->connect',$this->db->getMessage());
38
           $this->error->write('dblib->connect',print_r($dsn,true));
31
           $this->error->write('dblib->connect '.$this->database,$this->db->getMessage());
32
           $this->error->write('dblib->connect '.$this->database,print_r($dsn,true));
39 33
           $this->db = false;
40 34
           return false;
41 35
       }
......
53 47

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

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

  
29
    function erp($db,$error,$divStd,$divVerm,$doordnr,$docustnr,$preordnr,$precustnr,$INVnetto,$SHOPincl,$OEinsPart,$lager) {
32
    function erp($db,$error,$divStd,$divVerm,$doordnr,$docustnr,$preordnr,$precustnr,$INVnetto,$SHOPincl,$OEinsPart,$lager,$pricegroup,$ERPusrID) {
30 33
        $this->db = $db;
34
        $this->pricegroup = $pricegroup;
35
        $this->employee_id = $ERPusrID;
31 36
        $this->error = $error;
32 37
        $this->divStd  = $divStd;
33 38
        $this->divVerm = $divVerm;
......
40 45
        $this->OEinsPart = ($OEinsPart == 1)?true:false;
41 46
        $this->lager = ($lager)?$lager:1;
42 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
        }
43 60
    }
44 61

  
45 62
    function getTax() {
......
369 386
       $data = array(partnumber,description,longdescription,weight,sellprice,taxrate,partsgroup,unit)
370 387
       Rückgabe parts.id
371 388
       */
389
       $link = '<a href="../ic.pl?action=edit&id=%d" target="_blank">';
372 390
       if ($data['partnumber'] == '') {
373 391
           $this->error->write('erplib','Artikelnummer fehlt');
374 392
           return false;
......
408 426
       $sql .= "VALUES (:partnumber,:description,:sellprice,:weight,:notes,:shop,:unit,:partsgroup_id,";
409 427
       $sql .= ":image,:buchungsgruppen_id,1,1,1)";
410 428
       $rc = $this->db->insert($sql,$data);
429
       $data['parts_id'] = $this->chkPartnumber($data,false);
430
       if ( $this->pricegroup > 0 ) {
431
            $sql  = "INSERT INTO prices (parts_id,pricegroup_id,price) VALUES (:parts_id,:pricegroup,:shoppreis)";
432
            $data['pricegroup'] = $this->pricegroup;
433
            $rc = $this->db->insert($sql,$data);
434
       };
435
       if ( $data['onhand'] > 0 and $this->lager > 1) $this->insLager($data);
411 436
       $x =  $this->chkPartnumber($data,False);
412
       $this->error->out('Neuer Artikel: '.$data['partnumber'],true);
413
       $this->error->write('erplib','Artikel neu: '.$data['partnumber']);
437
       $this->error->write('erplib',$data['description'].' '.$data['partnumber']);
438
       $this->error->out(sprintf($link,$data['parts_id']).$data['description'].' '.$data['partnumber'].'</a>',true);
414 439
       return $x;
415 440
    }
441
    function insLager($data) {
442
        $rc = $this->db->Begin();
443
        $sql = "SELECT nextval(('id'::text)::regclass) as id from id";
444
        $rs = $this->db->getOne($sql);
445
        $sql  = "INSERT INTO inventory (warehouse_id,parts_id,shippingdate,employee_id,bin_id,qty,trans_id,trans_type_id,comment) ";
446
        $sql .= "VALUES (:wid,:parts_id,now(),:employee_id,:bid,:onhand,:next,:tt,'Shopübernahme')";
447
        $data['next'] = $rs['id'];
448
        $data['tt'] = $this->transtype;
449
        $data['bid'] = $this->lager;
450
        $data['wid'] = $this->warehouse_id;
451
        $data['employee_id'] = $this->employee_id;
452
        $rc = $this->db->insert($sql,$data);
453
        if ( $rc ) {
454
           $this->db->Commit();
455
        } else {
456
           $this->db->Rollback();
457
        }
458
    }
416 459
}
417 460
?>
peppershop/pepper.php
35 35
                            "waehrung"=>"currency","beschreibung"=>"notes",
36 36
                            "mwst"=>"mwst","versandart"=>"shipvia");
37 37
    var $orderparts = array("artikelname"=>"description","name"=>"description","preis"=>"sellprice","anzahl"=>"qty","artikel_nr"=>"partnumber",
38
                            "partsgroup"=>"partsgroup","beschreibung"=>"longdescription","gewicht"=>"weight",
39
                            "mwst_satz"=>"taxrate","bild_gross"=>"image","anzahl_einheit"=>"unit");
38
                            "partsgroup"=>"partsgroup","beschreibung"=>"longdescription","gewicht"=>"weight","shoppreis"=>"shoppreis",
39
                            "mwst_satz"=>"taxrate","bild_gross"=>"image","anzahl_einheit"=>"unit","lagerbestand"=>"onhand");
40 40
    var $pic = false;
41 41

  
42 42
    function pepper($db,$error,$dbname,
......
418 418
            $row['partsgroup'] = $this->_toERP($this->Kategorien[$row['katid']]);
419 419
            $row['name'] = $this->_toERP($row['name']);
420 420
            $row['beschreibung'] = $this->_toERP($row['beschreibung']);
421
            $row['shoppreis'] = $row['preis'];
421 422
            if (!$this->mwstLX) $row['preis'] = round(($row['preis'] / (100 + $row['mwst_satz']) * 100),$this->dezimal);
422 423
            $data[] = $this->translateTable($row,"orderparts");
423 424
        }

Auch abrufbar als: Unified diff