Specialization.SPECIALIZATION)) {
Specialization.STUDENT_CURRICULAR_PLAN_SPECIALIZATION)) {
    private GratuityLetterFileEntry createGratuityLetterFileEntryForGratuitySituation(            GratuitySituation gratuitySituation, String shortYear, Date totalPaymentEndDate)            throws InsufficientSibsPaymentPhaseCodesServiceException {        // ignore integrated master degrees for now        // if (gratuitySituation.getStudentCurricularPlan().getSpecialization()        // .equals(Specialization.INTEGRADO_TYPE)) {        //        // return gratuityLetterFileEntry;        // }        if ((gratuitySituation.getRemainingValue() == null)                || (gratuitySituation.getRemainingValue().doubleValue() <= 0)) {            // nothing to be done            return null;        }        Double scholarShipPartValue = null;        if (gratuitySituation.getStudentCurricularPlan().getSpecialization().equals(                Specialization.SPECIALIZATION)) {            scholarShipPartValue = gratuitySituation.getRemainingValue();        } else {            scholarShipPartValue = new Double(gratuitySituation.getRemainingValue().doubleValue()                    - (gratuitySituation.getGratuityValues().getFinalProofValue() == null ? 0                            : gratuitySituation.getGratuityValues().getFinalProofValue().doubleValue()));        }        if (scholarShipPartValue.doubleValue() <= 0) {            // nothing to be done;            return null;        }        StudentCurricularPlan studentCurricularPlan = gratuitySituation.getStudentCurricularPlan();        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");        // add total payment line        String sibsPaymentCode = determineTotalPaymentCode(studentCurricularPlan);        // Date endDate = gratuitySituation.getGratuityValues().getEndPayment();        //        // if (endDate != null &&        // endDate.before(Calendar.getInstance().getTime()) == true) {        // // end date already passed        // return null;        // }        // Date totalPaymentEndDate = Calendar.getInstance().getTime();        GratuityLetterFileEntry gratuityLetterFileEntry = new GratuityLetterFileEntry(                studentCurricularPlan);        gratuityLetterFileEntry.setTotalGratuityFullSibsReference(shortYear                + addCharToStringUntilMax(SibsOutgoingPaymentFileConstants.ZERO_CHAR,                        studentCurricularPlan.getStudent().getNumber().toString(),                        SibsOutgoingPaymentFileConstants.MAX_STUDENT_NUMBER_LENGTH) + sibsPaymentCode);        NumberFormat numberFormat = NumberFormat.getInstance();        DecimalFormat decimalFormat = (DecimalFormat) numberFormat;        decimalFormat.applyPattern("######.##");        gratuityLetterFileEntry.setTotalGratuityValue(decimalFormat.format(scholarShipPartValue                .doubleValue()));        gratuityLetterFileEntry.setTotalGratuityEndDate(simpleDateFormat.format(totalPaymentEndDate));        // int totalNumberOfPaymentPhases = 0;        //        // // add phase payment lines        // List paymentPhaseList =        // gratuitySituation.getGratuityValues().getPaymentPhaseList();        //        // double totalValueInPhases = 0;        // for (Iterator iter = paymentPhaseList.iterator(); iter.hasNext();) {        // PaymentPhase paymentPhase = (PaymentPhase) iter.next();        // totalValueInPhases += paymentPhase.getValue().doubleValue();        // }        //        // if ((scholarShipPartValue.doubleValue() - totalValueInPhases) > 0) {        // // there are no sufficient phases to pay the remaining value        // // so send the total value only        // return gratuityLetterFileEntry;        // }        //        // BeanComparator paymentPhaseDateComparator = new        // BeanComparator("endDate");        // ComparatorChain chainComparator = new ComparatorChain();        // chainComparator.addComparator(paymentPhaseDateComparator, true);        // paymentPhaseList = new ArrayList(paymentPhaseList);        // Collections.sort(paymentPhaseList, chainComparator);        //        // int paymentPhaseNumber = 1;        // double totalValueToDivideInPhases =        // scholarShipPartValue.doubleValue();        //        // for (Iterator iter = paymentPhaseList.iterator(); iter.hasNext();) {        // PaymentPhase paymentPhase = (PaymentPhase) iter.next();        //        // if        // (paymentPhase.getEndDate().before(Calendar.getInstance().getTime()))        // {        // // end date for that phase already passed        // continue;        // }        //        // if ((paymentPhaseNumber == 1)        // && (paymentPhase.getValue().doubleValue() >=        // totalValueToDivideInPhases)) {        // // phases are not required, because the total value is less then        // // the first phase        // return gratuityLetterFileEntry;        // }        //        // totalValueToDivideInPhases -= paymentPhase.getValue().doubleValue();        //        // sibsPaymentCode = determinePaymentPhaseCode(paymentPhaseNumber,        // studentCurricularPlan,        // gratuitySituation);        //        // GratuityLetterPaymentPhase gratuityLetterPaymentPhase = new        // GratuityLetterPaymentPhase();        // gratuityLetterPaymentPhase.setEndDate(simpleDateFormat.format(paymentPhase.getEndDate()));        //        // gratuityLetterPaymentPhase.setValue(paymentPhase.getValue().toString());        // gratuityLetterPaymentPhase.setFullSibsReference(shortYear        // + addCharToStringUntilMax(SibsOutgoingPaymentFileConstants.ZERO_CHAR,        // studentCurricularPlan.getStudent().getNumber().toString(),        // SibsOutgoingPaymentFileConstants.MAX_STUDENT_NUMBER_LENGTH)        // + sibsPaymentCode);        // gratuityLetterPaymentPhase.setEndDate(simpleDateFormat.format(paymentPhase.getEndDate()));        //        // gratuityLetterFileEntry.getGratuityLetterPaymentPhases().add(gratuityLetterPaymentPhase);        //        // totalNumberOfPaymentPhases++;        //        // paymentPhaseNumber++;        //        // }        //        // gratuityLetterFileEntry.setNumberOfPaymentPhases(totalNumberOfPaymentPhases);        return gratuityLetterFileEntry;    }