Spaces:
Running
Running
File size: 19,401 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 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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
<?php
require_once 'require_auth.php';
// Fetch basic stats and recent orders for the dashboard
try {
// Orders count and revenue
$stmt = $pdo->query("SELECT COUNT(*) as orders_count, COALESCE(SUM(total_amount),0) as revenue FROM orders");
$stats = $stmt->fetch(PDO::FETCH_ASSOC);
$orders_count = $stats['orders_count'] ?? 0;
$revenue = $stats['revenue'] ?? 0.00;
// Products count
$stmt = $pdo->query("SELECT COUNT(*) FROM products");
$products_count = (int)$stmt->fetchColumn();
// Customers count
$stmt = $pdo->query("SELECT COUNT(*) FROM customers");
$customers_count = (int)$stmt->fetchColumn();
// Recent orders (latest 10)
$stmt = $pdo->prepare("SELECT id, customer_name, status, total_amount, created_at FROM orders ORDER BY created_at DESC LIMIT 10");
$stmt->execute();
$recentOrders = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $e) {
// Graceful fallback to zeros/empty if the DB query fails
$orders_count = $orders_count ?? 0;
$revenue = $revenue ?? 0.00;
$products_count = $products_count ?? 0;
$customers_count = $customers_count ?? 0;
$recentOrders = [];
}
?>
<!DOCTYPE html>
<html lang="sl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Administracija | Čebelarstvo Cigoj</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<style>
.sidebar {
transition: all 0.3s;
}
.sidebar-link:hover {
background-color: rgba(251, 191, 36, 0.1);
}
.dashboard-card {
transition: transform 0.2s;
}
.dashboard-card:hover {
transform: translateY(-2px);
}
</style>
</head>
<body class="bg-gray-100 font-sans">
<!-- Admin Layout -->
<div class="flex h-screen">
<!-- Sidebar -->
<div class="sidebar bg-amber-800 text-white w-64 flex-shrink-0">
<div class="p-4 border-b border-amber-700">
<h1 class="text-xl font-bold flex items-center">
<i data-feather="hexagon" class="mr-2"></i>
Čebelarstvo Cigoj
</h1>
<p class="text-xs text-amber-200 mt-1">Administracija</p>
</div>
<nav class="p-4">
<ul class="space-y-2">
<li>
<a href="#" class="sidebar-link flex items-center px-3 py-2 rounded-lg bg-amber-700 text-white">
<i data-feather="home" class="mr-3"></i>
Nadzorna plošča
</a>
</li>
<li>
<a href="products.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-amber-200 hover:text-white">
<i data-feather="shopping-bag" class="mr-3"></i>
Izdelki
</a>
</li>
<li>
<a href="orders.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-amber-200 hover:text-white">
<i data-feather="file-text" class="mr-3"></i>
Naročila
</a>
</li>
<li>
<a href="customers.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-amber-200 hover:text-white">
<i data-feather="users" class="mr-3"></i>
Stranke
</a>
</li>
<li>
<a href="reports.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-amber-200 hover:text-white">
<i data-feather="bar-chart-2" class="mr-3"></i>
Poročila
</a>
</li>
<li>
<a href="settings.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-amber-200 hover:text-white">
<i data-feather="settings" class="mr-3"></i>
Nastavitve
</a>
</li>
</ul>
</nav>
</div>
<!-- Main Content -->
<div class="flex-1 overflow-auto">
<!-- Top Navigation -->
<header class="bg-white shadow-sm">
<div class="flex justify-between items-center p-4">
<div class="flex items-center">
<button class="p-2 rounded-full hover:bg-gray-100 mr-2">
<i data-feather="menu"></i>
</button>
<h2 class="text-lg font-semibold">Nadzorna plošča</h2>
</div>
<div class="flex items-center space-x-4">
<button class="p-2 rounded-full hover:bg-gray-100 relative">
<i data-feather="bell"></i>
<span class="absolute top-0 right-0 h-2 w-2 rounded-full bg-red-500"></span>
</button>
<div class="flex items-center">
<div class="w-8 h-8 rounded-full bg-amber-200 flex items-center justify-center mr-2">
<i data-feather="user"></i>
</div>
<span class="text-sm">Admin</span>
</div>
</div>
</div>
</header>
<!-- Dashboard Content -->
<main class="p-6">
<!-- Stats Cards -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
<div class="dashboard-card bg-white rounded-lg shadow p-6">
<div class="flex justify-between items-start">
<div>
<p class="text-gray-500 text-sm">Skupni prihodek</p>
<h3 class="text-2xl font-bold mt-1"><?php echo htmlspecialchars(number_format((float)$revenue, 2, ',', '.')) . '€'; ?></h3>
</div>
<div class="p-3 rounded-full bg-green-100 text-green-600">
<i data-feather="dollar-sign"></i>
</div>
</div>
<p class="text-green-600 text-sm mt-2 flex items-center">
<i data-feather="trending-up" class="mr-1"></i> V primerjavi s prejšnjim mesecem
</p>
</div>
<div class="dashboard-card bg-white rounded-lg shadow p-6">
<div class="flex justify-between items-start">
<div>
<p class="text-gray-500 text-sm">Naročila</p>
<h3 class="text-2xl font-bold mt-1"><?php echo htmlspecialchars((int)$orders_count); ?></h3>
</div>
<div class="p-3 rounded-full bg-blue-100 text-blue-600">
<i data-feather="shopping-cart"></i>
</div>
</div>
<p class="text-blue-600 text-sm mt-2 flex items-center">
<i data-feather="trending-up" class="mr-1"></i> Zadnjih <?php echo count($recentOrders); ?> naročil
</p>
</div>
<div class="dashboard-card bg-white rounded-lg shadow p-6">
<div class="flex justify-between items-start">
<div>
<p class="text-gray-500 text-sm">Izdelki</p>
<h3 class="text-2xl font-bold mt-1"><?php echo htmlspecialchars((int)$products_count); ?></h3>
</div>
<div class="p-3 rounded-full bg-purple-100 text-purple-600">
<i data-feather="package"></i>
</div>
</div>
<p class="text-purple-600 text-sm mt-2 flex items-center">
<i data-feather="alert-circle" class="mr-1"></i> Pregled zalog
</p>
</div>
<div class="dashboard-card bg-white rounded-lg shadow p-6">
<div class="flex justify-between items-start">
<div>
<p class="text-gray-500 text-sm">Stranke</p>
<h3 class="text-2xl font-bold mt-1"><?php echo htmlspecialchars((int)$customers_count); ?></h3>
</div>
<div class="p-3 rounded-full bg-amber-100 text-amber-600">
<i data-feather="users"></i>
</div>
</div>
<p class="text-amber-600 text-sm mt-2 flex items-center">
<i data-feather="trending-up" class="mr-1"></i> Novi uporabniki
</p>
</div>
</div>
<!-- Recent Orders -->
<div class="bg-white rounded-lg shadow overflow-hidden mb-8">
<div class="p-4 border-b flex justify-between items-center">
<h3 class="font-semibold">Zadnja naročila</h3>
<a href="#" class="text-sm text-amber-600 hover:text-amber-800">Prikaži vse</a>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Št. naročila</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Kupec</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Znesek</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Datum</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"></th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
<?php if (empty($recentOrders)): ?>
<tr>
<td colspan="6" class="px-6 py-4 text-sm text-gray-500">Ni naročil za prikaz.</td>
</tr>
<?php else: ?>
<?php foreach ($recentOrders as $order): ?>
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">#<?php echo htmlspecialchars($order['id']); ?></td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"><?php echo htmlspecialchars($order['customer_name']); ?></td>
<td class="px-6 py-4 whitespace-nowrap">
<?php
$status = $order['status'] ?? 'pending';
$badgeClass = 'bg-gray-100 text-gray-800';
if ($status === 'paid' || $status === 'completed') $badgeClass = 'bg-green-100 text-green-800';
if ($status === 'pending') $badgeClass = 'bg-yellow-100 text-yellow-800';
if ($status === 'shipped' || $status === 'sent') $badgeClass = 'bg-blue-100 text-blue-800';
?>
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full <?php echo $badgeClass; ?>"><?php echo htmlspecialchars(ucfirst($status)); ?></span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"><?php echo htmlspecialchars(number_format((float)$order['total_amount'], 2, ',', '.')) . '€'; ?></td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"><?php echo htmlspecialchars($order['created_at']); ?></td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<a href="orders.php?id=<?php echo urlencode($order['id']); ?>" class="text-amber-600 hover:text-amber-900">Ogled</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
<!-- Low Stock Products -->
<div class="bg-white rounded-lg shadow overflow-hidden">
<div class="p-4 border-b flex justify-between items-center">
<h3 class="font-semibold">Izdelki z nizko zalogo</h3>
<a href="#" class="text-sm text-amber-600 hover:text-amber-800">Prikaži vse</a>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Izdelek</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Zaloga</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"></th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
<tr>
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<div class="flex-shrink-0 h-10 w-10">
<img class="h-10 w-10 rounded" src="https://static.photos/nature/200x200/101" alt="">
</div>
<div class="ml-4">
<div class="text-sm font-medium text-gray-900">Cvetni prah 50g</div>
<div class="text-sm text-gray-500">4,50€</div>
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">PRD-001</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">3</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">Nizka zaloga</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<a href="#" class="text-amber-600 hover:text-amber-900">Uredi</a>
</td>
</tr>
<tr>
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<div class="flex-shrink-0 h-10 w-10">
<img class="h-10 w-10 rounded" src="https://static.photos/nature/200x200/102" alt="">
</div>
<div class="ml-4">
<div class="text-sm font-medium text-gray-900">Balzam za ustnice</div>
<div class="text-sm text-gray-500">2,50€</div>
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">PRD-005</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">5</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800">Opozorilo</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<a href="#" class="text-amber-600 hover:text-amber-900">Uredi</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</main>
</div>
</div>
<script>
feather.replace();
</script>
</body>
</html> |