forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InventoryQuantities.php
256 lines (224 loc) · 8.65 KB
/
InventoryQuantities.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
254
255
256
<?php
// InventoryQuantities.php - Report of parts with quantity. Sorts by part and shows
// all locations where there are quantities of the part
include('includes/session.php');
If (isset($_POST['PrintPDF'])) {
include('includes/PDFStarter.php');
$pdf->addInfo('Title',_('Inventory Quantities Report'));
$pdf->addInfo('Subject',_('Parts With Quantities'));
$FontSize=9;
$PageNumber=1;
$line_height=12;
$Xpos = $Left_Margin+1;
$WhereCategory = ' ';
$CatDescription = ' ';
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);
$CatDescription = $myrow[1];
}
if ($_POST['Selection'] == 'All') {
$sql = "SELECT locstock.stockid,
stockmaster.description,
locstock.loccode,
locations.locationname,
locstock.quantity,
locstock.reorderlevel,
stockmaster.decimalplaces,
stockmaster.serialised,
stockmaster.controlled
FROM locstock INNER JOIN stockmaster
ON locstock.stockid=stockmaster.stockid
INNER JOIN locations
ON locstock.loccode=locations.loccode
WHERE locstock.quantity <> 0
AND (stockmaster.mbflag='B' OR stockmaster.mbflag='M') " .
$WhereCategory . "
ORDER BY locstock.stockid,
locstock.loccode";
} else {
// sql to only select parts in more than one location
// The SELECT statement at the beginning of the WHERE clause limits the selection to
// parts with quantity in more than one location
$sql = "SELECT locstock.stockid,
stockmaster.description,
locstock.loccode,
locations.locationname,
locstock.quantity,
locstock.reorderlevel,
stockmaster.decimalplaces,
stockmaster.serialised,
stockmaster.controlled
FROM locstock INNER JOIN stockmaster
ON locstock.stockid=stockmaster.stockid
INNER JOIN locations
ON locstock.loccode=locations.loccode
WHERE (SELECT count(*)
FROM locstock
WHERE stockmaster.stockid = locstock.stockid
AND locstock.quantity <> 0
GROUP BY locstock.stockid) > 1
AND locstock.quantity <> 0
AND (stockmaster.mbflag='B' OR stockmaster.mbflag='M') " .
$WhereCategory . "
ORDER BY locstock.stockid,
locstock.loccode";
}
$result = DB_query($sql,'','',false,true);
if (DB_error_no() !=0) {
$Title = _('Inventory Quantities') . ' - ' . _('Problem Report');
include('includes/header.php');
prnMsg( _('The Inventory Quantity report could not be retrieved by the SQL because') . ' ' . DB_error_msg(),'error');
echo '<br /><a href="' .$RootPath .'/index.php">' . _('Back to the menu') . '</a>';
if ($debug==1){
echo '<br />' . $sql;
}
include('includes/footer.php');
exit;
}
if (DB_num_rows($result)==0){
$Title = _('Print Inventory Quantities Report');
include('includes/header.php');
prnMsg(_('There were no items with inventory quantities'),'error');
echo '<br /><a href="'.$RootPath.'/index.php">' . _('Back to the menu') . '</a>';
include('includes/footer.php');
exit;
}
PrintHeader($pdf,
$YPos,
$PageNumber,
$Page_Height,
$Top_Margin,
$Left_Margin,
$Page_Width,
$Right_Margin,
$CatDescription);
$FontSize=8;
$holdpart = " ";
While ($myrow = DB_fetch_array($result)){
if ($myrow['stockid'] != $holdpart) {
$YPos -=(2 * $line_height);
$holdpart = $myrow['stockid'];
} else {
$YPos -=($line_height);
}
// Parameters for addTextWrap are defined in /includes/class.pdf.php
// 1) X position 2) Y position 3) Width
// 4) Height 5) Text 6) Alignment 7) Border 8) Fill - True to use SetFillColor
// and False to set to transparent
$pdf->addTextWrap(50,$YPos,100,$FontSize,$myrow['stockid'],'',0);
$pdf->addTextWrap(150,$YPos,150,$FontSize,$myrow['description'],'',0);
$pdf->addTextWrap(310,$YPos,60,$FontSize,$myrow['loccode'],'left',0);
$pdf->addTextWrap(370,$YPos,50,$FontSize,locale_number_format($myrow['quantity'],
$myrow['decimalplaces']),'right',0);
$pdf->addTextWrap(420,$YPos,50,$FontSize,locale_number_format($myrow['reorderlevel'],
$myrow['decimalplaces']),'right',0);
if ($YPos < $Bottom_Margin + $line_height){
PrintHeader($pdf,$YPos,$PageNumber,$Page_Height,$Top_Margin,$Left_Margin,$Page_Width,
$Right_Margin,$CatDescription);
}
} /*end while loop */
if ($YPos < $Bottom_Margin + $line_height){
PrintHeader($pdf,$YPos,$PageNumber,$Page_Height,$Top_Margin,$Left_Margin,$Page_Width,
$Right_Margin,$CatDescription);
}
/*Print out the grand totals */
$pdf->OutputD($_SESSION['DatabaseName'] . '_Inventory_Quantities_' . Date('Y-m-d') . '.pdf');
$pdf->__destruct();
} else { /*The option to print PDF was not hit so display form */
$Title=_('Inventory Quantities Reporting');
include('includes/header.php');
echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/inventory.png" title="' . _('Inventory') . '" alt="" />' . ' ' . _('Inventory Quantities Report') . '</p>';
echo '<div class="page_help_text">' . _('Use this report to display the quantity of Inventory items in different categories.') . '</div><br />';
echo '<br />
<br />
<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">
<div>
<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
<table class="selection">
<tr>
<td>' . _('Selection') . ':</td>
<td><select name="Selection">
<option selected="selected" value="All">' . _('All') . '</option>
<option value="Multiple">' . _('Only Parts With Multiple Locations') . '</option>
</select></td>
</tr>';
$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 '<tr>
<td>' . _('In Stock Category') . ':</td>
<td><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></td>
</tr>
</table>
<br />
<div class="centre">
<input type="submit" name="PrintPDF" value="' . _('Print PDF') . '" />
</div>';
echo '</div>
</form>';
include('includes/footer.php');
} /*end of else not PrintPDF */
function PrintHeader(&$pdf,&$YPos,&$PageNumber,$Page_Height,$Top_Margin,$Left_Margin,
$Page_Width,$Right_Margin,$CatDescription) {
/*PDF page header for Reorder Level report */
if ($PageNumber>1){
$pdf->newPage();
}
$line_height=12;
$FontSize=9;
$YPos= $Page_Height-$Top_Margin;
$pdf->addTextWrap($Left_Margin,$YPos,300,$FontSize,$_SESSION['CompanyRecord']['coyname']);
$YPos -=$line_height;
$pdf->addTextWrap($Left_Margin,$YPos,150,$FontSize,_('Inventory Quantities Report'));
$pdf->addTextWrap($Page_Width-$Right_Margin-150,$YPos,160,$FontSize,_('Printed') . ': ' .
Date($_SESSION['DefaultDateFormat']) . ' ' . _('Page') . ' ' . $PageNumber,'left');
$YPos -= $line_height;
$pdf->addTextWrap($Left_Margin,$YPos,50,$FontSize,_('Category'));
$pdf->addTextWrap(95,$YPos,50,$FontSize,$_POST['StockCat']);
$pdf->addTextWrap(160,$YPos,150,$FontSize,$CatDescription,'left');
$YPos -=(2*$line_height);
/*set up the headings */
$Xpos = $Left_Margin+1;
$pdf->addTextWrap(50,$YPos,100,$FontSize,_('Part Number'), 'left');
$pdf->addTextWrap(150,$YPos,150,$FontSize,_('Description'), 'left');
$pdf->addTextWrap(310,$YPos,60,$FontSize,_('Location'), 'left');
$pdf->addTextWrap(370,$YPos,50,$FontSize,_('Quantity'), 'right');
$pdf->addTextWrap(420,$YPos,50,$FontSize,_('Reorder'), 'right');
$YPos -=$line_height;
$pdf->addTextWrap(415,$YPos,50,$FontSize,_('Level'), 'right');
$FontSize=8;
$PageNumber++;
} // End of PrintHeader() function
?>