{
    "matriculados": {
        "name": "Estudiantes y Matrículas",
        "description": "Lista de estudiantes matriculados con datos de sede, jornada, grado, curso y contacto.",
        "table": "matriculados",
        "sql": "SELECT \n    mat.ano_lectivo,\n    mat.numidentif AS id_estudiante,\n    al.documento AS doc_estudiante,\n    mat.nombre AS nombre_estudiante,\n    mat.grado,\n    mat.curso,\n    mat.numlista,\n    sedes.nombre AS sede,\n    jornada.descripcion AS jornada,\n    estado.descripcion AS estado,\n    al.telefono,\n    al.direccion,\n    al.correo_institucional AS email,\n    al.sexo,\n    al.fecha_nacimiento\nFROM matriculados mat\nINNER JOIN alumnos al ON al.numidentif = mat.numidentif\nLEFT JOIN datoscurso dc ON mat.ano_lectivo = dc.ano_lectivo AND mat.grado = dc.grado AND mat.curso = dc.curso\nLEFT JOIN sedes ON dc.cod_sede = sedes.codigo\nLEFT JOIN jornada ON dc.cod_jornada = jornada.codigo\nLEFT JOIN estado ON mat.estado = estado.codigo\nWHERE {condicion}\nORDER BY mat.grado, mat.curso, mat.numlista, mat.nombre",
        "columns": {
            "ano_lectivo": {
                "label": "Año",
                "type": "System.String",
                "w": 1.4,
                "align": "Center"
            },
            "grado": {
                "label": "Gr.",
                "type": "System.String",
                "w": 1,
                "align": "Center"
            },
            "curso": {
                "label": "Cu.",
                "type": "System.String",
                "w": 1,
                "align": "Center"
            },
            "numlista": {
                "label": "N°",
                "type": "System.String",
                "w": 0.8,
                "align": "Center"
            },
            "doc_estudiante": {
                "label": "Documento",
                "type": "System.String",
                "w": 2.8,
                "align": "Left"
            },
            "nombre_estudiante": {
                "label": "Estudiante",
                "type": "System.String",
                "w": 7,
                "align": "Left"
            },
            "sede": {
                "label": "Sede",
                "type": "System.String",
                "w": 3.5,
                "align": "Left"
            },
            "jornada": {
                "label": "Jornada",
                "type": "System.String",
                "w": 2.5,
                "align": "Left"
            },
            "estado": {
                "label": "Estado",
                "type": "System.String",
                "w": 2.2,
                "align": "Center"
            },
            "telefono": {
                "label": "Teléfono",
                "type": "System.String",
                "w": 2.5,
                "align": "Left"
            },
            "sexo": {
                "label": "Sexo",
                "type": "System.String",
                "w": 1.2,
                "align": "Center"
            }
        }
    },
    "notas": {
        "name": "Calificaciones y Rendimiento",
        "description": "Notas por periodos, definitivas y fallas por asignatura y estudiante.",
        "table": "notas",
        "sql": "SELECT \n    n.ano_lectivo,\n    m.grado,\n    m.curso,\n    m.numlista,\n    m.nombre AS nombre_estudiante,\n    a.documento AS doc_estudiante,\n    n.codigoasig AS cod_asignatura,\n    COALESCE(asig.descripcion, n.codigoasig) AS asignatura,\n    asig.cod_docente,\n    n.nota1,\n    n.nota2,\n    n.nota3,\n    n.nota4,\n    n.nota5,\n    n.definitiva,\n    n.recuperacion,\n    n.falta1,\n    n.falta2,\n    n.falta3,\n    n.falta4,\n    (n.falta1 + n.falta2 + n.falta3 + n.falta4) AS total_faltas\nFROM notas n\nINNER JOIN matriculados m ON m.numidentif = n.numidentif AND m.ano_lectivo = n.ano_lectivo\nLEFT JOIN alumnos a ON a.numidentif = n.numidentif\nLEFT JOIN asignaturas asig ON asig.codigo = n.codigoasig AND asig.ano_lectivo = n.ano_lectivo AND asig.grado = m.grado AND asig.curso = m.curso\nWHERE {condicion}\nORDER BY m.grado, m.curso, m.numlista, asig.descripcion",
        "columns": {
            "grado": {
                "label": "Gr.",
                "type": "System.String",
                "w": 1,
                "align": "Center"
            },
            "curso": {
                "label": "Cu.",
                "type": "System.String",
                "w": 1,
                "align": "Center"
            },
            "numlista": {
                "label": "N°",
                "type": "System.String",
                "w": 0.8,
                "align": "Center"
            },
            "nombre_estudiante": {
                "label": "Estudiante",
                "type": "System.String",
                "w": 6.5,
                "align": "Left"
            },
            "asignatura": {
                "label": "Asignatura",
                "type": "System.String",
                "w": 4.2,
                "align": "Left"
            },
            "cod_docente": {
                "label": "Doc.",
                "type": "System.String",
                "w": 1.5,
                "align": "Center"
            },
            "nota1": {
                "label": "P1",
                "type": "System.String",
                "w": 1.2,
                "align": "Center"
            },
            "nota2": {
                "label": "P2",
                "type": "System.String",
                "w": 1.2,
                "align": "Center"
            },
            "nota3": {
                "label": "P3",
                "type": "System.String",
                "w": 1.2,
                "align": "Center"
            },
            "nota4": {
                "label": "P4",
                "type": "System.String",
                "w": 1.2,
                "align": "Center"
            },
            "definitiva": {
                "label": "Def.",
                "type": "System.String",
                "w": 1.4,
                "align": "Center"
            },
            "total_faltas": {
                "label": "Fallas",
                "type": "System.Int32",
                "w": 1.4,
                "align": "Center"
            }
        }
    },
    "resumen_pivot": {
        "name": "Sábana \/ Matriz de Valoración (Hasta 28 Notas)",
        "description": "Matriz horizontal de calificaciones con 28 asignaturas en columnas individuales, materias perdidas y puesto.",
        "table": "notas_pivot",
        "sql": "SELECT \n    mat.ano_lectivo,\n    mat.grado,\n    mat.curso,\n    mat.numidentif,\n    mat.nombre,\n    mat.numlista,\n    dg.nombre AS director,\n    mat.estado,\n    SUM(IF(notas.nota2 = 'Bj' OR CAST(notas.nota2 AS DECIMAL(4,2)) < 3.0, 1, 0)) AS PERD,\n    GROUP_CONCAT(asig.siglas ORDER BY asig.orden SEPARATOR ' ') AS sig,\n    notas.prox_nota_min,\n    pa.prom_per1,\n    pa.prom_per2,\n    sedes.nombre AS sede,\n    jornada.descripcion AS jornada\nFROM asignaturas asig \nINNER JOIN matriculados mat ON mat.ano_lectivo = asig.ano_lectivo AND mat.grado = asig.grado AND mat.curso = asig.curso \nINNER JOIN notas ON notas.ano_lectivo = asig.ano_lectivo AND notas.codigoasig = asig.codigo AND notas.numidentif = mat.numidentif\nLEFT JOIN promalumnos pa ON pa.ano_lectivo = mat.ano_lectivo AND pa.numidentif = mat.numidentif \nLEFT JOIN docentes ON docentes.cedula = asig.cod_docente\nLEFT JOIN datoscurso dc ON asig.ano_lectivo = dc.ano_lectivo AND asig.grado = dc.grado AND asig.curso = dc.curso \nLEFT JOIN jornada ON dc.cod_jornada = jornada.codigo \nLEFT JOIN sedes ON dc.cod_sede = sedes.codigo\nLEFT JOIN docentes dg ON dc.director_grupo = dg.cedula\nWHERE mat.estado = 'A'\n  AND asig.ano_lectivo = '{ggs_ano}'\n  AND mat.ano_lectivo = '{ggs_ano}'\n  AND {condicion}\nGROUP BY mat.ano_lectivo, mat.grado, mat.curso, mat.numlista, mat.numidentif\nORDER BY mat.grado, mat.curso, mat.numlista, mat.nombre",
        "columns": {
            "numlista": {
                "label": "N°",
                "type": "System.String",
                "w": 0.7,
                "align": "Center"
            },
            "nombre": {
                "label": "Estudiante",
                "type": "System.String",
                "w": 5.8,
                "align": "Left"
            },
            "estado": {
                "label": "Est.",
                "type": "System.String",
                "w": 0.8,
                "align": "Center"
            },
            "PERD": {
                "label": "Perd",
                "type": "System.Int32",
                "w": 1,
                "align": "Center"
            },
            "prox_nota_min": {
                "label": "Prox Nota",
                "type": "System.String",
                "w": 1.4,
                "align": "Center"
            },
            "prom_per1": {
                "label": "Prom P1",
                "type": "System.String",
                "w": 1.2,
                "align": "Center"
            },
            "prom_per2": {
                "label": "Prom P2",
                "type": "System.String",
                "w": 1.2,
                "align": "Center"
            },
            "sede": {
                "label": "Sede",
                "type": "System.String",
                "w": 2.5,
                "align": "Left"
            },
            "jornada": {
                "label": "Jornada",
                "type": "System.String",
                "w": 2,
                "align": "Left"
            }
        }
    },
    "asignaturas": {
        "name": "Asignaturas y Carga Docente",
        "description": "Distribución de asignaturas, grados, cursos, áreas e intensidades horarias por docente.",
        "table": "asignaturas",
        "sql": "SELECT \n    asig.ano_lectivo,\n    asig.grado,\n    asig.curso,\n    asig.codigo,\n    asig.descripcion AS asignatura,\n    asig.ih AS intensidad_horaria,\n    asig.cod_docente,\n    COALESCE(doc.nombre, asig.cod_docente) AS nombre_docente,\n    asig.area,\n    asig.porcentaje\nFROM asignaturas asig\nLEFT JOIN docentes doc ON doc.codigo = asig.cod_docente\nWHERE {condicion}\nORDER BY asig.grado, asig.curso, asig.descripcion",
        "columns": {
            "ano_lectivo": {
                "label": "Año",
                "type": "System.String",
                "w": 1.5,
                "align": "Center"
            },
            "grado": {
                "label": "Gr.",
                "type": "System.String",
                "w": 1.2,
                "align": "Center"
            },
            "curso": {
                "label": "Cu.",
                "type": "System.String",
                "w": 1.2,
                "align": "Center"
            },
            "codigo": {
                "label": "Código",
                "type": "System.String",
                "w": 2,
                "align": "Center"
            },
            "asignatura": {
                "label": "Asignatura",
                "type": "System.String",
                "w": 7,
                "align": "Left"
            },
            "intensidad_horaria": {
                "label": "I.H.",
                "type": "System.Int32",
                "w": 1.4,
                "align": "Center"
            },
            "cod_docente": {
                "label": "Cód. Doc.",
                "type": "System.String",
                "w": 2,
                "align": "Center"
            },
            "nombre_docente": {
                "label": "Docente",
                "type": "System.String",
                "w": 6,
                "align": "Left"
            },
            "area": {
                "label": "Área",
                "type": "System.String",
                "w": 3.5,
                "align": "Left"
            }
        }
    },
    "auditoria": {
        "name": "Auditoría de Modificación de Notas (sc_log)",
        "description": "Historial de registros y cambios en calificaciones con fecha, usuario, grado, estudiante y valores anterior\/nuevo.",
        "table": "sc_log",
        "sql": "SELECT \n    l.id AS log_id,\n    l.inserted_date AS fecha_hora,\n    l.username AS usuario,\n    l.action AS accion,\n    CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(l.description, 'row_id : ', -1), '||', 1) AS UNSIGNED) AS nota_row_id,\n    n.ano_lectivo,\n    m.grado,\n    m.curso,\n    m.numlista,\n    COALESCE(m.nombre, a.nombre) AS nombre_estudiante,\n    COALESCE(asig.descripcion, n.codigoasig) AS asignatura,\n    asig.cod_docente,\n    CASE \n        WHEN l.description LIKE '%nota1 (new)%' THEN 'Nota 1 (P1)'\n        WHEN l.description LIKE '%nota2 (new)%' THEN 'Nota 2 (P2)'\n        WHEN l.description LIKE '%nota3 (new)%' THEN 'Nota 3 (P3)'\n        WHEN l.description LIKE '%nota4 (new)%' THEN 'Nota 4 (P4)'\n        WHEN l.description LIKE '%nota5 (new)%' THEN 'Nota 5 (P5)'\n        WHEN l.description LIKE '%definitiva (new)%' THEN 'Definitiva'\n        WHEN l.description LIKE '%recuperacion (new)%' THEN 'Recuperación'\n        ELSE 'Nota'\n    END AS campo_modificado,\n    TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(CASE WHEN l.description LIKE '%nota1 (old)%' THEN SUBSTRING_INDEX(l.description, 'nota1 (old)  :', -1) WHEN l.description LIKE '%nota2 (old)%' THEN SUBSTRING_INDEX(l.description, 'nota2 (old)  :', -1) WHEN l.description LIKE '%nota3 (old)%' THEN SUBSTRING_INDEX(l.description, 'nota3 (old)  :', -1) WHEN l.description LIKE '%nota4 (old)%' THEN SUBSTRING_INDEX(l.description, 'nota4 (old)  :', -1) WHEN l.description LIKE '%nota5 (old)%' THEN SUBSTRING_INDEX(l.description, 'nota5 (old)  :', -1) WHEN l.description LIKE '%definitiva (old)%' THEN SUBSTRING_INDEX(l.description, 'definitiva (old)  :', -1) ELSE SUBSTRING_INDEX(l.description, '(old)  :', -1) END, '||', 1), '||', 1)) AS valor_anterior,\n    TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(CASE WHEN l.description LIKE '%nota1 (new)%' THEN SUBSTRING_INDEX(l.description, 'nota1 (new)  :', -1) WHEN l.description LIKE '%nota2 (new)%' THEN SUBSTRING_INDEX(l.description, 'nota2 (new)  :', -1) WHEN l.description LIKE '%nota3 (new)%' THEN SUBSTRING_INDEX(l.description, 'nota3 (new)  :', -1) WHEN l.description LIKE '%nota4 (new)%' THEN SUBSTRING_INDEX(l.description, 'nota4 (new)  :', -1) WHEN l.description LIKE '%nota5 (new)%' THEN SUBSTRING_INDEX(l.description, 'nota5 (new)  :', -1) WHEN l.description LIKE '%definitiva (new)%' THEN SUBSTRING_INDEX(l.description, 'definitiva (new)  :', -1) ELSE SUBSTRING_INDEX(l.description, '(new)  :', -1) END, '||', 1), '||', 1)) AS valor_nuevo\nFROM sc_log l\nINNER JOIN notas n ON n.row_id = CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(l.description, 'row_id : ', -1), '||', 1) AS UNSIGNED)\nLEFT JOIN matriculados m ON m.numidentif = n.numidentif AND m.ano_lectivo = n.ano_lectivo\nLEFT JOIN alumnos a ON a.numidentif = n.numidentif\nLEFT JOIN asignaturas asig ON asig.codigo = n.codigoasig AND asig.ano_lectivo = n.ano_lectivo AND asig.grado = m.grado AND asig.curso = m.curso\nWHERE l.application LIKE '%notas%'\n  AND l.description LIKE '%row_id : %'\n  AND {condicion}\nORDER BY l.inserted_date DESC, m.grado, m.curso, m.numlista",
        "columns": {
            "fecha_hora": {
                "label": "Fecha\/Hora",
                "type": "System.DateTime",
                "w": 3.2,
                "align": "Center"
            },
            "usuario": {
                "label": "Usuario",
                "type": "System.String",
                "w": 2.4,
                "align": "Left"
            },
            "ano_lectivo": {
                "label": "Año",
                "type": "System.String",
                "w": 1.2,
                "align": "Center"
            },
            "grado": {
                "label": "Gr.",
                "type": "System.String",
                "w": 1,
                "align": "Center"
            },
            "curso": {
                "label": "Cu.",
                "type": "System.String",
                "w": 1,
                "align": "Center"
            },
            "numlista": {
                "label": "N°",
                "type": "System.String",
                "w": 0.8,
                "align": "Center"
            },
            "nombre_estudiante": {
                "label": "Estudiante",
                "type": "System.String",
                "w": 6.2,
                "align": "Left"
            },
            "asignatura": {
                "label": "Asignatura",
                "type": "System.String",
                "w": 4,
                "align": "Left"
            },
            "cod_docente": {
                "label": "Doc.",
                "type": "System.String",
                "w": 1.5,
                "align": "Center"
            },
            "campo_modificado": {
                "label": "Nota\/Campo",
                "type": "System.String",
                "w": 2.2,
                "align": "Center"
            },
            "valor_anterior": {
                "label": "Ant.",
                "type": "System.String",
                "w": 1.4,
                "align": "Center"
            },
            "valor_nuevo": {
                "label": "Nuevo",
                "type": "System.String",
                "w": 1.4,
                "align": "Center"
            }
        }
    }
}
