Package org.fenixedu.academic.domain.reports

Source Code of org.fenixedu.academic.domain.reports.EtiReportFile

/**
* Copyright © 2002 Instituto Superior Técnico
*
* This file is part of FenixEdu Academic.
*
* FenixEdu Academic is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FenixEdu Academic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FenixEdu Academic.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.fenixedu.academic.domain.reports;

import org.fenixedu.academic.domain.Attends;
import org.fenixedu.academic.domain.CurricularCourse;
import org.fenixedu.academic.domain.Degree;
import org.fenixedu.academic.domain.DegreeCurricularPlan;
import org.fenixedu.academic.domain.Enrolment;
import org.fenixedu.academic.domain.EnrolmentEvaluation;
import org.fenixedu.academic.domain.ExecutionSemester;
import org.fenixedu.academic.domain.StudentCurricularPlan;
import org.fenixedu.academic.domain.curriculum.EnrollmentState;
import org.fenixedu.academic.domain.student.Registration;
import org.fenixedu.academic.domain.student.Student;
import org.fenixedu.academic.domain.studentCurriculum.CurriculumModule;

import pt.utl.ist.fenix.tools.util.excel.Spreadsheet;
import pt.utl.ist.fenix.tools.util.excel.Spreadsheet.Row;

public class EtiReportFile extends EtiReportFile_Base {

    public EtiReportFile() {
        super();
    }

    @Override
    public String getJobName() {
        return "Listagem para ETI";
    }

    @Override
    protected String getPrefix() {
        return "etiGrades";
    }

    @Override
    public void renderReport(Spreadsheet spreadsheet) throws Exception {
        spreadsheet.setHeader("número aluno");
        setDegreeHeaders(spreadsheet, "aluno");
        spreadsheet.setHeader("semestre");
        spreadsheet.setHeader("ano lectivo");
        spreadsheet.setHeader("nome Disciplina");
        setDegreeHeaders(spreadsheet, "disciplina");
        spreadsheet.setHeader("creditos");
        spreadsheet.setHeader("estado");
        spreadsheet.setHeader("época");
        spreadsheet.setHeader("nota");
        spreadsheet.setHeader("época normal");
        spreadsheet.setHeader("época especial");
        spreadsheet.setHeader("melhoria");
        spreadsheet.setHeader("tipo Aluno");
        spreadsheet.setHeader("número inscricoes anteriores");
        spreadsheet.setHeader("executionCourseId");

        for (final Degree degree : Degree.readNotEmptyDegrees()) {
            if (checkDegreeType(getDegreeType(), degree)) {
                for (final DegreeCurricularPlan degreeCurricularPlan : degree.getDegreeCurricularPlansSet()) {
                    if (checkExecutionYear(getExecutionYear(), degreeCurricularPlan)) {
                        for (final CurricularCourse curricularCourse : degreeCurricularPlan.getAllCurricularCourses()) {
                            if (checkExecutionYear(getExecutionYear(), curricularCourse)) {

                                for (final CurriculumModule curriculumModule : curricularCourse.getCurriculumModulesSet()) {
                                    if (curriculumModule.isEnrolment()) {
                                        final Enrolment enrolment = (Enrolment) curriculumModule;
                                        if (enrolment.getExecutionYear() == getExecutionYear()) {
                                            final ExecutionSemester executionSemester = enrolment.getExecutionPeriod();
                                            if (curricularCourse.isAnual()) {
                                                addEtiRow(spreadsheet, curricularCourse.getDegree(), curricularCourse, enrolment,
                                                        executionSemester, executionSemester);
                                                if (executionSemester.getSemester().intValue() == 1) {
                                                    final ExecutionSemester nextSemester =
                                                            executionSemester.getNextExecutionPeriod();
                                                    addEtiRow(spreadsheet, curricularCourse.getDegree(), curricularCourse,
                                                            enrolment, nextSemester, executionSemester);
                                                }
                                            } else {
                                                addEtiRow(spreadsheet, curricularCourse.getDegree(), curricularCourse, enrolment,
                                                        executionSemester, executionSemester);
                                            }

                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    private void addEtiRow(final Spreadsheet spreadsheet, final Degree degree, final CurricularCourse curricularCourse,
            final Enrolment enrolment, final ExecutionSemester executionSemester,
            final ExecutionSemester executionSemesterForPreviousEnrolmentCount) {
        final StudentCurricularPlan studentCurricularPlan = enrolment.getStudentCurricularPlan();
        final Registration registration = studentCurricularPlan.getRegistration();
        final Student student = registration.getStudent();

        final Row row = spreadsheet.addRow();
        row.setCell(registration.getNumber());
        setDegreeCells(row, registration.getDegree());
        row.setCell(executionSemester.getSemester().toString());
        row.setCell(executionSemester.getExecutionYear().getYear());
        row.setCell(curricularCourse.getName());
        setDegreeCells(row, degree);
        row.setCell(enrolment.getEctsCredits().toString().replace('.', ','));
        row.setCell(enrolment.isApproved() ? EnrollmentState.APROVED.getDescription() : enrolment.getEnrollmentState()
                .getDescription());
        row.setCell(enrolment.getEnrolmentEvaluationType().getDescription());
        row.setCell(enrolment.getGradeValue());

        final EnrolmentEvaluation normal = enrolment.getLatestFinalNormalEnrolmentEvaluation();
        row.setCell(normal == null ? "" : normal.getGradeValue());
        final EnrolmentEvaluation special = enrolment.getLatestFinalSpecialSeasonEnrolmentEvaluation();
        row.setCell(special == null ? "" : special.getGradeValue());
        final EnrolmentEvaluation improvement = enrolment.getLatestFinalImprovementEnrolmentEvaluation();
        row.setCell(improvement == null ? "" : improvement.getGradeValue());

        row.setCell(registration.getRegistrationProtocol().getCode());
        row.setCell(countPreviousEnrolments(curricularCourse, executionSemesterForPreviousEnrolmentCount, student));
        Attends attends = null; // enrolment.getAttendsFor(executionSemester);
        for (final Attends a : enrolment.getAttendsSet()) {
            if (a.isFor(executionSemester)) {
                if (attends == null) {
                    attends = a;
                }
            }
        }
    }

    private String countPreviousEnrolments(final CurricularCourse curricularCourse, final ExecutionSemester executionPeriod,
            final Student student) {
        int count = 0;
        for (final CurriculumModule curriculumModule : curricularCourse.getCurriculumModulesSet()) {
            if (curriculumModule.isEnrolment()) {
                final Enrolment enrolment = (Enrolment) curriculumModule;
                if (executionPeriod.compareTo(enrolment.getExecutionPeriod()) > 0) {
                    if (enrolment.getStudentCurricularPlan().getRegistration().getStudent() == student) {
                        count++;
                    }
                }
            }
        }
        return Integer.toString(count);
    }
}
TOP

Related Classes of org.fenixedu.academic.domain.reports.EtiReportFile

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.