use of org.mifos.clientportfolio.newloan.domain.InstallmentFeeCalculatorFactory 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;
}
Aggregations