Search in sources :

Example 36 with CustomerBO

use of org.mifos.customers.business.CustomerBO in project head by mifos.

the class EditCustomerStatusAction method updateStatus.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward updateStatus(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    EditCustomerStatusActionForm editStatusActionForm = (EditCustomerStatusActionForm) form;
    CustomerBO customerBOInSession = (CustomerBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    if (customerBOInSession.isBlackListed() && customerBOInSession.getStatus().getValue() == CustomerConstants.CLIENT_CLOSED) {
        try {
            this.clientServiceFacade.removeFromBlacklist(customerBOInSession.getCustomerId());
            customerBOInSession.setVersionNo(customerBOInSession.getVersionNo() + 1);
        } catch (AccessDeniedException e) {
            throw new CustomerException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED);
        }
    }
    try {
        this.centerServiceFacade.updateCustomerStatus(customerBOInSession.getCustomerId(), customerBOInSession.getVersionNo(), editStatusActionForm.getFlagId(), editStatusActionForm.getNewStatusId(), editStatusActionForm.getNotes());
        createClientQuestionnaire.saveResponses(request, editStatusActionForm, customerBOInSession.getCustomerId());
    } catch (BusinessRuleException e) {
        throw new ApplicationException(e.getMessageKey(), e);
    }
    return mapping.findForward(getDetailAccountPage(form));
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) CustomerException(org.mifos.customers.exceptions.CustomerException) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) EditCustomerStatusActionForm(org.mifos.customers.struts.actionforms.EditCustomerStatusActionForm) CustomerBO(org.mifos.customers.business.CustomerBO) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 37 with CustomerBO

use of org.mifos.customers.business.CustomerBO in project head by mifos.

the class EditCustomerStatusAction method previewStatus.

@TransactionDemarcate(joinToken = true)
public ActionForward previewStatus(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    logger.debug("In EditCustomerStatusAction:preview()");
    CustomerBO customerBO = (CustomerBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    EditCustomerStatusActionForm statusActionForm = (EditCustomerStatusActionForm) form;
    statusActionForm.setCommentDate(DateUtils.getCurrentDate(getUserContext(request).getPreferredLocale()));
    if (StringUtils.isNotBlank(statusActionForm.getNewStatusId())) {
        CustomerStatusDetailDto customerStatusDetail = this.centerServiceFacade.retrieveCustomerStatusDetails(statusActionForm.getNewStatusIdValue(), statusActionForm.getFlagIdValue(), customerBO.getLevel().getValue());
        SessionUtils.setAttribute(SavingsConstants.NEW_STATUS_NAME, customerStatusDetail.getStatusName(), request);
        SessionUtils.setAttribute(SavingsConstants.FLAG_NAME, customerStatusDetail.getFlagName(), request);
    } else {
        SessionUtils.setAttribute(SavingsConstants.NEW_STATUS_NAME, null, request);
        SessionUtils.setAttribute(SavingsConstants.FLAG_NAME, null, request);
    }
    Short newStatusId = statusActionForm.getNewStatusIdValue();
    Short customerLevelId = statusActionForm.getLevelIdValue();
    List<CustomerCheckListBO> checklist = new CustomerPersistence().getStatusChecklist(newStatusId, customerLevelId);
    SessionUtils.setCollectionAttribute(SavingsConstants.STATUS_CHECK_LIST, checklist, request);
    if (statusActionForm.getNewStatusIdValue().equals(CustomerStatus.CLIENT_CLOSED.getValue())) {
        return createClientQuestionnaire.fetchAppliedQuestions(mapping, statusActionForm, request, ActionForwards.previewStatus_success);
    }
    return mapping.findForward(ActionForwards.previewStatus_success.toString());
}
Also used : CustomerCheckListBO(org.mifos.customers.checklist.business.CustomerCheckListBO) CustomerStatusDetailDto(org.mifos.dto.screen.CustomerStatusDetailDto) EditCustomerStatusActionForm(org.mifos.customers.struts.actionforms.EditCustomerStatusActionForm) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 38 with CustomerBO

use of org.mifos.customers.business.CustomerBO in project head by mifos.

the class LoanBOTest method repayInstallmentsShouldPopulateCalculatedInterestsForDIPBLoans.

@Test
public void repayInstallmentsShouldPopulateCalculatedInterestsForDIPBLoans() throws PersistenceException {
    final LegacyLoanDao legacyLoanDao = mock(LegacyLoanDao.class);
    final CustomerBO customerBO = mock(CustomerBO.class);
    final LoanSummaryEntity loanSummaryEntity = mock(LoanSummaryEntity.class);
    LoanBO loanBO = new LoanBO() {

        @Override
        public boolean isDecliningBalanceInterestRecalculation() {
            return true;
        }

        @Override
        public LegacyLoanDao getlegacyLoanDao() {
            return legacyLoanDao;
        }

        @Override
        public CustomerBO getCustomer() {
            return customerBO;
        }

        @Override
        public LoanSummaryEntity getLoanSummary() {
            return loanSummaryEntity;
        }
    };
    AccountActionTypes accountActionTypes = AccountActionTypes.LOAN_REPAYMENT;
    AccountActionEntity accountActionEntity = mock(AccountActionEntity.class);
    AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntityBuilder().with(loanBO).build();
    PersonnelBO user = new PersonnelBO();
    Money extraInterestDue = new Money(rupee, "0.98");
    Money interest = new Money(rupee, "10");
    Money interestDue = new Money(rupee, "2.07");
    when(legacyLoanDao.getPersistentObject(AccountActionEntity.class, accountActionTypes.getValue())).thenReturn(accountActionEntity);
    when(loanScheduleEntity.getPrincipalDue()).thenReturn(new Money(rupee, "1000"));
    when(loanScheduleEntity.getTotalFeeDueWithMiscFeeDue()).thenReturn(new Money(rupee, "10"));
    when(loanScheduleEntity.getPenaltyDue()).thenReturn(new Money(rupee, "10"));
    when(loanScheduleEntity.getPenalty()).thenReturn(new Money(rupee, "100"));
    when(loanScheduleEntity.getExtraInterestDue()).thenReturn(extraInterestDue);
    when(loanScheduleEntity.getExtraInterestPaid()).thenReturn(extraInterestDue);
    when(loanScheduleEntity.getInterest()).thenReturn(interest);
    when(loanScheduleEntity.getInterestDue()).thenReturn(interestDue);
    loanBO.repayInstallment(loanScheduleEntity, accountPaymentEntity, accountActionTypes, user, "", interestDue);
    Set<AccountTrxnEntity> accountTrxns = accountPaymentEntity.getAccountTrxns();
    AccountTrxnEntity accountTrxnEntity = accountTrxns.toArray(new AccountTrxnEntity[accountTrxns.size()])[0];
    LoanTrxnDetailEntity loanTrxnDetailEntity = (LoanTrxnDetailEntity) accountTrxnEntity;
    assertThat(loanTrxnDetailEntity.getInterestAmount().getAmount().doubleValue(), is(3.05));
    CalculatedInterestOnPayment calculatedInterestOnPayment = loanTrxnDetailEntity.getCalculatedInterestOnPayment();
    assertNotNull(calculatedInterestOnPayment);
    assertThat(calculatedInterestOnPayment.getExtraInterestPaid(), is(extraInterestDue));
    assertThat(calculatedInterestOnPayment.getInterestDueTillPaid(), is(interestDue));
    assertThat(calculatedInterestOnPayment.getOriginalInterest(), is(interest));
    Mockito.verify(loanScheduleEntity).makeEarlyRepaymentEntries(LoanConstants.PAY_FEES_PENALTY_INTEREST, interestDue, accountPaymentEntity.getPaymentDate());
}
Also used : AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) AccountActionTypes(org.mifos.accounts.util.helpers.AccountActionTypes) Money(org.mifos.framework.util.helpers.Money) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CustomerBO(org.mifos.customers.business.CustomerBO) LegacyLoanDao(org.mifos.accounts.loan.persistance.LegacyLoanDao) Test(org.junit.Test)

Example 39 with CustomerBO

use of org.mifos.customers.business.CustomerBO in project head by mifos.

the class SavingsCloseTest method whenClosingAccountShouldWithdrawRemainingBalanceOnAccount.

@Test
public void whenClosingAccountShouldWithdrawRemainingBalanceOnAccount() {
    Money remainingBalance = TestUtils.createMoney("100");
    savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(remainingBalance).build();
    AccountPaymentEntity payment = new AccountPaymentEntityBuilder().with(savingsAccount).with(remainingBalance).build();
    AccountNotesEntity notes = new AccountNotesEntityBuilder().build();
    CustomerBO customer = new ClientBuilder().buildForUnitTests();
    PersonnelBO loggedInUser = new PersonnelBuilder().build();
    // pre verification
    assertTrue(savingsAccount.getAccountPayments().isEmpty());
    // exercise test
    savingsAccount.closeAccount(payment, notes, customer, loggedInUser);
    // verification
    assertFalse(savingsAccount.getAccountPayments().isEmpty());
    AccountPaymentEntity withdrawalPayment = savingsAccount.getAccountPayments().get(0);
    assertThat(withdrawalPayment.getAmount(), is(TestUtils.createMoney("100")));
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) Money(org.mifos.framework.util.helpers.Money) AccountNotesEntityBuilder(org.mifos.accounts.business.AccountNotesEntityBuilder) AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) CustomerBO(org.mifos.customers.business.CustomerBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 40 with CustomerBO

use of org.mifos.customers.business.CustomerBO in project head by mifos.

the class SavingsCloseTest method whenClosingAccountShouldSetClosedDate.

@Test
public void whenClosingAccountShouldSetClosedDate() {
    Money remainingBalance = TestUtils.createMoney("100");
    savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(remainingBalance).build();
    AccountPaymentEntity payment = new AccountPaymentEntityBuilder().with(savingsAccount).with(remainingBalance).build();
    AccountNotesEntity notes = new AccountNotesEntityBuilder().build();
    CustomerBO customer = new ClientBuilder().buildForUnitTests();
    PersonnelBO loggedInUser = new PersonnelBuilder().build();
    // exercise test
    savingsAccount.closeAccount(payment, notes, customer, loggedInUser);
    // verification
    assertThat(new LocalDate(savingsAccount.getClosedDate()), is(new LocalDate()));
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) Money(org.mifos.framework.util.helpers.Money) AccountNotesEntityBuilder(org.mifos.accounts.business.AccountNotesEntityBuilder) AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) CustomerBO(org.mifos.customers.business.CustomerBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) LocalDate(org.joda.time.LocalDate) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Aggregations

CustomerBO (org.mifos.customers.business.CustomerBO)138 ArrayList (java.util.ArrayList)39 Money (org.mifos.framework.util.helpers.Money)38 MifosUser (org.mifos.security.MifosUser)38 UserContext (org.mifos.security.util.UserContext)37 LocalDate (org.joda.time.LocalDate)35 MifosRuntimeException (org.mifos.core.MifosRuntimeException)31 AccountException (org.mifos.accounts.exceptions.AccountException)30 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)27 BusinessRuleException (org.mifos.service.BusinessRuleException)27 MeetingBO (org.mifos.application.meeting.business.MeetingBO)23 ClientBO (org.mifos.customers.client.business.ClientBO)23 PersistenceException (org.mifos.framework.exceptions.PersistenceException)22 DateTime (org.joda.time.DateTime)20 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)20 Date (java.util.Date)19 Test (org.junit.Test)19 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)18 LoanBO (org.mifos.accounts.loan.business.LoanBO)17 HashMap (java.util.HashMap)15