<?php
header('Content-Type: application/json');
require_once dirname(__FILE__) . '/../../config.php';
$db = getDB();

// Ver columnas de regs2
$cols = $db->query("DESCRIBE regs2")->fetchAll(PDO::FETCH_ASSOC);
echo json_encode(['columnas_regs2' => array_column($cols, 'Field')]);

// Probar la consulta del cobrador (id_cobrador = 14597, mes=3, anio=2026)
$stmt = $db->prepare("
    SELECT idreg, apagar, cd, id_inver, status, fechap
    FROM regs2
    WHERE id_inver = ?
      AND status = 0
      AND apagar > 0
      AND MONTH(fechap) = ?
      AND YEAR(fechap) = ?
    LIMIT 5
");
$stmt->execute([14597, 3, 2026]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode(['cobrador_regs' => $rows]);
