forked from timschofield/webERP
-
Notifications
You must be signed in to change notification settings - Fork 89
/
BOMInquiry.php
245 lines (212 loc) · 8.13 KB
/
BOMInquiry.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
include('includes/session.php');
$Title = _('Costed Bill Of Material');
include('includes/header.php');
if (isset($_GET['StockID'])){
$StockID =trim(mb_strtoupper($_GET['StockID']));
} elseif (isset($_POST['StockID'])){
$StockID =trim(mb_strtoupper($_POST['StockID']));
}
if (!isset($_POST['StockID'])) {
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">
<div>
<br />
<div class="page_help_text">
'. _('Select a manufactured part') . ' (' . _('or Assembly or Kit part') . ') ' . _('to view the costed bill of materials') . '
<br />' . _('Parts must be defined in the stock item entry') . '/' . _('modification screen as manufactured') . ', ' . _('kits or assemblies to be available for construction of a bill of material') . '
</div>
<br />
<table class="selection">
<tr>
<td>' . _('Enter text extracts in the') . ' <b>' . _('description') . '</b>:</td>
<td><input tabindex="1" type="text" autofocus="autofocus" name="Keywords" size="20" maxlength="25" /></td>
<td><b>' . _('OR') . '</b></td>
<td>' . _('Enter extract of the') . ' <b>' . _('Stock Code') . '</b>:</td>
<td><input tabindex="2" type="text" name="StockCode" size="15" maxlength="20" /></td>
</tr>
</table>
<br />
<div class="centre">
<input tabindex="3" type="submit" name="Search" value="' . _('Search Now') . '" />
</div>
<br />
<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
}
if (isset($_POST['Search'])){
// Work around to auto select
if ($_POST['Keywords']=='' AND $_POST['StockCode']=='') {
$_POST['StockCode']='%';
}
if ($_POST['Keywords'] AND $_POST['StockCode']) {
prnMsg( _('Stock description keywords have been used in preference to the Stock code extract entered'), 'info' );
}
if ($_POST['Keywords']=='' AND $_POST['StockCode']=='') {
prnMsg( _('At least one stock description keyword or an extract of a stock code must be entered for the search'), 'info' );
} else {
if (mb_strlen($_POST['Keywords'])>0) {
//insert wildcard characters in spaces
$SearchString = '%' . str_replace(' ', '%', $_POST['Keywords']) . '%';
$sql = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units,
stockmaster.mbflag,
SUM(locstock.quantity) as totalonhand
FROM stockmaster INNER JOIN locstock
ON stockmaster.stockid = locstock.stockid
WHERE stockmaster.description " . LIKE . "'" . $SearchString . "'
AND (stockmaster.mbflag='M'
OR stockmaster.mbflag='K'
OR stockmaster.mbflag='A'
OR stockmaster.mbflag='G')
GROUP BY stockmaster.stockid,
stockmaster.description,
stockmaster.units,
stockmaster.mbflag
ORDER BY stockmaster.stockid";
} elseif (mb_strlen($_POST['StockCode'])>0){
$sql = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units,
stockmaster.mbflag,
sum(locstock.quantity) as totalonhand
FROM stockmaster INNER JOIN locstock
ON stockmaster.stockid = locstock.stockid
WHERE stockmaster.stockid " . LIKE . "'%" . $_POST['StockCode'] . "%'
AND (stockmaster.mbflag='M'
OR stockmaster.mbflag='K'
OR stockmaster.mbflag='G'
OR stockmaster.mbflag='A')
GROUP BY stockmaster.stockid,
stockmaster.description,
stockmaster.units,
stockmaster.mbflag
ORDER BY stockmaster.stockid";
}
$ErrMsg = _('The SQL to find the parts selected failed with the message');
$result = DB_query($sql,$ErrMsg);
} //one of keywords or StockCode was more than a zero length string
} //end of if search
if (isset($_POST['Search'])
AND isset($result)
AND !isset($SelectedParent)) {
echo '<br />
<table class="selection">';
$TableHeader = '<tr>
<th>' . _('Code') . '</th>
<th>' . _('Description') . '</th>
<th>' . _('On Hand') . '</th>
<th>' . _('Units') . '</th>
</tr>';
echo $TableHeader;
$j = 1;
while ($myrow=DB_fetch_array($result)) {
if ($myrow['mbflag']=='A' OR $myrow['mbflag']=='K'){
$StockOnHand = 'N/A';
} else {
$StockOnHand = locale_number_format($myrow['totalonhand'],2);
}
$tabindex=$j+4;
printf('<tr class="striped_row">
<td><input tabindex="' .$tabindex . '" type="submit" name="StockID" value="%s" /></td>
<td>%s</td>
<td class="number">%s</td>
<td>%s</td>
</tr>',
$myrow['stockid'],
$myrow['description'],
$StockOnHand,
$myrow['units'] );
$j++;
//end of page full new headings if
}
//end of while loop
echo '</table><br />';
}
if (!isset($_POST['StockID'])) {
echo '</div>
</form>';
}
if (isset($StockID) and $StockID!=""){
$result = DB_query("SELECT description,
units,
labourcost,
overheadcost
FROM stockmaster
WHERE stockid='" . $StockID . "'");
$myrow = DB_fetch_array($result);
$ParentLabourCost = $myrow['labourcost'];
$ParentOverheadCost = $myrow['overheadcost'];
$sql = "SELECT bom.parent,
bom.component,
stockmaster.description,
stockmaster.decimalplaces,
stockmaster.materialcost+ stockmaster.labourcost+stockmaster.overheadcost as standardcost,
bom.quantity,
bom.quantity * (stockmaster.materialcost+ stockmaster.labourcost+ stockmaster.overheadcost) AS componentcost
FROM bom INNER JOIN stockmaster
ON bom.component = stockmaster.stockid
WHERE bom.parent = '" . $StockID . "'
AND bom.effectiveafter <= '" . date('Y-m-d') . "'
AND bom.effectiveto > '" . date('Y-m-d') . "'";
$ErrMsg = _('The bill of material could not be retrieved because');
$BOMResult = DB_query ($sql,$ErrMsg);
if (DB_num_rows($BOMResult)==0){
prnMsg(_('The bill of material for this part is not set up') . ' - ' . _('there are no components defined for it'),'warn');
} else {
echo '<a href="'.$RootPath.'/index.php">' . _('Return to Main Menu') . '</a>';
echo '<p class="page_title_text">
<img src="'.$RootPath.'/css/'.$Theme.'/images/maintenance.png" title="' . _('Search') . '" alt="" />' . ' ' . $Title.'
</p>
<br />';
echo '<table class="selection">';
echo '<tr>
<th colspan="5">
<div class="centre"><b>' . $myrow[0] . ' : ' . _('per') . ' ' . $myrow[1] . '</b>
</div></th>
</tr>';
$TableHeader = '<tr>
<th>' . _('Component') . '</th>
<th>' . _('Description') . '</th>
<th>' . _('Quantity') . '</th>
<th>' . _('Unit Cost') . '</th>
<th>' . _('Total Cost') . '</th>
</tr>';
echo $TableHeader;
$j = 1;
$TotalCost = 0;
while ($myrow=DB_fetch_array($BOMResult)) {
$ComponentLink = '<a href="' . $RootPath . '/SelectProduct.php?StockID=' . $myrow['component'] . '">' . $myrow['component'] . '</a>';
/* Component Code Description Quantity Std Cost Total Cost */
printf('<tr class="striped_row">
<td>%s</td>
<td>%s</td>
<td class="number">%s</td>
<td class="number">%s</td>
<td class="number">%s</td>
</tr>',
$ComponentLink,
$myrow['description'],
locale_number_format($myrow['quantity'],$myrow['decimalplaces']),
locale_number_format($myrow['standardcost'],$_SESSION['CompanyRecord']['decimalplaces'] + 2),
locale_number_format($myrow['componentcost'],$_SESSION['CompanyRecord']['decimalplaces'] + 2));
$TotalCost += $myrow['componentcost'];
$j++;
}
$TotalCost += $ParentLabourCost;
echo '<tr>
<td colspan="4" class="number"><b>' . _('Labour Cost') . '</b></td>
<td class="number"><b>' . locale_number_format($ParentLabourCost,$_SESSION['CompanyRecord']['decimalplaces']) . '</b></td></tr>';
$TotalCost += $ParentOverheadCost;
echo '<tr><td colspan="4" class="number"><b>' . _('Overhead Cost') . '</b></td>
<td class="number"><b>' . locale_number_format($ParentOverheadCost,$_SESSION['CompanyRecord']['decimalplaces']) . '</b></td></tr>';
echo '<tr>
<td colspan="4" class="number"><b>' . _('Total Cost') . '</b></td>
<td class="number"><b>' . locale_number_format($TotalCost,$_SESSION['CompanyRecord']['decimalplaces']) . '</b></td>
</tr>';
echo '</table>';
}
} else { //no stock item entered
prnMsg(_('Enter a stock item code above') . ', ' . _('to view the costed bill of material for'),'info');
}
include('includes/footer.php');
?>