Diverse Verbesserungen u.a. Debugging
authorHolger Lindemann <hli@lenny.hoch.ul>
Wed, 11 Apr 2012 09:53:04 +0000 (11:53 +0200)
committerHolger Lindemann <hli@lenny.hoch.ul>
Wed, 11 Apr 2012 09:53:04 +0000 (11:53 +0200)
peppershop/ArtikelErpToShop.php
peppershop/ArtikelShopToErp.php
peppershop/BestellungShopToErp.php
peppershop/dblib.php
peppershop/erplib.php
peppershop/pepper.php

index c8cf075..ff8a56a 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+$debug = False;
+
 $api = php_sapi_name();
 if ( $api != "cli" ) {
     echo "<html>\n<head>\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n</head>\n<body>\n";
@@ -21,22 +24,23 @@ if ( $api != "cli" ) {
 
 include_once("conf$shopnr.php");
 include_once("error.php");
+//Fehlerinstanz
+$err = new error($api);
+
 include_once("dblib.php");
 include_once("pepper.php");
 include_once("erplib.php");
 include_once("Picture.php");
 
-//Fehlerinstanz
-$err = new error($api);
 
 //Bilder
 $pict = new picture($ERPftphost,$ERPftpuser,$ERPftppwd,$ERPimgdir,$SHOPftphost,$SHOPftpuser,$SHOPftppwd,$SHOPimgdir,$err);
 //$pict->original = false;
 
 //ERP-Instanz
-$erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err);
+$erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err,$debug);
 if ($erpdb->db->connected_database_name == $ERPdbname) {
-    $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstS,$OEinsPart,$lager);
+    $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstS,$OEinsPart,$lager,$pricegroup,$ERPusrID);
 } else {
     $err->out('Keine Verbindung zur ERP',true);
     exit();
index c8e1dd2..d7b4d1e 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+$debug = False;
+
 $api = php_sapi_name();
 if ( $api != "cli" ) {
     echo "<html>\n<head>\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n</head>\n<body>\n";
@@ -21,25 +24,26 @@ if ( $api != "cli" ) {
 
 include_once("conf$shopnr.php");
 include_once("error.php");
+//Fehlerinstanz
+$err = new error($api);
+
 include_once("dblib.php");
 include_once("pepper.php");
 include_once("erplib.php");
 
-//Fehlerinstanz
-$err = new error($api);
 
 
 //ERP-Instanz
-$erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err);
+$erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err,$debug);
 if ($erpdb->db->connected_database_name == $ERPdbname) {
-    $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstS,$OEinsPart,$lager);
+    $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstS,$OEinsPart,$lager,$pricegroup,$ERPusrID);
 } else {
     $err->out('Keine Verbindung zur ERP',true);
     exit();
 }
 
 //Shop-Instanz
-$shopdb = new mydb($SHOPhost,$SHOPdbname,$SHOPuser,$SHOPpass,$SHOPport,'mysql',$err);
+$shopdb = new mydb($SHOPhost,$SHOPdbname,$SHOPuser,$SHOPpass,$SHOPport,'mysql',$err,$debug);
 if ($shopdb->db->connected_database_name == $SHOPdbname) {
      $shop = new pepper($shopdb,$err,$SHOPdbname,$divStd,$divVerm,$minder,$nachn,$versandS,$versandV,$paypal,$treuhand,$mwstLX,$mwstS,$variantnr);
 } else {
index 4d59667..b0e1d74 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+$debug = False;
+
 $api = php_sapi_name();
 if ( $api != "cli" ) {
     echo "<html>\n<head>\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n</head>\n<body>\n";
@@ -21,18 +24,19 @@ if ( $api != "cli" ) {
 
 include_once("conf$shopnr.php");
 include_once("error.php");
+//Fehlerinstanz
+$err = new error();
+
 include_once("dblib.php");
 include_once("pepper.php");
 include_once("erplib.php");
-//Fehlerinstanz
-$err = new error();
 
 $err->out("Shop $shopnr, Bestellimport",true);
 
 //ERP-Instanz
-$erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err);
+$erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err,$debug);
 if ($erpdb->db->connected_database_name == $ERPdbname) {
-    $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstS,$OEinsPart,$lager);
+    $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstS,$OEinsPart,$lager,$pricegroup,$ERPusrID);
 } else {
     $err->out('Keine Verbindung zur ERP',true);
     exit();
index 6420749..c0797b6 100644 (file)
@@ -8,8 +8,9 @@ class mydb {
    var $error = false;
    var $debug = true;
    var $dbf = false;
+   var $database = false;
 
-   function mydb($host,$db,$user,$pass,$port,$proto,$error) {
+   function mydb($host,$db,$user,$pass,$port,$proto,$error,$debug) {
        $this->error = $error;
        $dsn = array('phptype'  => $proto,
                'username' => $user,
@@ -17,25 +18,18 @@ class mydb {
                'hostspec' => $host,
                'database' => $db,
                'port'     => $port);
-       if ( $this->debug ) {
-            $this->dbf = fopen ("tmp/shop.log","w");
-            if ( !$this->dbf ) $this->debug = false;
-       }
+       $this->debug = $debug;
+       $this->database = "-< $db >-";
        $this->connect($dsn);
     }
 
-    function log($txt) {
-       $now = date('Y-m-d H:i:s');
-       fputs($this->dbf,$now." : ".$txt."\n");
-    }
     function connect($dsn) {
        $options = array('result_buffering' => false,);
        $this->db = MDB2::connect($dsn,$options);
-       if ( $this->debug ) $this->log('Connect:');
+       if ( $this->debug ) $this->error->write('dblib->connect '.$this->database,'Connect:');
        if (PEAR::isError($this->db)) {
-           if ( $this->debug ) $this->log($this->db->getMessage());
-           $this->error->write('dblib->connect',$this->db->getMessage());
-           $this->error->write('dblib->connect',print_r($dsn,true));
+           $this->error->write('dblib->connect '.$this->database,$this->db->getMessage());
+           $this->error->write('dblib->connect '.$this->database,print_r($dsn,true));
            $this->db = false;
            return false;
        }
@@ -53,10 +47,9 @@ class mydb {
 
     function getAll($sql) {
         $rs = $this->db->queryAll($sql);
-        if ( $this->debug ) $this->log($sql);
+        if ( $this->debug ) $this->error->write('dblib->getAll '.$this->database,$sql);
         if (PEAR::isError($rs)) {
-            if ( $this->debug ) $this->log($rs->getUserinfo());
-            $this->error->write('dblib->getAll',$rs->getUserinfo());
+            $this->error->write('dblib->getAll '.$this->database,$rs->getUserinfo());
             return false;
         }
         return $rs;
@@ -64,38 +57,35 @@ class mydb {
  
     function getOne($sql) {
         $rs = $this->db->queryRow($sql);
-        if ( $this->debug ) $this->log($sql);
+        if ( $this->debug ) $this->error->write('dblib->getOne '.$this->database,$sql);
         if (PEAR::isError($rs)) {
-            if ( $this->debug ) $this->log($rs->getUserinfo());
-            $this->error->write('dblib->getOne',$rs->getUserinfo());
+            $this->error->write('dblib->getOne '.$this->database,$rs->getUserinfo());
             return false;
         }
         return $rs;
     }
     function query($sql) {
         $rc = $this->db->query($sql);
-        if ( $this->debug ) $this->log($sql);
+        if ( $this->debug ) $this->error->write('dblib->query '.$this->database,$sql);
         if (PEAR::isError($rc)) {
-            if ( $this->debug ) $this->log($rc->getUserinfo());
-            $this->error->write('dblib->query',$rc->getUserinfo());
+            $this->error->write('dblib->query '.$this->database,$rc->getUserinfo());
             return false;
         }
         return $rc;
     } 
     function insert($statement,$data) {
-        if ( $this->debug ) $this->log("INSERT ".$statement);
+        if ( $this->debug ) $this->error->write("dblib->insert ".$this->database,$statement);
         $sth = $this->db->prepare($statement);                      //Prepare
         if (PEAR::isError($sth)) {
-            $this->error->write('dblib->insert 1',$sth->getMessage());
+            $this->error->write('dblib->insert 1 '.$this->database,$sth->getMessage());
             $this->error->write('dblib->insert 2',$sth->getUserinfo());
             $this->rollback();
             return false;
         }
-        if ( $this->debug ) $this->log(print_r($data,true));
+        if ( $this->debug ) $this->error->write('dblib->insert',print_r($data,true));
         $rc =& $sth->execute($data);
         if (PEAR::isError($rc)) {
-            if ( $this->debug ) $this->log($rc->getUserinfo());
-            $this->error->write('dblib->insert 3',$rc->getUserinfo());
+            $this->error->write('dblib->insert 3 '.$this->database,$rc->getUserinfo());
             return false;
         }//else{
         //    $rc = $this->commit();
@@ -103,20 +93,18 @@ class mydb {
         return $rc;
     }
     function update($statement,$data) {  
-        if ( $this->debug ) $this->log("UPDATE ".$statement);
+        if ( $this->debug ) $this->error->write("dblib->update ".$this->database,$statement);
         $sth = $this->db->prepare($statement);                      //Prepare
         if (PEAR::isError($sth)) {
-            if ( $this->debug ) $this->log("ERRPOR ".$rc->getUserinfo());
-            $this->error->write('dblib->update 1',$sth->getMessage());
+            $this->error->write('dblib->update 1 '.$this->database,$sth->getMessage());
             $this->error->write('dblib->update 2',$sth->getUserinfo());
             $this->rollback();
             return false;
         }
-        if ( $this->debug ) $this->log(print_r($data,true));
+        if ( $this->debug ) $this->error->write('dblib->insert',print_r($data,true));
         $rc =& $sth->execute($data);
         if (PEAR::isError($rc)) {
-            if ( $this->debug ) $this->log("ERRPOR ".$rc->getUserinfo());
-            $this->error->write('dblib->update 3',$rc->getUserinfo());
+            $this->error->write('dblib->update 3 '.$this->database,$rc->getUserinfo());
             return false;
         }//else{
         //    $rc = $this->commit();
@@ -130,14 +118,14 @@ class mydb {
         }
         $sth = $this->db->prepare($statement);                      //Prepare
         if (PEAR::isError($sth)) {
-            $this->error->write('dblib->insertMultiple',$sth->getMessage());
+            $this->error->write('dblib->insertMultiple '.$this->database,$sth->getMessage());
             $this->rollback();
             return false;
         }
         $rc =& $this->db->beginTransaction();
         $rc =& $this->db->extended->executeMultiple($sth, $data);
         if (PEAR::isError($rc)) {
-            $this->error->write('dblib->insertMultiple',$rc->getUserinfo());
+            $this->error->write('dblib->insertMultiple '.$this->database,$rc->getUserinfo());
             $this->rollback();
             return false;
         }else{
index edbe754..00be5c1 100644 (file)
@@ -13,6 +13,7 @@ class erp {
 
     var $db = false;
     var $error = false;
+    var $pricegroup = 0;
     var $TAX = false;
     var $mkPart = true;
     var $divStd = false;
@@ -20,14 +21,18 @@ class erp {
     var $doordnr = false;
     var $docustnr = false;
     var $lager = 1;
+    var $warehouse_id = 0;
+    var $transtype = 0;
     var $preordnr = '';
     var $precustnr = '';
     var $OEinsPart = false;
     var $INVnetto = true; //Rechnungen mit Nettopreisen
     var $SHOPincl = true; //Shoppreise sind Brutto
 
-    function erp($db,$error,$divStd,$divVerm,$doordnr,$docustnr,$preordnr,$precustnr,$INVnetto,$SHOPincl,$OEinsPart,$lager) {
+    function erp($db,$error,$divStd,$divVerm,$doordnr,$docustnr,$preordnr,$precustnr,$INVnetto,$SHOPincl,$OEinsPart,$lager,$pricegroup,$ERPusrID) {
         $this->db = $db;
+        $this->pricegroup = $pricegroup;
+        $this->employee_id = $ERPusrID;
         $this->error = $error;
         $this->divStd  = $divStd;
         $this->divVerm = $divVerm;
@@ -40,6 +45,18 @@ class erp {
         $this->OEinsPart = ($OEinsPart == 1)?true:false;
         $this->lager = ($lager)?$lager:1;
         $this->getTax();
+        if ( $lager > 1 ) {
+            $sql  = "SELECT warehouse_id from bin where id = ".$this->lager;
+            $rs = $this->db->getOne($sql);
+            if ( $rs['warehouse_id'] > 0 ) {
+               $this->warehouse_id = $rs['warehouse_id'];
+                $sql = "SELECT id from transfer_type WHERE direction = 'in' and description = 'stock'";
+                $rs = $this->db->getOne($sql);
+                $this->transtype = $rs['id'];
+            } else {
+                $this->lager = 1;
+            }
+        }
     }
 
     function getTax() {
@@ -369,6 +386,7 @@ class erp {
        $data = array(partnumber,description,longdescription,weight,sellprice,taxrate,partsgroup,unit)
        Rückgabe parts.id
        */
+       $link = '<a href="../ic.pl?action=edit&id=%d" target="_blank">';
        if ($data['partnumber'] == '') {
            $this->error->write('erplib','Artikelnummer fehlt');
            return false;
@@ -408,10 +426,35 @@ class erp {
        $sql .= "VALUES (:partnumber,:description,:sellprice,:weight,:notes,:shop,:unit,:partsgroup_id,";
        $sql .= ":image,:buchungsgruppen_id,1,1,1)";
        $rc = $this->db->insert($sql,$data);
+       $data['parts_id'] = $this->chkPartnumber($data,false);
+       if ( $this->pricegroup > 0 ) {
+            $sql  = "INSERT INTO prices (parts_id,pricegroup_id,price) VALUES (:parts_id,:pricegroup,:shoppreis)";
+            $data['pricegroup'] = $this->pricegroup;
+            $rc = $this->db->insert($sql,$data);
+       };
+       if ( $data['onhand'] > 0 and $this->lager > 1) $this->insLager($data);
        $x =  $this->chkPartnumber($data,False);
-       $this->error->out('Neuer Artikel: '.$data['partnumber'],true);
-       $this->error->write('erplib','Artikel neu: '.$data['partnumber']);
+       $this->error->write('erplib',$data['description'].' '.$data['partnumber']);
+       $this->error->out(sprintf($link,$data['parts_id']).$data['description'].' '.$data['partnumber'].'</a>',true);
        return $x;
     }
+    function insLager($data) {
+        $rc = $this->db->Begin();
+        $sql = "SELECT nextval(('id'::text)::regclass) as id from id";
+        $rs = $this->db->getOne($sql);
+        $sql  = "INSERT INTO inventory (warehouse_id,parts_id,shippingdate,employee_id,bin_id,qty,trans_id,trans_type_id,comment) ";
+        $sql .= "VALUES (:wid,:parts_id,now(),:employee_id,:bid,:onhand,:next,:tt,'Shopübernahme')";
+        $data['next'] = $rs['id'];
+        $data['tt'] = $this->transtype;
+        $data['bid'] = $this->lager;
+        $data['wid'] = $this->warehouse_id;
+        $data['employee_id'] = $this->employee_id;
+        $rc = $this->db->insert($sql,$data);
+        if ( $rc ) {
+           $this->db->Commit();
+        } else {
+           $this->db->Rollback();
+        }
+    }
 }
 ?>
index c1faf8a..25a9d79 100644 (file)
@@ -35,8 +35,8 @@ class pepper {
                             "waehrung"=>"currency","beschreibung"=>"notes",
                             "mwst"=>"mwst","versandart"=>"shipvia");
     var $orderparts = array("artikelname"=>"description","name"=>"description","preis"=>"sellprice","anzahl"=>"qty","artikel_nr"=>"partnumber",
-                            "partsgroup"=>"partsgroup","beschreibung"=>"longdescription","gewicht"=>"weight",
-                            "mwst_satz"=>"taxrate","bild_gross"=>"image","anzahl_einheit"=>"unit");
+                            "partsgroup"=>"partsgroup","beschreibung"=>"longdescription","gewicht"=>"weight","shoppreis"=>"shoppreis",
+                            "mwst_satz"=>"taxrate","bild_gross"=>"image","anzahl_einheit"=>"unit","lagerbestand"=>"onhand");
     var $pic = false;
 
     function pepper($db,$error,$dbname,
@@ -418,6 +418,7 @@ class pepper {
             $row['partsgroup'] = $this->_toERP($this->Kategorien[$row['katid']]);
             $row['name'] = $this->_toERP($row['name']);
             $row['beschreibung'] = $this->_toERP($row['beschreibung']);
+            $row['shoppreis'] = $row['preis'];
             if (!$this->mwstLX) $row['preis'] = round(($row['preis'] / (100 + $row['mwst_satz']) * 100),$this->dezimal);
             $data[] = $this->translateTable($row,"orderparts");
         }