Revision 6555d5f7
Von Holger Lindemann vor mehr als 17 Jahren hinzugefügt
lxo-import/import_lib.php | ||
---|---|---|
69 | 69 |
"weight" => "Gewicht in Benutzerdefinition", |
70 | 70 |
"onhand" => "Lagerbestand", |
71 | 71 |
"notes" => "Beschreibung", |
72 |
"makemodel" => "Hersteller", |
|
73 |
"model" => "Modellbezeichnung", |
|
72 |
//"makemodel" => "Hersteller",
|
|
73 |
//"model" => "Modellbezeichnung",
|
|
74 | 74 |
"bin" => "Lagerort", |
75 | 75 |
"image" => "Pfad/Dateiname", |
76 | 76 |
"drawing" => "Pfad/Dateiname", |
... | ... | |
88 | 88 |
"shop" => "Shopartikel (Y/N)", |
89 | 89 |
"assembly" => "St?ckliste (Y/N); wird noch nicht unterst?tzt", |
90 | 90 |
"partsgroup" => "Warengruppenbezeichnung", |
91 |
"partsgroup1" => "2.Warengruppenbezeichnung", |
|
91 | 92 |
//"income_accno_0" => "?Nummer? f?r Erl?se Inland", |
92 | 93 |
//"income_accno_1" => "?Nummer? f?r Erl?se EG", |
93 | 94 |
//"income_accno_3" => "?Nummer? f?r Erl?se Ausland", |
... | ... | |
287 | 288 |
var $showErr = false; |
288 | 289 |
var $db = false; |
289 | 290 |
var $debug = false; |
291 |
var $logsql = false; |
|
292 |
var $errfile = false; |
|
293 |
var $logfile = false; |
|
294 |
|
|
290 | 295 |
|
291 | 296 |
/**************************************************** |
292 | 297 |
* uudecode |
... | ... | |
317 | 322 |
echo "$sql : $err\n"; |
318 | 323 |
} |
319 | 324 |
|
320 |
function showDebug($sql) { |
|
325 |
function showDebug($sql) {
|
|
321 | 326 |
echo $sql."\n"; |
322 | 327 |
if ($this->debug==2) { |
323 | 328 |
print_r($this->rc); |
324 | 329 |
}; |
325 | 330 |
} |
326 | 331 |
|
332 |
function logSql($sql) { |
|
333 |
if (!$this->logfile) $this->logfile=fopen("import.sql","a"); |
|
334 |
fputs($this->logfile,$sql."\n"); |
|
335 |
} |
|
327 | 336 |
function myDB($usr) { |
328 | 337 |
// Datenbankparameter des ERP-Users benutzen. |
329 | 338 |
$tmp = file_get_contents("../users/$usr.conf"); |
... | ... | |
357 | 366 |
|
358 | 367 |
function query($sql) { |
359 | 368 |
$this->rc=@$this->db->query($sql); |
369 |
if ($this->logsql) $this->logSql($sql); |
|
360 | 370 |
if ($this->debug) $this->showDebug($sql); |
361 | 371 |
if(DB::isError($this->rc)) { |
362 | 372 |
$this->dbFehler($sql,$this->rc->getMessage()); |
... | ... | |
367 | 377 |
} |
368 | 378 |
function getAll($sql) { |
369 | 379 |
$this->rc=@$this->db->getAll($sql,DB_FETCHMODE_ASSOC); |
380 |
if ($this->logsql) $this->logSql($sql); |
|
370 | 381 |
if ($this->debug) $this->showDebug($sql); |
371 | 382 |
if(DB::isError($this->rc)) { |
372 | 383 |
$this->dbFehler($sql,$this->rc->getMessage()); |
lxo-import/partsB.php | ||
---|---|---|
39 | 39 |
foreach($parts as $key=>$val) { |
40 | 40 |
echo "$key => $val<br>"; |
41 | 41 |
} |
42 |
echo "<br>Die erste Zeile enthält die Feldnamen der Daten in ihrer richtigen Reihenfolge<br>"; |
|
43 |
echo "Geben Sie das Trennzeichen der Datenspalten ein. Steuerzeichen können mit ihrem Dezimalwert geführt von einem "#" eingegebn werden (#11).<br><br>"; |
|
44 |
echo "Der "sellprice" kann um den eingegeben Wert geändert werden.<br><br>"; |
|
45 |
echo "Bei vorhandenen Artikelnummern (in der db), kann entweder ein Update auf den Preis durchgeführt werden oder der Artikel mit anderer Artikelnummer eingefügt werden.<br><br>"; |
|
42 | 46 |
echo "Jeder Artikel muß einer Buchungsgruppe zugeordnet werden. "; |
43 | 47 |
echo "Dazu muß entweder in der Maske eine Standardbuchungsgruppe gewählt werden <br>"; |
44 | 48 |
echo "oder es wird ein gültiges Konto in 'income_accno_id' und 'expense_accno_id' eingegeben. "; |
... | ... | |
50 | 54 |
|
51 | 55 |
$test = $_POST["test"]; |
52 | 56 |
$trenner = ($_POST["trenner"])?$_POST["trenner"]:","; |
57 |
$trennzeichen = ($_POST["trennzeichen"])?$_POST["trennzeichen"]:""; |
|
58 |
$precision = $_POST["precision"]; |
|
59 |
$quotation = $_POST["quotation"]; |
|
60 |
$quottype = $_POST["quottype"]; |
|
53 | 61 |
$file = "parts"; |
54 | 62 |
|
55 | 63 |
/* no data? */ |
... | ... | |
81 | 89 |
|
82 | 90 |
/* first check all elements */ |
83 | 91 |
echo "Checking data:<br>"; |
84 |
$err = import_parts($db, $file, $trenner, $parts, TRUE, FALSE, FALSE,$_POST); |
|
92 |
$_test=$_POST; |
|
93 |
$_test["precision"]=-1; |
|
94 |
$_test["quotation"]=0; |
|
95 |
$err = import_parts($db, $file, $trenner, $trennzeichen, $parts, TRUE, FALSE, FALSE,$_test); |
|
85 | 96 |
echo "$err Errors found\n"; |
86 | 97 |
|
87 | 98 |
|
... | ... | |
89 | 100 |
exit(0); |
90 | 101 |
|
91 | 102 |
/* just print data or insert it, if test is false */ |
92 |
import_parts($db, $file, $trenner, $parts, FALSE, !$test, TRUE,$_POST); |
|
103 |
import_parts($db, $file, $trenner, $trennzeichen, $parts, FALSE, !$test, TRUE,$_POST);
|
|
93 | 104 |
|
94 | 105 |
} else { |
95 | 106 |
$bugrus=getAllBG($db); |
... | ... | |
102 | 113 |
<input type="hidden" name="login" value="<?= $login ?>"> |
103 | 114 |
<table> |
104 | 115 |
<tr><td></td><td><input type="submit" name="ok" value="Hilfe"></td></tr> |
105 |
<tr><td>Trennzeichen</td><td><input type="text" size="2" maxlength="1" name="trenner" value=";"></td></tr> |
|
116 |
<tr><td>Trennzeichen</td><td> |
|
117 |
<input type="radio" name="trenner" value=";" checked>Semikolon |
|
118 |
<input type="radio" name="trenner" value=",">Komma |
|
119 |
<input type="radio" name="trenner" value="#9">Tabulator |
|
120 |
<input type="radio" name="trenner" value=" ">Leerzeichen |
|
121 |
<input type="radio" name="trenner" value="other"> |
|
122 |
<input type="text" size="2" name="trennzeichen" value=""> |
|
123 |
</td></tr> |
|
124 |
<tr><td>VK-Preis<br>Nachkomma:</td><td><input type="Radio" name="precision" value="0">0 |
|
125 |
<input type="Radio" name="precision" value="1">1 |
|
126 |
<input type="Radio" name="precision" value="2" checked>2 |
|
127 |
<input type="Radio" name="precision" value="3">3 |
|
128 |
<input type="Radio" name="precision" value="4">4 |
|
129 |
<input type="Radio" name="precision" value="5">5 |
|
130 |
</td></tr> |
|
131 |
<tr><td>VK-Preis<br>Aufschlag:</td><td><input type="text" name="quotation" size="5" value="0"> |
|
132 |
<input type="radio" name="quottype" value="P" checked>% |
|
133 |
<input type="radio" name="quottype" value="A">Absolut</td></tr> |
|
134 |
<tr><td>Vorhandene<br>Artikelnummer:</td><td><input type="radio" name="update" value="U" checked>Preis update durchführen<br> |
|
135 |
<input type="radio" name="update" value="I">mit neuer Nummer einfügen</td></tr> |
|
106 | 136 |
<tr><td>Test</td><td><input type="checkbox" name="test" value="1">ja</td></tr> |
107 | 137 |
<tr><td>Art</td><td><input type="Radio" name="ware" value="W">Ware |
108 | 138 |
<input type="Radio" name="ware" value="D">Dienstleistung |
lxo-import/parts_import.php | ||
---|---|---|
23 | 23 |
return $rs[0]["id"]; |
24 | 24 |
} |
25 | 25 |
|
26 |
//Mu? noch eingebunden werden |
|
27 |
function getMakemodel($db,$hersteller,$model,$partsid,$add=true) { |
|
28 |
$sql="select * from makemodel where make like '$hersteller' and model like = '$model'"; |
|
29 |
$rs=$db->getAll($sql); |
|
30 |
if (empty($rs[0]["id"]) && $add) { |
|
31 |
$sql="insert into makemodel (parts_id,make,model) values ($partsid,'$hersteller','$model')"; |
|
32 |
$rc=$db->query($sql); |
|
33 |
if (!$rc) return "f"; |
|
34 |
return getMakemodel($db,$hersteller,$model,$partsid,false); |
|
35 |
} |
|
36 |
if ($rs[0]["parts_id"]==$partsid) { return "t"; } |
|
37 |
else { return "f"; } |
|
38 |
} |
|
39 |
|
|
26 | 40 |
function getAccnoId($db, $accno) { |
27 | 41 |
$sql = "select id from chart where accno='$accno'"; |
28 | 42 |
$rs=$db->getAll($sql); |
29 | 43 |
return $rs[0]["id"]; |
30 | 44 |
} |
31 | 45 |
|
46 |
//Auf Artikelnummer testen, bzw. neue Nummer erzeugen |
|
32 | 47 |
function chkPartNumber($db,$number,$check) { |
33 | 48 |
if ($number<>"") { |
34 | 49 |
$sql = "select * from parts where partnumber = '$number'"; |
... | ... | |
54 | 69 |
return $number; |
55 | 70 |
} |
56 | 71 |
|
72 |
//Artikelnummer testen und wenn vorhanden Preis ?ndern |
|
73 |
function chkPartNumberUpd($db,$sellprice,$partnumber,$check){ |
|
74 |
if ($partnumber=="") { |
|
75 |
$nummer=chkPartNumber($db,$partnumber,$check); |
|
76 |
if ($nummer=="") { return -99; } |
|
77 |
else { return $nummer; }; |
|
78 |
} |
|
79 |
$sql = "select * from parts where partnumber = '$partnumber'"; |
|
80 |
$rs=$db->getAll($sql); |
|
81 |
if ($rs[0]["id"]>0) { |
|
82 |
if ($check) return -1; |
|
83 |
$sql="update parts set sellprice = $sellprice where partnumber = '$partnumber'"; |
|
84 |
$rc=$db->query($sql); |
|
85 |
if ($rc) return -1; |
|
86 |
return -99; |
|
87 |
} |
|
88 |
$nummer=chkPartNumber($db,$partnumber,$check); |
|
89 |
if ($nummer=="") { return -99; } |
|
90 |
else { return $nummer; }; |
|
91 |
} |
|
92 |
|
|
57 | 93 |
function getBuchungsgruppe($db, $income, $expense) { |
58 | 94 |
|
59 | 95 |
$income_id = getAccnoId($db, $income); |
... | ... | |
93 | 129 |
echo $things; |
94 | 130 |
} |
95 | 131 |
|
96 |
function import_parts($db, $file, $trenner, $fields, $check, $insert, $show,$maske) { |
|
132 |
function getStdUnit($db,$type) { |
|
133 |
$sql="select * from units where type='$type' order by sortkey limit 1"; |
|
134 |
$rs=$db->getAll($sql); |
|
135 |
if (empty($rs[0]["name"])) return "Stck"; |
|
136 |
return $rs[0]["name"]; |
|
137 |
} |
|
138 |
|
|
139 |
function import_parts($db, $file, $trenner, $trennzeichen, $fields, $check, $insert, $show,$maske) { |
|
140 |
|
|
141 |
$pgshow=false; |
|
142 |
$note2show=false; |
|
143 |
$fehler=0; |
|
144 |
$precision=$maske["precision"]; |
|
145 |
$quotation=$maske["quotation"]; |
|
146 |
$quottype=$maske["quottype"]; |
|
97 | 147 |
|
148 |
$Update=($maske["update"]=="U")?true:false; |
|
98 | 149 |
/* field description */ |
99 | 150 |
$parts_fld = array_keys($fields); |
100 | 151 |
|
... | ... | |
105 | 156 |
* read first line with table descriptions |
106 | 157 |
*/ |
107 | 158 |
show( $show, "<table border='1'><tr><td>#</td>\n"); |
159 |
if ($trenner=="other") $trenner=trim($trennzeichen); |
|
160 |
if (substr($trenner,0,1)=="#") if (strlen($trenner)>1) $trenner=chr(substr($trenner,1)); |
|
108 | 161 |
$infld=fgetcsv($f,1200,$trenner); |
109 | 162 |
foreach ($infld as $fld) { |
110 | 163 |
$fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>"")))); |
111 | 164 |
$in_fld[]=$fld; |
112 | 165 |
if (in_array(trim($fld),$parts_fld)) { |
113 |
show( $show, "<td>$fld</td>\n"); |
|
166 |
if ($fld=="partsgroup" || $fld=="partsgroup1" ) { |
|
167 |
$pgshow=true; |
|
168 |
} else { |
|
169 |
show( $show, "<td>$fld</td>\n"); |
|
170 |
} |
|
114 | 171 |
} |
115 | 172 |
} |
116 |
|
|
173 |
if (!in_array("unit",$infld)) { |
|
174 |
$stdunitW=getStdUnit($db,"dimension"); |
|
175 |
$stdunitD=getStdUnit($db,"service"); |
|
176 |
$unit=true; |
|
177 |
show( $show, "<td>unit</td>\n"); |
|
178 |
}; |
|
179 |
if ($pgshow) show( $show, "<td>partsgroup</td>\n"); |
|
180 |
$posprice=0; |
|
181 |
$posnumber=0; |
|
182 |
$j=0; |
|
183 |
foreach ($infld as $value) { |
|
184 |
if ($infld[$j]=="sellprice") $posprice=$j; |
|
185 |
if ($infld[$j]=="partnumber") $posnumber=$j; |
|
186 |
$j++; |
|
187 |
} |
|
117 | 188 |
$m=0; /* line */ |
118 | 189 |
$errors=0; /* number of errors detected */ |
119 | 190 |
$income_accno = ""; |
120 | 191 |
$expense_accno = ""; |
121 |
while ( ($zeile=fgetcsv($f,1200,$trenner)) != FALSE) { |
|
192 |
if ($quottype=="P") $quotation=($quotation+100)/100; |
|
193 |
while ( ($zeile=fgetcsv($f,15000,$trenner)) != FALSE) { |
|
122 | 194 |
$i=0; /* column */ |
123 | 195 |
$m++; /* increase line */ |
124 | 196 |
|
197 |
if ($Update) { |
|
198 |
$sellprice=$zeile[$posprice]; |
|
199 |
$partnumber=$zeile[$posnumber]; |
|
200 |
$sellprice = str_replace(",", ".", $sellprice); |
|
201 |
if ($quotation<>0) { |
|
202 |
if ($quottype=="A") { $sellprice += $quotation; } |
|
203 |
else { $sellprice = $sellprice * $quotation; } |
|
204 |
}; |
|
205 |
if ($precision>=0) $sellprice = round($sellprice,$precision); |
|
206 |
$rc=chkPartNumberUpd($db,$sellprice,$partnumber,!$insert); |
|
207 |
if ($rc==-1) { |
|
208 |
show($show,"<tr><td>Update </td><td>$partnumber:$sellprice</td></tr>\n"); |
|
209 |
continue; |
|
210 |
} else if ($rc==-99) { |
|
211 |
show($show,"<tr><td>Fehler Zeile $m</td></tr>\n"); |
|
212 |
continue; |
|
213 |
} else { |
|
214 |
$zeile[$posnumber]=$rc; |
|
215 |
} |
|
216 |
}; |
|
217 |
|
|
125 | 218 |
$sql="insert into $file "; |
126 | 219 |
$keys="("; |
127 | 220 |
$vals=" values ("; |
... | ... | |
132 | 225 |
$dienstleistung=false; |
133 | 226 |
$artikel=-1; |
134 | 227 |
$partNr=false; |
228 |
$pg_name_val=""; |
|
135 | 229 |
foreach($zeile as $data) { |
136 | 230 |
/* check if column will be imported */ |
137 | 231 |
if (!in_array(trim($in_fld[$i]),$parts_fld)) { |
... | ... | |
139 | 233 |
continue; |
140 | 234 |
}; |
141 | 235 |
$data=trim($data); |
142 |
//$data=addslashes($data); |
|
143 | 236 |
$key=$in_fld[$i]; |
144 | 237 |
/* add key and data */ |
145 |
if ($data==false or empty($data) or !$data) { |
|
146 |
show( $show, "<td>NULL</td>\n"); |
|
238 |
|
|
239 |
/* special case partsgroup1 */ |
|
240 |
if ($key == "partsgroup1") { |
|
241 |
if ($pg_name_val<>"") { |
|
242 |
if ($data<>"") $pg_name_val.="!".$data; |
|
243 |
} else { |
|
244 |
$pg_name_val=$data; |
|
245 |
} |
|
246 |
$i++; |
|
247 |
continue; |
|
248 |
} else if ($key == "partsgroup") { |
|
249 |
/* special case partsgroup */ |
|
250 |
$pg_name_val=$data; |
|
147 | 251 |
$i++; |
148 | 252 |
continue; |
149 |
} |
|
150 |
|
|
151 |
/* special case partsgroup */ |
|
152 |
if ($key == "partsgroup") { |
|
153 |
|
|
154 |
/* get ID of partsgroup or add new |
|
155 |
* partsgroup_id */ |
|
156 |
$data = getPartsgroupId($db, $data, $insert); |
|
157 |
$key = "partsgroup_id"; |
|
158 |
|
|
159 |
/* TODO error handling */ |
|
160 |
|
|
161 | 253 |
} else if ($key == "lastcost" || |
162 | 254 |
$key == "sellprice") { |
163 | 255 |
|
164 | 256 |
/* convert 0,0 numeric into 0.0 */ |
165 | 257 |
$data = str_replace(",", ".", $data); |
166 |
|
|
258 |
if ($key == "sellprice") { |
|
259 |
if ($quotation<>0) { |
|
260 |
if ($quottype=="A") { $data += $quotation; } |
|
261 |
else { $data = $data * $quotation; } |
|
262 |
}; |
|
263 |
if ($precision>=0) $data = round($data,$precision); |
|
264 |
} |
|
167 | 265 |
} else if ($key == "partnumber") { |
168 | 266 |
$partNr=true; |
169 | 267 |
$partnumber=chkPartNumber($db,$data,$check); |
... | ... | |
183 | 281 |
$data=mb_convert_encoding($data,"ISO-8859-15","auto"); |
184 | 282 |
$data=addslashes($data); |
185 | 283 |
} else if ($key == "unit") { |
284 |
if ($data=="") { |
|
285 |
if ($maske["ware"]=="W") { $data=$stdunitW; } |
|
286 |
else if ($maske["ware"]=="D") { $data=$stdunitD; } |
|
287 |
//else if ($maske["ware"]=="G") { $data=$stdunitD; //Noch machen!} |
|
288 |
else { $data=$stdunitW; }; |
|
289 |
} |
|
186 | 290 |
/* convert st?ck and Stunde */ |
187 | 291 |
if (preg_match("/^st..?ck$/i", $data)) |
188 | 292 |
$data = "Stck"; |
... | ... | |
211 | 315 |
show( $show, "<td>$data</td>\n"); |
212 | 316 |
continue; |
213 | 317 |
} |
318 |
if ($data==false or empty($data) or !$data) { |
|
319 |
show( $show, "<td>NULL</td>\n"); |
|
320 |
$i++; |
|
321 |
continue; |
|
322 |
} |
|
214 | 323 |
/* convert JA to Yes */ |
215 |
if ($data == "J" ) |
|
216 |
$data = "Y"; |
|
217 |
|
|
324 |
if ($data === "J" || $data === "j") $data = "Y"; |
|
218 | 325 |
$vals.="'".$data."',"; |
219 |
show( $show, "<td>$data</td>\n");
|
|
326 |
show( $show, "<td>".htmlentities($data)."</td>\n");
|
|
220 | 327 |
$keys.=$key.","; |
221 |
|
|
222 | 328 |
$i++; |
223 | 329 |
} |
330 |
if ($unit) { |
|
331 |
if ($maske["ware"]=="D") { $einh=$stdunitD; } |
|
332 |
else { $einh=$stdunitW; } |
|
333 |
$keys.="unit,"; |
|
334 |
$vals.="'$einh',"; |
|
335 |
show( $show,"<td>$einh</td>\n"); |
|
336 |
} |
|
337 |
/* special case partsgroup */ |
|
338 |
if ($pgshow) { |
|
339 |
if ($pg_name_val) { |
|
340 |
/* get ID of partsgroup or add new |
|
341 |
* partsgroup_id */ |
|
342 |
$ID = getPartsgroupId($db, $pg_name_val, $insert); |
|
343 |
$keys.= "partsgroup_id,"; |
|
344 |
$vals.="'".$ID."',"; |
|
345 |
show( $show, "<td>".htmlentities($pg_name_val).":$ID</td>\n"); |
|
346 |
} else { |
|
347 |
show( $show,"<td>NULL</td>\n"); |
|
348 |
} |
|
349 |
} |
|
224 | 350 |
if ($artikel==-1) { |
225 | 351 |
if ($maske["ware"]=="D") { $artikel=false; } |
226 | 352 |
else { $artikel=true; }; |
Auch abrufbar als: Unified diff
VK-Preisupdate
Rundung des VK-Preises
VK-Preis Update von vorhandenen Artikeln
Zwei Artikelgruppenfelder auswerten für partsgroup