-- ============================================================
-- Validación GEOSTARK NOMINA v7.1 - Prestaciones
-- Solo consultas. No modifica datos.
-- ============================================================

SELECT 'nomina_tasas_interes_bcv' AS tabla, COUNT(*) AS registros FROM nomina_tasas_interes_bcv
UNION ALL SELECT 'nomina_salario_historial', COUNT(*) FROM nomina_salario_historial
UNION ALL SELECT 'nomina_prestaciones_eventos', COUNT(*) FROM nomina_prestaciones_eventos
UNION ALL SELECT 'nomina_prestaciones_intereses', COUNT(*) FROM nomina_prestaciones_intereses;

SELECT periodo_ym, tasa_activa_anual, tasa_pasiva_anual, tasa_promedio_anual, aplica_prestaciones
FROM nomina_tasas_interes_bcv
ORDER BY periodo_ym DESC
LIMIT 24;

SELECT tipo, estado, COUNT(*) AS registros, ROUND(SUM(monto_bs),2) AS monto_bs
FROM nomina_prestaciones_eventos
GROUP BY tipo, estado
ORDER BY tipo, estado;

SELECT metodo, COUNT(*) AS registros, ROUND(SUM(capital_base_bs),2) AS capital_bs, ROUND(SUM(interes_bs),2) AS interes_bs
FROM nomina_prestaciones_intereses
WHERE estado='REGISTRADO'
GROUP BY metodo;

SELECT h.persona_id, p.cedula, p.nombre, p.apellido, COUNT(*) AS registros_historial
FROM nomina_salario_historial h
LEFT JOIN personas p ON p.id = h.persona_id
GROUP BY h.persona_id, p.cedula, p.nombre, p.apellido
ORDER BY registros_historial DESC, p.apellido ASC
LIMIT 30;
