-
Notifications
You must be signed in to change notification settings - Fork 18
/
purchases.php
200 lines (183 loc) · 8.73 KB
/
purchases.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
<?php
session_start();
// 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 getOrderData($table, $userId, $timestamp_column = 'order_at') {
global $con; // Assuming $con is your database connection variable
// Query to select data from the table by ID
$query = "SELECT * FROM $table WHERE user_id='$userId' ORDER BY $timestamp_column DESC";
// Execute the query
$result = mysqli_query($con, $query);
// Check if the query was successful
if ($result) {
return $result; // Return the mysqli_result object
} else {
// Return false if query execution failed
return false;
}
}
?>
<link rel="stylesheet" href="assets/css/transac.css">
<section class="p-5 p-md-5 text-sm-start" id="Purchases" style="margin-bottom: 100px;">
<div class="container" style="margin-top: 60px;">
<div class="row">
<div class="col-md-10">
<h1 style="font-family: 'suez one'; color: #013D67;"><i class="fas fa-chart-line"></i> Transactions</h1>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<div class="card shadow-sm rounded-3 p-3 mt-2 text-center link-body">
<div class="row align-items-center options ">
<div class="links col-md-3">
<a class="main-link active" href="#">Pending Orders</a>
</div>
<div class="links col-md-3">
<a class="main-link" href="deliverOrder.php">Orders for Delivery</a>
</div>
<div class="links col-md-3">
<a class="main-link" href="completedOrder.php">Completed Orders</a>
</div>
<div class="links col-md-3">
<a class="main-link" href="cancelOrder.php">Cancelled Orders</a>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<div class="card shadow-sm rounded-3 p-4 mt-3 text-center">
<div class="row align-items-center">
<div class="col-md-1 d-none d-md-block">
<h6>No.</h6>
</div>
<div class="col-md-2 col-6">
<h6>Items</h6>
</div>
<div class="col-md-2 d-none d-md-block">
<h6>Status</h6>
</div>
<div class="col-md-1 d-none d-md-block">
<h6>Total</h6>
</div>
<div class="col-md-2 d-none d-md-block">
<h6>Date</h6>
</div>
<div class="col-md-2 col-6">
<h6>View Details</h6>
</div>
<div class="col-md-2 d-none d-md-block">
<h6>Cancel Order</h6>
</div>
</div>
<?php
$orderItems = getOrderData('orders', $userId); // GET ORDERS BASED ON USER ID
// Flag to check if any orders out for delivery are found
$ordersOngoingFound = false;
// Iterate through each order
foreach ($orderItems as $order) {
if ($order['status'] == 'Ongoing') {
// Set flag to true if at least one order is found
$ordersOngoingFound = true;
// Fetch the first product for this order
$productItem = getFirstProductByOrderId($order['id']);
// Check if productItem is not null before accessing its elements
if ($productItem !== null) {
?>
<!-- Display Cart Items -->
<div class="card mt-4 cart_data cartpage text-center" style="border:none;">
<div class="row align-items-center p-1">
<div class="col-md-1 d-none d-md-block">
<h5><?= $order['id']; ?></h5>
</div>
<div class="col-md-2 col-6">
<h5><?= $productItem['product_name']; ?></h5>
</div>
<div class="col-md-2 d-none d-md-block">
<h5><?= $order['status']; ?></h5>
</div>
<div class="col-md-1 d-none d-md-block">
<h5><span class="price" style="font-family: 'Poppins', sans-serif;">₱<?= $order['grand_total']; ?></span></h5>
</div>
<div class="col-md-2 d-none d-md-block">
<h5 class="orderDate"><?= formatDate($order['order_at']); ?></h5>
</div>
<div class="col-md-2 align-items-center col-6">
<a href="payment.php?id=<?= $order['id']; ?>" class="btn bg-blue">View Details</a>
</div>
<div class="col-md-2 d-none d-md-block">
<form id="statusForm<?= $order['id']; ?>" action="functions/order_code.php" method="POST">
<input type="hidden" name="order_id" value="<?= $order['id']; ?>">
<select class="reasonSelect" name="reason" style="padding: 8px; border-radius: 10px;" required>
<option value="Unknown" selected>Select Reason</option>
<option value="Incorrect Order">Incorrect Order</option>
<option value="Change of Mind">Change of Mind</option>
<option value="Duplicate Order">Duplicate Order</option>
<option value="Other">Other</option>
</select>
<input type="submit" class="btn bg-red updateButton" style="margin-top: 10px;" name="cancelOrderBtn" value="Cancel Order" disabled>
</form>
</div>
</div>
</div>
<?php
} else {
?>
<!-- No Product Found Message -->
<div class="card mt-4 cart_data cartpage text-center" style="border:none;">
<div class="row align-items-center p-1">
<div class="col-md-10">
<h5 class="errorMessage">No product found for order ID #<?= $order['id']; ?></h5>
</div>
<div class="col-md-2">
<form action="functions/order_code.php" method="POST">
<input type="hidden" name="order_id" value="<?= $order['id']; ?>">
<input type="submit" class="btn bg-red" name="cancelOrderBtn" value="Cancel Order">
</form>
</div>
</div>
</div>
<?php
}
}
}
// If no orders out for delivery are found, display message
if (!$ordersOngoingFound) {
?>
<!-- No Orders Out for Delivery Message -->
<div class="card rounded-3 p-3 mt-3 text-center" style="font-family: 'Poppins'; border:none;">
<span>No ongoing orders.</span>
</div>
<?php
}
?>
</div>
</div>
</div>
</section>
<script>
// Function to toggle the submit button based on reason select
function toggleButton(reasonSelect) {
var form = reasonSelect.closest('form');
var updateButton = form.querySelector('.updateButton'); // Assuming class .updateButton is used for update button
if (reasonSelect.value !== 'Unknown') {
updateButton.removeAttribute('disabled'); // Enable the button when a valid reason is selected
} else {
updateButton.setAttribute('disabled', 'disabled'); // Disable the button for 'Unknown'
}
}
// Initial setup: Attach onchange event listeners to all reason selects
var reasonSelects = document.querySelectorAll('.reasonSelect');
reasonSelects.forEach(function(select) {
select.addEventListener('change', function() {
toggleButton(this);
});
});
</script>
<!--------------- FOOTER --------------->
<?php include('includes/footer.php'); ?>