-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.php
142 lines (119 loc) · 5.86 KB
/
transaction.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_once "includes/header.php";
include_once "config/config.php";
?>
<?php
if (!isset($_SESSION['user'])){
// header("Location: localhost/Freshcery");
echo "<script> window.location.href = ".URL()." </script>";
exit();
}
?>
<?php
if (isset($_GET['id'])){
$id = $_GET['id'];
// Checking if the ID matches the user's id
if ($id != $_SESSION['user']['id']){
echo "<script> window.location.href = ".URL()." </script>";
exit();
}
// Getting all the orders for the user
$sql = "SELECT * FROM orders WHERE user_id = :user_id";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':user_id', $id);
$stmt->execute();
$orders = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Getting the count of orders
$count = count($orders);
$i = 0;
}
else {
echo "<script> window.location.href = ".URL('404.php')." </script>";
exit();
}
?>
<div id="page-content" class="page-content">
<div class="banner">
<div class="jumbotron jumbotron-bg text-center rounded-0" style="background-image: url('assets/img/bg-header.jpg');">
<div class="container">
<h1 class="pt-5">
Your Transactions
</h1>
<p class="lead">
Save time and leave the groceries to us.
</p>
</div>
</div>
</div>
<section id="cart">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-striped table-hover mt-4">
<thead>
<tr>
<th width="5%">#</th>
<th>Invoice</th>
<th>Date</th>
<th>Total</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
<?php if($count > 0 ): ?>
<?php foreach ($orders as $order) :?>
<?php
// Determine the class based on the order status
$status = strtolower($order['status']); // Convert status to lowercase to standardize
$statusStyle = '';
switch ($status) {
case 'pending':
$statusStyle = 'background-color: #ffcc00; color: #000; padding: 3px 10px; border-radius: 10px;';
break;
case 'completed':
$statusStyle = 'background-color: #4caf50; color: #fff; padding: 3px 10px; border-radius: 10px;';
break;
case 'cancelled':
$statusStyle = 'background-color: #f44336; color: #fff; padding: 3px 10px; border-radius: 10px;';
break;
default:
$statusStyle = ''; // No styles if status doesn't match
break;
}
?>
<tr>
<td><?=++$i?></td>
<td>
<?=generateAlphanumericString($order['id'])?>
</td>
<td>
<?=date("Y-m-d", strtotime($order['created_at']))?>
</td>
<td>
USD <?=$order['total_price']?>
</td>
<td>
<span style="<?=$statusStyle?>">
<?=$status?>
</span>
</td>
</tr>
<?php endforeach;?>
<?php else: ?>
<tr>
<td colspan="6">No transaction found.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
</div>
<?php
include_once "includes/footer.php";
?>