-
Notifications
You must be signed in to change notification settings - Fork 3
/
CopyBOM.php
168 lines (146 loc) · 4.12 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
<?php
/**
* Author: Ashish Shukla <gmail.com!wahjava>
*
* Script to duplicate BoMs.
*/
/* $Id$*/
$title = _('Copy a BOM to New Item Code');
include('includes/session.inc');
include('includes/header.inc');
include('includes/SQL_CommonFunctions.inc');
if(isset($_POST['Submit'])) {
$stkid = $_POST['stkid'];
$type = $_POST['type'];
$newstkid = '';
if($type == 'N') {
$newstkid = $_POST['tostkid'];
} else {
$newstkid = $_POST['exstkid'];
}
$result = DB_query("begin", $db);
if($type == 'N') {
/* duplicate rows into stockmaster */
$sql = "INSERT INTO stockmaster
SELECT '".$newstkid."' AS stockid,
categoryid,
description,
longdescription,
units,
mbflag,
lastcurcostdate,
actualcost,
lastcost,
materialcost,
labourcost,
overheadcost,
lowestlevel,
discontinued,
controlled,
eoq,
volume,
kgs,
barcode,
discountcategory,
taxcatid,
serialised,
appendfile,
perishable,
decimalplaces,
nextserialno,
pansize,
shrinkfactor,
netweight
FROM stockmaster
WHERE stockid='".$stkid."';";
$result = DB_query($sql, $db);
} else {
$sql = "SELECT lastcurcostdate,
actualcost,
lastcost,
materialcost,
labourcost,
overheadcost,
lowestlevel
FROM stockmaster
WHERE stockid='".$stkid."';";
$result = DB_query($sql, $db);
$row = DB_fetch_row($result);
$sql = "UPDATE stockmaster set
lastcurcostdate = '".$row[0]."',
actualcost = ".$row[1].",
lastcost = ".$row[2].",
materialcost = ".$row[3].",
labourcost = ".$row[4].",
overheadcost = ".$row[5].",
lowestlevel = ".$row[6]."
WHERE stockid='".$newstkid."';";
$result = DB_query($sql, $db);
}
$sql = "INSERT INTO bom
SELECT '".$newstkid."' AS parent,
component,
workcentreadded,
loccode,
effectiveafter,
effectiveto,
quantity,
autoissue
FROM bom
WHERE parent='".$stkid."';";
$result = DB_query($sql, $db);
if($type == 'N') {
$sql = "INSERT INTO locstock
SELECT loccode,
'".$newstkid."' AS stockid,
0 AS quantity,
reorderlevel
FROM locstock
WHERE stockid='".$stkid."';";
$result = DB_query($sql, $db);
}
$result = DB_query('commit', $db);
UpdateCost($db, $newstkid);
header('Location: BOMs.php?Select='.$newstkid);
} 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 '<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');";
$result = DB_query($sql, $db);
echo '<table class="selection">
<tr>
<td>' . _('From Stock ID') . '</td>';
echo '<td><select name="stkid">';
while($row = DB_fetch_row($result)) {
echo '<option value="'.$row[0].'">'.$row[0].' -- '.$row[1].'</option>';
}
echo '</select></td>
</tr>';
echo '<tr>
<td><input type="radio" name="type" value="N" checked="" />' . _(' To New Stock ID') . '</td></td><td>';
echo '<input type="text" maxlength="20" name="tostkid" /></td></tr>';
$sql = "SELECT stockid,
description
FROM stockmaster
WHERE stockid NOT IN (SELECT DISTINCT parent FROM bom)
AND mbflag IN ('M', 'A', 'K');";
$result = DB_query($sql, $db);
if (DB_num_rows($result) > 0) {
echo '<tr>
<td><input type="radio" name="type" value="E" />'._('To Existing Stock ID') . '</td><td>';
echo '<select name="exstkid">';
while($row = DB_fetch_row($result)) {
echo '<option value="'.$row[0].'">'.$row[0].' -- '.$row[1].'</option>';
}
echo '</select>';
}
echo '</table>';
echo '<br /><div class="centre"><button type="submit" name="Submit">' , _('Submit') . '</button></div><br /></form>';
include('includes/footer.inc');
}
?>