<?php
include(__DIR__ . '/../config.php');
include(__DIR__ . '/../header/header.php');

$stmt = $pdo->query("SELECT * FROM orders ORDER BY id DESC");
$orders = $stmt->fetchAll();
?>

<div class="container py-5">

<h2>Orders</h2>

<table class="table table-bordered">
<tr>
<th>ID</th>
<th>Name</th>
<th>Phone</th>
<th>Total</th>
<th>Date</th>
<th>View</th>
</tr>

<?php foreach($orders as $o): ?>
<tr>
<td><?= $o['id']; ?></td>
<td><?= htmlspecialchars($o['customer_name']); ?></td>
<td><?= $o['customer_phone']; ?></td>
<td>KES <?= number_format($o['total']); ?></td>
<td><?= $o['created_at']; ?></td>
<td>
<a href="admin_order_view.php?id=<?= $o['id']; ?>" class="btn btn-sm btn-primary">View</a>
</td>
</tr>
<?php endforeach; ?>

</table>

</div>