#!/usr/bin/env php format('Y-m-d') !== $dateInput) { echo "Error: Invalid date format. Expected Y-m-d (e.g., 2026-01-01)\n"; exit(1); } $date = $dateInput; echo "=== Checking daily_summary for date: $date ===\n\n"; // Check entry_events count $stmt = $db->prepare(' SELECT COUNT(*) as total_count FROM entry_events e INNER JOIN locations l ON e.location_code = l.code AND l.is_active = 1 INNER JOIN gates g ON e.location_code = g.location_code AND e.gate_code = g.gate_code AND g.is_active = 1 WHERE DATE(e.event_time) = CAST(? AS DATE) '); $stmt->execute([$date]); $entryResult = $stmt->fetch(); $entryCount = (int) ($entryResult['total_count'] ?? 0); // Check daily_summary count $stmt = $db->prepare(' SELECT SUM(total_count) as total_count, SUM(total_amount) as total_amount FROM daily_summary WHERE summary_date = CAST(? AS DATE) '); $stmt->execute([$date]); $summaryResult = $stmt->fetch(); $summaryCount = (int) ($summaryResult['total_count'] ?? 0); $summaryAmount = (int) ($summaryResult['total_amount'] ?? 0); // Check detail per location/gate/category $stmt = $db->prepare(' SELECT location_code, gate_code, category, total_count, total_amount FROM daily_summary WHERE summary_date = CAST(? AS DATE) ORDER BY total_count DESC '); $stmt->execute([$date]); $details = $stmt->fetchAll(); echo "entry_events: $entryCount events\n"; echo "daily_summary: $summaryCount events (Rp " . number_format($summaryAmount, 0, ',', '.') . ")\n\n"; if ($entryCount > 0 && $summaryCount == 0) { echo "❌ PROBLEM: entry_events has data but daily_summary is empty!\n"; echo "Run: php bin/daily_summary.php $date\n"; } elseif ($entryCount > 0 && $summaryCount > 0 && abs($entryCount - $summaryCount) > ($entryCount * 0.1)) { $diff = abs($entryCount - $summaryCount); $diffPercent = ($diff / max($entryCount, $summaryCount)) * 100; echo "⚠️ WARNING: Count mismatch! Difference: $diff ($diffPercent%)\n"; echo "Run: php bin/daily_summary.php $date\n"; } elseif ($entryCount > 0 && $summaryCount > 0) { echo "✓ OK: Counts match\n"; } if (!empty($details)) { echo "\nDetails (top 10):\n"; $count = 0; foreach ($details as $row) { if ($count++ >= 10) break; echo sprintf( " %s / %s / %s: %d events (Rp %s)\n", $row['location_code'], $row['gate_code'], $row['category'], $row['total_count'], number_format($row['total_amount'], 0, ',', '.') ); } if (count($details) > 10) { echo " ... and " . (count($details) - 10) . " more\n"; } } echo "\n";