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

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

SELECT 'Eventos con salario_moneda inválida' AS revision, COUNT(*) AS total
FROM nomina_vacaciones_eventos
WHERE estado='REGISTRADO'
  AND (salario_moneda IS NULL OR salario_moneda='' OR salario_moneda='0');

SELECT 'Eventos con origen_registro inválido' AS revision, COUNT(*) AS total
FROM nomina_vacaciones_eventos
WHERE estado='REGISTRADO'
  AND (origen_registro IS NULL OR origen_registro='' OR origen_registro='0');

SELECT 'Eventos con soporte/referencia débil' AS revision, COUNT(*) AS total
FROM nomina_vacaciones_eventos
WHERE estado='REGISTRADO'
  AND (soporte_referencia IS NULL OR LENGTH(TRIM(soporte_referencia)) < 12);

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

SELECT 'Eventos con mojibake en snapshot_json' AS revision, COUNT(*) AS total
FROM nomina_vacaciones_eventos
WHERE snapshot_json IS NOT NULL
  AND CAST(snapshot_json AS CHAR) REGEXP 'Ã|Â|â€';

SELECT 'Historial salarial con mojibake en snapshot_json' AS revision, COUNT(*) AS total
FROM nomina_salario_historial
WHERE snapshot_json IS NOT NULL
  AND CAST(snapshot_json AS CHAR) REGEXP 'Ã|Â|â€';

SELECT id, persona_id, fecha_documento, tipo, salario_moneda, origen_registro, soporte_referencia, fuente_salario, tasa_bcv_usada
FROM nomina_vacaciones_eventos
WHERE estado='REGISTRADO'
ORDER BY id DESC
LIMIT 20;
