<?php
// Test script to verify accounting_entries API is working
header('Content-Type: application/json');

require_once 'config/database.php';
require_once 'models/AccountingEntry.php';

try {
    $database = new Database();
    $conn = $database->getConnection();
    
    if (!$conn) {
        echo json_encode(['success' => false, 'message' => 'Database connection failed']);
        exit;
    }

    // Test 1: Check if accounting_entries table has data
    $sql = "SELECT COUNT(*) as count FROM accounting_entries";
    $stmt = $conn->prepare($sql);
    $stmt->execute();
    $count = $stmt->fetch(PDO::FETCH_ASSOC)['count'];
    
    echo json_encode([
        'success' => true,
        'database_connected' => true,
        'entries_count' => $count,
        'test_result' => $count > 0 ? 'Data exists in accounting_entries table' : 'No data in accounting_entries table'
    ]);
    
} catch (Exception $e) {
    echo json_encode([
        'success' => false,
        'message' => $e->getMessage()
    ]);
}
?>
