21 |
21 |
}
|
22 |
22 |
return $rs[0]["id"];
|
23 |
23 |
}
|
24 |
|
function insertParts($db,$insert,$show,$data) {
|
|
24 |
function getPricegroup($db) {
|
|
25 |
$sql="SELECT * from pricegroup";
|
|
26 |
$rs=$db->getAll($sql);
|
|
27 |
$data = false;
|
|
28 |
if ($rs) foreach ($rs as $row) {
|
|
29 |
$data["pg_".strtolower($row["pricegroup"])]=$row["id"];
|
|
30 |
};
|
|
31 |
return $data;
|
|
32 |
}
|
|
33 |
function insertParts($db,$insert,$show,$data,$pricegroup) {
|
25 |
34 |
if ($show) {
|
26 |
35 |
show('<tr>',false);
|
27 |
|
show($data["partnumber"]); show($data["lastcost"]); show($data["sellprice"]);
|
|
36 |
show($data["partnumber"]); show($data["lastcost"]); show($data["sellprice"]); show($data["listprice"]);
|
28 |
37 |
show($data["description"]); show(substr($data["notes"],0,25));show($data["ean"]);
|
29 |
38 |
show($data["weight"]); show($data["image"]); show($data["partsgroup_id"]);
|
30 |
39 |
show($data["buchungsgruppen_id"]);show($data["income_accno"]); show($data["expense_accno"]);
|
... | ... | |
38 |
47 |
if ($insert) {
|
39 |
48 |
$sqlIa = 'INSERT INTO parts (';
|
40 |
49 |
$sqlIa .= 'partnumber,description,notes,ean,unit,';
|
41 |
|
$sqlIa .= 'weight,image,sellprice,lastcost,partsgroup_id,';
|
|
50 |
$sqlIa .= 'weight,image,sellprice,listprice,lastcost,partsgroup_id,';
|
42 |
51 |
$sqlIa .= 'buchungsgruppen_id,income_accno_id,expense_accno_id,inventory_accno_id,';
|
43 |
52 |
$sqlIa .= 'microfiche,drawing,rop,assembly,shop,makemodel,import) ';
|
44 |
|
$sqlIa .= 'VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
|
|
53 |
$sqlIa .= 'VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
|
45 |
54 |
$data["import"]=time();
|
46 |
55 |
$rc=$db->execute($sqlIa,$data);
|
47 |
56 |
} else {
|
48 |
57 |
$rc = true;
|
49 |
58 |
}
|
|
59 |
if ($pricegroup) $ok = insPrices($db,$data["partnumber"],$pricegroup);
|
50 |
60 |
if ($show) {
|
51 |
61 |
if ($rc)
|
52 |
62 |
show('<b>ok</b>');
|
... | ... | |
56 |
66 |
}
|
57 |
67 |
return $rc;
|
58 |
68 |
}
|
59 |
|
function updPrice($db,$insert,$show,$partnumber,$lastcost,$sellprice,$shop) {
|
|
69 |
function updPrice($db,$insert,$show,$partnumber,$lastcost,$sellprice,$listprice,$pricegroup,$shop) {
|
60 |
70 |
if ($show) {
|
61 |
71 |
show('<tr>',false);
|
62 |
|
show($partnumber); show($lastcost); show($sellprice);
|
|
72 |
show($partnumber); show($lastcost); show($sellprice); show($listprice);
|
63 |
73 |
}
|
64 |
74 |
if ($insert) {
|
65 |
75 |
$sqlPr = 'UPDATE PARTS SET ';
|
66 |
|
$sqlPr .= 'sellprice = ?, lastcost = ?, shop = ? ';
|
|
76 |
$sqlPr .= 'sellprice = ?, listprice = ?, lastcost = ?, shop = ? ';
|
67 |
77 |
$sqlPr .= 'WHERE partnumber = ?';
|
68 |
|
$rc=$db->execute($sqlPr,array("sellprice"=>$sellprice,"lastcost"=>$lastcost,"shop"=>$shop,"partnumber"=>$partnumber));
|
|
78 |
$rc=$db->execute($sqlPr,array("sellprice"=>$sellprice,"listprice"=>$listprice,"lastcost"=>$lastcost,"shop"=>$shop,"partnumber"=>$partnumber));
|
69 |
79 |
} else {
|
70 |
80 |
$rc = true;
|
71 |
81 |
}
|
|
82 |
if ($pricegroup) $ok = insPrices($db,$partnumber,$pricegroup);
|
72 |
83 |
if ($show) {
|
73 |
84 |
if ($rc)
|
74 |
85 |
show('<b>ok</b>');
|
... | ... | |
78 |
89 |
}
|
79 |
90 |
return $rc;
|
80 |
91 |
}
|
81 |
|
function updParts($db,$insert,$show,$partnumber,$lastcost,$sellprice,
|
|
92 |
function updParts($db,$insert,$show,$partnumber,$lastcost,$sellprice,$listprice,
|
82 |
93 |
$description,$notes,$ean,$weight,$image,
|
83 |
|
$partsgroup_id, $shop) {
|
|
94 |
$partsgroup_id,$pricegroup, $shop) {
|
84 |
95 |
if ($show) {
|
85 |
96 |
show('<tr>',false);
|
86 |
|
show($partnumber); show($lastcost); show($sellprice);
|
|
97 |
show($partnumber); show($lastcost); show($sellprice); show($listprice);
|
87 |
98 |
show($description); show(substr($notes,0,25));show($ean);
|
88 |
99 |
show($weight); show($image); show($partsgroup_id);
|
89 |
100 |
}
|
90 |
101 |
if ($insert) {
|
91 |
102 |
$sqlUa = 'UPDATE PARTS SET ';
|
92 |
103 |
$sqlUa .= 'description = ?, notes = ?, ean = ?, weight = ?, image = ?, ';
|
93 |
|
$sqlUa .= 'sellprice = ?, lastcost = ?, partsgroup_id = ?, shop = ? ';
|
|
104 |
$sqlUa .= 'sellprice = ?, listprice = ?, lastcost = ?, partsgroup_id = ?, shop = ? ';
|
94 |
105 |
$sqlUa .= 'WHERE partnumber = ?';
|
95 |
106 |
$rc=$db->execute($sqlUa,array($description,$notes,$ean,$weight,$image,
|
96 |
|
$sellprice,$lastcost,$partsgroup_id,$shop,$partnumber));
|
|
107 |
$sellprice,$listprice,$lastcost,$partsgroup_id,$shop,$partnumber));
|
97 |
108 |
} else {
|
98 |
109 |
$rc = true;
|
99 |
110 |
}
|
|
111 |
if ($pricegroup) $ok = insPrices($db,$partnumber,$pricegroup);
|
100 |
112 |
if ($show) {
|
101 |
113 |
if ($rc)
|
102 |
114 |
show('<b>ok</b>');
|
... | ... | |
139 |
151 |
$rs=$db->getAll($sql);
|
140 |
152 |
if ($rs[0]["articlenumber"]) {
|
141 |
153 |
preg_match("/([^0-9]+)?([0-9]+)([^0-9]+)?/", $rs[0]["articlenumber"] , $regs);
|
142 |
|
print_r($regs);
|
143 |
154 |
$number=$regs[1].($regs[2]+1).$regs[3];
|
144 |
155 |
}
|
145 |
156 |
$sql = "update defaults set articlenumber = '$number'";
|
... | ... | |
190 |
201 |
return $rs[0]["name"];
|
191 |
202 |
}
|
192 |
203 |
|
|
204 |
function insPrices($db,$pid,$prices) {
|
|
205 |
$rc = $db->query("BEGIN");
|
|
206 |
$sql="delete from prices where parts_id = ".$pid;
|
|
207 |
$rc = $db->query($sql);
|
|
208 |
$sql = "insert into prices (parts_id,pricegroup_id,price) values ((select id from parts where partnumber = '%s'),%d,%0.5f)";
|
|
209 |
foreach ($prices as $key => $val) {
|
|
210 |
$rc = $db->query(sprintf($sql,$pid,$key,$val));
|
|
211 |
if (!$rc) {
|
|
212 |
$db->query("ROLLBACK");
|
|
213 |
return false;
|
|
214 |
}
|
|
215 |
}
|
|
216 |
$db->query("COMMIT");
|
|
217 |
return true;
|
|
218 |
}
|
|
219 |
|
193 |
220 |
function import_parts($db, $file, $trenner, $trennzeichen, $fields, $check, $insert, $show ,$maske) {
|
194 |
221 |
$precision=$maske["precision"];
|
195 |
222 |
$quotation=$maske["quotation"];
|
... | ... | |
207 |
234 |
if ($show) show("<table border='1'>\n",false);
|
208 |
235 |
|
209 |
236 |
/* field description */
|
210 |
|
$parts_fld = array_keys($fields);
|
|
237 |
$prices = getPricegroup($db);
|
|
238 |
if ($prices) {
|
|
239 |
$priceskey = array_keys($prices);
|
|
240 |
$parts_fld = array_merge(array_keys($fields),$priceskey);
|
|
241 |
} else {
|
|
242 |
$parts_fld = array_keys($fields);
|
|
243 |
}
|
211 |
244 |
|
212 |
245 |
/* open csv file */
|
213 |
246 |
$f=fopen($file.'.csv',"r");
|
... | ... | |
217 |
250 |
*/
|
218 |
251 |
if ($show) {
|
219 |
252 |
show('<tr>',false);
|
220 |
|
show("partnumber"); show("lastcost"); show("sellprice");
|
|
253 |
show("partnumber"); show("lastcost"); show("sellprice"); show("listprice");
|
221 |
254 |
show("description");show("notes"); show("ean");
|
222 |
255 |
show("weight"); show("image"); show("partsgroup_id");
|
223 |
256 |
show("bg"); show("income_accno"); show("expense_accno");
|
... | ... | |
264 |
297 |
|
265 |
298 |
/* VK-Preis bilden */
|
266 |
299 |
$sellprice = str_replace(",", ".", $zeile[$fldpos["sellprice"]]);
|
|
300 |
$listprice = str_replace(",", ".", $zeile[$fldpos["listprice"]]);
|
267 |
301 |
$lastcost = str_replace(",", ".", $zeile[$fldpos["lastcost"]]);
|
|
302 |
if ($prices) {
|
|
303 |
foreach ($prices as $pkey=>$val) {
|
|
304 |
$pricegroup[$val] = str_replace(",", ".", $zeile[$fldpos[$pkey]]);
|
|
305 |
}
|
|
306 |
}
|
268 |
307 |
if ($quotation<>0) {
|
269 |
308 |
if ($quottype=="A") { $sellprice += $quotation; }
|
270 |
309 |
else { $sellprice = $sellprice * $quotation; }
|
271 |
310 |
};
|
272 |
311 |
if ($lastcost=="") unset($lastcost);
|
273 |
312 |
if ($sellprice=="") unset($sellprice);
|
|
313 |
if ($listprice=="") unset($listprice);
|
274 |
314 |
|
275 |
315 |
/* Langtext zusammenbauen */
|
276 |
316 |
if ($zeile[$fldpos["notes"]]) {
|
... | ... | |
283 |
323 |
//Kundenspezifisch:
|
284 |
324 |
//$notes1 = preg_replace('/""[^ ]/','"',$zeile[$fldpos["notes1"]]);
|
285 |
325 |
$notes1 = addslashes($zeile[$fldpos["notes1"]]);
|
286 |
|
echo "!".$notes1."!<br>";
|
287 |
326 |
if (Translate) translate($notes1);
|
288 |
|
echo "!".$notes1."!<br>";
|
289 |
327 |
if ($notes) {
|
290 |
328 |
$notes .= "\n".$notes1;
|
291 |
329 |
} else {
|
... | ... | |
402 |
440 |
} else {
|
403 |
441 |
$shop = $maske["shop"];
|
404 |
442 |
}
|
405 |
|
|
406 |
443 |
// Artikel updaten
|
407 |
444 |
|
408 |
445 |
if (getPartsid($db,trim($zeile[$fldpos["partnumber"]]))) {
|
... | ... | |
410 |
447 |
if ($Update) {
|
411 |
448 |
/* Updates durchf?hren */
|
412 |
449 |
if ($UpdText=='1') {
|
413 |
|
$u += updParts($db,$insert,$show,$zeile[$fldpos["partnumber"]],$lastcost,$sellprice,
|
|
450 |
$u += updParts($db,$insert,$show,$zeile[$fldpos["partnumber"]],$lastcost,$sellprice,$listprice,
|
414 |
451 |
$description,$notes,$zeile[$fldpos["ean"]],$weight,
|
415 |
|
$zeile[$fldpos["image"]],$partsgroup_id, $shop);
|
|
452 |
$zeile[$fldpos["image"]],$partsgroup_id,$pricegroup, $shop);
|
416 |
453 |
} else {
|
417 |
|
$u += updPrice($db,$insert,$show,$zeile[$fldpos["partnumber"]],$lastcost,$sellprice,$shop);
|
|
454 |
$u += updPrice($db,$insert,$show,$zeile[$fldpos["partnumber"]],$lastcost,$sellprice,$listprice,$pricegroup,$shop);
|
418 |
455 |
}
|
419 |
456 |
continue;
|
420 |
457 |
// n?chste Zeile
|
... | ... | |
435 |
472 |
"description"=>$description,"notes"=>$notes,
|
436 |
473 |
"ean"=>$zeile[$fldpos["ean"]],"unit"=>$unit,
|
437 |
474 |
"weight"=>$weight,"image"=>$zeile[$fldpos["image"]],
|
438 |
|
"sellprice"=>$sellprice,"lastcost"=>$lastcost,
|
|
475 |
"sellprice"=>$sellprice,"lastcost"=>$lastcost,"listprice"=>$listprice,
|
439 |
476 |
"partsgroup_id"=>$partsgroup_id,
|
440 |
477 |
"buchungsgruppen_id"=>$bg,"income_accno"=>$income_accno,
|
441 |
478 |
"expense_accno"=>$expense_accno,"inventory_accno"=>$inventory_accno,
|
442 |
479 |
"microfiche"=>$zeile[$fldpos["microfiche"]],"drawing"=>$zeile[$fldpos["drawing"]],
|
443 |
480 |
"rop"=>$rop,"assembly"=>$assembly,
|
444 |
|
"shop"=>$shop,"makemodel"=>$makemodel)
|
|
481 |
"shop"=>$shop,"makemodel"=>$makemodel),$pricegroup
|
445 |
482 |
);
|
446 |
483 |
if ($hersteller>0 && $model) {
|
447 |
484 |
$partsid=getPartsid($db,$zeile[$fldpos["partnumber"]]);
|
Preisgruppen Import, Listpeis, MicroFich, Drawing