<?php
// Include your database connection code here, and ensure $conn is defined.
include_once 'shikanisha.kts.php';

$response = array();

// Execute the SQL query to fetch data
$sql = "SELECT `salary_id`, `phone_number`, `salary`, `salary_date`, `method`, `purpose` FROM `employee_salary`";
$result = mysqli_query($conn, $sql);

if ($result) {
    $response['success'] = true;
    $tableData = '';

    while ($row = mysqli_fetch_assoc($result)) {
        $tableData .= '<tr>
            <td>' . $row['salary_id'] . '</td>
            <td>' . $row['phone_number'] . '</td>
            <td>' . $row['salary'] . '</td>
            <td>' . $row['salary_date'] . '</td>
            <td>' . $row['method'] . '</td>
            <td>' . $row['purpose'] . '</td>
            <td>
                <button class="btn btn-primary edit-button" data-salaryid="' . $row['salary_id'] . '">Edit</button>
                <button class="btn btn-danger delete-button" data-salaryid="' . $row['salary_id'] . '">Delete</button>
            </td>
        </tr>';
    }

    $response['tableData'] = $tableData;
} else {
    $response['success'] = false;
    $response['message'] = 'Error executing the SQL query.';
}

// Return the response as JSON
header('Content-type: application/json');
echo json_encode($response);
?>
