Search in sources :

Example 1 with InstallmentDate

use of org.mifos.accounts.util.helpers.InstallmentDate in project head by mifos.

the class LoanBO method createUnroundedLoanSchedulesFromInstallments.

private List<LoanScheduleEntity> createUnroundedLoanSchedulesFromInstallments(List<InstallmentDate> installmentDates, Money loanInterest, Money loanAmount, ScheduledEvent meetingScheduledEvent, List<InstallmentPrincipalAndInterest> principalWithInterestInstallments, Set<AccountFeesEntity> accountFees) {
    List<LoanScheduleEntity> unroundedLoanSchedules = new ArrayList<LoanScheduleEntity>();
    List<FeeInstallment> feeInstallments = new ArrayList<FeeInstallment>();
    if (!getAccountFees().isEmpty()) {
        InstallmentFeeCalculatorFactory installmentFeeCalculatorFactory = new InstallmentFeeCalculatorFactoryImpl();
        for (AccountFeesEntity accountFeesEntity : accountFees) {
            RateAmountFlag feeType = accountFeesEntity.getFees().getFeeType();
            InstallmentFeeCalculator installmentFeeCalculator = installmentFeeCalculatorFactory.create(getFeeDao(), feeType);
            Double feeAmount = accountFeesEntity.getFeeAmount();
            Money accountFeeAmount = installmentFeeCalculator.calculate(feeAmount, loanAmount, loanInterest, accountFeesEntity.getFees());
            accountFeesEntity.setAccountFeeAmount(accountFeeAmount);
        }
        feeInstallments = FeeInstallment.createMergedFeeInstallments(meetingScheduledEvent, accountFees, installmentDates.size());
    }
    int installmentIndex = 0;
    for (InstallmentDate installmentDate1 : installmentDates) {
        InstallmentPrincipalAndInterest em = principalWithInterestInstallments.get(installmentIndex);
        LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity(this, getCustomer(), installmentDate1.getInstallmentId(), new java.sql.Date(installmentDate1.getInstallmentDueDate().getTime()), PaymentStatus.UNPAID, em.getPrincipal(), em.getInterest());
        for (FeeInstallment feeInstallment : feeInstallments) {
            if (feeInstallment.getInstallmentId().equals(installmentDate1.getInstallmentId()) && !feeInstallment.getAccountFeesEntity().getFees().isTimeOfDisbursement()) {
                LoanFeeScheduleEntity loanFeeScheduleEntity = new LoanFeeScheduleEntity(loanScheduleEntity, feeInstallment.getAccountFeesEntity().getFees(), feeInstallment.getAccountFeesEntity(), feeInstallment.getAccountFee());
                loanScheduleEntity.addAccountFeesAction(loanFeeScheduleEntity);
            } else if (feeInstallment.getInstallmentId().equals(installmentDate1.getInstallmentId()) && isInterestDeductedAtDisbursement() && feeInstallment.getAccountFeesEntity().getFees().isTimeOfDisbursement()) {
                // FIXME - keithw - isInterestDeductedAtDisbursement is not relevant but one integration test fails
                // when this is removed. leaving in but test is most likely wrong. LoanBOIntegrationTest.testRemoveLoanDisbursalFee
                LoanFeeScheduleEntity loanFeeScheduleEntity = new LoanFeeScheduleEntity(loanScheduleEntity, feeInstallment.getAccountFeesEntity().getFees(), feeInstallment.getAccountFeesEntity(), feeInstallment.getAccountFee());
                loanScheduleEntity.addAccountFeesAction(loanFeeScheduleEntity);
            }
        }
        unroundedLoanSchedules.add(loanScheduleEntity);
        installmentIndex++;
    }
    return unroundedLoanSchedules;
}
Also used : RateAmountFlag(org.mifos.accounts.fees.util.helpers.RateAmountFlag) ArrayList(java.util.ArrayList) InstallmentFeeCalculator(org.mifos.clientportfolio.newloan.domain.InstallmentFeeCalculator) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) Money(org.mifos.framework.util.helpers.Money) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) InstallmentFeeCalculatorFactoryImpl(org.mifos.clientportfolio.newloan.domain.InstallmentFeeCalculatorFactoryImpl) InstallmentPrincipalAndInterest(org.mifos.accounts.loan.util.helpers.InstallmentPrincipalAndInterest) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) InstallmentFeeCalculatorFactory(org.mifos.clientportfolio.newloan.domain.InstallmentFeeCalculatorFactory)

Example 2 with InstallmentDate

use of org.mifos.accounts.util.helpers.InstallmentDate in project head by mifos.

the class LoanBO method applyPeriodicFee.

/**
     * The fee (new or to be updated) is applied to the given list of AccountActionDateEntity(s). Note that the entities
     * are the actual entity objects referenced by the loan, so this method acts by side-effect, adding fees to the
     * given entities.
     *
     * @param fee
     *            the periodic FeeBO to apply to the given AccountActionDateEntity(s)
     * @param charge
     *            the
     * @param dueInstallments
     * @throws AccountException
     * @throws PersistenceException
     */
private void applyPeriodicFee(final FeeBO fee, final Double charge, final List<AccountActionDateEntity> dueInstallments) throws AccountException {
    // Create an AccountFeesEntity linking the loan to the given fee fee and charge if the fee hasn't been applied,
    // or
    // update the applied fee's AccountFeesEntity.feeAmount with the given charge. Then set the
    // AccountFeeEntity.accountFeeAmount to this loan's originalInterest.
    AccountFeesEntity accountFee = getAccountFee(fee, charge);
    Set<AccountFeesEntity> accountFeeSet = new HashSet<AccountFeesEntity>();
    accountFeeSet.add(accountFee);
    populateAccountFeeAmount(accountFeeSet, loanSummary.getOriginalInterest());
    // Extract the list of InstallmentDate(s) from the given AccountActionDateEntity(s). Note that
    // the installmentId(s) likely do not start with 1 since the fee may be applied after some
    // installment dates have passed.
    List<InstallmentDate> installmentDates = new ArrayList<InstallmentDate>();
    for (AccountActionDateEntity accountActionDateEntity : dueInstallments) {
        installmentDates.add(new InstallmentDate(accountActionDateEntity.getInstallmentId(), accountActionDateEntity.getActionDate()));
    }
    // Get the full list of all loan InstallmentDate(s), past, present and future, without adjusting for holidays.
    // This will work correctly only if adjusting periodic fees is done when no installments have been paid
    //        boolean isRepaymentIndepOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
    //        List<InstallmentDate> nonAdjustedInstallmentDates = getInstallmentDates(getLoanMeeting(), noOfInstallments,
    //                getInstallmentSkipToStartRepayment(), isRepaymentIndepOfMeetingEnabled,
    //                false);
    // Use handlePeriodic to adjust fee installments for holiday periods and combine multiple fee installments due
    // for the
    // same loan installment. Finally, apply these updated fees to the given dueInstallments list and update
    // loan summary and activity tables.
    /*
         * old way List<FeeInstallment> feeInstallmentList = mergeFeeInstallments(handlePeriodic(accountFee,
         * installmentDates, nonAdjustedInstallmentDates));
         */
    // new way
    ScheduledEvent loanScheduledEvent = ScheduledEventFactory.createScheduledEventFrom(this.getMeetingForAccount());
    List<FeeInstallment> feeInstallmentList = FeeInstallment.createMergedFeeInstallmentsForOneFeeStartingWith(loanScheduledEvent, accountFee, dueInstallments.size(), dueInstallments.get(0).getInstallmentId());
    Money totalFeeAmountApplied = applyFeeToInstallments(feeInstallmentList, dueInstallments);
    updateLoanSummary(fee.getFeeId(), totalFeeAmountApplied);
    updateLoanActivity(fee.getFeeId(), totalFeeAmountApplied, fee.getFeeName() + AccountConstants.APPLIED);
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) ScheduledEvent(org.mifos.schedule.ScheduledEvent) Money(org.mifos.framework.util.helpers.Money) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) ArrayList(java.util.ArrayList) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate)

Example 3 with InstallmentDate

use of org.mifos.accounts.util.helpers.InstallmentDate in project head by mifos.

the class AnyScheduledEventLoanInstallmentGenerator method generate.

@Override
public List<InstallmentDate> generate(LocalDate actualDisbursementDate, int numberOfInstallments, GraceType graceType, int gracePeriodDuration, Short officeId) {
    List<InstallmentDate> installmentDates = new ArrayList<InstallmentDate>();
    if (numberOfInstallments > 0) {
        List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
        List<Holiday> holidays = new ArrayList<Holiday>();
        LocalDate startFromMeetingDate = null;
        if (scheduledEvent instanceof DailyScheduledEvent) {
            startFromMeetingDate = actualDisbursementDate.plusDays(scheduledEvent.getEvery());
        } else {
            startFromMeetingDate = actualDisbursementDate.plusDays(1);
        }
        holidays = holidayDao.findAllHolidaysFromDateAndNext(officeId, startFromMeetingDate.toString());
        int occurrences = numberOfInstallments;
        if (graceType == GraceType.GRACEONALLREPAYMENTS) {
            occurrences += gracePeriodDuration;
        }
        ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
        List<Date> dueDates = new ArrayList<Date>();
        List<DateTime> installmentDateTimes = dateGeneration.generateScheduledDates(occurrences, startFromMeetingDate.toDateMidnight().toDateTime(), scheduledEvent, false);
        for (DateTime installmentDate : installmentDateTimes) {
            dueDates.add(installmentDate.toDate());
        }
        installmentDates = createInstallmentDates(dueDates);
        if (graceType == GraceType.GRACEONALLREPAYMENTS) {
            removeInstallmentsNeedNotPay(gracePeriodDuration, installmentDates);
        }
    }
    return installmentDates;
}
Also used : DailyScheduledEvent(org.mifos.schedule.internal.DailyScheduledEvent) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration) ScheduledDateGeneration(org.mifos.schedule.ScheduledDateGeneration) Holiday(org.mifos.application.holiday.business.Holiday) Days(org.joda.time.Days) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)

Example 4 with InstallmentDate

use of org.mifos.accounts.util.helpers.InstallmentDate in project head by mifos.

the class AnyScheduledEventLoanInstallmentGenerator method removeInstallmentsNeedNotPay.

private void removeInstallmentsNeedNotPay(final int installmentSkipToStartRepayment, final List<InstallmentDate> installmentDates) {
    int removeCounter = 0;
    for (int i = 0; i < installmentSkipToStartRepayment; i++) {
        installmentDates.remove(removeCounter);
    }
    // re-adjust the installment ids
    if (installmentSkipToStartRepayment > 0) {
        int count = installmentDates.size();
        for (int i = 0; i < count; i++) {
            InstallmentDate instDate = installmentDates.get(i);
            instDate.setInstallmentId(new Short(Integer.toString(i + 1)));
        }
    }
}
Also used : InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate)

Example 5 with InstallmentDate

use of org.mifos.accounts.util.helpers.InstallmentDate in project head by mifos.

the class AnyScheduledEventLoanInstallmentGenerator method createInstallmentDates.

private List<InstallmentDate> createInstallmentDates(final List<Date> dueDates) {
    List<InstallmentDate> installmentDates = new ArrayList<InstallmentDate>();
    int installmentId = 1;
    for (Date date : dueDates) {
        installmentDates.add(new InstallmentDate((short) installmentId++, date));
    }
    return installmentDates;
}
Also used : ArrayList(java.util.ArrayList) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate)

Aggregations

InstallmentDate (org.mifos.accounts.util.helpers.InstallmentDate)25 ArrayList (java.util.ArrayList)18 Date (java.util.Date)12 LocalDate (org.joda.time.LocalDate)12 Money (org.mifos.framework.util.helpers.Money)10 DateTime (org.joda.time.DateTime)9 FeeInstallment (org.mifos.accounts.util.helpers.FeeInstallment)9 ScheduledEvent (org.mifos.schedule.ScheduledEvent)7 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)6 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)6 MeetingBO (org.mifos.application.meeting.business.MeetingBO)5 Days (org.joda.time.Days)4 InstallmentPrincipalAndInterest (org.mifos.accounts.loan.util.helpers.InstallmentPrincipalAndInterest)4 Holiday (org.mifos.application.holiday.business.Holiday)4 FiscalCalendarRules (org.mifos.config.FiscalCalendarRules)4 ScheduledDateGeneration (org.mifos.schedule.ScheduledDateGeneration)4 HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration (org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)4 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 RateAmountFlag (org.mifos.accounts.fees.util.helpers.RateAmountFlag)2