-- ============================================================
-- GEOSTARK NOMINA - VALIDACION V8.2 VACACIONES CALENDARIO
-- No modifica datos. Compatible MariaDB/MySQL.
-- ============================================================

SELECT 'Eventos vacaciones registrados' AS revision, COUNT(*) AS total
FROM nomina_vacaciones_eventos;

SELECT 'Eventos vacaciones con moneda/origen inválido' AS revision, COUNT(*) AS total
FROM nomina_vacaciones_eventos
WHERE IFNULL(salario_moneda,'') IN ('', '0')
   OR IFNULL(origen_registro,'') IN ('', '0');

SELECT 'Eventos vacaciones sin tasa BCV congelada' AS revision, COUNT(*) AS total
FROM nomina_vacaciones_eventos
WHERE IFNULL(tasa_bcv_usada,0) = 0
  AND IFNULL(fuente_salario,'') <> 'AJUSTE_HISTORICO';

SELECT 'Eventos vacaciones sin snapshot' AS revision, COUNT(*) AS total
FROM nomina_vacaciones_eventos
WHERE snapshot_json IS NULL OR CAST(snapshot_json AS CHAR) = '';

SELECT 'Trabajadores activos sin fecha de ingreso válida' AS revision, COUNT(*) AS total
FROM personas
WHERE IFNULL(estatus_laboral,'ACTIVO')='ACTIVO'
  AND (fecha_ingreso IS NULL OR CAST(fecha_ingreso AS CHAR)='0000-00-00' OR fecha_ingreso > CURDATE());

SELECT 'Historial salarial sincronizado' AS revision, COUNT(*) AS total
FROM nomina_salario_historial;

SELECT 'Calendario laboral activo aplicable a nómina' AS revision, COUNT(*) AS total
FROM nomina_calendario_laboral
WHERE activo=1 AND aplica_nomina=1;

SELECT ve.id, ve.fecha_documento, ve.fecha_inicio, ve.fecha_fin, ve.tipo,
       ve.dias_disfrute, ve.dias_bono, ve.salario_moneda, ve.origen_registro,
       ve.fuente_salario, ve.tasa_bcv_usada, ve.soporte_referencia
FROM nomina_vacaciones_eventos ve
ORDER BY ve.id DESC
LIMIT 10;
