-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorder_admin.php
More file actions
262 lines (210 loc) · 10.3 KB
/
order_admin.php
File metadata and controls
262 lines (210 loc) · 10.3 KB
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<!-- Untuk Akses Masuk -->
<?php
session_start();
// cek apakah yang mengakses halaman ini sudah login
if ($_SESSION['level'] == "") {
header("location:login.php?pesan=gagal");
}
?>
<?php
include('koneksi.php');
// Menghapus data dari tabel orders
if (isset($_GET['delete_id'])) {
$delete_id = $_GET['delete_id'];
$deleteQuery = "DELETE FROM orders WHERE id = $delete_id";
mysqli_query($koneksi, $deleteQuery);
header("Location: order_admin.php");
exit();
}
mysqli_close($koneksi);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Orders Admin</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans:400,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Great+Vibes" rel="stylesheet">
<link rel="stylesheet" href="css/open-iconic-bootstrap.min.css">
<link rel="stylesheet" href="css/animate.css">
<link rel="stylesheet" href="css/owl.carousel.min.css">
<link rel="stylesheet" href="css/owl.theme.default.min.css">
<link rel="stylesheet" href="css/magnific-popup.css">
<link rel="stylesheet" href="css/aos.css">
<link rel="stylesheet" href="css/ionicons.min.css">
<link rel="stylesheet" href="css/bootstrap-datepicker.css">
<link rel="stylesheet" href="css/jquery.timepicker.css">
<link rel="stylesheet" href="css/flaticon.css">
<link rel="stylesheet" href="css/icomoon.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php include 'header_admin.php'; ?>
<br><br><br>
<div class="container mt-5">
<h2>Tabel Orders</h2>
<div class="text-center mb-3">
<a href="order_admin.php?status=completed" class="btn btn-info mr-2">Completed Orders</a>
<a href="order_admin.php?status=pending" class="btn btn-warning">Pending Orders</a>
</div>
<div class="table-responsive">
<table class="table table-bordered">
<thead class="thead-dark">
<tr>
<th>ID</th>
<th>Nama Pelanggan</th>
<th>Nomor Meja</th>
<th>Nama Produk</th>
<th>Total Harga</th>
<th>Tanggal</th>
<th>Status Transaksi</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php
include('koneksi.php');
$status = $_GET['status'] ?? '';
if ($status === 'completed') {
$query = "SELECT * FROM orders WHERE status_transaksi = 'completed'";
} elseif ($status === 'pending') {
$query = "SELECT * FROM orders WHERE status_transaksi = 'pending'";
} else {
$query = "SELECT * FROM orders";
}
$result = mysqli_query($koneksi, $query);
if ($result && mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['nama_pelanggan'] . "</td>";
echo "<td>" . $row['nomor_meja'] . "</td>";
echo "<td>";
// Membagi item menjadi bagian-bagian terpisah dan menampilkan checkbox sebelumnya
$items = explode(", ", $row['nama_produk']);
foreach ($items as $item) {
$checkboxValue = $row['id'] . '_' . $item; // Menggunakan nilai unik untuk setiap checkbox
$isChecked = (isset($_SESSION[$checkboxValue]) && $_SESSION[$checkboxValue] === 'true') ? 'checked' : '';
echo "<div>";
echo "<input type='checkbox' name='menu_checked[]' value='" . $checkboxValue . "' " . $isChecked . ">" . $item . "<br>";
echo "</div>";
}
echo "</td>";
echo "<td>" . $row['total_harga'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>
<form action='order_admin.php' method='post'>";
echo "<select id='status_" . $row['id'] . "' name='status_transaksi' class='form-control'>";
echo "<option value='pending' " . (($row['status_transaksi'] == 'pending') ? 'selected' : '') . ">Pending</option>";
echo "<option value='completed' " . (($row['status_transaksi'] == 'completed') ? 'selected' : '') . ">Completed</option>";
echo "</select>";
echo "<input type='hidden' name='order_id' value='" . $row['id'] . "'>";
echo "<button type='submit' name='update_status' class='btn btn-primary btn-sm mt-2'>Update</button>";
echo "</form>";
echo "</td>";
echo "<td>"; // Buka kolom baru untuk aksi Delete
echo "<a href='order_admin.php?delete_id=" . $row['id'] . "' class='btn btn-danger btn-sm' onclick='return confirm(\"Delete this order?\");'>Delete</a>";
echo "</td>"; // Tutup kolom aksi Delete
echo "</tr>";
}
} else {
echo "<tr><td colspan='9'>Tidak ada data dalam tabel orders.</td></tr>";
}
if (isset($_POST['update_status'])) {
$order_id = $_POST['order_id'];
$status_transaksi = $_POST['status_transaksi'];
$updateQuery = "UPDATE orders SET status_transaksi = '$status_transaksi' WHERE id = $order_id";
$updateResult = mysqli_query($koneksi, $updateQuery);
if ($updateResult) {
echo '<script>alert("Status transaksi berhasil diperbarui!"); window.location.replace("order_admin.php");</script>';
} else {
echo '<script>alert("Gagal memperbarui status transaksi.");</script>';
}
}
mysqli_close($koneksi);
?>
</tbody>
</table>
</div>
</div>
<br><br><br>
<div class="container">
<div class="row justify-content-end mt-3">
<div class="col-auto">
<a href="laporan-cetak.php" class="btn btn-success" target="_blank">Download Laporan PDF</a>
</div>
</div>
</div>
<br><br><br><br><br>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('.update-status').on('click', function(e) {
e.preventDefault();
var orderID = $(this).data('order-id');
var status = $('#status_' + orderID).val();
$.ajax({
type: 'POST',
url: 'order_admin.php',
data: {
update_status: true,
order_id: orderID,
status_transaksi: status
},
success: function(response) {
alert("Status transaksi berhasil diperbarui!");
// You can do other things like updating the UI if necessary
},
error: function() {
alert("Gagal memperbarui status transaksi.");
}
});
});
});
</script>
<script>
document.addEventListener("DOMContentLoaded", function() {
const checkboxes = document.querySelectorAll('input[name="menu_checked[]"]');
checkboxes.forEach(function(checkbox) {
checkbox.addEventListener('change', function() {
const checkboxValue = this.value;
if (this.checked) {
sessionStorage.setItem(checkboxValue, 'true');
} else {
sessionStorage.removeItem(checkboxValue);
}
});
const checkboxValue = checkbox.value;
const isChecked = sessionStorage.getItem(checkboxValue);
if (isChecked === 'true') {
checkbox.checked = true;
}
});
});
</script>
<!-- loader -->
<div id="ftco-loader" class="show fullscreen"><svg class="circular" width="48px" height="48px">
<circle class="path-bg" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke="#eeeeee" />
<circle class="path" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke-miterlimit="10" stroke="#F96D00" />
</svg></div>
<script src="js/jquery.min.js"></script>
<script src="js/jquery-migrate-3.0.1.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src="js/jquery.waypoints.min.js"></script>
<script src="js/jquery.stellar.min.js"></script>
<script src="js/owl.carousel.min.js"></script>
<script src="js/jquery.magnific-popup.min.js"></script>
<script src="js/aos.js"></script>
<script src="js/jquery.animateNumber.min.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script src="js/jquery.timepicker.min.js"></script>
<script src="js/scrollax.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBVWaKrjvy3MaE7SQ74_uJiULgl1JY0H2s&sensor=false"></script>
<script src="js/google-map.js"></script>
<script src="js/main.js"></script>
</body>
</html>