36780-vm/admin/order_detail.php
Flatlogic Bot 026744b461 v3
2025-12-09 10:07:44 +00:00

95 lines
4.4 KiB
PHP

<?php
require_once __DIR__ . '/../db/config.php';
require_once __DIR__ . '/partials/header.php';
if (!isset($_GET['id']) || empty($_GET['id'])) {
header('Location: orders.php');
exit;
}
$order_id = $_GET['id'];
$pdo = db();
// Fetch order details
$stmt = $pdo->prepare('SELECT * FROM orders WHERE id = ?');
$stmt->execute([$order_id]);
$order = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$order) {
die('Order not found.');
}
// Fetch order items
$stmt = $pdo->prepare('SELECT oi.quantity, oi.price, p.name FROM order_items oi JOIN products p ON oi.product_id = p.id WHERE oi.order_id = ?');
$stmt->execute([$order_id]);
$items = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<div class="container-fluid">
<div class="row">
<?php require_once __DIR__ . '/partials/sidebar.php'; ?>
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Detail Pesanan #<?php echo htmlspecialchars($order['id']); ?></h1>
<a href="orders.php" class="btn btn-secondary">Kembali ke Daftar Pesanan</a>
</div>
<div class="row">
<div class="col-md-6">
<h4>Informasi Pelanggan</h4>
<p><strong>Nama:</strong> <?php echo htmlspecialchars($order['customer_name']); ?></p>
<p><strong>Email:</strong> <?php echo htmlspecialchars($order['customer_email']); ?></p>
</div>
<div class="col-md-6">
<h4>Informasi Pesanan</h4>
<p><strong>Total:</strong> Rp <?php echo number_format($order['total_amount'], 2, ',', '.'); ?></p>
<p><strong>Status:</strong> <span class="badge bg-info"><?php echo htmlspecialchars($order['status']); ?></span></p>
<p><strong>Tanggal:</strong> <?php echo date('d M Y, H:i', strtotime($order['created_at'])); ?></p>
<form action="order_update_status.php" method="POST" class="mt-3">
<input type="hidden" name="order_id" value="<?php echo $order['id']; ?>">
<div class="input-group">
<select name="status" class="form-select">
<option value="Pending" <?php echo ($order['status'] == 'Pending') ? 'selected' : ''; ?>>Pending</option>
<option value="Processing" <?php echo ($order['status'] == 'Processing') ? 'selected' : ''; ?>>Processing</option>
<option value="Shipped" <?php echo ($order['status'] == 'Shipped') ? 'selected' : ''; ?>>Shipped</option>
<option value="Completed" <?php echo ($order['status'] == 'Completed') ? 'selected' : ''; ?>>Completed</option>
<option value="Cancelled" <?php echo ($order['status'] == 'Cancelled') ? 'selected' : ''; ?>>Cancelled</option>
</select>
<button type="submit" class="btn btn-success">Update Status</button>
</div>
</form>
</div>
</div>
<h4 class="mt-4">Item Pesanan</h4>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Produk</th>
<th>Jumlah</th>
<th>Harga</th>
<th>Subtotal</th>
</tr>
</thead>
<tbody>
<?php foreach ($items as $item): ?>
<tr>
<td><?php echo htmlspecialchars($item['name']); ?></td>
<td><?php echo htmlspecialchars($item['quantity']); ?></td>
<td>Rp <?php echo number_format($item['price'], 2, ',', '.'); ?></td>
<td>Rp <?php echo number_format($item['price'] * $item['quantity'], 2, ',', '.'); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</main>
</div>
</div>
<?php require_once __DIR__ . '/partials/footer.php'; ?>