-
Notifications
You must be signed in to change notification settings - Fork 18
/
transaction_details.php
211 lines (192 loc) · 8.56 KB
/
transaction_details.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
<?php
session_start();
// Check authentication
if (!isset($_SESSION['auth'])) {
$_SESSION['message'] = "Please login first";
header('Location: index.php');
exit();
}
// INCLUDE NECESSARY FILES
include('includes/header.php');
include('includes/orderbar.php');
include('functions/userFunctions.php');
// GET USER ID FROM SESSION
$userId = $_SESSION['user_id'];
// FUNCTION TO GET ORDER DETAILS INCLUDING PRODUCT DETAILS
function getOrderDetaild($con, $order_id) {
// Prepare the SQL query to fetch order details with product information
$query = "SELECT * FROM order_transac WHERE order_id = ?";
$stmt = $con->prepare($query);
// Bind parameters and execute the statement
$stmt->bind_param("i", $order_id);
$stmt->execute();
// Get result
$result = $stmt->get_result();
// Check if the query executed successfully
if ($result && $result->num_rows > 0) {
// Initialize variables to store order details
$orderDetails = array();
$products = array();
// Fetch the order details (assuming only one row for the order details)
$row = $result->fetch_assoc();
$orderDetails['order_transac_id'] = $row['order_transac_id'];
$orderDetails['order_id'] = $row['order_id'];
$orderDetails['subtotal'] = $row['subtotal'];
$orderDetails['status'] = $row['status'];
$orderDetails['additional_fee'] = $row['additional_fee'];
$orderDetails['grand_total'] = $row['grand_total'];
$orderDetails['user_name'] = $row['user_name'];
$orderDetails['phone'] = $row['phone'];
$orderDetails['address'] = $row['address'];
$orderDetails['order_at'] = $row['order_at'];
// Loop through the result to fetch product details
do {
$products[] = array(
'product_id' => $row['product_id'],
'product_name' => $row['product_name'],
'product_image' => $row['product_image'],
'quantity' => $row['quantity'],
'price' => $row['price']
);
} while ($row = $result->fetch_assoc());
// Close the statement
$stmt->close();
// Return order details and products as an associative array
return array(
'orderDetails' => $orderDetails,
'products' => $products
);
} else {
// If no results found, return false or handle error as needed
return false;
}
}
// Fetch order details from URL parameter
if (isset($_GET['id'])) {
$order_id = $_GET['id'];
// Call getOrderDetaild to fetch order details including products
$orderData = getOrderDetaild($con, $order_id);
if ($orderData) {
// Extract order details and products from orderData array
$orderDetails = $orderData['orderDetails'];
$products = $orderData['products'];
} else {
// Handle case where order details are not found
echo "Order details not found.";
}
} else {
// Handle case where order ID parameter is not set
echo "Order ID not provided.";
}
?>
<!-- HTML Section for Payment Details -->
<section class="p-5 p-md-5 mt-4 text-sm-start" style="font-family: 'Poppins'">
<div class="container">
<div class="row">
<div class="col-md-10">
<h1 style="font-family: 'Suez One', sans-serif; color: #013D67;"><i class="fas fa-coins"></i> Payment Details</h1>
</div>
</div>
<div class="row">
<div class="col-md-3 text-center">
<!-- Delivery Details Card -->
<div class="card shadow-sm rounded-3 p-2 mt-4">
<h4>Order ID #<?= $orderDetails['order_transac_id'] ?></h4>
<h6><?= formatDate($orderDetails['order_at']); ?></h6>
</div>
<div class="card shadow-sm rounded-3 p-3 mt-2">
<h4>Order Status</h4>
<div class="p-1">
<h6><?= $orderDetails['status'] ?></h6>
</div>
</div>
<div class="card shadow-sm rounded-3 p-3 mt-2">
<h5>Delivery Details</h5>
<div class="p-1">
<h6>Customer Name: <br><?= $orderDetails['user_name'] ?></h6>
</div>
<div class="p-1">
<h6>Contact Number: <br><?= $orderDetails['phone'] ?></h6>
</div>
<div class="p-1">
<h6>Address: <br><?= $orderDetails['address'] ?></h6>
</div>
</div>
</div>
<div class="col-md-9">
<!-- Order Summary Card -->
<div class="card shadow-sm rounded-3 p-3 mt-4 text-center">
<div class="row align-items-center">
<div class="col-6 col-md-2">
<h5>Quantity</h5>
</div>
<div class="col-6 col-md-4">
<h5>Items</h5>
</div>
<div class="col-md-3 d-none d-md-block">
<h5>Price</h5>
</div>
<div class="col-md-3 d-none d-md-block">
<h5>Total</h5>
</div>
</div>
</div>
<!-- Displaying Product Details -->
<?php foreach ($products as $product) {
$itemTotal = $product['quantity'] * $product['price'];
?>
<div class="card shadow-sm rounded-3 p-3 mt-2 text-center">
<div class="row align-items-center">
<div class="col-6 col-md-2">
<h5><?= $product['quantity'] ?></h5>
</div>
<div class="col-6 col-md-2">
<img src="uploads/<?= $product['product_image'] ?>" width="80px" alt="<?= $product['product_name'] ?>" class="rounded-3">
</div>
<div class="col-md-2 d-none d-md-block">
<h5><?= $product['product_name'] ?></h5>
</div>
<div class="col-md-3 d-none d-md-block">
<h5><?= $product['price'] ?></h5>
</div>
<div class="col-md-3 d-none d-md-block">
<h5><span style="font-family: 'Poppins', sans-serif;">₱<?= $itemTotal ?>.00</span></h5>
</div>
</div>
</div>
<?php } ?>
<!-- Order Summary Card -->
<div class="card shadow-sm rounded-3 p-3 mt-2">
<h5>Order Summary</h5>
<!-- Display subtotal, additional fee, and grand total -->
<div class="row align-items-center justify-content-between">
<div class="col-6 col-md-6 text-start">
<h5>Subtotal:</h5>
</div>
<div class="col-6 col-md-6 text-end">
<h5><span style="font-family: 'Poppins', sans-serif;">₱<?= $orderDetails['subtotal'] ?>.00</span></h5>
</div>
</div>
<div class="row align-items-center justify-content-between">
<div class="col-6 col-md-6 text-start">
<h5>Additional Fee:</h5>
</div>
<div class="col-6 col-md-6 text-end">
<h5><span style="font-family: 'Poppins', sans-serif;">₱<?= $orderDetails['additional_fee'] ?>.00</span></h5>
</div>
</div>
<div class="row align-items-center justify-content-between">
<div class="col-6 col-md-6 text-start">
<h5>Grand Total:</h5>
</div>
<div class="col-6 col-md-6 text-end">
<h5><span style="font-family: 'Poppins', sans-serif;">₱<?= $orderDetails['grand_total'] ?>.00</span></h5>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- FOOTER -->
<?php include('includes/footer.php'); ?>