X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=lxo-import%2FaddressB.php;h=df0cfc50e7c84939be67271854479dd846ccb68a;hb=b354d72972e377a3007f8f03ad9b719488c4b3bf;hp=a365e142d754dd8ecac9162aa0660f02502bb616;hpb=29c981ee335ebc5c21722a265360665e3af2bb20;p=kivitendo-erp.git
diff --git a/lxo-import/addressB.php b/lxo-import/addressB.php
index a365e142d..df0cfc50e 100644
--- a/lxo-import/addressB.php
+++ b/lxo-import/addressB.php
@@ -69,12 +69,11 @@ if (!$file) ende ("Kein Datenfile");
$trenner=($_POST["trenner"])?$_POST["trenner"]:",";
if ($trenner=="other") {
$trenner=trim($trennzeichen);
- if (substr($trenner,0,1)=="#") if (strlen($trenner)>1) $trenner=chr(substr($trenner,1));
}
+if (substr($trenner,0,1)=="#") if (strlen($trenner)>1) $trenner=chr(substr($trenner,1));
if (!file_exists($dir.$file.".csv")) ende("$file.csv nicht im Ordner oder leer");
-
if (!$db->chkcol($file)) ende("Importspalte kann nicht angelegt werden");
$employee=chkUsr($_SESSION["employee"]);
@@ -114,18 +113,54 @@ $kunde_fld = array_keys($address);
}
}
+function chkBusiness($data,$id=true) {
+global $db;
+ if ($id) {
+ $rs = $db->getAll("select id from business where id =$data");
+ } else {
+ $rs = $db->getAll("select id from business where decription ilike '$data'");
+ }
+ if ($rs[0]["id"]) {
+ return $rs[0]["id"];
+ } else {
+ return "null";
+ }
+}
+
+function chkSalesman($data,$id=true) {
+global $db;
+ if ($id) {
+ $rs = $db->getAll("select id from employee where id =$data");
+ } else {
+ $rs = $db->getAll("select id from employee where login ilike '$data'");
+ }
+ if ($rs[0]["id"]) {
+ return $rs[0]["id"];
+ } else {
+ return "null";
+ }
+}
+
$f=fopen($dir.$file.".csv","r");
$zeile=fgets($f,1200);
-$infld=split($trenner,strtolower($zeile));
+$infld=explode($trenner,strtolower($zeile));
$first=true;
$ok=true;
+$p=0;
foreach ($infld as $fld) {
$fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>""))));
- if ($fld=="branche" && !$crm) { $in_fld[]=""; continue; };
- if ($fld=="sw" && !$crm) { $in_fld[]=""; continue; };
- $in_fld[]=$fld;
+ if (in_array($fld,$kunde_fld)) {
+ if ($fld=="branche" && !$crm) { continue; };
+ if ($fld=="sw" && !$crm) { continue; };
+ $in_fld[$fld]=$p;
+ //$fldpos[$fld]=$p;
+ //$in_fld[]=$fld;
+ }
+ $p++;
}
-
+$infld = array_keys($in_fld);
+$infld[] = "import";
+$infld = implode(",",$infld);
$j=0;
$m=0;
$zeile=fgetcsv($f,1200,$trenner);
@@ -135,16 +170,75 @@ if ($ok) while (!feof($f)){
$anrede="";
$Matchcode="";
$sql="insert into $file ";
- $keys="(";
- $vals=" values (";
+ $keys=array();
+ $vals=array();
$number=false;
- foreach($zeile as $data) {
- if (!in_array(trim($in_fld[$i]),$kunde_fld)) {
- if ($in_fld[$i]=="anrede") { $anrede=addslashes(trim($data)); }
- $i++;
- continue;
- };
- $data=trim($data);
+ //foreach($zeile as $data) {
+
+ foreach($in_fld as $fld => $pos) {
+ switch ($fld) {
+ case "name" :
+ case "department_1" :
+ case "department_2" :
+ case "matchcode" :
+ case "street" :
+ case "city" :
+ case "notes" :
+ case "sw" :
+ case "branche" :
+ case "country" :
+ case "contact" :
+ case "homepage" :
+ case "email" :
+ case "bank" : $data = addslashes(trim($zeile[$pos]));
+ if (Translate) translate($data);
+ case "ustid" : $data = strtr(trim($zeile[$pos])," ","");
+ case "bank_code" : $data = trim($zeile[$pos]);
+ case "account_number":
+ case "greeting" :
+ case "taxnumber" :
+ case "zipcode" :
+ case "phone" :
+ case "fax" : $data = trim($zeile[$pos]);
+ $data = "'$data'";
+ if ($data=="''") {
+ $vals[] = "null";
+ } else {
+ $vals[] = $data;
+ }
+ break;
+ case "business_id" : $vals[] = chkBusiness(trim($zeile[$pos]));
+ break;
+ case "salesman_id" : $vals[] = chkSalesman(trim($zeile[$pos]));
+ break;
+ case "taxincluded" : $data = strtolower(substr($zeile[$pos],0,1));
+ if ($data!="f" && $data!="t") { $vals[] = "'f'"; }
+ else { $vals[] = "'".$data."'";}
+ break;
+ case "taxzone_id" : $data = trim($zeile[$pos])*1;
+ if ($data>3 && $data<0) $data = 0;
+ $vals[] = $data;
+ break;
+ case "creditlimit" :
+ case "discount" :
+ case "terms" : $vals[] = trim($zeile[$pos])*1;
+ break;
+ case "customernumber":
+ case "vendornumber" : $data = trim($zeile[$pos]);
+ if (empty($data) or !$data) {
+ $vals[] = getKdId();
+ $number = true;
+ } else {
+ $vals[] = chkKdId($data);
+ $number = true;
+ }
+ break;
+ }
+ };
+ if (!in_array("taxzone_id",$in_fld)) {
+ $in_fld[] = "taxzone_id";
+ $vals[] = 0;
+ }
// seit 2.6 ist die DB-Kodierung UTF-8 @holger Ansonsten einmal vorher die DB-Encoding auslesen
// Falls die Daten ISO-kodiert kommen entsprechend wandeln
// done!
@@ -152,78 +246,26 @@ if ($ok) while (!feof($f)){
// die blöde mb_detect... tut leider nicht immer, daher die Möglichkeit der Auswahl
// TODO Umlaute am Anfang wurden bei meinem Test nicht übernommen (Ãsterreich). S.a.:
// http://forum.de.selfhtml.org/archiv/2007/1/t143904/
-
- if (Translate) translate($data);
-
- //$data=htmlentities($data);
- $data=addslashes($data);
- if ($in_fld[$i]==$file."number") { // customernumber || vendornumber
- if (empty($data) or !$data) {
- $data=getKdId();
- $number=true;
- } else {
- $data=chkKdId($data);
- $number=true;
- }
- } else if ($in_fld[$i]=="taxincluded"){
- $data=strtolower(substr($data,0,1));
- if ($data!="f" && $data!="t") $data="f";
- } else if ($in_fld[$i]=="ustid"){
- $data=strtr($data," ","");
- } /*else if ($in_fld[$i]=="matchcode") {
- $matchcode=$data;
- $i++;
- continue;
- if ($data==false or empty($data) or !$data) {
- if (in_array($in_fld[$i],array("name"))) {
- $data=$matchcode;
- }
- }
- }*/
-
- $keys.=$in_fld[$i].",";
- if ($data==false or empty($data) or !$data) {
- $vals.="null,";
- } else {
- if ($in_fld[$i]=="contact"){
- if ($anrede) {
- $vals.="'$anrede $data',";
- } else {
- $vals.="'$data',";
- }
- } else {
- $vals.="'".$data."',";
- }
- }
- $i++;
- }
- if (!$number) {
- $keys.=$file."number,";
- $vals.="'".getKdId()."',";
- }
- if ($keys<>"(") {
- if ($test) {
+ if ($test) {
if ($first) {
- echo "
\n";
- echo "".str_replace(","," | ",substr($keys,1,-1))." |
\n";
+ echo "\n";
+ echo implode(' | ',array_keys($in_fld));
+ echo " |
\n";
$first=false;
};
- $vals=str_replace("',","'",substr($vals,9,-1));
- echo " | ".str_replace("null,","null | ",$vals)." |
\n";
+ echo "";
+ echo implode(' | ',$vals);
+ echo " |
\n";
//echo "Import $j
\n";
flush();
- } else {
- $sql.=$keys."taxzone_id,import)";
- $sql.=$vals."0,$nun)";
- $rc=$db->query($sql);
- if (!$rc) echo "Fehler: ".$sql."
";
- }
- $j++;
} else {
- $vals=str_replace("',","'",substr($vals,9,-1));
- echo " | ".str_replace("null,","null | ",$vals)." |
\n";
- flush();
- }
+ $vals[] = $nun;
+ $sql = "INSERT INTO $file (".$infld.") values (".implode(",",$vals).")";
+ $rc=$db->query($sql);
+ if ($j % 10 == 0) { echo "."; flush(); };
+ if (!$rc) { echo "
Fehler: ".$sql."
"; flush(); };
+ }
+ $j++;
$zeile=fgetcsv($f,1200,$trenner);
}
fclose($f);