6 if (file_exists ("conf$login.php")) {
 
   8         require "conf$login.php";
 
  15 $landarray=array("DEUTSCHLAND"=>"D","STEREICH"=>"A","OESTEREICH"=>"A","SCHWEIZ"=>"CH");
 
  16 $EU=2;  //EU ohne UStID, 1 = EU mit UStID
 
  18         'Germany'=>array('code'=>'DE','tax'=>0),                'Austria'=>array('code'=>'AU','tax'=>$EU),                      'Belgium'=>array('code'=>'BE','tax'=>$EU),
 
  19         'Bulgaria'=>array('code'=>'BG','tax'=>$EU),             'Czech Republic'=>array('code'=>'CZ','tax'=>$EU),       'Denmark'=>array('code'=>'DK','tax'=>$EU),
 
  20         'Estonia'=>array('code'=>'EE','tax'=>$EU),              'Spain'=>array('code'=>'ES','tax'=>$EU),                        'Finland'=>array('code'=>'FI','tax'=>$EU),
 
  21         'France'=>array('code'=>'FR','tax'=>$EU),               'United Kingdom'=>array('code'=>'GB','tax'=>$EU),       'Greece'=>array('code'=>'GR','tax'=>$EU),
 
  22         'Hungary'=>array('code'=>'HU','tax'=>$EU),              'Ireland'=>array('code'=>'IE','tax'=>$EU),                      'Italy'=>array('code'=>'IT','tax'=>$EU),
 
  23         'Luxembourg'=>array('code'=>'LU','tax'=>$EU),   'Malta'=>array('code'=>'MT','tax'=>$EU),                        'Netherlands'=>array('code'=>'NL','tax'=>$EU),
 
  24         'Poland'=>array('code'=>'PL','tax'=>$EU),               'Portugal'=>array('code'=>'PT','tax'=>$EU),             'Romania'=>array('code'=>'RO','tax'=>$EU),
 
  25         'Sweden'=>array('code'=>'SE','tax'=>$EU),               'Slovenia'=>array('code'=>'SI','tax'=>$EU),             'Slovakia (Slovak Republic)'=>array('code'=>'SK','tax'=>$EU),
 
  26         'Cyprus'=>array('code'=>'CY','tax'=>$EU),               'Lithuania'=>array('code'=>'LT','tax'=>$EU),            'Latvia'=>array('code'=>'LV','tax'=>$EU));
 
  35 $ERPdns= array('phptype'  => 'pgsql',
 
  36                'username' => $ERPuser,
 
  37                'password' => $ERPpass,
 
  38                'hostspec' => $ERPhost,
 
  39                'database' => $ERPdbname,
 
  42 $SHOPdns=array('phptype'  => 'mysql',
 
  43                'username' => $SHOPuser,
 
  44                'password' => $SHOPpass,
 
  45                'hostspec' => $SHOPhost,
 
  46                'database' => $SHOPdbname,
 
  50 /****************************************************
 
  51 * Debugmeldungen in File schreiben
 
  52 ****************************************************/
 
  53 if ($debug) { $log=fopen("tmp/shop.log","a"); } // zum Debuggen
 
  56 /****************************************************
 
  57 * Shopverbindung aufbauen
 
  58 ****************************************************/
 
  59 $shop=DB::connect($SHOPdns);
 
  60 if (!$shop) shopFehler("",$shop->getDebugInfo());
 
  61 if (DB::isError($shop)) {
 
  62         $nun=date("Y-m-d H:i:s");
 
  63         if ($log) fputs($log,$nun.": Shop-Connect\n");
 
  64         shopFehler("",$shop->getDebugInfo());
 
  65         die ($shop->getDebugInfo());
 
  68 /****************************************************
 
  69 * ERPverbindung aufbauen
 
  70 ****************************************************/
 
  71 $erp=DB::connect($ERPdns);
 
  72 if (!$erp) shopFehler("",$erp->getDebugInfo());
 
  73 if (DB::isError($erp)) {
 
  74         $nun=date("Y-m-d H:i:s");
 
  75         if ($log) fputs($log,$nun.": ERP-Connect\n");
 
  76         shopFehler("",$erp->getDebugInfo());
 
  77         die ($erp->getDebugInfo());
 
  79         $erp->autoCommit(true);
 
  83 /****************************************************
 
  84 * SQL-Befehle absetzen
 
  85 ****************************************************/
 
  86 function query($db,$sql,$function="--") {
 
  87         $nun=date("d.m.y H:i:s");
 
  88         //if ($db<>"shop") { echo "$sql!$db!<br>"; flush(); };
 
  89         if ($GLOBALS["log"]) fputs($GLOBALS["log"],$nun.": ".$function."\n".$sql."\n");
 
  90         $rc=$GLOBALS[$db]->query($sql);
 
  91         if ($GLOBALS["log"]) fputs($GLOBALS["log"],print_r($rc,true)."\n");
 
  95                 if ($GLOBALS["log"]) fputs($GLOBALS["log"],print_r($rs,true)."\n");
 
 100 /****************************************************
 
 102 ****************************************************/
 
 103 function getAll($db,$sql,$function="--") {
 
 104         $nun=date("d.m.y H:i:s");
 
 105         if ($GLOBALS["log"]) fputs($GLOBALS["log"],$nun.": ".$function."\n".$sql."\n");
 
 106         $rs=$GLOBALS[$db]->getAll($sql,DB_FETCHMODE_ASSOC);
 
 107         if ($rs["message"]<>"") {
 
 108                 if ($GLOBALS["log"]) fputs($GLOBALS["log"],print_r($rs,true)."\n");
 
 111                 if ($GLOBALS["log"]) fputs($GLOBALS["log"],print_r($rs,true)."\n");
 
 116 /****************************************************
 
 118 * in: sql,err = string
 
 120 * Fehlermeldungen ausgeben
 
 121 *****************************************************/
 
 122 function shopFehler($sql,$err) {
 
 125                 echo "</td></tr></table><font color='red'>$sql : $err</font><br>";
 
 128 /****************************************************
 
 129 * Nächste Auftragsnummer (ERP) holen
 
 130 ****************************************************/
 
 131 function getNextAnr() {
 
 132         $sql="select * from defaults";
 
 133         $sql1="update defaults set sonumber=";
 
 134         $rs2=getAll("erp",$sql,"getNextAnr");
 
 135         if ($rs2[0]["sonumber"]) {
 
 136                 $auftrag=$rs2[0]["sonumber"]+1;
 
 137                 $rc=query("erp",$sql1.$auftrag,"getNextAnr");
 
 139                         echo "Kann keine Auftragsnummer erzeugen - Abbruch";
 
 148 /****************************************************
 
 149 * Nächste Kundennummer (ERP) holen
 
 150 ****************************************************/
 
 151 function getNextKnr() {
 
 152         $sql="select * from defaults";
 
 153         $sql1="update defaults set customernumber='";
 
 154         $rs2=getAll("erp",$sql,"getNextKnr");
 
 155         if ($rs2[0]["customernumber"]) {
 
 156                 $kdnr=$rs2[0]["customernumber"]+1;
 
 157                 $rc=query("erp",$sql1.$kdnr."'","getNextKnr");
 
 159                         echo "Kann keine Kundennummer erzeugen - Abbruch";
 
 169 $buchungsgruppen=array();
 
 170 $warengruppen=array();
 
 172 function getBugru() {
 
 173         $sql ="select B.id,tax.rate from buchungsgruppen B left join chart on income_accno_id_0=chart.id left join taxkeys T on ";
 
 174         $sql.="T.chart_id=income_accno_id_0 left join tax on tax.id=T.tax_id where T.startdate<=now()";
 
 175         $rs=getAll("erp",$sql,"getBugru");
 
 176         if ($rs) foreach ($rs as $row) {
 
 177                 $steuer=sprintf("%0.2f",$row["rate"]*100);
 
 178                 $GLOBALS["buchungsgruppen"][$steuer]=$row["id"];