File size: 3,886 Bytes
c7257f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php
require_once 'require_auth.php';
// Fetch orders and items
try {
    $stmt = $pdo->prepare("SELECT * FROM orders ORDER BY created_at DESC");
    $stmt->execute();
    $orders = $stmt->fetchAll(PDO::FETCH_ASSOC);

    foreach ($orders as &$order) {
        $stmt = $pdo->prepare("SELECT * FROM order_items WHERE order_id = ?");
        $stmt->execute([$order['id']]);
        $order['items'] = $stmt->fetchAll(PDO::FETCH_ASSOC);
    }
} catch (Exception $e) {
    $orders = [];
}
?>
<!DOCTYPE html>
<html lang="sl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin - Naročila</title>
    <script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 font-sans">
    <div class="max-w-6xl mx-auto p-6">
        <h1 class="text-2xl font-bold mb-4">Vsa naročila</h1>

        <?php if (empty($orders)): ?>
            <p class="text-gray-600">Ni naročil za prikaz.</p>
        <?php else: ?>
            <?php foreach ($orders as $order): ?>
                <div class="bg-white shadow rounded mb-4 p-4">
                    <div class="flex justify-between items-start">
                        <div>
                            <h2 class="text-lg font-semibold">Naročilo #<?php echo htmlspecialchars($order['id']); ?></h2>
                            <p class="text-sm text-gray-600"><?php echo htmlspecialchars($order['customer_name']); ?> — <?php echo htmlspecialchars($order['customer_email']); ?></p>
                            <p class="text-sm text-gray-600">Status: <?php echo htmlspecialchars($order['status']); ?></p>
                        </div>
                        <div class="text-right">
                            <p class="text-sm text-gray-600"><?php echo htmlspecialchars($order['created_at']); ?></p>
                            <p class="text-lg font-bold"><?php echo htmlspecialchars(number_format((float)$order['total_amount'], 2, ',', '.')) . '€'; ?></p>
                        </div>
                    </div>

                    <?php if (!empty($order['items'])): ?>
                        <div class="mt-3">
                            <table class="w-full text-left text-sm">
                                <thead class="text-xs text-gray-500 uppercase">
                                    <tr>
                                        <th>Izdelek</th>
                                        <th class="text-right">Količina</th>
                                        <th class="text-right">Enotna cena</th>
                                        <th class="text-right">Skupaj</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ($order['items'] as $item): ?>
                                        <tr>
                                            <td><?php echo htmlspecialchars($item['product_name'] ?? $item['name'] ?? 'Izdelek'); ?></td>
                                            <td class="text-right"><?php echo htmlspecialchars($item['quantity']); ?></td>
                                            <td class="text-right"><?php echo htmlspecialchars(number_format((float)($item['unit_price'] ?? $item['price'] ?? 0), 2, ',', '.')) . '€'; ?></td>
                                            <td class="text-right"><?php echo htmlspecialchars(number_format((float)($item['unit_price'] * $item['quantity']), 2, ',', '.')) . '€'; ?></td>
                                        </tr>
                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                    <?php endif; ?>
                </div>
            <?php endforeach; ?>
        <?php endif; ?>
    </div>
</body>
</html>