Search in sources :

Example 16 with FeeInstallment

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

the class FeeInstallmentTest method createMergedFeeInstallmentsForOneFeeAccountScheduledEveryWeekFeeScheduledEveryOtherWeekShouldGetOneFeeInstallmentPerEveryOtherAccountEvent.

@Test
public void createMergedFeeInstallmentsForOneFeeAccountScheduledEveryWeekFeeScheduledEveryOtherWeekShouldGetOneFeeInstallmentPerEveryOtherAccountEvent() {
    ScheduledEvent accountEvent = new ScheduledEventBuilder().every(1).weeks().build();
    FeeBO feeBO = createWeeklyFeeBO(2);
    AccountFeesEntity accountFeesEntity = createAccountFeesEntity(feeBO, 10.0);
    List<FeeInstallment> feeInstallments = FeeInstallment.createMergedFeeInstallmentsForOneFee(accountEvent, accountFeesEntity, 4);
    assertThat(feeInstallments.size(), is(2));
    assertFeeInstallment(feeInstallments.get(0), 1, 10.0, feeBO);
    assertFeeInstallment(feeInstallments.get(1), 3, 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)

Example 17 with FeeInstallment

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

the class LoanBO method applyOneTimeFee.

private void applyOneTimeFee(final FeeBO fee, final Double charge, final AccountActionDateEntity accountActionDateEntity) throws AccountException {
    LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDateEntity;
    AccountFeesEntity accountFee = new AccountFeesEntity(this, fee, charge, FeeStatus.ACTIVE.getValue(), new DateTimeService().getCurrentJavaDateTime(), null);
    Set<AccountFeesEntity> accountFeeSet = new HashSet<AccountFeesEntity>();
    accountFeeSet.add(accountFee);
    populateAccountFeeAmount(accountFeeSet, loanSummary.getOriginalInterest());
    List<AccountActionDateEntity> loanScheduleEntityList = new ArrayList<AccountActionDateEntity>();
    loanScheduleEntityList.add(loanScheduleEntity);
    List<InstallmentDate> installmentDates = new ArrayList<InstallmentDate>();
    installmentDates.add(new InstallmentDate(accountActionDateEntity.getInstallmentId(), accountActionDateEntity.getActionDate()));
    List<FeeInstallment> feeInstallmentList = new ArrayList<FeeInstallment>();
    feeInstallmentList.add(handleOneTime(accountFee, installmentDates));
    Money totalFeeAmountApplied = applyFeeToInstallments(feeInstallmentList, loanScheduleEntityList);
    filterTimeOfDisbursementFees(loanScheduleEntity, fee);
    updateLoanSummary(fee.getFeeId(), totalFeeAmountApplied);
    updateLoanActivity(fee.getFeeId(), totalFeeAmountApplied, fee.getFeeName() + AccountConstants.APPLIED);
}
Also used : ArrayList(java.util.ArrayList) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) DateTimeService(org.mifos.framework.util.DateTimeService) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 18 with FeeInstallment

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

the class LoanBO method applyFeeToInstallments.

private Money applyFeeToInstallments(final List<FeeInstallment> feeInstallmentList, final List<AccountActionDateEntity> accountActionDateList) {
    Date lastAppliedDate = null;
    Money totalFeeAmountApplied = new Money(getCurrency());
    AccountFeesEntity accountFeesEntity = null;
    for (AccountActionDateEntity accountActionDateEntity : accountActionDateList) {
        LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDateEntity;
        for (FeeInstallment feeInstallment : feeInstallmentList) {
            if (feeInstallment.getInstallmentId().equals(loanScheduleEntity.getInstallmentId())) {
                lastAppliedDate = loanScheduleEntity.getActionDate();
                totalFeeAmountApplied = totalFeeAmountApplied.add(feeInstallment.getAccountFee());
                /*
                     * AccountFeesActionDetailEntity accountFeesActionDetailEntity = new LoanFeeScheduleEntity(
                     * loanScheduleEntity, feeInstallment .getAccountFeesEntity().getFees(),
                     * feeInstallment.getAccountFeesEntity(), feeInstallment.getAccountFee()); loanScheduleEntity
                     * .addAccountFeesAction(accountFeesActionDetailEntity);
                     */
                if (feeInstallment.getAccountFeesEntity().getFees().isPeriodic() && loanScheduleEntity.isFeeAlreadyAttatched(feeInstallment.getAccountFeesEntity().getFees().getFeeId())) {
                    LoanFeeScheduleEntity loanFeeScheduleEntity = (LoanFeeScheduleEntity) loanScheduleEntity.getAccountFeesAction(feeInstallment.getAccountFeesEntity().getFees().getFeeId());
                    loanFeeScheduleEntity.setFeeAmount(loanFeeScheduleEntity.getFeeAmount().add(feeInstallment.getAccountFee()));
                } else {
                    AccountFeesActionDetailEntity accountFeesActionDetailEntity = new LoanFeeScheduleEntity(loanScheduleEntity, feeInstallment.getAccountFeesEntity().getFees(), feeInstallment.getAccountFeesEntity(), feeInstallment.getAccountFee());
                    loanScheduleEntity.addAccountFeesAction(accountFeesActionDetailEntity);
                }
                accountFeesEntity = feeInstallment.getAccountFeesEntity();
            }
        }
    }
    accountFeesEntity.setLastAppliedDate(lastAppliedDate);
    addAccountFees(accountFeesEntity);
    return totalFeeAmountApplied;
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate)

Example 19 with FeeInstallment

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

the class CustomerAccountBO method applyPeriodicFee.

/*
     * Package-level visibility for testing
     */
void applyPeriodicFee(final FeeBO fee, final Money charge, final List<AccountActionDateEntity> dueInstallments) throws AccountException {
    AccountFeesEntity accountFee = getAccountFee(fee, charge.getAmountDoubleValue());
    accountFee.setAccountFeeAmount(charge);
    List<InstallmentDate> installmentDates = new ArrayList<InstallmentDate>();
    for (AccountActionDateEntity accountActionDateEntity : dueInstallments) {
        installmentDates.add(new InstallmentDate(accountActionDateEntity.getInstallmentId(), accountActionDateEntity.getActionDate()));
    }
    //        List<FeeInstallment> feeInstallmentList = mergeFeeInstallments(handlePeriodic(accountFee, installmentDates));
    ScheduledEvent loanScheduledEvent = ScheduledEventFactory.createScheduledEventFrom(this.getMeetingForAccount());
    List<FeeInstallment> feeInstallmentList = FeeInstallment.createMergedFeeInstallmentsForOneFeeStartingWith(loanScheduledEvent, accountFee, dueInstallments.size(), dueInstallments.get(0).getInstallmentId());
    // MIFOS-3701: we want to display only fee charge, not the totalFeeAmountApplied
    applyFeeToInstallments(feeInstallmentList, dueInstallments);
    updateCustomerActivity(fee.getFeeId(), charge, fee.getFeeName() + AccountConstants.APPLIED);
    accountFee.setFeeStatus(FeeStatus.ACTIVE);
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) DailyScheduledEvent(org.mifos.schedule.internal.DailyScheduledEvent) ScheduledEvent(org.mifos.schedule.ScheduledEvent) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) ArrayList(java.util.ArrayList) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate)

Example 20 with FeeInstallment

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

the class IndividualLoanScheduleFactory method createUnroundedLoanSchedulesFromInstallments.

private List<LoanScheduleEntity> createUnroundedLoanSchedulesFromInstallments(List<InstallmentDate> installmentDates, Money loanInterest, Money loanAmount, ScheduledEvent meetingScheduledEvent, List<InstallmentPrincipalAndInterest> principalWithInterestInstallments, List<AccountFeesEntity> accountFees, CustomerBO customer) {
    List<LoanScheduleEntity> unroundedLoanSchedules = new ArrayList<LoanScheduleEntity>();
    List<AccountFeesEntity> accountFeesWithNoTimeOfDibursementFees = new ArrayList<AccountFeesEntity>();
    List<FeeInstallment> feeInstallments = new ArrayList<FeeInstallment>();
    if (!accountFees.isEmpty()) {
        InstallmentFeeCalculatorFactory installmentFeeCalculatorFactory = new InstallmentFeeCalculatorFactoryImpl();
        for (AccountFeesEntity accountFeesEntity : accountFees) {
            RateAmountFlag feeType = accountFeesEntity.getFees().getFeeType();
            InstallmentFeeCalculator installmentFeeCalculator = installmentFeeCalculatorFactory.create(this.feeDao, feeType);
            Double feeAmountOrRate = accountFeesEntity.getFeeAmount();
            Money accountFeeAmount = installmentFeeCalculator.calculate(feeAmountOrRate, loanAmount, loanInterest, accountFeesEntity.getFees());
            accountFeesEntity.setAccountFeeAmount(accountFeeAmount);
            if (!accountFeesEntity.isTimeOfDisbursement()) {
                accountFeesWithNoTimeOfDibursementFees.add(accountFeesEntity);
            }
        }
        feeInstallments = FeeInstallment.createMergedFeeInstallments(meetingScheduledEvent, accountFeesWithNoTimeOfDibursementFees, installmentDates.size());
    }
    int installmentIndex = 0;
    for (InstallmentDate installmentDate1 : installmentDates) {
        InstallmentPrincipalAndInterest em = principalWithInterestInstallments.get(installmentIndex);
        LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity(null, customer, 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())) {
                LoanFeeScheduleEntity loanFeeScheduleEntity = new LoanFeeScheduleEntity(loanScheduleEntity, feeInstallment.getAccountFeesEntity().getFees(), feeInstallment.getAccountFeesEntity(), feeInstallment.getAccountFee());
                loanScheduleEntity.addAccountFeesAction(loanFeeScheduleEntity);
            }
        }
        unroundedLoanSchedules.add(loanScheduleEntity);
        installmentIndex++;
    }
    return unroundedLoanSchedules;
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) RateAmountFlag(org.mifos.accounts.fees.util.helpers.RateAmountFlag) ArrayList(java.util.ArrayList) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) Money(org.mifos.framework.util.helpers.Money) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) LoanFeeScheduleEntity(org.mifos.accounts.loan.business.LoanFeeScheduleEntity) InstallmentPrincipalAndInterest(org.mifos.accounts.loan.util.helpers.InstallmentPrincipalAndInterest) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity)

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