use of org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto in project head by mifos.
the class LoanServiceFacadeWebTier method retrieveOriginalLoanSchedule.
@Override
public OriginalScheduleInfoDto retrieveOriginalLoanSchedule(Integer accountId) {
try {
List<OriginalLoanScheduleEntity> loanScheduleEntities = loanBusinessService.retrieveOriginalLoanSchedule(accountId);
ArrayList<RepaymentScheduleInstallment> repaymentScheduleInstallments = new ArrayList<RepaymentScheduleInstallment>();
for (OriginalLoanScheduleEntity loanScheduleEntity : loanScheduleEntities) {
repaymentScheduleInstallments.add(loanScheduleEntity.toDto());
}
LoanBO loan = this.loanDao.findById(accountId);
return new OriginalScheduleInfoDto(loan.getLoanAmount().toString(), loan.getDisbursementDate(), repaymentScheduleInstallments);
} catch (PersistenceException e) {
throw new MifosRuntimeException(e);
}
}
use of org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto in project head by mifos.
the class LoanAccountActionTest method getLoanRepaymentScheduleShouldValidateViewDate.
@Test
public void getLoanRepaymentScheduleShouldValidateViewDate() throws Exception {
ActionForward getLoanScheduleFailure = new ActionForward("getLoanRepaymentScheduleFailure");
java.sql.Date extraInterestDate = TestUtils.getSqlDate(10, 7, 2010);
Errors errors = new Errors();
errors.addError(LoanConstants.CANNOT_VIEW_REPAYMENT_SCHEDULE, new String[] { extraInterestDate.toString() });
when(loanBusinessService.computeExtraInterest(loanBO, extraInterestDate)).thenReturn(errors);
when(form.getScheduleViewDateValue(Locale.US)).thenReturn(extraInterestDate);
when(request.getParameter("accountId")).thenReturn("1");
when(mapping.findForward("getLoanRepaymentScheduleFailure")).thenReturn(getLoanScheduleFailure);
when(loanServiceFacade.retrieveOriginalLoanSchedule(Matchers.<Integer>any())).thenReturn(new OriginalScheduleInfoDto("100", new Date(), Collections.<RepaymentScheduleInstallment>emptyList()));
ActionForward forward = loanAccountAction.getLoanRepaymentSchedule(mapping, form, request, response);
assertThat(forward, is(getLoanScheduleFailure));
verify(form).resetScheduleViewDate();
}
use of org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto in project head by mifos.
the class OriginalScheduleInfoHelper method sumRepaymentSchedule.
public static OriginalScheduleInfoDto sumRepaymentSchedule(List<OriginalScheduleInfoDto> originalScheduleInfoDtos) {
Money sumAmount = new Money(Money.getDefaultCurrency(), new Double(0.0));
Date disburseDate = null;
List<RepaymentScheduleInstallment> newRepayments = new ArrayList<RepaymentScheduleInstallment>();
RepaymentScheduleInstallment sumRepayment = new RepaymentScheduleInstallment();
for (OriginalScheduleInfoDto dto : originalScheduleInfoDtos) {
sumRepayment = sumRepayment.init();
Money dtoAmount = new Money(Money.getDefaultCurrency(), new Double(dto.getLoanAmount()));
sumAmount = sumAmount.add(dtoAmount);
for (RepaymentScheduleInstallment scheduleInstallment : dto.getOriginalLoanScheduleInstallment()) {
sumRepayment.setFees(sumRepayment.getFees().add(scheduleInstallment.getFees()));
sumRepayment.setMiscFees(sumRepayment.getMiscFees().add(scheduleInstallment.getMiscFees()));
sumRepayment.setMiscPenalty(sumRepayment.getMiscPenalty().add(scheduleInstallment.getMiscPenalty()));
sumRepayment.setPrincipal(sumRepayment.getPrincipal().add(scheduleInstallment.getPrincipal()));
sumRepayment.setInterest(sumRepayment.getInterest().add(scheduleInstallment.getInterest()));
sumRepayment.setTotalAndTotalValue(sumRepayment.getTotalValue().add(scheduleInstallment.getTotalValue()));
sumRepayment.setDueDate(scheduleInstallment.getDueDate());
}
newRepayments.add(sumRepayment);
if (null == disburseDate) {
disburseDate = dto.getDisbursementDate();
}
}
return new OriginalScheduleInfoDto(sumAmount.toString(), disburseDate, newRepayments);
}
use of org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto in project head by mifos.
the class LoanAccountAction method getLoanRepaymentSchedule.
@TransactionDemarcate(saveToken = true)
public ActionForward getLoanRepaymentSchedule(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
LoanAccountActionForm loanAccountActionForm = (LoanAccountActionForm) form;
UserContext userContext = getUserContext(request);
Integer loanId = Integer.valueOf(request.getParameter(ACCOUNT_ID));
Locale locale = userContext.getPreferredLocale();
Date viewDate = loanAccountActionForm.getScheduleViewDateValue(locale);
LoanBO loan = getLoan(loanId);
setSessionAtributeForGLIM(request, loan);
loan.updateDetails(userContext);
Errors errors = loanBusinessService.computeExtraInterest(loan, viewDate);
if (errors.hasErrors()) {
loanAccountActionForm.resetScheduleViewDate();
}
OriginalScheduleInfoDto originalSchedule = this.loanServiceFacade.retrieveOriginalLoanSchedule(loanId);
String memberAccountIdParam = request.getParameter("memberAccountId");
if (StringUtils.isNotBlank(memberAccountIdParam)) {
Integer memberId = Integer.valueOf(memberAccountIdParam);
LoanBO member = loan.findMemberById(memberId);
if (member != null) {
SessionUtils.setAttribute(CustomerConstants.CUSTOMER_NAME, member.getCustomer().getDisplayName(), request);
SessionUtils.setAttribute(CustomerConstants.GLOBAL_CUST_NUM, member.getCustomer().getGlobalCustNum(), request);
}
}
SessionUtils.setAttribute(Constants.BUSINESS_KEY, loan, request);
SessionUtils.setAttribute(Constants.ORIGINAL_SCHEDULE_AVAILABLE, originalSchedule.hasOriginalInstallments(), request);
SessionUtils.setAttribute(Constants.VIEW_DATE, viewDate, request);
String forward = errors.hasErrors() ? ActionForwards.getLoanRepaymentScheduleFailure.toString() : ActionForwards.getLoanRepaymentSchedule.toString();
addErrors(request, getActionErrors(errors));
return mapping.findForward(forward);
}
use of org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto in project head by mifos.
the class LoanAccountAction method viewOriginalSchedule.
@TransactionDemarcate(joinToken = true)
public ActionForward viewOriginalSchedule(final ActionMapping mapping, @SuppressWarnings("unused") final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
UserContext userContext = getUserContext(request);
Integer loanId = Integer.valueOf(request.getParameter(ACCOUNT_ID));
LoanBO loan = (LoanBO) SessionUtils.getAttribute(BUSINESS_KEY, request);
boolean originalSchedule = (request.getParameter("individual") == null ? true : false);
OriginalScheduleInfoDto dto = loanServiceFacade.retrieveOriginalLoanSchedule(loanId);
SessionUtils.setAttribute("originalSchedule", originalSchedule, request);
SessionUtils.setAttribute(CustomerConstants.DISBURSEMENT_DATE, dto.getDisbursementDate(), request);
SessionUtils.setAttribute(CustomerConstants.LOAN_AMOUNT, dto.getLoanAmount(), request);
SessionUtils.setCollectionAttribute(LoanConstants.ORIGINAL_INSTALLMENTS, dto.getOriginalLoanScheduleInstallment(), request);
return mapping.findForward(ActionForwards.viewOriginalSchedule.name());
}
Aggregations