106 lines
5.8 KiB
PHP

<?php
/**
* TELVERO LOGS DASHBOARD (V9.5 - DEPRECATED FIX)
*/
session_start();
ini_set('display_errors', 0);
error_reporting(E_ALL);
require __DIR__ . '/vendor/autoload.php';
if (file_exists(__DIR__ . '/.env')) {
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
}
if (!isset($_SESSION['user'])) {
die("Toegang geweigerd. Log eerst in.");
}
$db = new mysqli($_ENV['DB_HOST'], $_ENV['DB_USER'], $_ENV['DB_PASS'], $_ENV['DB_NAME']);
// 1. Totalen van vandaag
$today_stats = $db->query("SELECT COUNT(id) as total_orders, IFNULL(SUM(amount), 0) as total_revenue FROM sales_logs WHERE action_type = 'order_created' AND DATE(created_at) = CURDATE()")->fetch_assoc();
// 2. Performance per agent (username)
$agent_stats = $db->query("SELECT username, COUNT(id) as orders, IFNULL(SUM(amount), 0) as revenue FROM sales_logs WHERE action_type = 'order_created' AND DATE(created_at) = CURDATE() GROUP BY username ORDER BY orders DESC");
// 3. Laatste 50 logs
$logs = $db->query("SELECT * FROM sales_logs ORDER BY created_at DESC LIMIT 50");
?>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8">
<title>Telvero Logs</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-slate-50 p-8 font-sans text-slate-900">
<div class="max-w-6xl mx-auto">
<header class="flex justify-between items-center mb-10">
<h1 class="text-2xl font-black italic uppercase">TELVERO <span class="text-blue-600">LOGS</span></h1>
<a href="index.html" class="bg-white border px-6 py-2 rounded-2xl text-[10px] font-black uppercase tracking-widest hover:bg-slate-50 transition">Panel</a>
</header>
<div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-10">
<div class="bg-white p-8 rounded-[2.5rem] shadow-sm border-b-8 border-emerald-500">
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1">Omzet Vandaag</p>
<p class="text-4xl font-black italic">€<?php echo number_format((float)($today_stats['total_revenue'] ?? 0), 2, ',', '.'); ?></p>
</div>
<div class="bg-white p-8 rounded-[2.5rem] shadow-sm border-b-8 border-blue-600">
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1">Orders Vandaag</p>
<p class="text-4xl font-black italic"><?php echo $today_stats['total_orders']; ?></p>
</div>
</div>
<div class="grid grid-cols-12 gap-8">
<div class="col-span-12 lg:col-span-4">
<div class="bg-white p-8 rounded-[2.5rem] shadow-sm h-full">
<h2 class="text-[10px] font-black uppercase tracking-widest mb-6 border-b pb-4 text-slate-400 italic">Agent Ranking</h2>
<div class="space-y-4">
<?php while($row = $agent_stats->fetch_assoc()): ?>
<div class="flex justify-between items-center bg-slate-50 p-4 rounded-3xl border border-slate-100">
<span class="text-xs font-black uppercase italic"><?php echo htmlspecialchars($row['username']); ?></span>
<span class="bg-white px-4 py-1 rounded-full border text-[10px] font-black"><?php echo $row['orders']; ?> orders</span>
</div>
<?php endwhile; ?>
</div>
</div>
</div>
<div class="col-span-12 lg:col-span-8">
<div class="bg-white rounded-[2.5rem] shadow-sm overflow-hidden border border-slate-100">
<table class="w-full text-left">
<thead class="bg-slate-900 text-white">
<tr>
<th class="p-5 text-[9px] font-black uppercase tracking-widest opacity-60">Tijd</th>
<th class="p-5 text-[9px] font-black uppercase tracking-widest opacity-60">Agent</th>
<th class="p-5 text-[9px] font-black uppercase tracking-widest opacity-60">Inhoud</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
<?php while($log = $logs->fetch_assoc()): ?>
<tr class="hover:bg-slate-50 transition-colors">
<td class="p-5 text-[10px] font-bold text-slate-400"><?php echo date('H:i', strtotime($log['created_at'])); ?></td>
<td class="p-5 text-xs font-black uppercase italic"><?php echo htmlspecialchars($log['username']); ?></td>
<td class="p-5 text-[11px] font-bold">
<?php if($log['action_type'] == 'order_created'): ?>
<span class="text-emerald-500 font-black">ORDER #<?php echo $log['order_id']; ?></span>
<span class="text-slate-400 mx-1">|</span> €<?php echo number_format((float)($log['amount'] ?? 0), 2, ',', '.'); ?>
<span class="text-slate-300 ml-2 italic text-[9px]"><?php echo $log['mediacode']; ?></span>
<?php else: ?>
<span class="text-blue-500 uppercase font-black"><?php echo str_replace('_', ' ', $log['action_type']); ?></span>
<span class="text-slate-400 italic font-normal ml-2"><?php echo htmlspecialchars($log['details']); ?></span>
<?php endif; ?>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</body>
</html>