Revision 1ccda159
Von Holger Lindemann vor etwa 14 Jahren hinzugefügt
lxo-import/import_lib.php | ||
---|---|---|
279 | 279 |
$rs=$db->getAll($sql); |
280 | 280 |
return $rs; |
281 | 281 |
} |
282 |
function getAllUnits($db,$type) { |
|
283 |
$sql = "select * from units where type = '$type' order by sortkey"; |
|
284 |
$rs=$db->getAll($sql); |
|
285 |
return $rs; |
|
286 |
} |
|
282 | 287 |
|
283 | 288 |
function anmelden() { |
284 | 289 |
ini_set("gc_maxlifetime","3600"); |
lxo-import/partsB.php | ||
---|---|---|
8 | 8 |
Holger Lindemann <hli@lx-system.de> |
9 | 9 |
*/ |
10 | 10 |
|
11 |
$dir="../users/"; |
|
12 |
$gz_bin = "/bin/gzip -df "; |
|
13 |
$zip_bin = "/usr/bin/unzip -o -d ".$dir; |
|
11 | 14 |
|
12 | 15 |
function ende($txt) { |
13 | 16 |
echo "Abbruch: $txt<br>"; |
... | ... | |
44 | 47 |
define("ServerCode",$tmpcode); |
45 | 48 |
} |
46 | 49 |
//Zeichensatz sollte gleich sein, sonst ist die Datenkonvertierung nutzlos |
47 |
//DB und LxO müssen ja nicht auf der gleichen Maschiene sein.
|
|
50 |
//DB und LxO müssen ja nicht auf der gleichen Maschine sein. |
|
48 | 51 |
if($tmpcode<>$db->getClientCode()) { |
49 | 52 |
$rc = $db->setClientCode($tmpcode); |
50 | 53 |
} |
... | ... | |
104 | 107 |
ende ("Kein Datenfile angegeben"); |
105 | 108 |
|
106 | 109 |
/* copy file */ |
107 |
$dir="../users/"; |
|
108 |
if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".csv")) { |
|
110 |
if (substr($_FILES["Datei"]["name"],-2)=="gz") { |
|
111 |
if (move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".csv.gz")) { |
|
112 |
echo $gz_bin.$dir.$file.".csv.gz"; |
|
113 |
exec ($gz_bin.$dir.$file.".csv.gz"); |
|
114 |
} else { |
|
115 |
ende ("Upload von Datei fehlerhaft.".$_FILES["Datei"]["error"]); |
|
116 |
}; |
|
117 |
} else if (substr($_FILES["Datei"]["name"],-3)=="zip") { |
|
118 |
if (move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".zip")) { |
|
119 |
exec ($zip_bin.$dir.$file.".zip"); |
|
120 |
} else { |
|
121 |
ende ("Upload von Datei fehlerhaft.".$_FILES["Datei"]["error"]); |
|
122 |
}; |
|
123 |
} else if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".csv")) { |
|
109 | 124 |
ende ("Upload von Datei fehlerhaft.".$_FILES["Datei"]["error"]); |
110 |
} |
|
125 |
};
|
|
111 | 126 |
|
112 | 127 |
/* check if file is really there */ |
113 | 128 |
if (!file_exists($dir.$file.'.csv') or filesize($dir.$file.'.csv')==0) |
... | ... | |
129 | 144 |
|
130 | 145 |
} else { |
131 | 146 |
$bugrus=getAllBG($db); |
147 |
$serviceunit=getAllUnits($db,"service"); |
|
148 |
$dimensionunit=getAllUnits($db,"dimension"); |
|
132 | 149 |
?> |
133 | 150 |
|
134 | 151 |
<p class="listtop">Artikelimport für die ERP<p> |
... | ... | |
166 | 183 |
<tr><td>Art</td><td><input type="Radio" name="ware" value="W" checked>Ware |
167 | 184 |
<input type="Radio" name="ware" value="D">Dienstleistung |
168 | 185 |
<input type="Radio" name="ware" value="G">gemischt (Spalte 'art' vorhanden)</td></tr> |
186 |
<tr><td>Default Einheiten<br></td><td><select name="dimensionunit"> |
|
187 |
<?php if ($dimensionunit) foreach ($dimensionunit as $u) { ?> |
|
188 |
<option value="<?php echo $u["name"] ?>"><?php echo $u["name"]."\n" ?> |
|
189 |
<?php } ?> |
|
190 |
</select><select name="serviceunit"> |
|
191 |
<?php if ($serviceunit) foreach ($serviceunit as $u) { ?> |
|
192 |
<option value="<?php echo $u["name"] ?>"><?php echo $u["name"]."\n" ?> |
|
193 |
<?php } ?> |
|
194 |
</select> |
|
195 |
</td></tr> |
|
169 | 196 |
<tr><td>Default Bugru<br></td><td><select name="bugru"> |
170 | 197 |
<?php if ($bugrus) foreach ($bugrus as $bg) { ?> |
171 | 198 |
<option value="<?php echo $bg["id"] ?>"><?php echo $bg["description"]."\n" ?> |
172 | 199 |
<?php } ?> |
173 | 200 |
</select> |
174 |
<input type="radio" name="bugrufix" value="0">nie<br> |
|
175 |
<input type="radio" name="bugrufix" value="1" checked>für alle Artikel verwenden |
|
176 |
<input type="radio" name="bugrufix" value="2">für Artikel ohne passende Bugru |
|
201 |
<input type="radio" name="bugrufix" value="1" >für alle Artikel verwenden |
|
202 |
<input type="radio" name="bugrufix" value="2" checked>für Artikel ohne passende Bugru |
|
177 | 203 |
</td></tr> |
178 | 204 |
<tr><td>Daten</td><td><input type="file" name="Datei"></td></tr> |
179 | 205 |
<tr><td>Verwendete<br />Zeichecodierung</td><td> |
lxo-import/parts_import.php | ||
---|---|---|
41 | 41 |
show($data["rop"]); show($data["assembly"]); show($data["makemodel"]); |
42 | 42 |
show($data["shop"]); |
43 | 43 |
} |
44 |
|
|
44 | 45 |
/*foreach ($data as $key=>$val) { |
45 | 46 |
echo $key.":".gettype($val).":".gettype($data[$key]).":".$val."<br>"; |
46 | 47 |
}*/ |
47 | 48 |
if ($insert) { |
49 |
$data["import"]=time(); |
|
48 | 50 |
$sqlIa = 'INSERT INTO parts ('; |
49 | 51 |
$sqlIa .= 'partnumber,description,notes,ean,unit,'; |
50 | 52 |
$sqlIa .= 'weight,image,sellprice,listprice,lastcost,partsgroup_id,'; |
51 | 53 |
$sqlIa .= 'buchungsgruppen_id,income_accno_id,expense_accno_id,inventory_accno_id,'; |
52 | 54 |
$sqlIa .= 'microfiche,drawing,rop,assembly,shop,makemodel,import) '; |
53 |
$sqlIa .= 'VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'; |
|
54 |
$data["import"]=time(); |
|
55 |
$rc=$db->execute($sqlIa,$data); |
|
55 |
//$sqlIa .= 'VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'; |
|
56 |
//$rc=$db->execute($sqlIa,$data); |
|
57 |
$sqlIa .= "VALUES ('%s','%s','%s','%s','%s',%0.5f,'%s',%0.5f,%0.5f,%0.5f,%d,%d,%d,%d,%d,'%s','%s',%.0f,'%s','%s','%s',%s)"; |
|
58 |
$sql = sprintf($sqlIa,$data['partnumber'],$data['description'],$data['notes'],$data['ean'], |
|
59 |
$data['unit'],$data['weight'],$data['image'],$data['sellprice'], |
|
60 |
$data['listprice'],$data['lastcost'],$data['partsgroup_id'], |
|
61 |
$data['buchungsgruppen_id'],$data['income_accno_id'],$data['expense_accno_id'], |
|
62 |
$data['inventory_accno_id'],$data['microfiche'],$data['drawing'],$data['rop'], |
|
63 |
$data['assembly'],$data['shop'],$data['makemodel'],$data['import']); |
|
64 |
$rc = $db->query($sql); |
|
56 | 65 |
} else { |
57 | 66 |
$rc = true; |
58 | 67 |
} |
... | ... | |
203 | 212 |
|
204 | 213 |
function insPrices($db,$pid,$prices) { |
205 | 214 |
$rc = $db->query("BEGIN"); |
206 |
$sql="delete from prices where parts_id = ".$pid;
|
|
215 |
$sql="delete from prices where parts_id = (select id from parts where partnumber = '$pid')";
|
|
207 | 216 |
$rc = $db->query($sql); |
208 | 217 |
$sql = "insert into prices (parts_id,pricegroup_id,price) values ((select id from parts where partnumber = '%s'),%d,%0.5f)"; |
209 | 218 |
foreach ($prices as $key => $val) { |
... | ... | |
226 | 235 |
$Update=($maske["update"]=="U")?true:false; |
227 | 236 |
$UpdText=($maske["TextUpd"]=="1")?true:false; |
228 | 237 |
|
229 |
$stdunitW=getStdUnit($db,"dimension"); |
|
230 |
$stdunitD=getStdUnit($db,"service"); |
|
238 |
//$stdunitW=getStdUnit($db,"dimension"); |
|
239 |
//$stdunitD=getStdUnit($db,"service"); |
|
240 |
$stdunitW=$maske["dimensionunit"]; |
|
241 |
$stdunitD=$maske["serviceunit"]; |
|
231 | 242 |
if ($quottype=="P") $quotation=($quotation+100)/100; |
232 | 243 |
|
233 | 244 |
if ($show && !$insert) show("<b>Testimport</b>",false); |
... | ... | |
242 | 253 |
$parts_fld = array_keys($fields); |
243 | 254 |
} |
244 | 255 |
|
256 |
if ($trenner=="other") $trenner=trim($trennzeichen); |
|
257 |
if (substr($trenner,0,1)=="#") if (strlen($trenner)>1) $trenner=chr(substr($trenner,1)); |
|
258 |
|
|
245 | 259 |
/* open csv file */ |
246 |
$f=fopen($file.'.csv',"r"); |
|
247 |
|
|
260 |
if (file_exists($file."head.csv")) { |
|
261 |
$fh=fopen($file.'head.csv',"r"); |
|
262 |
// Erst einmal die erste Zeile mit den richtigen Feldbezeichnungen einlesen. |
|
263 |
$infld=fgetcsv($fh,1200,$trenner); |
|
264 |
fclose($fh); |
|
265 |
$f=fopen($file.'.csv',"r"); |
|
266 |
// Erst einmal die erste Zeile mit den falschen Feldbezeichnungen einlesen. |
|
267 |
$tmp=fgetcsv($f,1200,$trenner); |
|
268 |
} else { |
|
269 |
$f=fopen($file.'.csv',"r"); |
|
270 |
// Erst einmal die erste Zeile mit den Feldbezeichnungen einlesen. |
|
271 |
$infld=fgetcsv($f,1200,$trenner); |
|
272 |
} |
|
273 |
|
|
248 | 274 |
/* |
249 | 275 |
* read first line with table descriptions |
250 | 276 |
*/ |
... | ... | |
259 | 285 |
show("</tr>\n",false); |
260 | 286 |
} |
261 | 287 |
|
262 |
if ($trenner=="other") $trenner=trim($trennzeichen); |
|
263 |
if (substr($trenner,0,1)=="#") if (strlen($trenner)>1) $trenner=chr(substr($trenner,1)); |
|
264 | 288 |
|
265 |
// Erst einmal die erste Zeile mit den Feldbezeichnungen einlesen. |
|
266 |
$infld=fgetcsv($f,1200,$trenner); |
|
267 | 289 |
$p=0; |
268 | 290 |
foreach ($infld as $fld) { |
269 | 291 |
$fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>"")))); |
... | ... | |
300 | 322 |
$listprice = str_replace(",", ".", $zeile[$fldpos["listprice"]]); |
301 | 323 |
$lastcost = str_replace(",", ".", $zeile[$fldpos["lastcost"]]); |
302 | 324 |
if ($prices) { |
303 |
foreach ($prices as $pkey=>$val) { |
|
304 |
$pricegroup[$val] = str_replace(",", ".", $zeile[$fldpos[$pkey]]); |
|
325 |
foreach ($prices as $pkey=>$val) { |
|
326 |
if (array_key_exists($pkey,$fldpos)) |
|
327 |
$pricegroup[$val] = str_replace(",", ".", $zeile[$fldpos[$pkey]]); |
|
305 | 328 |
} |
306 | 329 |
} |
307 | 330 |
if ($quotation<>0) { |
... | ... | |
345 | 368 |
|
346 | 369 |
/* sind Hersteller und Modelnummer hinterlegt |
347 | 370 |
wenn ja, erfolgt er insert sp?ter */ |
371 |
$makemodel = 'f'; |
|
348 | 372 |
if (!empty($zeile[$fldpos["makemodel"]]) and !$artikel) { |
349 | 373 |
$mm = $zeile[$fldpos["makemodel"]]; |
350 | 374 |
if (Translate) translate($mm); |
... | ... | |
472 | 496 |
"description"=>$description,"notes"=>$notes, |
473 | 497 |
"ean"=>$zeile[$fldpos["ean"]],"unit"=>$unit, |
474 | 498 |
"weight"=>$weight,"image"=>$zeile[$fldpos["image"]], |
475 |
"sellprice"=>$sellprice,"lastcost"=>$lastcost,"listprice"=>$listprice, |
|
499 |
"sellprice"=>$sellprice, |
|
500 |
"lastcost"=>$lastcost, |
|
501 |
"listprice"=>$listprice, |
|
476 | 502 |
"partsgroup_id"=>$partsgroup_id, |
477 |
"buchungsgruppen_id"=>$bg,"income_accno"=>$income_accno, |
|
478 |
"expense_accno"=>$expense_accno,"inventory_accno"=>$inventory_accno,
|
|
503 |
"buchungsgruppen_id"=>$bg,"income_accno_id"=>$income_accno,
|
|
504 |
"expense_accno_id"=>$expense_accno,"inventory_accno_id"=>$inventory_accno,
|
|
479 | 505 |
"microfiche"=>$zeile[$fldpos["microfiche"]],"drawing"=>$zeile[$fldpos["drawing"]], |
480 | 506 |
"rop"=>$rop,"assembly"=>$assembly, |
481 | 507 |
"shop"=>$shop,"makemodel"=>$makemodel),$pricegroup |
users/partshead.csv | ||
---|---|---|
1 |
partnumber fvId wgr partsgroup ean model ErsatzArt makemodel MarkeText description cat01 cat01Text cat02 cat02Text cat03 cat03Text cat04 cat04Text KzStueck KzAL KzAktion KzSperre pg_1 pg_2 listprice lastcost InfLagME InfLagWE |
Auch abrufbar als: Unified diff
Artikelupload mit gezipten Daten und beliebigen Header