Search in sources :

Example 1 with FeeInstallment

use of org.mifos.accounts.util.helpers.FeeInstallment 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 FeeInstallment

use of org.mifos.accounts.util.helpers.FeeInstallment 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 FeeInstallment

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

the class FeeInstallmentTest method createMergedFeeInstallmentsForTwoFeesBothAccountAndFeesAreScheduledEveryWeekShouldGetOneFeeInstallmentPerAccountEventPerFee.

/**********************************
     * Tests verify merging fees when two or more fees are attached to the account
     *
     * TODO: KRP: Remove the assumption of order that fee installments appear in the created list.
     **********************************/
@Test
public void createMergedFeeInstallmentsForTwoFeesBothAccountAndFeesAreScheduledEveryWeekShouldGetOneFeeInstallmentPerAccountEventPerFee() {
    ScheduledEvent masterEvent = new ScheduledEventBuilder().every(1).weeks().build();
    FeeBO feeBO1 = createWeeklyFeeBO(1);
    FeeBO feeBO2 = createWeeklyFeeBO(1);
    AccountFeesEntity accountFeesEntity1 = createAccountFeesEntity(feeBO1, 10.0);
    AccountFeesEntity accountFeesEntity2 = createAccountFeesEntity(feeBO2, 13.0);
    List<AccountFeesEntity> accountFees = Arrays.asList(new AccountFeesEntity[] { accountFeesEntity1, accountFeesEntity2 });
    List<FeeInstallment> feeInstallments = FeeInstallment.createMergedFeeInstallments(masterEvent, accountFees, 3);
    assertThat(feeInstallments.size(), is(6));
    assertFeeInstallment(feeInstallments.get(0), 1, 10.0, feeBO1);
    assertFeeInstallment(feeInstallments.get(1), 2, 10.0, feeBO1);
    assertFeeInstallment(feeInstallments.get(2), 3, 10.0, feeBO1);
    assertFeeInstallment(feeInstallments.get(3), 1, 13.0, feeBO2);
    assertFeeInstallment(feeInstallments.get(4), 2, 13.0, feeBO2);
    assertFeeInstallment(feeInstallments.get(5), 3, 13.0, feeBO2);
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) ScheduledEventBuilder(org.mifos.domain.builders.ScheduledEventBuilder) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Example 4 with FeeInstallment

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

the class FeeInstallmentTest method createMergedFeeInstallmentsForOneFeeAccountScheduledEveryOtherWeekFeeScheduledEveryWeekt.

@Test
public void createMergedFeeInstallmentsForOneFeeAccountScheduledEveryOtherWeekFeeScheduledEveryWeekt() {
    ScheduledEvent masterEvent = new ScheduledEventBuilder().every(2).weeks().build();
    FeeBO feeBO = createWeeklyFeeBO(1);
    AccountFeesEntity accountFeesEntity = createAccountFeesEntity(feeBO, 10.0);
    List<FeeInstallment> feeInstallments = FeeInstallment.createMergedFeeInstallmentsForOneFee(masterEvent, accountFeesEntity, 4);
    assertThat(feeInstallments.size(), is(4));
    assertFeeInstallment(feeInstallments.get(0), 1, 10.0, feeBO);
    assertFeeInstallment(feeInstallments.get(1), 2, 20.0, feeBO);
    assertFeeInstallment(feeInstallments.get(2), 3, 20.0, feeBO);
    assertFeeInstallment(feeInstallments.get(3), 4, 20.0, feeBO);
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) ScheduledEventBuilder(org.mifos.domain.builders.ScheduledEventBuilder) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Example 5 with FeeInstallment

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

the class FeeInstallmentTest method createMergedFeeInstallmentsForOneFeeAccountScheduledEveryThirdMonthFeeScheduledEverySecondMonth.

@Test
public void createMergedFeeInstallmentsForOneFeeAccountScheduledEveryThirdMonthFeeScheduledEverySecondMonth() throws Exception {
    ScheduledEvent accountScheduledEvent = new ScheduledEventBuilder().every(3).months().onDayOfMonth(3).build();
    FeeBO feeBO = createMonthlyOnDayFeeBO(2);
    AccountFeesEntity accountFeesEntity = createAccountFeesEntity(feeBO, 10.0);
    List<FeeInstallment> feeInstallments = FeeInstallment.createMergedFeeInstallmentsForOneFee(accountScheduledEvent, accountFeesEntity, 4);
    assertThat(feeInstallments.size(), is(4));
    assertFeeInstallment(feeInstallments.get(0), 1, 10.0, feeBO);
    assertFeeInstallment(feeInstallments.get(1), 2, 10.0, feeBO);
    assertFeeInstallment(feeInstallments.get(2), 3, 20.0, feeBO);
    assertFeeInstallment(feeInstallments.get(3), 4, 10.0, feeBO);
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) ScheduledEventBuilder(org.mifos.domain.builders.ScheduledEventBuilder) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Aggregations

FeeInstallment (org.mifos.accounts.util.helpers.FeeInstallment)25 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)17 ScheduledEvent (org.mifos.schedule.ScheduledEvent)12 InstallmentDate (org.mifos.accounts.util.helpers.InstallmentDate)11 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)9 FeeBO (org.mifos.accounts.fees.business.FeeBO)9 ScheduledEventBuilder (org.mifos.domain.builders.ScheduledEventBuilder)9 Money (org.mifos.framework.util.helpers.Money)9 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)7 Date (java.util.Date)4 LocalDate (org.joda.time.LocalDate)4 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 AccountFeesActionDetailEntity (org.mifos.accounts.business.AccountFeesActionDetailEntity)2 RateAmountFlag (org.mifos.accounts.fees.util.helpers.RateAmountFlag)2 InstallmentPrincipalAndInterest (org.mifos.accounts.loan.util.helpers.InstallmentPrincipalAndInterest)2 MeetingBO (org.mifos.application.meeting.business.MeetingBO)2 DateTimeService (org.mifos.framework.util.DateTimeService)2