<?php
// Final verification of income report fixes
session_start();
$_SESSION['user_id'] = 1;

echo "<h2>Final Income Report Verification</h2>";

// Test the main page
ob_start();
include 'income_report.php';
$output = ob_get_contents();
ob_end_clean();

echo "<h3>Issue Check:</h3>";

$issues = [];
if (strpos($output, 'SQLSTATE[42S22]') !== false) {
    $issues[] = "Column not found error still present";
}

if (strpos($output, 'SQLSTATE[42000]') !== false) {
    $issues[] = "Syntax error still present";
}

if (strpos($output, 'Unknown column') !== false) {
    $issues[] = "Unknown column error still present";
}

if (empty($issues)) {
    echo "<div style='background: #d4edda; padding: 15px; border: 1px solid #c3e6cb; border-radius: 5px;'>";
    echo "<h3 style='color: #155724;'>✅ ALL ISSUES RESOLVED!</h3>";
    echo "<p>The income report page is now working correctly.</p>";
    echo "</div>";
    
    // Check if we can see the main content
    if (strpos($output, 'আয় রিপোর্ট') !== false) {
        echo "<p style='color: green;'>✅ Bengali title found - page rendering correctly</p>";
    }
    
    if (strpos($output, 'মোট আয়') !== false) {
        echo "<p style='color: green;'>✅ Financial summary section found</p>";
    }
    
    if (strpos($output, 'পেমেন্ট পদ্ধতি') !== false) {
        echo "<p style='color: green;'>✅ Payment method section found</p>";
    }
    
} else {
    echo "<div style='background: #f8d7da; padding: 15px; border: 1px solid #f5c6cb; border-radius: 5px;'>";
    echo "<h3 style='color: #721c24;'>❌ Remaining Issues:</h3>";
    echo "<ul>";
    foreach ($issues as $issue) {
        echo "<li>$issue</li>";
    }
    echo "</ul>";
    echo "</div>";
}

// Show page title
if (preg_match('/<title>(.*?)<\/title>/', $output, $matches)) {
    echo "<p><strong>Page Title:</strong> " . htmlspecialchars($matches[1]) . "</p>";
}

echo "<hr>";
echo "<h3>Quick Access Links:</h3>";
echo "<ul>";
echo "<li><a href='income_report.php' target='_blank'>📊 View Income Report Page</a></li>";
echo "<li><a href='populate_sample_data.php' target='_blank'>💾 Populate Sample Data</a></li>";
echo "<li><a href='diagnose_income_report.php' target='_blank'>🔍 Run Full Diagnostic</a></li>";
echo "</ul>";

echo "<h3>Content Preview:</h3>";
echo "<div style='background: #f8f9fa; padding: 10px; border: 1px solid #dee2e6; max-height: 200px; overflow-y: auto;'>";
echo htmlspecialchars(substr($output, 0, 800));
echo "</div>";
?>