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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations