forked from KwaMoja/KwaMoja
/
ReorderLevelLocation.php
203 lines (170 loc) · 7.17 KB
/
ReorderLevelLocation.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
<?php
// ReorderLevelLocation.php - Report of reorder level by category
include ('includes/session.php');
$Title = _('Reorder Level Location Reporting');
include ('includes/header.php');
echo '<p class="page_title_text">
<img src="', $RootPath, '/css/', $_SESSION['Theme'], '/images/inventory.png" title="', _('Inventory'), '" alt="" />', ' ', _('Inventory Reorder Level Location Report'), '
</p>';
//update database if update pressed
if (isset($_POST['submit'])) {
for ($i = 1;$i < count($_POST);$i++) { //loop through the returned customers
if (isset($_POST['StockID' . $i]) and is_numeric(filter_number_format($_POST['ReorderLevel' . $i]))) {
$SQLUpdate = "UPDATE locstock SET reorderlevel = '" . filter_number_format($_POST['ReorderLevel' . $i]) . "',
bin = '" . strtoupper($_POST['BinLocation' . $i]) . "'
WHERE loccode = '" . $_POST['StockLocation'] . "'
AND stockid = '" . $_POST['StockID' . $i] . "'";
$Result = DB_query($SQLUpdate);
}
}
}
if (isset($_POST['submit']) or isset($_POST['Update'])) {
if ($_POST['NumberOfDays'] == '') {
header('Location: ReorderLevelLocation.php');
}
if ($_POST['Sequence'] == 1) {
$Sequence = "qtyinvoice DESC, locstock.stockid";
} else {
$Sequence = "locstock.stockid";
}
$SQL = "SELECT locstock.stockid,
description,
reorderlevel,
bin,
quantity,
decimalplaces,
canupd
FROM locstock
INNER JOIN stockmaster
ON locstock.stockid = stockmaster.stockid
INNER JOIN locationusers
ON locationusers.loccode=locstock.loccode
AND locationusers.userid='" . $_SESSION['UserID'] . "'
AND locationusers.canview=1
WHERE stockmaster.categoryid = '" . $_POST['StockCat'] . "'
AND locstock.loccode = '" . $_POST['StockLocation'] . "'
AND stockmaster.discontinued = 0
ORDER BY '" . $Sequence . "' ASC";
$Result = DB_query($SQL);
$SqlLoc = "SELECT locationname
FROM locations
WHERE loccode='" . $_POST['StockLocation'] . "'";
$ResultLocation = DB_query($SqlLoc);
$Location = DB_fetch_array($ResultLocation);
echo '<p class="page_title_text">', _('Location : '), '', $Location['locationname'], '</p>';
echo '<p class="page_title_text">', _('Number Of Days Sales : '), '', locale_number_format($_POST['NumberOfDays'], 0), '', _(' Days '), '</p>';
echo '<form action="ReorderLevelLocation.php" method="post" id="Update">';
echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />';
echo '<table>
<tr>
<th>', _('Code'), '</th>
<th>', _('Description'), '</th>
<th>', _('Total Invoiced'), '<br />', _('At Location'), '</th>
<th>', _('On Hand'), '<br />', _('At All Locations'), '</th>
<th>', _('On Hand'), '<br />', _('At Location'), '</th>
<th>', _('Reorder Level'), '</th>
</tr>';
$i = 1;
while ($MyRow = DB_fetch_array($Result)) {
//variable for update data
echo '<input type="hidden" value="', $_POST['Sequence'], '" name="Sequence" />';
echo '<input type="hidden" value="', $_POST['StockLocation'], '" name="StockLocation" />';
echo '<input type="hidden" value="', $_POST['StockCat'], '" name="StockCat" />';
echo '<input type="hidden" value="', locale_number_format($_POST['NumberOfDays'], 0), '" name="NumberOfDays" />';
$SqlInv = "SELECT SUM(-qty) AS qtyinvoiced
FROM stockmoves
WHERE stockid='" . $MyRow['stockid'] . "'
AND (type=10 OR type=11)
AND loccode='" . $_POST['StockLocation'] . "'
AND trandate >= '" . FormatDateForSQL(DateAdd(Date($_SESSION['DefaultDateFormat']), 'd', -filter_number_format($_POST['NumberOfDays']))) . "'";
$ResultInvQty = DB_query($SqlInv);
$SalesRow = DB_fetch_array($ResultInvQty);
//get On Hand all
//find the quantity onhand item
$SqlOH = "SELECT SUM(quantity) AS qty
FROM locstock
INNER JOIN locationusers
ON locationusers.loccode=locstock.loccode
AND locationusers.userid='" . $_SESSION['UserID'] . "'
AND locationusers.canview=1
WHERE stockid='" . $MyRow['stockid'] . "'";
$TotQtyResult = DB_query($SqlOH);
$TotQtyRow = DB_fetch_array($TotQtyResult);
echo '<tr class="striped_row">
<td>', $MyRow['stockid'], '</td>
<td>', $MyRow['description'], '</td>
<td class="number">', locale_number_format($SalesRow['qtyinvoiced'], $MyRow['decimalplaces']), '</td>
<td class="number">', locale_number_format($TotQtyRow['qty'], $MyRow['decimalplaces']), '</td>
<td class="number">', locale_number_format($MyRow['quantity'], $MyRow['decimalplaces']), '</td>
<td class="number">';
if ($MyRow['canupd'] == 1) {
echo '<input type="text" class="number" name="ReorderLevel', $i, '" maxlength="10" size="10" value="', locale_number_format($MyRow['reorderlevel'], 0), '" />
<input type="hidden" name="StockID', $i, '" value="', $MyRow['stockid'], '" /></td>
<td><input type="text" name="BinLocation', $i, '" maxlength="10" size="10" value="', $MyRow['bin'], '" /></td>';
} else {
echo locale_number_format($MyRow['reorderlevel'], 0), '</td><td>', $MyRow['bin'], '</td>';
}
echo '</tr>';
++$i;
} //end of looping
echo '</table>';
echo '<div class="centre">
<input type="submit" name="submit" value="', _('Update'), '" />
</div>
</form>';
} else {
/*The option to submit was not hit so display form */
echo '<div class="page_help_text">', _('Use this report to display the reorder levels for Inventory items in different categories.'), '</div>';
echo '<form action="', htmlspecialchars(basename(__FILE__), ENT_QUOTES, 'UTF-8'), '" method="post">';
echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />';
$SQL = "SELECT locationname,
locations.loccode
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>';
echo '<field>
<label for="StockLocation">', _('Location'), ':</label>
<select name="StockLocation"> ';
while ($MyRow = DB_fetch_array($ResultStkLocs)) {
echo '<option value="', $MyRow['loccode'], '">', $MyRow['locationname'], '</option>';
}
echo '</select>
</field>';
$SQL = "SELECT categoryid,
categorydescription
FROM stockcategory
ORDER BY categorydescription";
$Result1 = DB_query($SQL);
echo '<field>
<label for="StockCat">', _('Category'), ':</label>
<select required="required" name="StockCat">';
while ($MyRow1 = DB_fetch_array($Result1)) {
echo '<option value="', $MyRow1['categoryid'], '">', $MyRow1['categorydescription'], '</option>';
}
echo '</select>
</field>';
echo '<field>
<label for="NumberOfDays">', _('Number Of Days Sales'), ':</label>
<input type="text" class="number" name="NumberOfDays" required="required" maxlength="3" size="4" value="0" />
<field>';
echo '<field>
<label for="Sequence">', _('Order By'), ':</label>
<select name="Sequence">
<option value="1">', _('Total Invoiced'), '</option>
<option value="2">', _('Item Code'), '</option>
</select>
</field>';
echo '</fieldset>';
echo '<div class="centre">
<input type="submit" name="submit" value="', _('Submit'), '" />
</div>';
echo '</form>';
}
/*end of else not submit */
include ('includes/footer.php');
?>