-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpurchase_history.php
139 lines (131 loc) · 6.81 KB
/
purchase_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
<?php
require('services/check_user_login.php');
include("services/connect.php");
?>
<!doctype html>
<html class="no-js" lang="en">
<head>
<?php include('user/components/head.php') ?>
</head>
<body>
<?php
include("services/connect.php");
?>
<!-- header start -->
<?php include('user/components/header.php') ?>
<!-- header end -->
<!-- body start -->
<body>
<div class="cart-main-area pt-95 pb-100">
<br><br><br><br><br><br><br>
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-6">
<h1 class="cart-heading">Lịch sử mua hàng</h1>
<form action="#">
<div class="table-content table-responsive">
<?php
//lấy giỏ hàng
if (isset($_SESSION['user'])) {
//$cart = $_SESSION['cart'];
$user_id = $_SESSION['user']['id'];
$sql = " SELECT * FROM orders WHERE id_user = '$user_id' ";
$rs = mysqli_query($connect, $sql);
$total = 0;
$count = 0;
?>
<table class="table table-hover">
<thead>
<tr>
<th>STT</th>
<th>Ngày tạo đơn</th>
<th>Thành tiền</th>
<th>Trạng thái</th>
<th>Chi tiết đơn hàng </th>
<th>Hành động</th>
</thead>
<tbody>
<?php foreach ($rs as $item) :
$total += $item['total_price'];
$count++;
?>
<tr>
<td><?= $count ?></td>
<td><?= $item['created_at'] ?></td>
<td><?= number_format($item['total_price']) . 'VND' ?></td>
<td class="
<?php if ($item['status'] === 'Đang xử lý') {
echo 'text-warning';
} else if ($item['status'] === 'Thành công' || $item['status'] === 'Đã duyệt') {
echo 'text-success';
} else if ($item['status'] === 'Đã hủy' || $item['status'] === 'Đã xóa') {
echo 'text-danger';
} ?>"><?= $item['status'] ?></td>
<td>
<a class="cart-btn" href="order_details.php?id=<?php echo $item['id'] ?>">Chi tiết</a>
</td>
<?php if ($item['status'] === 'Đang xử lý') { ?>
<td>
<!-- <a class="cart-btn text-danger" href="cancel_order.php?id=<?php echo $item['id'] ?>">Hủy đơn</a> -->
<a class="cart-btn text-danger" href="javascript:void(0);" onclick="remove(<?php echo $item['id'] ?>)">Hủy đơn</a>
</td>
<?php } ?>
</tr>
<?php endforeach ?>
<tr>
<td colspan=" 4"><strong>Tổng tiền</strong>
</td>
<td><b id="tongTien"><?= number_format($total) ?></b></td>
</tr>
</tbody>
</table>
<?php
} else {
echo 'Đăng nhập để xem lại lịch sử mua hàng';
}
?>
</div>
<div class="row">
<div class="col-md-5 ml-auto">
<div class="cart-page-total">
<a href="index.php">Trở về trang chủ</a>
</div>
</div>
</div>
</form>
<form action="cancel_order.php" method="POST" id="form_delete">
<input type="hidden" name="id" id="id_delete">
</form>
</div>
</div>
</div>
</div>
<!-- all js here -->
<?php include('user/components/link_footer.php') ?>
</body>
<?php include('user/components/footer.php'); ?>
<script>
function remove(id) {
console.log(id)
$("#id_delete").val(id);
const form = $('#form_delete');
swal({
title: "Bạn chắc chắn?",
text: "Khi đã xóa, bạn sẽ không thể lấy lại được bản ghi!",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
$('#form_delete').submit();
swal("Bạn đã xóa một bản ghi! " + id, {
icon: "success",
});
} else {
swal("Bản ghi an toàn!");
}
});
}
</script>
</html>