<?php
// Endpoint: /backend/api/horarios/quincenas_con_datos.php
require_once __DIR__ . '/../../config/database.php';
header('Content-Type: application/json');

try {
    $db = new Database();
    $conn = $db->connect();
    // Solo quincenas que tengan datos en ExportacionesHorarios
    $sql = "SELECT q.id_quincena, q.nombre FROM Quincenas q WHERE q.id_quincena IN (SELECT DISTINCT quincena_id FROM ExportacionesHorarios) ORDER BY q.nombre DESC";
    $stmt = $conn->prepare($sql);
    $stmt->execute();
    $quincenas = $stmt->fetchAll(PDO::FETCH_ASSOC);
    echo json_encode(['ok' => true, 'quincenas' => $quincenas]);
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode(['ok' => false, 'error' => $e->getMessage()]);
}
