-
Notifications
You must be signed in to change notification settings - Fork 0
/
supplies.inc.php
134 lines (89 loc) · 3.27 KB
/
supplies.inc.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
<?php
include("../../checklist/includes/db.inc.php");
// **********************************************************************************
function getLocations() {
$db = CreateConnection();
$sql = "SELECT * FROM inv_loc";
$result = mysql_query($sql,$db) or print "Could not get list of LOCATIONS. " . mysql_error();
$list = array();
while ($row = mysql_fetch_assoc($result)) {
array_push ($list,$row);
}
CloseConnection($db);
return $list;
}
// **********************************************************************************
function getProducts($loc) {
$db = CreateConnection();
$sql = "SELECT prod_id FROM inv_loc_prod WHERE loc_id = '" . $loc . "'";
$result = mysql_query($sql,$db) or print "Could not get the list of PRODUCTS. " . mysql_error();
$prod_list = array();
while ($row = mysql_fetch_assoc($result)) {
array_push($prod_list,$row);
}
$big_list = array();
foreach ($prod_list as $val) {
$sql = "SELECT * FROM inv_prod WHERE prod_id = '" . $val['prod_id'] . "'";
$result = mysql_query($sql,$db) or print "Could not get Product Info. " . mysql_error();
while ($row = mysql_fetch_assoc($result)) {
array_push($big_list,$row);
}
}
CloseConnection($db);
return $big_list;
}
// **************************************************************************************
function getAllSupplies() {
$db = CreateConnection();
$sql = "SELECT * FROM inv_prod";
$result = mysql_query($sql,$db) or print "Could not get the list of all SUPPLIES. " . mysql_error();
$list =array();
while ($row = mysql_fetch_assoc($result)) {
array_push($list, $row);
}
CloseConnection($db);
return $list;
}
// **************************************************************************************
function updateRecords($info) {
$db = CreateConnection($db);
foreach($info as $key => $val) {
$flag = "good";
$sql = "UPDATE `inv_prod` ";
$sql2 = "INSERT INTO `inv_out` (out_lab, out_prod_id, out_amount) VALUES ('" . $info['lab'] . "',";
switch($key) {
case 'lab':
$flag = "bad";
break; // set flag to BAD will cause the query below not to run
case 'letter_box':
$val = $val *10; // 10 reams per box of paper
$sql .= " SET prod_amount = (prod_amount - " . $val . ") WHERE prod_id = 7"; // 7 is paper
$sql2 .= " '7', '" . $val . "')";
break;
case 'letter_ream':
$sql .= " SET prod_amount = (prod_amount - " . $val . ") WHERE prod_id = 7";
$sql2 .= " '7', '" . $val . "')";
break;
case 'tabloid_box':
$val = $val *10; // 10 reams per box
$sql .= " SET prod_amount = (prod_amount - " . $val . ") WHERE prod_id = 10";
$sql2 .= " '10', '" . $val . "')";
break;
case 'tabloid_ream':
$sql .= " SET prod_amount = (prod_amount - " . $val . ") WHERE prod_id = 10";
$sql2 .= " '10', '" . $val . "')";
break;
default:
$sql .= " SET prod_amount = (prod_amount - " . $val . ") WHERE prod_id = " . $key;
$sql2 .= " '" . $key . "', '" . $val . "')";
}
if ($flag == "good") {
mysql_query($sql,$db) or print "<p>Oh no! " . mysql_error() . "</p>";
if ($val >=1) { // only run the query for the products tha twere removed (amount is not zero)
mysql_query($sql2,$db) or print "<p>Problem with the second query!!! " . mysql_error() . "</p>";
}
}
}
CloseConnection($db);
}
?>