use of org.mifos.accounts.loan.business.RepaymentResultsHolder in project head by mifos.
the class Schedule method computePayableAmountForFutureInstallments.
public RepaymentResultsHolder computePayableAmountForFutureInstallments(Date asOfDate) {
List<Installment> futureInstallments = getInstallmentsOnOrAfter(asOfDate);
RepaymentResultsHolder repaymentResultsHolder = new RepaymentResultsHolder();
BigDecimal payableAmount = BigDecimal.ZERO;
repaymentResultsHolder.setWaiverAmount(BigDecimal.ZERO);
if (!futureInstallments.isEmpty()) {
BigDecimal outstandingPrincipal = getOutstandingPrincipal(asOfDate);
Installment firstFutureInstallment = futureInstallments.get(0);
BigDecimal interestDue = computeAndAdjustInterest(firstFutureInstallment, getDurationForAdjustment(firstFutureInstallment, asOfDate), outstandingPrincipal);
repaymentResultsHolder.setWaiverAmount(interestDue);
payableAmount = payableAmount.add(interestDue).add(firstFutureInstallment.getExtraInterestDue()).add(firstFutureInstallment.getFeesDue()).add(firstFutureInstallment.getMiscFeesDue()).add(firstFutureInstallment.getPenaltyDue()).add(firstFutureInstallment.getMiscPenaltyDue());
for (Installment futureInstallment : futureInstallments) {
payableAmount = payableAmount.add(futureInstallment.getPrincipalDue());
}
}
repaymentResultsHolder.setTotalRepaymentAmount(payableAmount);
return repaymentResultsHolder;
}
use of org.mifos.accounts.loan.business.RepaymentResultsHolder in project head by mifos.
the class LoanAccountServiceFacadeWebTier method retrieveLoanRepaymentDetails.
@Override
public RepayLoanDto retrieveLoanRepaymentDetails(String globalAccountNumber) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
LoanBO loan = this.loanDao.findByGlobalAccountNum(globalAccountNumber);
try {
personnelDao.checkAccessPermission(userContext, loan.getOfficeId(), loan.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
Money repaymentAmount;
Money waiverAmount;
if (loan.isDecliningBalanceInterestRecalculation()) {
RepaymentResultsHolder repaymentResultsHolder = scheduleCalculatorAdaptor.computeRepaymentAmount(loan, DateUtils.getCurrentDateWithoutTimeStamp());
repaymentAmount = new Money(loan.getCurrency(), repaymentResultsHolder.getTotalRepaymentAmount());
waiverAmount = new Money(loan.getCurrency(), repaymentResultsHolder.getWaiverAmount());
} else {
repaymentAmount = loan.getEarlyRepayAmount();
waiverAmount = loan.waiverAmount();
}
Money waivedRepaymentAmount = repaymentAmount.subtract(waiverAmount);
List<SavingsDetailDto> savingsInUse = clientServiceFacade.retrieveSavingsInUseForClient(loan.getCustomer().getCustomerId());
List<SavingsDetailDto> accountsForTransfer = new ArrayList<SavingsDetailDto>();
if (savingsInUse != null) {
for (SavingsDetailDto savingsAccount : savingsInUse) {
if (savingsAccount.getAccountStateId().equals(AccountState.SAVINGS_ACTIVE.getValue())) {
accountsForTransfer.add(savingsAccount);
}
}
}
return new RepayLoanDto(repaymentAmount.toString(), waivedRepaymentAmount.toString(), loan.isInterestWaived(), accountsForTransfer);
}
use of org.mifos.accounts.loan.business.RepaymentResultsHolder in project head by mifos.
the class LoanAccountServiceFacadeWebTierTest method shouldReturnRepayLoanDtoWithAllDataPopulatedForDecliningBalanceInterestRecalculation.
@Test
public void shouldReturnRepayLoanDtoWithAllDataPopulatedForDecliningBalanceInterestRecalculation() {
setMifosUserFromContext();
String accountNumber = "1234";
LoanBO loanBO = mock(LoanBO.class);
Money repaymentAmount = TestUtils.createMoney("1234");
Money interest = TestUtils.createMoney("100");
DateTime currentDate = new DateTime(2010, 10, 30, 0, 0, 0, 0);
new DateTimeService().setCurrentDateTime(currentDate);
RepaymentResultsHolder repaymentResultsHolder = new RepaymentResultsHolder();
repaymentResultsHolder.setTotalRepaymentAmount(repaymentAmount.getAmount());
repaymentResultsHolder.setWaiverAmount(interest.getAmount());
when(loanDao.findByGlobalAccountNum(accountNumber)).thenReturn(loanBO);
when(scheduleCalculatorAdaptor.computeRepaymentAmount(loanBO, currentDate.toDate())).thenReturn(repaymentResultsHolder);
when(loanBO.getCurrency()).thenReturn(repaymentAmount.getCurrency());
when(loanBO.isDecliningBalanceInterestRecalculation()).thenReturn(true);
when(loanBO.getOfficeId()).thenReturn((short) 1);
when(loanBO.getCustomer()).thenReturn(customer);
when(customer.getLoanOfficerId()).thenReturn((short) 1);
RepayLoanDto repayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(accountNumber);
verify(loanDao).findByGlobalAccountNum(accountNumber);
verify(scheduleCalculatorAdaptor).computeRepaymentAmount(loanBO, currentDate.toDate());
verify(loanBO, never()).waiverAmount();
verify(loanBO, never()).getEarlyRepayAmount();
verify(loanBO).isDecliningBalanceInterestRecalculation();
assertEquals(repayLoanDto.getEarlyRepaymentMoney(), repaymentAmount.toString());
assertEquals(repayLoanDto.getWaivedRepaymentMoney(), repaymentAmount.subtract(interest).toString());
}
Aggregations