<?php
header('Content-Type: application/json; charset=utf-8');
require_once __DIR__ . '/../../../../backend/db/conexion.php';

try {
    $sql = "SELECT * FROM PreNominaIncidencias ORDER BY Nombre_completo ASC";
    $result = $conn->query($sql);
    if (!$result) {
        http_response_code(500);
        echo json_encode(['error' => 'Error en la consulta', 'detail' => $conn->error]);
        exit;
    }

    $rows = [];
    while ($r = $result->fetch_assoc()) {
        $rows[] = $r;
    }

    echo json_encode($rows, JSON_UNESCAPED_UNICODE);
} catch (Exception $ex) {
    http_response_code(500);
    echo json_encode(['error' => 'Excepción', 'message' => $ex->getMessage()]);
}

?>
