This repository has been archived by the owner on Apr 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
orderDetail.php
executable file
·362 lines (314 loc) · 16.8 KB
/
orderDetail.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<?php
include('boilerplate.php');
if (!$customer_id) {
echo '<script>
location.href="login.php"
</script>';
}
if (!$_GET['id']) {
echo '<script>
location.href="error.php"
</script>';
}
$order_id = $_GET['id'];
include "dbConfig.php";
$queries = new queries;
$sendEmail = new sendEmail;
if (isset($_POST['cancel'])) {
$fullName = $_SESSION['name'];
$email = $_SESSION['email'];
$url = "https://" . $_SERVER['SERVER_NAME'] . "/aanav/orderDetail.php?id=".$order_id;
$url2 = "https://" . $_SERVER['SERVER_NAME'] . "/aanav/contact.php";
$subject = 'Thank you';
$body = '<p style="color:#66FCF1; font-size: 32px;" >Hi ' . $fullName . '</p><p style="color:grey; font-size: 16px;" >Your order has been cancelled successfully.</p>
<p><a style="background-color: #66FCF1;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
-webkit-transition-duration: 0.4s;
transition-duration: 0.4s;"
href="' . $url . '">Order Details</a></p><p style="color:red; font-size: 10px;" > Need Help ? <a href="' . $url2 . '" >Contact Us</a></p>';
$sql = "UPDATE orders SET status='0',modified_date=now() WHERE customer_id = '$customer_id' AND status<4 AND order_id=".$order_id;
if (mysqli_query($connect, $sql)) {
$sendEmail->send($fullName, $email, $subject, $body);
$_SESSION['order'] = "Your order has been cancelled successfully.";
}
}
if (isset($_POST['return'])) {
$fullName = $_SESSION['name'];
$email = $_SESSION['email'];
$url = "https://" . $_SERVER['SERVER_NAME'] . "/aanav/orderDetail.php?id=".$order_id;
$url2 = "https://" . $_SERVER['SERVER_NAME'] . "/aanav/contact.php";
$subject = 'Thank you';
$body = '<p style="color:#66FCF1; font-size: 32px;" >Hi ' . $fullName . '</p><p style="color:grey; font-size: 16px;" >Your refund request has been registered successfully.We will contact you soon.</p>
<p><a style="background-color: #66FCF1;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
-webkit-transition-duration: 0.4s;
transition-duration: 0.4s;"
href="' . $url . '">Order Details</a></p><p style="color:red; font-size: 10px;" > Need Help ? <a href="' . $url2 . '">Contact Us</a></p>';
$sql = "UPDATE orders SET status='5',modified_date=now() WHERE customer_id = '$customer_id' AND status='4' AND order_id=".$order_id;
if (mysqli_query($connect, $sql)) {
$sendEmail->send($fullName, $email, $subject, $body);
$_SESSION['order'] = "Your refund request has been registered successfully.We will contact you soon.";
}
}
?>
<section class="borderless-table carousel-info">
<div class="container">
<div class="row">
<?php if (isset($_SESSION['order'])) : ?>
<div class="col-md-6 mx-auto text-center">
<div class="alert alert-success">
<?php echo $_SESSION['order']; ?>
</div>
</div>
<?php endif; ?>
<?php unset($_SESSION['order']); ?>
<?php
$orders = mysqli_query($connect, "SELECT * FROM orders WHERE customer_id = '$customer_id' and order_id = '$order_id'");
$order_prop = mysqli_fetch_assoc($orders);
?>
<div class="col-lg-12 mx-auto my-3">
<div class="container">
<div class="row">
<div class="col-lg-6">
<table class="table table-borderless">
<tr>
<th>Name</th>
<td><span class="badge badge-light"><?php echo $order_prop['full_name'] ?></span></td>
</tr>
<tr>
<th>Email</th>
<td><span class="badge badge-light"><?php echo $order_prop['email'] ?></span></td>
</tr>
<tr>
<th>Phone</th>
<td><span class="badge badge-light"><?php echo $order_prop['phone'] ?></span></td>
</tr>
<tr>
<th>Order placed at</th>
<td><span class="badge badge-light"><?php echo $order_prop['created_date'] ?></span></td>
</tr>
<tr>
<th>Order updated at</th>
<td><span class="badge badge-light"><?php echo $order_prop['modified_date'] ?></span></td>
</tr>
<tr>
<th>Quantity</th>
<td><span class="badge badge-info"><?php echo $order_prop['total_qty'] ?> pcs</span></td>
</tr>
<tr>
<th>Total</th>
<td><span class="badge badge-success">₹ <?php echo $order_prop['total_amt'] ?></span>
</td>
</tr>
</table>
</div>
<div class="col-lg-6">
<table class="table table-borderless">
<?php if ($order_prop['store_id'] == 0) { ?>
<tr>
<th>Order Status</th>
<td>
<?php if ($order_prop['status'] == 0) { ?>
<span class="badge badge-danger">Cancelled</span>
<?php } else if ($order_prop['status'] == 1) { ?>
<span class="badge badge-warning">Placed</span>
<?php } else if ($order_prop['status'] == 2) { ?>
<span class="badge badge-success">Approved</span>
<?php } else if ($order_prop['status'] == 3) { ?>
<span class="badge badge-info">Shipped</span>
<?php } else if ($order_prop['status'] == 4) { ?>
<span class="badge badge-success">Deliverd</span>
<?php } else if ($order_prop['status'] == 5) { ?>
<span class="badge badge-info">Refund Requested</span>
<?php } else if ($order_prop['status'] == 6) { ?>
<span class="badge badge-success">Refunded</span>
<?php } else { ?>
<span class="badge badge-danger">Error</span>
<?php } ?>
</td>
</tr>
<tr>
<th>Payment Type</th>
<td><span class="badge badge-light"><?php echo $order_prop['payment_type'] ?></td>
</tr>
<tr>
<th>Delivery Type</th>
<td><span class="badge badge-light">Home Delivery </td>
</tr>
<tr>
<th>Address</th>
<td><span class="badge badge-light"><?php echo $order_prop['street_address'] ?><?php echo $order_prop['street_address'] ?></td>
</tr>
<tr>
<th>City</th>
<td><span class="badge badge-light"><?php echo $order_prop['city'] ?></td>
</tr>
<tr>
<th>State</th>
<td><span class="badge badge-light"><?php echo $order_prop['state'] ?></td>
</tr>
<tr>
<th>Pincode</th>
<td><span class="badge badge-light"><?php echo $order_prop['pincode'] ?></td>
</tr>
<tr>
<?php } else { ?>
<tr>
<th>Order Status</th>
<td>
<?php if ($order_prop['status'] == 0) { ?>
<span class="badge badge-danger">Cancelled</span>
<?php } else if ($order_prop['status'] == 1) { ?>
<span class="badge badge-warning">Placed</span>
<?php } else if ($order_prop['status'] == 2) { ?>
<span class="badge badge-success">Approved</span>
<?php } else if ($order_prop['status'] == 3) { ?>
<span class="badge badge-info">Shipped</span>
<?php } else if ($order_prop['status'] == 4) { ?>
<span class="badge badge-success">Deliverd</span>
<?php } else if ($order_prop['status'] == 5) { ?>
<span class="badge badge-info">Refund Requested</span>
<?php } else if ($order_prop['status'] == 6) { ?>
<span class="badge badge-success">Refunded</span>
<?php } else { ?>
<span class="badge badge-danger">Error</span>
<?php } ?>
</td>
</tr>
<tr>
<th>Payment Type</th>
<td><span class="badge badge-light"><?php echo $order_prop['payment_type'] ?></td>
</tr>
<tr>
<th>Delivery Type</th>
<td><span class="badge badge-light">Store Pickup</td>
</tr>
<?php $store_sql = "SELECT * FROM store WHERE store_id =" . $order_prop['store_id'];
$store_query = mysqli_query($connect, $store_sql);
while ($store_row = mysqli_fetch_array($store_query)) {
?>
<tr>
<th>Store Name</th>
<td><span class="badge badge-light"><?php echo $store_row['store_name'] ?></td>
</tr>
<tr>
<th>Store Email</th>
<td><span class="badge badge-light"><?php echo $store_row['email'] ?></td>
</tr>
<tr>
<th>Store Phone</th>
<td><span class="badge badge-light"><?php echo $store_row['phone'] ?></td>
</tr>
<tr>
<th>Store Address</th>
<td><span class="badge badge-light"><?php echo $store_row['address'] ?></td>
</tr>
<?php }
} ?>
</table>
</div>
</div>
<div class="col-lg-6 mx-auto mt-5 text-center">
<a href="invoice.php?id=<?php echo $order_id ?>" class="m-2 btn btn-sm btn-success">
<i class="fa fa-download mr-2"></i> <b>Download Invoice</b></a>
<?php if ($order_prop['status'] > 0 && $order_prop['status'] < 4 ) { ?>
<form method="post" class="comment-form">
<button type="submit" name="cancel" class="m-2 btn btn-sm btn-danger">
<i class="fa fa-window-close mr-2"></i><b>Cancel Order</b></button>
</form>
<?php } else if ($order_prop['status'] == 4) { ?>
<form method="post" class="comment-form">
<button type="submit" name="return" class="m-2 btn btn-sm btn-info">
<i class="fa fa-undo mr-2"></i><b>Request Refund</b></button>
</form>
<?php } ?>
</div>
<div class="col-lg-9 mt-5 mx-auto">
<div class="cart-table">
<table>
<thead>
<tr>
<th>Product</th>
<th>Name</th>
<th>Specs</th>
<th>Cost</th>
<th>Qty</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM order_detail WHERE customer_id = '$customer_id' and order_id = '$order_id'
ORDER BY order_item_id DESC";
$run = mysqli_query($connect, $sql);
$count = mysqli_num_rows($run);
if (!$count) {
echo '<script>
location.href="error.php"
</script>';
}
while ($row = mysqli_fetch_assoc($run)) : {
$id = $row['order_item_id'];
$pid = $row['product_id'];
$vid = $row['variant_id'];
$img_sql = mysqli_query($connect, "SELECT file FROM product where id='$pid'");
$pro_prop = mysqli_fetch_assoc($img_sql);
$result_2 = mysqli_query($connect, "SELECT color,size FROM variant where variant_id='$vid'");
$attr_prop = mysqli_fetch_assoc($result_2);
$color_id = $attr_prop['color'];
$size_id = $attr_prop['size'];
$result_3 = mysqli_query($connect, "SELECT value FROM attribute where attr_id='$color_id'");
$variant_prop = mysqli_fetch_assoc($result_3);
$color = $variant_prop['value'];
$result_4 = mysqli_query($connect, "SELECT value FROM attribute where attr_id='$size_id'");
$variant_prop = mysqli_fetch_assoc($result_4);
$size = $variant_prop['value'];
?>
<tr>
<td class="cart-pic first-row"><a href="product.php?id=<?php echo $pid ?>">
<img width="150" height="150" src="uploads/<?php echo $pro_prop['file'] ?>" alt="product image"></a></td>
<td class="cart-title first-row">
<span style="font-size: 1.1em;" class="badge badge-light"><?php echo $row['product_name'] ?></span>
</td>
<td class="cart-title first-row">
<a style="color:white; background-color:<?php echo $color ?>;" class="badge "><b><?php echo $size ?></b></a>
</td>
<td class="cart-title first-row">
<span class="badge badge-info">₹ <?php echo $row['price'] ?></span>
</td>
<td class="cart-title first-row">
<span class="badge badge-light">
<?php echo $row['units'] ?></span>
</td>
<td class="cart-title first-row">
<span class="badge badge-success">₹ <?php echo $row['total'] ?></span>
</td>
</tr>
<?php }
endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<?php include('footer.php'); ?>