Search in sources :

Example 1 with LoanAccountActionForm

use of org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm in project head by mifos.

the class LoanBusinessServiceTest method shouldComputeVariableInstallmentScheduleForVariableInstallmentsIfVariableInstallmentsIsEnabledAndInstallmentsArePassed.

@Test
public void shouldComputeVariableInstallmentScheduleForVariableInstallmentsIfVariableInstallmentsIsEnabledAndInstallmentsArePassed() {
    RepaymentScheduleInstallment installment1 = getRepaymentScheduleInstallment("01-Sep-2010", 1, "94.4", "4.6", "1", "75", "0", "0");
    RepaymentScheduleInstallment installment2 = getRepaymentScheduleInstallment("08-Sep-2010", 2, "94.8", "4.2", "1", "100", "0", "0");
    RepaymentScheduleInstallment installment3 = getRepaymentScheduleInstallment("15-Sep-2010", 3, "95.3", "3.7", "1", "100", "0", "0");
    LoanAccountActionForm loanAccountActionForm = mock(LoanAccountActionForm.class);
    List<RepaymentScheduleInstallment> installments = asList(installment1, installment2, installment3);
    when(loanAccountActionForm.getLoanAmount()).thenReturn("1000");
    when(loanAccountActionForm.getLoanAmountValue()).thenReturn(new Money(rupee, "1000"));
    when(loanAccountActionForm.getInterestRate()).thenReturn("24");
    when(loanAccountActionForm.isVariableInstallmentsAllowed()).thenReturn(true);
    loanBusinessService.applyDailyInterestRatesWhereApplicable(new LoanScheduleGenerationDto(TestUtils.getDate(22, 8, 2010), loanBO, loanAccountActionForm.isVariableInstallmentsAllowed(), loanAccountActionForm.getLoanAmountValue(), loanAccountActionForm.getInterestDoubleValue()), installments);
    verify(loanBO).updateInstallmentSchedule(installments);
}
Also used : LoanAccountActionForm(org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm) Money(org.mifos.framework.util.helpers.Money) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) Test(org.junit.Test)

Example 2 with LoanAccountActionForm

use of org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm in project head by mifos.

the class LoanAccountActionIndividualLoansIntegrationTest method testShouldCallDeleteMethodIfExistingMembersRemoved.

@Test
public void testShouldCallDeleteMethodIfExistingMembersRemoved() throws Exception {
    GlimLoanUpdater glimLoanUpdaterMock = createMock(GlimLoanUpdater.class);
    LoanAccountAction loanAccountAction = new LoanAccountAction(ApplicationContextProvider.getBean(LoanBusinessService.class), new ConfigurationBusinessService(), glimLoanUpdaterMock);
    LoanBO loanMock = createMock(LoanBO.class);
    Locale locale = Locale.ENGLISH;
    expect(loanMock.getAccountId()).andReturn(2).anyTimes();
    ClientBO customerMock = createMock(ClientBO.class);
    expect(loanMock.getCustomer()).andReturn(customerMock).anyTimes();
    expect(customerMock.getGlobalCustNum()).andReturn("3").anyTimes();
    LoanAccountActionForm loanAccountActionForm = new LoanAccountActionForm();
    List<LoanAccountDetailsDto> clientDetails = new ArrayList<LoanAccountDetailsDto>();
    List<LoanBO> loans = new ArrayList<LoanBO>();
    loans.add(loanMock);
    glimLoanUpdaterMock.delete(loanMock);
    expectLastCall().atLeastOnce();
    replay(glimLoanUpdaterMock, loanMock, customerMock);
    loanAccountAction.handleIndividualLoans(loanMock, loanAccountActionForm, true, clientDetails, loans, locale);
    verify(glimLoanUpdaterMock, loanMock, customerMock);
}
Also used : Locale(java.util.Locale) LoanAccountActionForm(org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm) LoanBusinessService(org.mifos.accounts.loan.business.service.LoanBusinessService) LoanBO(org.mifos.accounts.loan.business.LoanBO) ClientBO(org.mifos.customers.client.business.ClientBO) ConfigurationBusinessService(org.mifos.config.business.service.ConfigurationBusinessService) ArrayList(java.util.ArrayList) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) Test(org.junit.Test)

Example 3 with LoanAccountActionForm

use of org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm in project head by mifos.

the class LoanAccountActionIndividualLoansIntegrationTest method testShouldCallUpdateMethodIfExistingMembersChanged.

@Test
public void testShouldCallUpdateMethodIfExistingMembersChanged() throws Exception {
    GlimLoanUpdater glimLoanUpdaterMock = createMock(GlimLoanUpdater.class);
    LoanAccountAction loanAccountAction = new LoanAccountAction(ApplicationContextProvider.getBean(LoanBusinessService.class), new ConfigurationBusinessService(), glimLoanUpdaterMock);
    LoanBO loanMock = createMock(LoanBO.class);
    Locale locale = Locale.ENGLISH;
    expect(loanMock.getAccountId()).andReturn(2).anyTimes();
    ClientBO customerMock = createMock(ClientBO.class);
    expect(loanMock.getCustomer()).andReturn(customerMock).anyTimes();
    expect(customerMock.getCustomerId()).andReturn(3).anyTimes();
    LoanAccountActionForm loanAccountActionForm = new LoanAccountActionForm();
    List<LoanAccountDetailsDto> clientDetails = new ArrayList<LoanAccountDetailsDto>();
    LoanAccountDetailsDto LOAN_ACCOUNT_DETAILS_WITH_LOAN_AMOUNT_300 = LoanAccountDetailsDto.createInstanceForTest("3", "2", "300.0", "2");
    clientDetails.add(LOAN_ACCOUNT_DETAILS_WITH_LOAN_AMOUNT_300);
    List<LoanBO> loans = new ArrayList<LoanBO>();
    loans.add(loanMock);
    glimLoanUpdaterMock.updateIndividualLoan(null, null, null, LOAN_ACCOUNT_DETAILS_WITH_LOAN_AMOUNT_300, loanMock);
    expectLastCall().atLeastOnce();
    replay(glimLoanUpdaterMock, loanMock, customerMock);
    loanAccountAction.handleIndividualLoans(loanMock, loanAccountActionForm, true, clientDetails, loans, locale);
    verify(glimLoanUpdaterMock, loanMock, customerMock);
}
Also used : Locale(java.util.Locale) LoanAccountActionForm(org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm) LoanBusinessService(org.mifos.accounts.loan.business.service.LoanBusinessService) LoanBO(org.mifos.accounts.loan.business.LoanBO) ClientBO(org.mifos.customers.client.business.ClientBO) ConfigurationBusinessService(org.mifos.config.business.service.ConfigurationBusinessService) ArrayList(java.util.ArrayList) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) Test(org.junit.Test)

Example 4 with LoanAccountActionForm

use of org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm 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 LoanAccountActionForm

use of org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm in project head by mifos.

the class LoanAccountAction method manage.

@TransactionDemarcate(joinToken = true)
public ActionForward manage(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    LoanAccountActionForm loanActionForm = (LoanAccountActionForm) form;
    String globalAccountNum = request.getParameter(GLOBAL_ACCOUNT_NUM);
    CustomerBO customer = getCustomerFromRequest(request);
    if (isGlimEnabled() || isNewGlimEnabled()) {
        populateGlimAttributes(request, loanActionForm, globalAccountNum, customer);
    }
    String recurMonth = customer.getCustomerMeeting().getMeeting().getMeetingDetails().getRecurAfter().toString();
    handleRepaymentsIndependentOfMeetingIfConfigured(request, loanActionForm, recurMonth);
    LoanBO loanBO = new LoanDaoHibernate(new GenericDaoHibernate()).findByGlobalAccountNum(globalAccountNum);
    UserContext userContext = getUserContext(request);
    loanBO.setUserContext(userContext);
    SessionUtils.setAttribute(PROPOSED_DISBURSAL_DATE, loanBO.getDisbursementDate(), request);
    SessionUtils.removeAttribute(LOANOFFERING, request);
    LoanOfferingBO loanOffering = getLoanOffering(loanBO.getLoanOffering().getPrdOfferingId(), userContext.getLocaleId());
    loanActionForm.setInstallmentRange(loanBO.getMaxMinNoOfInstall());
    loanActionForm.setLoanAmountRange(loanBO.getMaxMinLoanAmount());
    MaxMinInterestRate interestRateRange = loanBO.getMaxMinInterestRate();
    loanActionForm.setMaxInterestRate(interestRateRange.getMaxLoanAmount());
    loanActionForm.setMinInterestRate(interestRateRange.getMinLoanAmount());
    loanActionForm.setExternalId(loanBO.getExternalId());
    if (null != loanBO.getFund()) {
        loanActionForm.setLoanOfferingFund(loanBO.getFund().getFundId().toString());
    }
    if (configService.isRepaymentIndepOfMeetingEnabled()) {
        MeetingDetailsEntity meetingDetail = loanBO.getLoanMeeting().getMeetingDetails();
        loanActionForm.setMonthDay("");
        loanActionForm.setMonthWeek("0");
        loanActionForm.setMonthRank("0");
        if (meetingDetail.getRecurrenceTypeEnum() == RecurrenceType.MONTHLY) {
            setMonthlySchedule(loanActionForm, meetingDetail);
        } else {
            setWeeklySchedule(loanActionForm, meetingDetail);
        }
    }
    setSessionAtributeForGLIM(request, loanBO);
    SessionUtils.setAttribute(LOANOFFERING, loanOffering, request);
    // Retrieve and set into the session all collateral types from the
    // lookup_value_locale table associated with the current user context
    // locale
    SessionUtils.setCollectionAttribute(MasterConstants.COLLATERAL_TYPES, legacyMasterDao.getLookUpEntity(MasterConstants.COLLATERAL_TYPES).getCustomValueListElements(), request);
    SessionUtils.setCollectionAttribute(MasterConstants.BUSINESS_ACTIVITIES, legacyMasterDao.findValueListElements(MasterConstants.LOAN_PURPOSES), request);
    SessionUtils.setCollectionAttribute(CUSTOM_FIELDS, new ArrayList<CustomFieldDefinitionEntity>(), request);
    SessionUtils.setAttribute(RECURRENCEID, loanBO.getLoanMeeting().getMeetingDetails().getRecurrenceTypeEnum().getValue(), request);
    SessionUtils.setAttribute(RECURRENCENAME, loanBO.getLoanMeeting().getMeetingDetails().getRecurrenceType().getRecurrenceName(), request);
    SessionUtils.setCollectionAttribute(LOANFUNDS, getFunds(loanOffering), request);
    setRequestAttributesForEditPage(request, loanBO);
    InformationOrderServiceFacade informationOrderServiceFacade = ApplicationContextProvider.getBean(InformationOrderServiceFacade.class);
    SessionUtils.setCollectionAttribute("detailsInformationOrder", informationOrderServiceFacade.getInformationOrder("CreateLoan"), request);
    setFormAttributes(loanBO, form, request);
    return mapping.findForward(ActionForwards.manage_success.toString());
}
Also used : GenericDaoHibernate(org.mifos.accounts.savings.persistence.GenericDaoHibernate) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MaxMinInterestRate(org.mifos.accounts.loan.business.MaxMinInterestRate) CustomFieldDefinitionEntity(org.mifos.application.master.business.CustomFieldDefinitionEntity) LoanAccountActionForm(org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm) InformationOrderServiceFacade(org.mifos.platform.questionnaire.service.InformationOrderServiceFacade) LoanDaoHibernate(org.mifos.accounts.loan.persistance.LoanDaoHibernate) MeetingDetailsEntity(org.mifos.application.meeting.business.MeetingDetailsEntity) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) CustomerBO(org.mifos.customers.business.CustomerBO) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

LoanAccountActionForm (org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm)17 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)10 LoanBO (org.mifos.accounts.loan.business.LoanBO)9 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)6 LoanAccountDetailsDto (org.mifos.dto.domain.LoanAccountDetailsDto)6 UserContext (org.mifos.security.util.UserContext)6 Locale (java.util.Locale)4 CustomFieldDefinitionEntity (org.mifos.application.master.business.CustomFieldDefinitionEntity)4 Money (org.mifos.framework.util.helpers.Money)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 ActionErrors (org.apache.struts.action.ActionErrors)3 MessageLookup (org.mifos.application.master.MessageLookup)3 MifosRuntimeException (org.mifos.core.MifosRuntimeException)3 LoanActivityDto (org.mifos.dto.domain.LoanActivityDto)3 ValueListElement (org.mifos.dto.domain.ValueListElement)3 LoanInformationDto (org.mifos.dto.screen.LoanInformationDto)3 ApplicationException (org.mifos.framework.exceptions.ApplicationException)3