forked from timschofield/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStockLocStatus.php
253 lines (224 loc) · 10.9 KB
/
StockLocStatus.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
246
247
248
249
250
251
252
253
<?php
/* Shows the stock on hand together with outstanding sales orders and outstanding purchase orders by stock location for all items in the selected stock category */
include('includes/session.php');
$Title = _('All Stock Status By Location/Category');
$ViewTopic = 'Inventory';
$BookMark = 'StockLocStatus';
include('includes/header.php');
echo '<p class="page_title_text"><img alt="" src="', $RootPath, '/css/', $Theme,
'/images/magnifier.png" title="',// Icon image.
$Title, '" /> ',// Icon title.
$Title, '</p>';// Page title.
include ('includes/SQL_CommonFunctions.inc');
include('includes/StockFunctions.php');
if(isset($_GET['StockID'])) {
$StockID = trim(mb_strtoupper($_GET['StockID']));
} elseif(isset($_POST['StockID'])) {
$StockID = trim(mb_strtoupper($_POST['StockID']));
}
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
$SQL = "SELECT locations.loccode, locationname
FROM locations
INNER JOIN locationusers ON locationusers.loccode=locations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1";
$ResultStkLocs = DB_query($SQL);
echo '<fieldset>
<legend>', _('Inquiry Criteria'), '</legend>
<field>
<label for="StockLocation">' . _('From Stock Location') . ':</label>
<select name="StockLocation"> ';
while($MyRow=DB_fetch_array($ResultStkLocs)) {
if(isset($_POST['StockLocation']) AND $_POST['StockLocation']!='All') {
if($MyRow['loccode'] == $_POST['StockLocation']) {
echo '<option selected="selected" value="' . $MyRow['loccode'] . '">' . $MyRow['locationname'] . '</option>';
} else {
echo '<option value="' . $MyRow['loccode'] . '">' . $MyRow['locationname'] . '</option>';
}
} elseif($MyRow['loccode']==$_SESSION['UserStockLocation']) {
echo '<option selected="selected" value="' . $MyRow['loccode'] . '">' . $MyRow['locationname'] . '</option>';
$_POST['StockLocation']=$MyRow['loccode'];
} else {
echo '<option value="' . $MyRow['loccode'] . '">' . $MyRow['locationname'] . '</option>';
}
}
echo '</select>
</field>';
$SQL="SELECT categoryid,
categorydescription
FROM stockcategory
ORDER BY categorydescription";
$Result1 = DB_query($SQL);
if(DB_num_rows($Result1)==0) {
echo '</table><p>';
prnMsg(_('There are no stock categories currently defined please use the link below to set them up'),'warn');
echo '<br /><a href="' . $RootPath . '/StockCategories.php">' . _('Define Stock Categories') . '</a>';
include ('includes/footer.php');
exit;
}
echo '<field>
<label for="StockCat">' . _('In Stock Category') . ':</label>
<select name="StockCat">';
if(!isset($_POST['StockCat'])) {
$_POST['StockCat']='All';
}
if($_POST['StockCat']=='All') {
echo '<option selected="selected" value="All">' . _('All') . '</option>';
} else {
echo '<option value="All">' . _('All') . '</option>';
}
while($MyRow1 = DB_fetch_array($Result1)) {
if($MyRow1['categoryid']==$_POST['StockCat']) {
echo '<option selected="selected" value="' . $MyRow1['categoryid'] . '">' . $MyRow1['categorydescription'] . '</option>';
} else {
echo '<option value="' . $MyRow1['categoryid'] . '">' . $MyRow1['categorydescription'] . '</option>';
}
}
echo '</select>
</field>';
echo '<field>
<label for="BelowReorderQuantity">' . _('Shown Only Items Where') . ':</label>
<select name="BelowReorderQuantity">';
if(!isset($_POST['BelowReorderQuantity'])) {
$_POST['BelowReorderQuantity']='All';
}
if($_POST['BelowReorderQuantity']=='All') {
echo '<option selected="selected" value="All">' . _('All') . '</option>
<option value="Below">' . _('Only items below re-order quantity') . '</option>
<option value="NotZero">' . _('Only items where stock is available') . '</option>
<option value="OnOrder">' . _('Only items currently on order') . '</option>';
} else if($_POST['BelowReorderQuantity']=='Below') {
echo '<option value="All">' . _('All') . '</option>
<option selected="selected" value="Below">' . _('Only items below re-order quantity') . '</option>
<option value="NotZero">' . _('Only items where stock is available') . '</option>
<option value="OnOrder">' . _('Only items currently on order') . '</option>';
} else if($_POST['BelowReorderQuantity']=='OnOrder') {
echo '<option value="All">' . _('All') . '</option>
<option value="Below">' . _('Only items below re-order quantity') . '</option>
<option value="NotZero">' . _('Only items where stock is available') . '</option>
<option selected="selected" value="OnOrder">' . _('Only items currently on order') . '</option>';
} else {
echo '<option value="All">' . _('All') . '</option>
<option value="Below">' . _('Only items below re-order quantity') . '</option>
<option selected="selected" value="NotZero">' . _('Only items where stock is available') . '</option>
<option value="OnOrder">' . _('Only items currently on order') . '</option>';
}
echo '</select>
</field>
</fieldset>';
echo '<div class="centre noPrint">
<input name="ShowStatus" type="submit" value="', _('Show Stock Status'), '" />
</div>';
if(isset($_POST['ShowStatus'])) {
if($_POST['StockCat']=='All') {
$SQL = "SELECT locstock.stockid,
stockmaster.description,
locstock.loccode,
locstock.bin,
locations.locationname,
locstock.quantity,
locstock.reorderlevel,
stockmaster.decimalplaces,
stockmaster.serialised,
stockmaster.controlled
FROM locstock,
stockmaster,
locations
WHERE locstock.stockid=stockmaster.stockid
AND locstock.loccode = '".$_POST['StockLocation']."'
AND locstock.loccode=locations.loccode
AND (stockmaster.mbflag='B' OR stockmaster.mbflag='M')
ORDER BY locstock.stockid";
} else {
$SQL = "SELECT locstock.stockid,
stockmaster.description,
locstock.loccode,
locstock.bin,
locations.locationname,
locstock.quantity,
locstock.reorderlevel,
stockmaster.decimalplaces,
stockmaster.serialised,
stockmaster.controlled
FROM locstock,
stockmaster,
locations
WHERE locstock.stockid=stockmaster.stockid
AND locstock.loccode = '" . $_POST['StockLocation'] . "'
AND locstock.loccode=locations.loccode
AND (stockmaster.mbflag='B' OR stockmaster.mbflag='M')
AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
ORDER BY locstock.stockid";
}
$ErrMsg = _('The stock held at each location cannot be retrieved because');
$DbgMsg = _('The SQL that failed was');
$LocStockResult = DB_query($SQL, $ErrMsg, $DbgMsg);
echo '<table cellpadding="5" cellspacing="4" class="selection">
<thead>
<tr>
<th colspan="9">', DisplayDateTime(), '</th>
</tr>
<tr>
<th class="SortedColumn">', _('StockID'), '</th>
<th class="SortedColumn">', _('Description'), '</th>
<th class="SortedColumn">', _('Quantity On Hand'), '</th>
<th class="SortedColumn">', _('Bin Loc'), '</th>
<th class="SortedColumn">', _('Re-Order Level'), '</th>
<th class="SortedColumn">', _('Demand'), '</th>
<th class="SortedColumn">', _('Available'), '</th>
<th class="SortedColumn">', _('On Order'), '</th>
<th class="SortedColumn">', _('Controlled'), '</th>
</tr>
</thead>
<tbody>';
while($MyRow=DB_fetch_array($LocStockResult)) {
$StockID = $MyRow['stockid'];
// get the demand for the item at the location
$DemandQty = GetDemand($StockID, $MyRow['loccode']);
// Get the QOO
$QOO = GetQuantityOnOrder($StockID, $MyRow['loccode']);
if(($_POST['BelowReorderQuantity']=='Below' AND ($MyRow['quantity']-$MyRow['reorderlevel']-$DemandQty)<0)
OR $_POST['BelowReorderQuantity']=='All' OR $_POST['BelowReorderQuantity']=='NotZero'
OR ($_POST['BelowReorderQuantity']=='OnOrder' AND $QOO != 0)) {
if(($_POST['BelowReorderQuantity']=='NotZero') AND (($MyRow['quantity']-$DemandQty)>0)) {
echo '<tr class="striped_row">
<td><a target="_blank" href="' . $RootPath . '/StockStatus.php?StockID=', mb_strtoupper($MyRow['stockid']), '">', mb_strtoupper($MyRow['stockid']), '</a></td>
<td class="text">', $MyRow['description'], '</td>
<td class="number">', locale_number_format($MyRow['quantity'],$MyRow['decimalplaces']), '</td>
<td>', $MyRow['bin'], '</td>
<td class="number">', locale_number_format($MyRow['reorderlevel'],$MyRow['decimalplaces']), '</td>
<td class="number">', locale_number_format($DemandQty,$MyRow['decimalplaces']), '</td>
<td class="number"><a target="_blank" href="' . $RootPath . '/SelectProduct.php?StockID=', mb_strtoupper($MyRow['stockid']), '">', locale_number_format($MyRow['quantity'] - $DemandQty,$MyRow['decimalplaces']), '</a></td>
<td class="number">', locale_number_format($QOO,$MyRow['decimalplaces']), '</td>';
if($MyRow['serialised'] ==1) { /*The line is a serialised item*/
echo '<td><a target="_blank" href="' . $RootPath . '/StockSerialItems.php?Serialised=Yes&Location=' . $MyRow['loccode'] . '&StockID=' . $StockID . '">' . _('Serial Numbers') . '</a></td></tr>';
} elseif($MyRow['controlled']==1) {
echo '<td><a target="_blank" href="' . $RootPath . '/StockSerialItems.php?Location=' . $MyRow['loccode'] . '&StockID=' . $StockID . '">' . _('Batches') . '</a></td></tr>';
} else {
echo '<td>' . _('Not Controlled') . '</td></tr>';
}
} else if($_POST['BelowReorderQuantity']!='NotZero') {
echo '<tr class="striped_row">
<td><a target="_blank" href="' . $RootPath . '/StockStatus.php?StockID=', mb_strtoupper($MyRow['stockid']), '">', mb_strtoupper($MyRow['stockid']), '</a></td>
<td>', $MyRow['description'], '</td>
<td class="number">', locale_number_format($MyRow['quantity'],$MyRow['decimalplaces']), '</td>
<td>', $MyRow['bin'], '</td>
<td class="number">', locale_number_format($MyRow['reorderlevel'],$MyRow['decimalplaces']), '</td>
<td class="number">', locale_number_format($DemandQty,$MyRow['decimalplaces']), '</td>
<td class="number"><a target="_blank" href="' . $RootPath . '/SelectProduct.php?StockID=', mb_strtoupper($MyRow['stockid']), '">', locale_number_format($MyRow['quantity'] - $DemandQty,$MyRow['decimalplaces']), '</a></td>
<td class="number">', locale_number_format($QOO,$MyRow['decimalplaces']), '</td>';
if($MyRow['serialised'] ==1) { /*The line is a serialised item*/
echo '<td><a target="_blank" href="' . $RootPath . '/StockSerialItems.php?Serialised=Yes&Location=' . $MyRow['loccode'] . '&StockID=' . $StockID . '">' . _('Serial Numbers') . '</a></td></tr>';
} elseif($MyRow['controlled']==1) {
echo '<td><a target="_blank" href="' . $RootPath . '/StockSerialItems.php?Location=' . $MyRow['loccode'] . '&StockID=' . $StockID . '">' . _('Batches') . '</a></td></tr>';
} else {
echo '<td>' . _('Not Controlled') . '</td></tr>';
}
} //end of page full new headings if
} //end of if BelowOrderQuantity or all items
}
//end of while loop
echo '</tbody></table>';
} /* Show status button hit */
echo '</form>';
include('includes/footer.php');
?>