Search in sources :

Example 1 with OriginalScheduleInfoDto

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);
    }
}
Also used : RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with OriginalScheduleInfoDto

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();
}
Also used : Errors(org.mifos.platform.validations.Errors) ActionErrors(org.apache.struts.action.ActionErrors) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) ActionForward(org.apache.struts.action.ActionForward) Date(java.util.Date) Test(org.junit.Test)

Example 3 with OriginalScheduleInfoDto

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);
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 4 with OriginalScheduleInfoDto

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);
}
Also used : Locale(java.util.Locale) LoanAccountActionForm(org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm) ActionErrors(org.apache.struts.action.ActionErrors) Errors(org.mifos.platform.validations.Errors) UserContext(org.mifos.security.util.UserContext) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) Date(java.util.Date) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 5 with OriginalScheduleInfoDto

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());
}
Also used : UserContext(org.mifos.security.util.UserContext) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

OriginalScheduleInfoDto (org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto)9 Date (java.util.Date)7 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)6 ActionErrors (org.apache.struts.action.ActionErrors)4 Test (org.junit.Test)4 LoanBO (org.mifos.accounts.loan.business.LoanBO)4 Errors (org.mifos.platform.validations.Errors)4 ArrayList (java.util.ArrayList)3 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)3 UserContext (org.mifos.security.util.UserContext)3 Locale (java.util.Locale)2 ActionForward (org.apache.struts.action.ActionForward)2 OriginalLoanScheduleEntity (org.mifos.accounts.loan.business.OriginalLoanScheduleEntity)2 LoanAccountActionForm (org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm)2 Money (org.mifos.framework.util.helpers.Money)2 DateTime (org.joda.time.DateTime)1 OriginalScheduleInfoDtoMatcher (org.mifos.accounts.loan.business.matchers.OriginalScheduleInfoDtoMatcher)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 PersistenceException (org.mifos.framework.exceptions.PersistenceException)1