-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_itemService.php
More file actions
187 lines (148 loc) · 5.11 KB
/
_itemService.php
File metadata and controls
187 lines (148 loc) · 5.11 KB
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
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
function getItemByID($itemID) {
// Create connection
$conn = getDBConnection();
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "
SELECT brand.description AS brand ,category.description AS category,item.id,
item.model,item.selling_price,item.min_price,item.description AS itmdescription,item.image_path,store_area.description,item.stock,item.bcn FROM item INNER JOIN category
ON item.category_id = category.id
INNER JOIN brand ON item.brand_id = brand.id
INNER JOIN store_area ON item.store_area = store_area.id
WHERE item.id = '$itemID' ";
// echo $sql;
$result = mysqli_query($conn, $sql);
return $result;
}
function getAllItem() {
// Create connection
$conn = getDBConnection();
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "
SELECT brand.description AS brand ,category.description AS category,item.id,
item.model,item.selling_price,item.min_price,item.description,item.image_path,item.itmstatus,
store_area.description,item.stock FROM item INNER JOIN category
ON item.category_id = category.id
INNER JOIN brand ON item.brand_id = brand.id
INNER JOIN store_area ON item.store_area = store_area.id WHERE item.itmstatus = 'ACT'
";
// echo $sql;
$result = mysqli_query($conn, $sql);
return $result;
}
function getAll() {
// Create connection
$conn = getDBConnection();
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "
SELECT brand.description AS brand ,category.description AS category,item.id,
item.model,item.selling_price,item.min_price,item.description,item.image_path,item.itmstatus,
store_area.description,item.stock FROM item INNER JOIN category
ON item.category_id = category.id
INNER JOIN brand ON item.brand_id = brand.id
INNER JOIN store_area ON item.store_area = store_area.id
";
// echo $sql;
$result = mysqli_query($conn, $sql);
return $result;
}
function updateStockData() {
$conn = getDBConnection();
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = " UPDATE item SET selling_price = " . $_POST['selling_price'] . ", min_price = " . $_POST['min_price'] . " , stock = " . $_POST['stock'] . " WHERE id = " . $_POST['itemID'] . " ";
if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
mysqli_close($conn);
}
function itemSearchExplorer() {
// Create connection
$conn = getDBConnection();
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = " SELECT brand.description AS brand ,category.description AS category,item.id,
item.model,item.selling_price,item.min_price,item.description,item.image_path,item.bcn,
store_area.description,item.stock FROM item INNER JOIN category
ON item.category_id = category.id
INNER JOIN brand ON item.brand_id = brand.id
INNER JOIN store_area ON item.store_area = store_area.id " . dynamicWhereBuilder();
// echo 'SQL :'. $sql;
$result = mysqli_query($conn, $sql);
return $result;
}
function itemBCNSearchExplorer() {
// Create connection
$conn = getDBConnection();
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = " SELECT brand.description AS brand ,category.description AS category,item.id,
item.model,item.selling_price,item.min_price,item.description,item.image_path,item.bcn,
store_area.description,item.stock FROM item INNER JOIN category
ON item.category_id = category.id
INNER JOIN brand ON item.brand_id = brand.id
INNER JOIN store_area ON item.store_area = store_area.id WHERE item.bcn = '".$_POST['bcn']."' AND item.itmstatus = 'ACT' ";
// echo 'SQL :'. $sql;
$result = mysqli_query($conn, $sql);
return $result;
}
function dynamicWhereBuilder() {
$sql = "";
$x = 0;
$category_id = $_POST['category_id'];
$brand_id = $_POST['brand_id'];
$store_area = $_POST['store_area'];
$model = $_POST['model'];
if ($_POST['model'] != "") {
$sql = " item.model LIKE '%$model%' ";
$x = 1;
}
if ($_POST['category_id'] != "") {
if ($x == 1) {
$sql = $sql . ' AND ';
}
$sql = $sql . " item.category_id = '$category_id' ";
$x = 1;
}
if ($_POST['brand_id'] != "") {
if ($x == 1) {
$sql = $sql . ' AND ';
}
$sql = $sql . " item.brand_id = '$brand_id' ";
$x = 1;
}
if ($_POST['store_area'] != "") {
if ($x == 1) {
$sql = $sql . ' AND ';
}
$sql = $sql . " item.store_area = '$store_area' ";
$x = 1;
}
if ($sql != '') {
$sql = " WHERE item.itmstatus = 'ACT' AND " . $sql;
}
return $sql;
}
?>