forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CopyBOM.php
210 lines (188 loc) · 5.56 KB
/
CopyBOM.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/**
* Author: Ashish Shukla <gmail.com!wahjava>
*
* Script to duplicate BoMs.
*/
include('includes/session.php');
$Title = _('Copy a BOM to New Item Code');
include('includes/header.php');
include('includes/SQL_CommonFunctions.inc');
if(isset($_POST['Submit'])) {
$StockID = $_POST['StockID'];
$NewOrExisting = $_POST['NewOrExisting'];
$NewStockID = '';
$InputError = 0; //assume the best
if($NewOrExisting == 'N') {
$NewStockID = $_POST['ToStockID'];
if (mb_strlen($NewStockID)==0 OR $NewStockID==''){
$InputError = 1;
prnMsg(_('The new item code cannot be blank. Enter a new code for the item to copy the BOM to'),'error');
}
} else {
$NewStockID = $_POST['ExStockID'];
}
if ($InputError==0){
$result = DB_Txn_Begin();
if($NewOrExisting == 'N') {
/* duplicate rows into stockmaster */
$sql = "INSERT INTO stockmaster( stockid,
categoryid,
description,
longdescription,
units,
mbflag,
actualcost,
lastcost,
materialcost,
labourcost,
overheadcost,
lowestlevel,
discontinued,
controlled,
eoq,
volume,
grossweight,
barcode,
discountcategory,
taxcatid,
serialised,
perishable,
digitals,
nextserialno,
pansize,
shrinkfactor,
netweight )
SELECT '".$NewStockID."' AS stockid,
categoryid,
description,
longdescription,
units,
mbflag,
actualcost,
lastcost,
materialcost,
labourcost,
overheadcost,
lowestlevel,
discontinued,
controlled,
eoq,
volume,
grossweight,
barcode,
discountcategory,
taxcatid,
serialised,
perishable,
digitals,
nextserialno,
pansize,
shrinkfactor,
netweight
FROM stockmaster
WHERE stockid='".$StockID."';";
$result = DB_query($sql);
} else {
$sql = "SELECT lastcostupdate,
actualcost,
lastcost,
materialcost,
labourcost,
overheadcost,
lowestlevel
FROM stockmaster
WHERE stockid='".$StockID."';";
$result = DB_query($sql);
$myrow = DB_fetch_row($result);
$sql = "UPDATE stockmaster set
lastcostupdate = '" . $myrow[0] . "',
actualcost = " . $myrow[1] . ",
lastcost = " . $myrow[2] . ",
materialcost = " . $myrow[3] . ",
labourcost = " . $myrow[4] . ",
overheadcost = " . $myrow[5] . ",
lowestlevel = " . $myrow[6] . "
WHERE stockid='".$NewStockID."';";
$result = DB_query($sql);
}
$sql = "INSERT INTO bom
SELECT '".$NewStockID."' AS parent,
sequence,
component,
workcentreadded,
loccode,
effectiveafter,
effectiveto,
quantity,
autoissue,
remark,
digitals
FROM bom
WHERE parent='".$StockID."';";
$result = DB_query($sql);
if($NewOrExisting == 'N') {
$sql = "INSERT INTO locstock (loccode,
stockid,
quantity,
reorderlevel,
bin )
SELECT loccode,
'".$NewStockID."' AS stockid,
0 AS quantity,
reorderlevel,
bin
FROM locstock
WHERE stockid='".$StockID."'";
$result = DB_query($sql);
}
$result = DB_Txn_Commit();
UpdateCost($NewStockID);
header('Location: BOMs.php?Select='.$NewStockID);
ob_end_flush();
} //end if there is no input error
} else {
echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/inventory.png" title="' . _('Contract') . '" alt="" />' . ' ' . $Title . '</p>';
echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
$sql = "SELECT stockid,
description
FROM stockmaster
WHERE stockid IN (SELECT DISTINCT parent FROM bom)
AND mbflag IN ('M', 'A', 'K', 'G');";
$result = DB_query($sql);
echo '<table class="selection">
<tr>
<td>' . _('From Stock ID') . '</td>';
echo '<td><select name="StockID">';
while($myrow = DB_fetch_row($result)) {
echo '<option value="'.$myrow[0].'">' . $myrow[0].' -- '.$myrow[1] . '</option>';
}
echo '</select></td>
</tr>';
echo '<tr>
<td><input type="radio" name="NewOrExisting" value="N" />' . _(' To New Stock ID') . '</td>';
echo '<td><input type="text" maxlength="20" autofocus="autofocus" pattern="[a-zA-Z0-9_\-]*" name="ToStockID" title="' . _('Enter a new item code to copy the existing item and its bill of material to. Item codes can contain only alpha-numeric characters, underscore or hyphens.') . '" /></td></tr>';
$sql = "SELECT stockid,
description
FROM stockmaster
WHERE stockid NOT IN (SELECT DISTINCT parent FROM bom)
AND mbflag IN ('M', 'A', 'K', 'G');";
$result = DB_query($sql);
if (DB_num_rows($result) > 0) {
echo '<tr>
<td><input type="radio" name="NewOrExisting" checked="checked" value="E" />' . _('To Existing Stock ID') . '</td><td>';
echo '<select name="ExStockID">';
while($myrow = DB_fetch_row($result)) {
echo '<option value="'.$myrow[0].'">' . $myrow[0].' -- '.$myrow[1] . '</option>';
}
echo '</select></td></tr>';
}
echo '</table>';
echo '<br /><div class="centre"><input type="submit" name="Submit" value="Submit" /></div>
</div>
</form>';
include('includes/footer.php');
}
?>