<?php
// backend/contabilidad/validar_reingreso.php
require_once '../db/conexion.php';
header('Content-Type: application/json');

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    http_response_code(405);
    echo json_encode(['error' => 'Método no permitido']);
    exit;
}

$input = json_decode(file_get_contents('php://input'), true);
$curps = isset($input['curps']) ? $input['curps'] : [];
if (!is_array($curps) || empty($curps)) {
    http_response_code(400);
    echo json_encode(['error' => 'CURPs requeridos']);
    exit;
}

$placeholders = implode(',', array_fill(0, count($curps), '?'));
$sql = "SELECT CURP FROM reingresos WHERE CURP IN ($placeholders)";
$stmt = $conn->prepare($sql);
$stmt->bind_param(str_repeat('s', count($curps)), ...$curps);
$stmt->execute();
$result = $stmt->get_result();
$reingresos = [];
while ($row = $result->fetch_assoc()) {
    $reingresos[] = $row['CURP'];
}
$stmt->close();
$conn->close();

echo json_encode(['reingresos' => $reingresos]);
