forked from timschofield/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReorderLevel.php
228 lines (207 loc) · 8.43 KB
/
ReorderLevel.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
<?php
// ReorderLevel.php - Report of parts with quantity below reorder level
// Shows if there are other locations that have quantities for the parts that are short
include ('includes/session.php');
use Dompdf\Dompdf;
if (isset($_POST['PrintPDF']) or isset($_POST['View'])) {
if ($_POST['StockCat'] != 'All') {
$WhereCategory = " AND stockmaster.categoryid='" . $_POST['StockCat'] . "'";
$SQL = "SELECT categoryid,
categorydescription
FROM stockcategory
WHERE categoryid='" . $_POST['StockCat'] . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_row($Result);
$CategoryDescription = $MyRow[1];
} else {
$WhereCategory = "";
$CategoryDescription = _('All');
}
$HTML = '';
if (isset($_POST['PrintPDF'])) {
$HTML .= '<html>
<head>';
$HTML .= '<link href="css/reports.css" rel="stylesheet" type="text/css" />';
}
$HTML .= '<meta name="author" content="WebERP " . $Version">
<meta name="Creator" content="webERP http://www.weberp.org">
</head>
<body>
<div class="centre" id="ReportHeader">
' . $_SESSION['CompanyRecord']['coyname'] . '<br />
' . _('Reorder Level Report') . '<br />
' . _('Printed') . ': ' . Date($_SESSION['DefaultDateFormat']) . '<br />
' . _('Category') . ' - ' . $_POST['StockCat'] . ' - ' . $CategoryDescription . '<br />
' . _('Location') . ' - ' . $_POST['StockLocation'] . '<br />
</div>
<table>
<thead>
<tr>
<th>' . _('Part Number') . '</th>
<th>' . _('Description') . '</th>
<th>' . _('Location') . '</th>
<th>' . _('Quantity') . '</th>
<th>' . _('Reorder') . '</th>
<th>' . _('On Order') . '</th>
<th>' . _('Needed') . '</th>
</tr>
</thead>
<tbody>';
$WhereLocation = " ";
if ($_POST['StockLocation'] != 'All') {
$WhereLocation = " AND locstock.loccode='" . $_POST['StockLocation'] . "' ";
}
$SQL = "SELECT locstock.stockid,
stockmaster.description,
locstock.loccode,
locations.locationname,
locstock.quantity,
locstock.reorderlevel,
stockmaster.decimalplaces,
stockmaster.serialised,
stockmaster.controlled
FROM locstock
INNER JOIN locationusers
ON locationusers.loccode=locstock.loccode
AND locationusers.userid='" . $_SESSION['UserID'] . "'
AND locationusers.canview=1,
stockmaster
LEFT JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid,
locations
WHERE locstock.stockid=stockmaster.stockid " . $WhereLocation . "AND locstock.loccode=locations.loccode
AND locstock.reorderlevel > locstock.quantity
AND (stockmaster.mbflag='B' OR stockmaster.mbflag='M') " . $WhereCategory . " ORDER BY locstock.loccode,locstock.stockid";
$Result = DB_query($SQL, '', '', false, true);
while ($MyRow = DB_fetch_array($Result)) {
$OnOrderSQL = "SELECT SUM(quantityord-quantityrecd) AS quantityonorder
FROM purchorders
LEFT JOIN purchorderdetails
ON purchorders.orderno=purchorderdetails.orderno
WHERE purchorders.status != 'Cancelled'
AND purchorders.status != 'Rejected'
AND purchorders.status != 'Pending'
AND purchorders.status != 'Completed'
AND purchorderdetails.itemcode='" . $MyRow['stockid'] . "'
AND purchorders.intostocklocation='" . $MyRow['loccode'] . "'";
$OnOrderResult = DB_query($OnOrderSQL);
$OnOrderRow = DB_fetch_array($OnOrderResult);
$Shortage = $MyRow['reorderlevel'] - $MyRow['quantity'] - $OnOrderRow['quantityonorder'];
$HTML .= '<tr>
<td>' . $MyRow['stockid'] . '</td>
<td>' . $MyRow['description'] . '</td>
<td>' . $MyRow['loccode'] . '</td>
<td class="number">' . locale_number_format($MyRow['quantity'], $MyRow['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($MyRow['reorderlevel'], $MyRow['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($OnOrderRow['quantityonorder'], $MyRow['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($Shortage, $MyRow['decimalplaces']) . '</td>
</tr>';
}
if (isset($_POST['PrintPDF'])) {
$HTML .= '</tbody>
<div class="footer fixed-section">
<div class="right">
<span class="page-number">Page </span>
</div>
</div>
</table>';
} else {
$HTML .= '</tbody>
</table>
<div class="centre">
<form><input type="submit" name="close" value="' . _('Close') . '" onclick="window.close()" /></form>
</div>';
}
$HTML .= '</body>
</html>';
if (isset($_POST['PrintPDF'])) {
$dompdf = new Dompdf(['chroot' => __DIR__]);
$dompdf->loadHtml($HTML);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper($_SESSION['PageSize'], 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream($_SESSION['DatabaseName'] . '_ReOrderLevel_' . date('Y-m-d') . '.pdf', array(
"Attachment" => false
));
} else {
$Title = _('Reorder Level Reporting');
include ('includes/header.php');
echo '<p class="page_title_text"><img src="' . $RootPath . '/css/' . $Theme . '/images/inventory.png" title="' . _('Inventory') . '" alt="" />' . ' ' . _('Inventory Reorder Level Report') . '</p>';
echo $HTML;
include ('includes/footer.php');
}
} else { /*The option to print PDF was not hit so display form */
$Title = _('Reorder Level Reporting');
$ViewTopic = 'Inventory';
$BookMark = '';
include ('includes/header.php');
echo '<p class="page_title_text"><img src="' . $RootPath . '/css/' . $Theme . '/images/inventory.png" title="' . _('Inventory') . '" alt="" />' . ' ' . _('Inventory Reorder Level Report') . '</p>';
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($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post" target="_blank">';
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>', _('Report Criteria') , '</legend>
<field>
<label for="StockLocation">' . _('From Stock Location') . ':</label>
<select name="StockLocation"> ';
if (!isset($_POST['StockLocation'])) {
$_POST['StockLocation'] = 'All';
}
if ($_POST['StockLocation'] == 'All') {
echo '<option selected="selected" value="All">' . _('All') . '</option>';
} else {
echo '<option value="All">' . _('All') . '</option>';
}
while ($MyRow = DB_fetch_array($ResultStkLocs)) {
if ($MyRow['loccode'] == $_POST['StockLocation']) {
echo '<option selected="selected" value="' . $MyRow['loccode'] . '">' . $MyRow['locationname'] . '</option>';
} else {
echo '<option value="' . $MyRow['loccode'] . '">' . $MyRow['locationname'] . '</option>';
}
}
echo '</select>
</field>';
$SQL = "SELECT categoryid, categorydescription FROM stockcategory WHERE stocktype<>'A' ORDER BY categorydescription";
$Result1 = DB_query($SQL);
if (DB_num_rows($Result1) == 0) {
echo '</td></field>
</table>';
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 '</fieldset>
<div class="centre">
<input type="submit" name="PrintPDF" title="PDF" value="' . _('Print PDF') . '" />
<input type="submit" name="View" title="View" value="' . _('View') . '" />
</div>';
echo '</form>';
include ('includes/footer.php');
} /*end of else not PrintPDF */