FITOMN of AM v3
8/25/2017 - 11:59 PM

sp2RPT_CES_ObtenerReporteSIE - Se agregan la información faltante y los filtros necesario para la consulta

sp2RPT_CES_ObtenerReporteSIE - Se agregan la información faltante y los filtros necesario para la consulta


----------------------------INICIO PROCEDIMIENTO ------------------------
IF OBJECT_ID('sp2RPT_CES_ObtenerReporteSIE ', 'P') IS NOT NULL
      DROP PROC sp2RPT_CES_ObtenerReporteSIE 
GO

CREATE PROCEDURE [dbo].[sp2RPT_CES_ObtenerReporteSIE]
(
	@idPlantel     listaSmallInt READONLY,
	@idOfEduc      listaSmallInt READONLY,
	@iFolioPeriodo BIGINT,
	@idPlanEst     listaSmallInt READONLY,
	@idEstatusInsc listaTinyint READONLY
/* --------------------------------------------------------------------------------------------------------------
	FECHA	   |    AUTOR		|	DESCRIPCION
 23/ago./2017  | Luis Bernal	| 
--------------------------------------------------------------------------------------------------------------*/
)
AS
BEGIN 

	SET NOCOUNT ON;

	SELECT
		   cna.sNivel AS GRADO,
		   cpe.sNombre AS 'PLAN DE ESTUDIO',
		   ISNULL(cpe.sCveRegistro, '') AS 'CLAVE DE PLAN DE ESTUDIO',
		   '' AS 'MODALIDAD',
		   ISNULL(cpe.sRVOE, '') AS 'ACUERDO',
		   ISNULL(cpe.dRVOE, '') AS 'FECHA DE ACUERDO',
		   coe.sNombre AS 'CARRERA/OFERTA EDUCATIVA',
		   CAST(cg.iGrado AS CHAR(2)) + '° ' + cp.sUnidad AS 'PERIODO/GRADO',
		   cp2.sNombreOficial AS 'CICLO ESCOLAR',
		   ca2.sAsignatura AS 'MATERIA',
		   ca.sApellidoPaterno + ' ' + ca.sApellidoMaterno + ' ' + ca.sNombre AS 'ALUMNO',
		   ca.sCURP AS 'CURP ALUMNO',
		   cg.sNombre AS 'GRUPO',
		   ISNULL(cep.sNombreEscuela, '') AS 'ESCUELA DE PROCEDENCIA',
		   cei.sEstatus AS 'TIPO DE INGRESO',
		   cp3.sApellidoP + ' ' + cp3.sApellidoM + ' ' + cp3.sNombre AS 'DOCENTE',
		   ce2.sCorreo AS 'DIRECCIÓN PERSONAL DEL DOCENTE',
		   ce2.sCURP AS 'CURP DOCENTE',
		   ISNULL(cp3.sRFC, '') AS 'RFC DOCENTE',
		   CAST(cp3.dFechaN AS DATE) AS 'FECHA DE NACIMIENTO DOCENTE',
		   cs.sSexo AS 'SEXO DOCENTE',
		   cp4.sPais AS 'PAIS NACIMIENTO DOCENTE',
		   ce.sEstado AS 'ESTADO/ENTIDAD DOCENTE',
		   cm.sMunicipio AS 'MUNICIPIO DOCENTE',
		   dbo.fnCuentaInscripcionesAcademicas(ci.iFolioPeriodo, cta.idGrupo, cta.idAsignatura) AS 'NO. DE ALUMNOS',
		   (SELECT SUM(dHorasPago) FROM dbo.ft2RPT_CES_ObtenerHorarioByGpoPeriodoProfAsignatura(cta.idGrupo, ci.iFolioPeriodo, cgc.idProfesor, cta.idAsignatura, 0)) AS 'HORAS IMPARTE',
		   cp3.sCarrera AS 'CARRERA DEL DOCENTE',
		   cp3.sCedulaProf AS 'CEDULA PROFESIONAL DEL DOCENTE',
		   CAST(ce2.dFechaCedulaProf AS DATE) AS 'FECHA DE EMISIÓN DE CEDULA PROFESIONAL',
		   CAST(ce2.dFechaRegistro AS DATE) AS 'FECHA DE INGRESO A LA INSTITUCIÓN',
		   ISNULL(fnHorL.dHorarioInicio, '') AS 'LUNES INICIA',
		   ISNULL(fnHorL.dHorarioFin, '')    AS 'LUNES TERMINA',
		   ISNULL(fnHorM.dHorarioInicio, '') AS 'MARTES INICIA',
		   ISNULL(fnHorM.dHorarioFin, '')    AS 'MARTES TERMINA',
		   ISNULL(fnHorMi.dHorarioInicio, '') AS 'MIERCOLES INICIA',
		   ISNULL(fnHorMi.dHorarioFin, '')    AS 'MIERCOLES TERMINA',
		   ISNULL(fnHorJ.dHorarioInicio, '') AS 'JUEVES INICIA',
		   ISNULL(fnHorJ.dHorarioFin, '')    AS 'JUEVES TERMINA',
		   ISNULL(fnHorV.dHorarioInicio, '') AS 'VIERNES INICIA',
		   ISNULL(fnHorV.dHorarioFin, '')    AS 'VIERNES TERMINA',
		   ISNULL(fnHorS.dHorarioInicio, '') AS 'SABADO INICIA',
		   ISNULL(fnHorS.dHorarioFin, '')    AS 'SABADO TERMINA',
		   ISNULL(fnHorD.dHorarioInicio, '') AS 'DOMINGO INICIA',
		   ISNULL(fnHorD.dHorarioFin, '')    AS 'DOMINGO TERMINA',
		   (fnFinanzas.dBeca * 100) AS 'PORCENTAJE DE BECAS',
		   fnFinanzas.mInscripcion AS 'CUOTA INSCRIPCION',
		   fnFinanzas.mColegiatura AS 'CUOTA COLEGIATURA',
		   ISNULL(dbo.fnObtenerCalificacionFinalRedondeo(cta.iFolio, cfe2.idEvaluacion), '') AS 'CALIFICACION',
		   '' AS 'FECHA EXAMEN',
		   cei.sEstatus AS 'ESTATUS'
	FROM dbo.Cat_Alumnos AS ca 
		 INNER JOIN dbo.Cat_NivelAcad AS cna ON cna.idNivel = ca.idNivelAcad
		 INNER JOIN dbo.Ctrl_Inscripciones AS ci ON ci.idAlumno = ca.idAlumno AND ci.iFolioPeriodo = @iFolioPeriodo
		 INNER JOIN @idPlantel AS ip ON ip.id = ci.idPlantel
		 INNER JOIN @idOfEduc AS ioe ON ioe.id = ci.idOfEduc
		 INNER JOIN @idEstatusInsc AS iei ON iei.id = ci.idEstatusInsc
		 INNER JOIN dbo.Ctrl_TrayectoriaAcademica AS cta ON cta.iFolioInscripcion = ci.iFolio
		 LEFT  JOIN dbo.Ctrl_TrayectoriaAcademicaDet AS ctad ON ctad.iFolioTrayectoria = cta.iFolio
		 INNER JOIN dbo.Cat_PlanEstudios AS cpe ON cpe.idPlanEstudios = cta.idPlanEstudios
		 INNER JOIN dbo.Cat_Planes AS cp ON cp.idPlan = cpe.idPlan
		 INNER JOIN dbo.Ctrl_FormEvaluacion AS cfe2 ON cfe2.idFormEvaluacion = cpe.idFormEvaluacion
		 INNER JOIN dbo.Cat_OfEduc AS coe ON coe.idOfEduc = ci.idOfEduc
		 INNER JOIN dbo.Ctrl_Grupos AS cg ON cg.idGrupo = cta.idGrupo
		 INNER JOIN dbo.Ctrl_Periodos AS cp2 ON cp2.iFolio = ci.iFolioPeriodo
		 INNER JOIN dbo.Cat_Asignaturas AS ca2 ON ca2.idAsignatura = cta.idAsignatura
		 LEFT JOIN dbo.Cat_EscuelasProcedencia AS cep ON cep.idEscuelaProcedencia = ca.idEscuelaProcedencia
		 INNER JOIN dbo.Cat_EstatusInsc AS cei ON cei.idEstatus = ci.idEstatusInsc
		 INNER JOIN dbo.Ctrl_GrupoClases AS cgc ON cgc.idGrupo = cta.idGrupo 
												   AND cgc.idAsignatura = cta.idAsignatura
												   AND cgc.iFolioPeriodo = ci.iFolioPeriodo
		 -- INFO DOCENTES --
		 LEFT JOIN dbo.Cat_Profesores AS cp3 ON cp3.idProfesor = cgc.idProfesor
		 LEFT JOIN dbo.Cat_Sexos AS cs ON cs.idSexo = cp3.idSexo
		 LEFT JOIN dbo.Cat_Estados AS ce ON ce.idEstado = cp3.idEstado
		 LEFT JOIN dbo.Cat_Paises AS cp4 ON cp4.idPais = ce.idPais
		 LEFT JOIN dbo.Cat_Municipios AS cm ON cm.idMunicipio = cp3.idMunicipio
		 LEFT JOIN dbo.Cat_Empleados AS ce2 ON ce2.idProfesor = cp3.idProfesor
		 -- INFO HORARIOS --
		 OUTER APPLY ft2RPT_CES_ObtenerHorarioByGpoPeriodoProfAsignatura(cta.idGrupo, ci.iFolioPeriodo, cgc.idProfesor, cta.idAsignatura, 1) AS fnHorL
		 OUTER APPLY ft2RPT_CES_ObtenerHorarioByGpoPeriodoProfAsignatura(cta.idGrupo, ci.iFolioPeriodo, cgc.idProfesor, cta.idAsignatura, 2) AS fnHorM
		 OUTER APPLY ft2RPT_CES_ObtenerHorarioByGpoPeriodoProfAsignatura(cta.idGrupo, ci.iFolioPeriodo, cgc.idProfesor, cta.idAsignatura, 3) AS fnHorMi
		 OUTER APPLY ft2RPT_CES_ObtenerHorarioByGpoPeriodoProfAsignatura(cta.idGrupo, ci.iFolioPeriodo, cgc.idProfesor, cta.idAsignatura, 4) AS fnHorJ
		 OUTER APPLY ft2RPT_CES_ObtenerHorarioByGpoPeriodoProfAsignatura(cta.idGrupo, ci.iFolioPeriodo, cgc.idProfesor, cta.idAsignatura, 5) AS fnHorV
		 OUTER APPLY ft2RPT_CES_ObtenerHorarioByGpoPeriodoProfAsignatura(cta.idGrupo, ci.iFolioPeriodo, cgc.idProfesor, cta.idAsignatura, 6) AS fnHorS
		 OUTER APPLY ft2RPT_CES_ObtenerHorarioByGpoPeriodoProfAsignatura(cta.idGrupo, ci.iFolioPeriodo, cgc.idProfesor, cta.idAsignatura, 7) AS fnHorD
		 -- INFO FINANCIERA --
		 OUTER APPLY fnAF_VENT_ObtenerBecaColegiaturaInscripcion(CI.iFolio) AS fnFinanzas
	ORDER BY coe.sNombre,
			 ca.sApellidoPaterno + ' ' + ca.sApellidoMaterno + ' ' + ca.sNombre, 
			 cp2.sNombreOficial,
			 fnHorL.dHorarioInicio, 
			 fnHorM.dHorarioInicio, 
			 fnHorMi.dHorarioInicio, 
			 fnHorJ.dHorarioInicio, 
			 fnHorV.dHorarioInicio, 
			 fnHorS.dHorarioInicio, 
			 fnHorD.dHorarioInicio

END