-
Notifications
You must be signed in to change notification settings - Fork 1
/
seller.php
287 lines (271 loc) · 13.9 KB
/
seller.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?php
require_once './includes/db.php';
$user_id = 0; // Initialize user_id with a default value
if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];
}
if ($user_id != 0) {
// SQL: Get the 'sts' value from the 'users' table for the logged-in user
$sql = "SELECT sts FROM users WHERE user_id = '$user_id'";
$result = mysqli_query($conn, $sql);
if ($result) {
$row = mysqli_fetch_assoc($result);
$user_sts = $row['sts'];
if ($user_sts === 'Unverified') {
// Redirect to the account_confirm page if 'sts' is 'Unverified'
header("Location: account_confirm.php");
exit();
} else {
}
} else {
echo "Error: " . mysqli_error($conn);
}
} else {
}
$user_id = $_SESSION['user_id'];
$total_order = 0;
$query3 = "SELECT COUNT(*) AS count2, SUM(order_total) AS total_order FROM orders WHERE seller_id = '$user_id'";
$res2 = mysqli_query($conn, $query3);
$row3 = mysqli_fetch_assoc($res2);
$count2 = $row3['count2'];
$total_order = $row3['total_order'];
$query4 = "SELECT COUNT(*) AS count3 FROM products WHERE seller_id = '$user_id' AND product_status = 'On Sale'";
$re2 = mysqli_query($conn, $query4);
$row4 = mysqli_fetch_assoc($re2);
$count3 = $row4['count3'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Seller Dashboard</title>
<?php require_once './includes/head.php'; ?>
<style>
</style>
</head>
<body class="pad">
<div class="container">
<?php require_once './includes/sidenav.php';?>
<div class="row">
<div class="col-11">
<h1 style="padding-top: 10px;">SELLER DASHBOARD</h1>
</div>
<div class="col-1 d-flex float-end">
<?php require_once './extension/notif_seller.php';?>
</div>
</div>
<div class="row">
<div class="col-xl-4 col-md-4 mb-4">
<div class="card card-custom shadow py-2">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="font-weight-bold text-primary text-uppercase mb-1" style="font-size: small;">
TOTAL ORDERS</div>
<div class="h5 mb-0 font-weight-bold text-gray-800" style="font-size: x-large;"><?php echo $count2; ?></div>
</div>
<div class="col-auto text-primary">
<ion-icon size="large" name="receipt-outline"></ion-icon>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-4 col-md-4 mb-4">
<div class="card shadow py-2">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="font-weight-bold text-success text-uppercase mb-1" style="font-size: small;">
TOTAL SALES</div>
<div class="h5 mb-0 font-weight-bold text-gray-800" style="font-size: x-large;"><?php echo CURRENCY . number_format($total_order, 2); ?></div>
</div>
<div class="col-auto text-success">
<ion-icon size="large" name="cash-outline"></ion-icon>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-4 col-md-4 mb-4">
<div class="card shadow py-2">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="font-weight-bold text-warning text-uppercase mb-1" style="font-size: small;">
PRODUCT ON SALE</div>
<div class="h5 mb-0 font-weight-bold text-gray-800" style="font-size: x-large;"><?php echo $count3; ?></div>
</div>
<div class="col-auto text-warning">
<ion-icon size="large" name="trending-up-outline"></ion-icon>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row mb-3">
<div class="col-md-8">
<div class="table bg-white shadow-sm">
<table class="table table-responsive table-info">
<thead class="text-center">
<tr>
<td colspan="3">RECENT ORDERS</td>
</tr>
</thead>
<thead class="table-light text-center">
<tr>
<td>BUYER</td>
<td>ORDER QTY</td>
<td>TOTAL AMT</td>
</tr>
</thead>
<tbody class="text-center">
<?php
$sql = "SELECT o.*, u.fullname
FROM orders o
INNER JOIN users u ON o.user_id = u.user_id
WHERE o.seller_id = '$user_id'
ORDER BY o.date_place DESC
LIMIT 5";
$result = mysqli_query($conn, $sql);
foreach($result as $row){
?>
<tr>
<td><?php echo $row['fullname'] ?></td>
<td><?php echo $row['order_qty'] ?></td>
<td><?php echo $row['order_total'] ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="table bg-white shadow-sm" style="height: 17.5em; display:block; overflow-y:scroll;">
<table class="table table-responsive table-warning">
<thead class="text-center">
<tr>
<td colspan="3">PRODUCTS ON CART</td>
</tr>
</thead>
<thead class="table-light text-center">
<tr>
<td>BUYER</td>
<td>PRODUCT</td>
<td>QTY</td>
</tr>
</thead>
<tbody class="text-center">
<?php
$sql = "SELECT c.order_qty, u.fullname, p.product_name
FROM cart c
INNER JOIN users u ON c.user_id = u.user_id
INNER JOIN products p ON c.product_id = p.product_id
WHERE p.seller_id = $user_id";
$result = mysqli_query($conn, $sql);
foreach ($result as $row) {
?>
<tr>
<td><?php echo $row['fullname']; ?></td>
<td><?php echo $row['product_name']; ?></td>
<td><?php echo $row['order_qty']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<div class="col-md-4">
<div class="card shadow-sm mb-3" style="background-color: #C7DAC7;">
<div class="card-body">
<h3 class="text-center" style="background-color: white;">GENERATE SALES REPORT</h3>
<form action="" method="POST">
<div class="input-group mb-3">
<span class="input-group-text">Between</span>
<input type="date" name="start_date" class="form-control" required>
<span class="input-group-text"> and </span>
<input type="date" name="end_date" class="form-control" required>
<button type="submit" class="text-center btn btn-secondary" name="generatefi">GENERATE</button>
</div>
</form>
<form action="" method="POST">
<div class="input-group">
<span class="input-group-text">This Date</span>
<input type="date" name="this_date" class="form-control" required>
<button type="submit" class="text-center btn btn-secondary" name="generatefi1">GENERATE</button>
</div>
</form>
<?php
if (isset($_POST['generatefi'])) {
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
$showViewButton1 = true;
} else {
$showViewButton1 = false;
}
if (isset($_POST['generatefi1'])) {
$this_date = $_POST['this_date'];
$showViewButton = true;
} else {
$showViewButton = false;
}
?>
<form action="./extension/generate_sales_report.php" method="POST" target="_target">
<?php if ($showViewButton1): ?>
<div class="input-group mb-3 text-center">
<input type="text" name="start_date" class="form-control" value="<?php echo $start_date; ?>" aria-label="Username">
<span class="input-group-text">BETWEEN</span>
<input type="text" name="end_date" class="form-control" value="<?php echo $end_date; ?>" aria-label="Server">
</div>
<div class="text-center">
<button type="submit" id="generatefi" class="text-center btn btn-secondary" name="view"><ion-icon name="document-outline"></ion-icon>VIEW</button>
</div>
<?php elseif($showViewButton): ?>
<div class="input-group mb-3 text-center">
<span class="input-group-text">This Date</span>
<input type="text" name="this_date" class="form-control" value="<?php echo $this_date; ?>">
</div>
<div class="text-center">
<button type="submit" id="generatefi" class="text-center btn btn-secondary" name="view1"><ion-icon name="document-outline"></ion-icon>VIEW</button>
</div>
<?php endif; ?>
</form>
</div>
</div>
<div class="table bg-white shadow-sm" style="height: 20em; display:block; overflow-y:scroll;">
<table class="table table-responsive table-danger">
<thead class="text-center">
<tr>
<td colspan="3">PRODUCT OUT OF STOCK</td>
</tr>
</thead>
<thead class="table-light text-center">
<tr>
<td>NAME</td>
<td>PRODUCT STOCK LEFT</td>
<td></td>
</tr>
</thead>
<tbody class="text-center">
<?php
$sql = "SELECT * FROM products WHERE seller_id = '$user_id' AND product_stock < min_order AND product_status = 'On Sale'
ORDER BY product_stock ASC";
$result = mysqli_query($conn, $sql);
foreach($result as $row){
?>
<tr class="table-danger">
<td><?php echo $row['product_name'] ?></td>
<td><?php echo $row['product_stock'] ?></td>
<td></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</body>
</html>