-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathpartsedit.php
145 lines (143 loc) · 6.43 KB
/
partsedit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
require_once("inc/stdLib.php");
require_once('inc/wvLib.php');
$menu = $_SESSION['menu'];
$head = mkHeader();
?>
<html>
<head><title>LX - CRM - Partsedit</title>
<?php
echo $menu['stylesheets'];
echo $menu['javascripts'];
echo $head['CRMCSS'];
echo $head['JQUERY'];
echo $head['JQUERYUI'];
echo $head['THEME'];
?>
</head>
<body>
<?php
echo $menu['pre_content'];
echo $menu['start_content'];
if ( isset( $_POST["sichern"] ) ) {
$sql = "SELECT * FROM pricegroup ORDER by id";
$prgr = $GLOBALS['dbh']->getAll($sql);
$sqlparts = "UPDATE parts SET partnumber = '%s', description = '%s', lastcost = %0.5f, listprice = %0.5f, sellprice = %0.5f WHERE id = %d";
$chkparts = "SELECT id FROM parts WHERE partnumber = '%s'";
$delprice = "DELETE FROM prices WHERE parts_id = %d";
$insprice = "INSERT INTO prices (parts_id,pricegroup_id,price) VALUES (%d,%d,%0.5f)";
if ($_POST) while( list($key,$val) = each( $_POST['partnumber'] ) ) {
$ok = true;
if ( $_POST['oldpnr'][$key] != $val ) {
$rs = $GLOBALS['dbh']->getAll(sprintf($chkparts,$val));
if ( count($rs) > 0 ) {
echo "$val doppelt <br>";
$ok = false;
}
}
if ( $ok ) {
echo "$key ";
$sql = sprintf($sqlparts,$val,$_POST['description'][$key],
strtr($_POST['lastcost'][$key] ,",","."),
strtr($_POST['listprice'][$key],",","."),
strtr($_POST['sellprice'][$key],",","."),$key);
$rc = $GLOBALS['dbh']->myquery($sql);
if ( $rc and $prgr ) {
$rc = $GLOBALS['dbh']->begin();
$rc = $GLOBALS['dbh']->myquery(sprintf($delprice,$key));
foreach( $prgr as $price ) {
if ( $_POST[$price['id']][$key] ) {
$rc = $GLOBALS['dbh']->myquery(sprintf($insprice,$key,$price['id'],strtr($_POST[$price['id']][$key],",",".") ) );
if ( !$rc ) {
$GLOBALS['dbh']->rollback();
echo "Error Preisgruppe (".$price['pricegroup'].")<br>";
break;
}
}
}
$GLOBALS['dbh']->commit();
echo "update ok<br>";
};
};
};
};
if ( isset( $_POST["such"] ) ) {
$where = array('1=1');
$sql = "SELECT P.id as pid,P.partnumber,P.description,P.lastcost,P.listprice,P.sellprice,";
$sql .= "PC.pricegroup_id,PC.price,PC.id FROM parts P left join prices PC on P.id=PC.parts_id WHERE ";
if ( isset($_POST['partnumber'] ) and $_POST['partnumber'] != '' ) $where[] = "partnumber ilike '".strtr($_POST['partnumber'],"*?","%_")."'";
if ( isset($_POST['description'] ) and $_POST['description'] != '' ) $where[] = "description ilike '".strtr($_POST['description'],"*?","%_")."%'";
if ( isset($_POST['partsgroup_id'] ) and $_POST['partsgroup_id'] != '' ) $where[] = "partsgroup_id = ".$_POST['partsgroup_id'];
$sql .= implode(' and ',$where)." ORDER BY P.partnumber,PC.pricegroup_id";
$rs = $GLOBALS['dbh']->getAll($sql);
$lastid = 0;
if ( $rs ) {
$sql = "SELECT * FROM pricegroup ORDER by id";
$prgr = $GLOBALS['dbh']->getAll($sql);
$prices = array();
if ( $prgr ) foreach ($prgr as $row ) { $prices[$row['id']] = '';};
foreach ( $rs as $row ) {
if ( $lastid != $row['pid'] ) {
//$parts[$row['pid']] = array_merge(array_slice($row,0,6),$prices);
//tut nicht wie es soll. Keine Ahnung warum.
$parts[$row['pid']] = array_slice($row,0,6);
if ( $prgr ) foreach ($prgr as $price ) { $parts[$row['pid']][$price['id']] = '';};
if ( $row['pricegroup_id'] ) $parts[$row['pid']][$row['pricegroup_id']] = $row['price'];
$lastid = $row['pid'];
} else {
$parts[$lastid][$row['pricegroup_id']] = $row['price'];
}
};
}
};
$partsgrp=getAllPG();
?>
<form name="parts" method="post" action="partsedit.php">
<?php
if ( $parts ) {
echo "<table>";
echo "<tr><td>ID</td><td>ArtNr</td><td>Artikel</td><td>EK</td><td>Liste</td><td>VK</td>";
$cnt = count($parts[0]);
if ( $prgr ) foreach($prgr as $cell) { echo "<td>".$cell['pricegroup']."</td>"; };
echo "</tr>\n";
foreach ($parts as $row) {
echo '<tr><td>'.$row['pid'].'</td>';
$pid = $row['pid'];
unset($row['pid']);
echo '<input type="hidden" name="oldpnr['.$pid.']" value="'.$row['partnumber'].'" size="35">';
while(list($key,$val) = each($row)) {
if ( $key == 'description' ) {
echo '<td><input type="text" name="'.$key.'['.$pid.']" value="'.$val.'" size="35"></td>';
} else {
echo '<td><input type="text" name="'.$key.'['.$pid.']" value="'.$val.'" size="10"></td>';
}
};
echo "</tr>\n";
};
echo "</table>\n";
echo "<input type='submit' name='sichern' value='sichern'><br>";
echo "<br><a href='partsedit.php'>neue Suche</a>";
} else {
?>
<form name="artikel" method="post" action="partsedit.php">
<table class="karte" width="100%">
<tr><td>Artikelnummer</td>
<td><input type="text" name="partnumber" value=""></td></tr>
<tr><td>Artikel:</td>
<td><input type="text" name="description" value="" size="30"></td></tr>
<tr><td>Warengruppe:</td>
<td>
<select name="partsgroup_id" Style="width:450px" >
<option value=''>Artikel ohne Warengruppe</option>
<?php
if ($partsgrp) foreach ($partsgrp as $zeile) {
echo "\t<option value='".$zeile["id"]."'>".$zeile["partsgroup"]."</option>\n";
}
?>
</select>
</td></tr>
<tr><td><input type="submit" name="such" value="suchen" ></td><td></td></tr>
</table>
<?php }; echo "</form>"; echo $menu['end_content']; ?>
</body>
</html>