<?php
header('Content-Type: application/json');
include_once('../../includes/config.php');

// Check if table exists
$result = mysqli_query($con, "SHOW TABLES LIKE 'tblhold_bills'");
$exists = mysqli_num_rows($result) > 0;

if ($exists) {
    // Get table info
    $countResult = mysqli_query($con, "SELECT COUNT(*) as total FROM tblhold_bills");
    $count = mysqli_fetch_assoc($countResult);
    
    $structureResult = mysqli_query($con, "DESCRIBE tblhold_bills");
    $columns = [];
    while ($row = mysqli_fetch_assoc($structureResult)) {
        $columns[] = $row['Field'];
    }
    
    echo json_encode([
        'exists' => true,
        'totalRecords' => $count['total'],
        'columns' => $columns
    ]);
} else {
    echo json_encode([
        'exists' => false,
        'message' => 'Table tblhold_bills does not exist. Please run setup script.'
    ]);
}

mysqli_close($con);
?>
