prepare('SELECT COUNT(*) as count, MIN(event_time) as first_event, MAX(event_time) as last_event FROM entry_events WHERE DATE(event_time) = ?'); $stmt->execute([$date]); $entryResult = $stmt->fetch(); $entryCount = $entryResult['count']; echo " entry_events:\n"; echo " Count: $entryCount events\n"; if ($entryCount > 0) { echo " First event: " . ($entryResult['first_event'] ?? 'N/A') . "\n"; echo " Last event: " . ($entryResult['last_event'] ?? 'N/A') . "\n"; // Get sample data $stmt = $db->prepare('SELECT event_time, location_code, gate_code, category FROM entry_events WHERE DATE(event_time) = ? ORDER BY event_time DESC LIMIT 5'); $stmt->execute([$date]); $samples = $stmt->fetchAll(); echo " Sample events (last 5):\n"; foreach ($samples as $sample) { echo " - " . $sample['event_time'] . " | " . $sample['location_code'] . " | " . $sample['gate_code'] . " | " . $sample['category'] . "\n"; } } // Check daily_summary $stmt = $db->prepare('SELECT COUNT(*) as count, SUM(total_count) as total_count, SUM(total_amount) as total_amount FROM daily_summary WHERE summary_date = ?'); $stmt->execute([$date]); $summaryResult = $stmt->fetch(); $summaryCount = $summaryResult['count']; $summaryTotal = $summaryResult['total_count'] ?? 0; $summaryAmount = $summaryResult['total_amount'] ?? 0; echo " daily_summary:\n"; echo " Records: $summaryCount\n"; echo " Total count: $summaryTotal\n"; echo " Total amount: $summaryAmount\n"; if ($entryCount > 0 && $summaryCount == 0) { echo " ⚠️ WARNING: Data exists in entry_events but NOT aggregated to daily_summary!\n"; echo " Run: php bin/daily_summary.php $date\n"; } echo "\n"; } // Check all dates with data echo "=== All dates with entry_events (last 10) ===\n"; $stmt = $db->query('SELECT DATE(event_time) as date, COUNT(*) as count FROM entry_events GROUP BY DATE(event_time) ORDER BY date DESC LIMIT 10'); $results = $stmt->fetchAll(); foreach ($results as $row) { echo $row['date'] . ' - ' . $row['count'] . ' events' . "\n"; } echo "\n=== All dates with daily_summary (last 10) ===\n"; $stmt = $db->query('SELECT summary_date, SUM(total_count) as total FROM daily_summary GROUP BY summary_date ORDER BY summary_date DESC LIMIT 10'); $results = $stmt->fetchAll(); foreach ($results as $row) { echo $row['summary_date'] . ' - ' . $row['total'] . ' total' . "\n"; }