-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorder_history.php
142 lines (132 loc) · 7.55 KB
/
order_history.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
<?php
include 'includes/common.php';
error_reporting(0);
if (!(isset($_SESSION["email"]))) {
header('location: index.php');
}
if (isset($_POST['cancel'])) {
$user_id = $_SESSION['user_id'];
$order_id = $_POST['cancel'];
$query = "DELETE FROM cart_items WHERE user_id='$user_id' and order_id='$order_id'";
$result = mysqli_query($con, $query) or die($mysqli_error($con));
?>
<script>
window.alert("Order Cancelled.");
</script>
<?php
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Super Market - Order History</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/style.css">
<!-- <link rel="stylesheet" href="assets/css/home.css"> -->
<script type="text/javascript" src="bootstrap/js/jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<?php include 'includes/login-navbar.php'; ?>
<div id="container" class="container mt-4 mb-4">
<div class="row">
<div class="col-sm-12">
<?php
$user_id = $_SESSION['user_id'];
$query = "SELECT DISTINCT order_id FROM cart_items WHERE user_id='$user_id' and order_id IS NOT NULL";
$result = mysqli_query($con, $query) or die($mysqli_error($con));
$collapse = 0;
$num = mysqli_num_rows($result);
if ($num != 0) {
while ($ans = mysqli_fetch_array($result)) {
$collapse++;
?>
<div class="accordion accordion-flush" id="accordionFlushExample">
<div class="accordion-item">
<h2 class="accordion-header d-flex" id="flush-headingOne">
<button class="accordion-button collapsed fw-bold" type="button" data-bs-toggle="collapse" data-bs-target="<?php echo '#flush-collapse' . $collapse; ?>" aria-expanded="false" aria-controls="<?php echo 'flush-collapse' . $collapse; ?>">
Order Id : <?php echo $ans['order_id']; ?>
</button>
<form action="order_history.php" method="POST" id="cancelorder" style="width: 15%;">
<button form="cancelorder" name="cancel" type="submit" value="<?php echo $ans['order_id']; ?>" class="btn btn-outline-danger form-control" style="margin-left: 3px; height: 90%;">Cancel Order</button>
</form>
</h2>
<div id="<?php echo 'flush-collapse' . $collapse; ?>" class="accordion-collapse collapse" aria-labelledby="flush-headingOne" data-bs-parent="#accordionFlushExample">
<div class="accordion-body">
<table class="table text-center">
<thead>
<tr>
<th>Product #</th>
<th>Product Name</th>
<th>Category</th>
<th>Brand</th>
<th>Quantity</th>
<th>Price (per unit)</th>
</tr>
</thead>
<tbody>
<?php
$order_id = $ans['order_id'];
$query = "SELECT products.*, amount FROM products, cart_items WHERE products.id=product_id and user_id='$user_id' and order_id='$order_id'";
$res = mysqli_query($con, $query) or die($mysqli_error($con));
$num = mysqli_num_rows($res);
if ($num != 0) {
$total = 0;
while ($row = mysqli_fetch_array($res)) {
?>
<tr>
<th><?php echo $row['id']; ?></th>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['category']; ?></td>
<td><?php echo $row['brand']; ?></td>
<td><?php echo $row['amount']; ?></td>
<td>₹<?php echo $row['price']; ?></td>
</tr>
<?php
$total += $row['price'] * $row['amount'];
}
?>
<tr>
<th></th>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="fw-bold">Amount Paid : <?php echo '₹' . ($total - ($total * 0.1) + 40); ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php
}
if ($num < 3) {
?>
<div class="row justify-content-center align-items-center text-center" style="height: 50vh;"></div>
<?php
}
} else {
?>
<div class="row justify-content-center align-items-center text-center" style="height: 67.5vh;">
<p>You Have Not Placed an Order Yet. Click <a href="ccart.php" class="text-decoration-none">here</a> to Order.</p>
</div>
<?php
}
?>
</div>
</div>
</div>
<?php include 'includes/login-footer.php' ?>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
</body>
</html>