forked from SecareLupus/fc_pos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinventoryreport.php
188 lines (166 loc) · 6.09 KB
/
inventoryreport.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
<?php
/**
* @file inventoryreport.php
* @brief inventoryreport.php is a page for reporting on the state of inventory.
*
* @todo This page fails silently on submit. Look into that.
*
* This file includes:
* funcs.inc:
* - Used for the config.inc include
* - displayErrorDie()
* - money()
*
* Possible Arguments:
* SESSION:
* - ID - The ID of the active user, required for appending to
* some queries.
* - inv - Used to determine whether the active user has inventory
* privs.
*
* POST:
* - change - This value will be set to 1 when we need to do work.
* - boardcard - If this value is set, it will set GET['boardcard'] to
* the same value, which will restrict the items shown to only board
* games and card games.
* - qty - Array of itemIDs and quantities for each. This array will update
* all given items to the new quantities.
*
* GET:
* - boardcard - If this variable is set, it will restrict the items shown to
* only board games and card games.
* - noblank - If this variable is set, it will restrict the items shown to
* only those with >0 quantity.
* - sort - The name of the department the active user wants to sort by.
*
* @link http://www.worldsapartgames.org/fc/inventoryreport.php @endlink
*
* @author Michael Whitehouse
* @author Creidieki Crouch
* @author Desmond Duval
* @copyright 2009-2014 Pioneer Valley Gaming Collective
* @version 1.8d
* @since Project has existed since time immemorial.
*/
$title = 'Inventory Report';
$version = "1.8d";
require_once 'funcs.inc';
require_once 'header.php';
$cxn = open_stream();
$allowcount = ($_SESSION['inv'] == 1);
// change inventory
if ($_POST['change'] == 1) {
$_GET['boardcard'] = $_POST['boardcard'];
echo "<hr><font size=+2>Adjusting Quantities</font><br>\n";
$sql = "INSERT INTO invEvent (type, staffID, invDate, closed) "
. "VALUES (1, ". $_SESSION['ID'] . ", NOW(), 1)";
if (!query($cxn, $sql)) {
displayErrorDie("Unable to set invEvent");
}
$ied = $cxn->insert_id;
echo "Inventory Event ID: $ied<br>";
extract($_POST);
foreach ($qty as $ID => $newqty) {
// if a number is put in
if (is_numeric($newqty)) {
echo "Item #$ID<br>";
// find old quantity
$sql = "SELECT description, qty, price, cost FROM items WHERE ID='$ID'";
$result = query($cxn, $sql);
$row = mysqli_fetch_assoc($result);
$oldqty = $row['qty'];
$qtychange = $newqty - $oldqty;
$cost = $row['cost'];
$price = $row['price'];
$desc = $row['description'];
// only do the thing if there is actually a change
if ($qtychange != 0) {
// create itemChange
$sql = "INSERT INTO itemChange (itemID, invEventID, qty, cost, price)
VALUES ($ID, $ied, $qtychange, $cost, $price)";
if (query($cxn, $sql)) {
echo "$desc Item Change Created<br>";
} else {
displayErrorDie("Error Submitting itemChange for $desc ($ID)");
}
// change item quantity
$sql = "UPDATE items SET qty=$newqty WHERE ID=$ID";
if (query($cxn, $sql)) {
echo "$desc Qty changed $qtychange to $newqty<br>";
} else {
displayErrorDie("Error Submitting qty for $desc ($ID)");
}
}
}
}
echo "<hr>";
}
$validColumns = array('ID', 'department', 'manufacturer', 'price', 'cost', 'inv', 'UPC', 'alternate1', 'alternate2', 'qty', 'description', 'tax');
if (isset($_GET['sort'])) {
$sort = (in_array($_GET['sort'], $validColumns)) ? 'ORDER BY ' . $_GET['sort'] : '';
}
if ($_GET['noblank'] == 1) {
$noblank = "WHERE qty > 0";
if ($_GET['boardcard'] == 1) {
$boardcard = "AND (department LIKE 'Board Games' OR department LIKE 'Card Games')";
}
} elseif ($_GET['boardcard'] == 1) {
$boardcard = "WHERE (department LIKE 'Board Games' OR department LIKE 'Card Games')";
}
$sql = "SELECT * FROM items $noblank $boardcard $sort";
$result = query($cxn, $sql);
echo "<form action='inventoryreport.php' method='get'>
<select name='sort'>\n";
foreach ($validColumns as $vc) {
echo "<option value='$vc'>$vc</option>\n";
}
$isbc = ($_GET['boardcard'] == 1) ? " checked" : "";
echo "</select><br>
<input type='checkbox' name='noblank' value=1> Do not show 0 quantity items<br>
<input type='checkbox' name='boardcard' value=1 $isbc> Board/Card Games Only?<br>
<input type='submit' name='submit' value='sort'></form><p>";
if ($allowcount) {
echo "<form action='inventoryreport.php' method='post'>\n";
}
echo "<table cellpadding=3 border><tr>
<td>ID</td>
<td width=100>Name</td>
<td>Price</td>
<td>Cost</td>
<td>Qty</td>
<td>Tax</td>
<td>Inv</td>
<td>UPC<br>Alt1<br>Alt2</td>
<td>Department<br>Manufacturer</td>\n";
if ($allowcount) {
echo "<td>Current Qty</td>\n";
}
echo "</tr>\n";
while ($row = mysqli_fetch_assoc($result)) {
extract($row);
echo "<tr>
<td><a name='$ID'>$ID</td>
<td><a href='edititem.php?ID=$ID'>$description</a></td>
<td>" . money($price) . "</td>
<td>" . money($cost) . "</td>
<td>$qty</td>
<td>" . (($tax == 1) ? "YES" : "NO") . "</td>
<td>" . (($inv == 1) ? "YES" : "NO") . "</td>
<td>$UPC<br>$alternate1<br>$alternate2</td>
<td>$department<br>$manufacturer</td>\n";
if ($allowcount) {
echo "<td><input name='qty[$ID]' size=5 maxlength=5></td>\n";
}
echo "</tr>";
}
echo "</table><br>";
if ($allowcount) {
if ($_GET['boardcard'] == 1) {
echo "<input name='boardcard' value='1' type='hidden'>";
}
echo "<input name='change' value='1' type='hidden'>
<input name='submit' value='submit' type='submit'></form>
<br>";
}
require 'footer.php';
?>