Search in sources :

Example 31 with CustomerAccountBO

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

the class CustomerAccountAction method load.

@TransactionDemarcate(saveToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    String globalCustNum = ((CustomerAccountActionForm) form).getGlobalCustNum();
    if (StringUtils.isBlank(globalCustNum)) {
        // NOTE: see CustomerAction.getAllActivity for explanation of this craziness
        globalCustNum = (String) SessionUtils.getAttribute("customerGlobalNum", request.getSession());
    }
    CustomerBO customerBO = this.customerDao.findCustomerBySystemId(globalCustNum);
    CustomerAccountBO customerAccount = customerBO.getCustomerAccount();
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, customerAccount, request);
    List<CustomerRecentActivityDto> recentActivities = this.centerServiceFacade.retrieveRecentActivities(customerBO.getCustomerId(), 3);
    SessionUtils.setCollectionAttribute(CustomerConstants.RECENT_ACTIVITIES, recentActivities, request);
    ActionForwards forward = getForward(customerBO);
    return mapping.findForward(forward.toString());
}
Also used : CustomerAccountActionForm(org.mifos.customers.struts.actionforms.CustomerAccountActionForm) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) ActionForwards(org.mifos.application.util.helpers.ActionForwards) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerRecentActivityDto(org.mifos.dto.screen.CustomerRecentActivityDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 32 with CustomerAccountBO

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

the class CloseLoanActionStrutsTest method testRescheduleLoan.

@Test
public void testRescheduleLoan() throws Exception {
    loanBO = getLoanAccount();
    loanBO.approve(legacyPersonnelDao.getPersonnel(PersonnelConstants.TEST_USER), "approved", currentDate.toLocalDate());
    addRequestParameter("recordLoanOfficerId", "1");
    addRequestParameter("accountId", loanBO.getAccountId().toString());
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, loanBO, request);
    request.getSession().setAttribute(Constants.USER_CONTEXT_KEY, userContext);
    addRequestParameter("notes", "reschedule");
    addRequestParameter("newStatusId", "8");
    addRequestParameter("input", "loan");
    addRequestParameter("method", "update");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    actionPerform();
    verifyForward(ActionForwards.loan_detail_page.toString());
    CustomerAccountBO closedAccount = group.getCustomerAccount();
    Assert.assertEquals(AccountState.CUSTOMER_ACCOUNT_ACTIVE, closedAccount.getState());
    Session session = StaticHibernateUtil.getSessionTL();
    //        session.beginTransaction();
    loanBO = (LoanBO) session.get(LoanBO.class, loanBO.getAccountId());
    List<TransactionHistoryDto> history = loanBO.getTransactionHistoryView();
    for (TransactionHistoryDto entry : history) {
        Assert.assertEquals(AccountConstants.LOAN_RESCHEDULED, entry.getType());
    }
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) TransactionHistoryDto(org.mifos.dto.screen.TransactionHistoryDto) Session(org.hibernate.Session) Test(org.junit.Test)

Example 33 with CustomerAccountBO

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

the class CustomerApplyAdjustmentActionStrutsTest method applyPayment.

private void applyPayment() throws Exception {
    createInitialObjects();
    accountBO = client.getCustomerAccount();
    Date currentDate = new Date(System.currentTimeMillis());
    CustomerAccountBO customerAccountBO = (CustomerAccountBO) accountBO;
    customerAccountBO.setUserContext(userContext);
    CustomerScheduleEntity accountAction = (CustomerScheduleEntity) customerAccountBO.getAccountActionDate(Short.valueOf("1"));
    CustomerAccountBOTestUtils.setMiscFeePaid(accountAction, TestUtils.createMoney(100));
    CustomerAccountBOTestUtils.setMiscPenaltyPaid(accountAction, TestUtils.createMoney(100));
    CustomerAccountBOTestUtils.setPaymentDate(accountAction, currentDate);
    accountAction.setPaymentStatus(PaymentStatus.PAID);
    AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(accountBO, TestUtils.createMoney(100), "1111", currentDate, new PaymentTypeEntity(Short.valueOf("1")), new Date(System.currentTimeMillis()));
    CustomerTrxnDetailEntity accountTrxnEntity = new CustomerTrxnDetailEntity(accountPaymentEntity, AccountActionTypes.PAYMENT, Short.valueOf("1"), accountAction.getActionDate(), TestObjectFactory.getPersonnel(userContext.getId()), currentDate, TestUtils.createMoney(200), "payment done", null, TestUtils.createMoney(100), TestUtils.createMoney(100));
    for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : accountAction.getAccountFeesActionDetails()) {
        CustomerAccountBOTestUtils.setFeeAmountPaid((CustomerFeeScheduleEntity) accountFeesActionDetailEntity, TestUtils.createMoney(100));
        FeesTrxnDetailEntity feeTrxn = new FeesTrxnDetailEntity(accountTrxnEntity, accountFeesActionDetailEntity.getAccountFee(), accountFeesActionDetailEntity.getFeeAmount());
        CustomerBOTestUtils.addFeesTrxnDetail(accountTrxnEntity, feeTrxn);
    // totalFees = accountFeesActionDetailEntity.getFeeAmountPaid();
    }
    accountPaymentEntity.addAccountTrxn(accountTrxnEntity);
    AccountTestUtils.addAccountPayment(accountPaymentEntity, customerAccountBO);
    TestObjectFactory.updateObject(customerAccountBO);
    StaticHibernateUtil.flushSession();
    customerAccountBO = TestObjectFactory.getObject(CustomerAccountBO.class, customerAccountBO.getAccountId());
    client = customerAccountBO.getCustomer();
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, client, request);
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) CustomerTrxnDetailEntity(org.mifos.customers.business.CustomerTrxnDetailEntity) CustomerScheduleEntity(org.mifos.customers.business.CustomerScheduleEntity) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.sql.Date) FeesTrxnDetailEntity(org.mifos.accounts.business.FeesTrxnDetailEntity)

Example 34 with CustomerAccountBO

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

the class CustomerAccountCreationTest method firstCustomerScheduleIsAlwaysTheClosestMatchingDayOfWeekAndDoesNotTakeIntoAccountMonthlyMeetingFrequency.

@Test
public void firstCustomerScheduleIsAlwaysTheClosestMatchingDayOfWeekAndDoesNotTakeIntoAccountMonthlyMeetingFrequency() throws Exception {
    // setup
    applicableCalendarEvents = new CalendarEventBuilder().build();
    DateTime tue19thOfApril = new DateTime().withDate(2011, 4, 19);
    accountFees = new ArrayList<AccountFeesEntity>();
    MeetingBO centerMeeting = new MeetingBuilder().customerMeeting().monthly().every(2).occuringOnA(WeekDay.MONDAY).startingFrom(tue19thOfApril.minusDays(1).toDate()).onDayOfMonth(18).build();
    CenterBO center = new CenterBuilder().active().withActivationDate(tue19thOfApril).with(centerMeeting).build();
    // exercise test
    CustomerAccountBO centerAccount = CustomerAccountBO.createNew(center, accountFees, centerMeeting, applicableCalendarEvents);
    // verification
    List<AccountActionDateEntity> centerSchedules = new ArrayList<AccountActionDateEntity>(centerAccount.getAccountActionDates());
    LocalDate firstCenterDate = new LocalDate(centerSchedules.get(0).getActionDate());
    LocalDate mon18thOfMay = new DateTime().withDate(2011, 5, 18).toLocalDate();
    assertThat(firstCenterDate, is(mon18thOfMay));
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ArrayList(java.util.ArrayList) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) LocalDate(org.joda.time.LocalDate) CalendarEventBuilder(org.mifos.domain.builders.CalendarEventBuilder) DateTime(org.joda.time.DateTime) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Example 35 with CustomerAccountBO

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

the class SaveCollectionSheetStructureValidator method validateAccount.

private void validateAccount(Integer customerId, Integer accountId, Short currencyId, ValidationAccountTypes accountType) {
    AccountBO account;
    try {
        account = legacyAccountDao.getAccount(accountId);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
    if (account == null) {
        addValidationError(InvalidSaveCollectionSheetReason.ACCOUNT_NOT_FOUND, "Customer Id: " + customerId + " Account Id: " + accountId);
        return;
    }
    if (!validAccountOwnership(account, customerId, accountType)) {
        addValidationError(InvalidSaveCollectionSheetReason.ACCOUNT_DOESNT_BELONG_TO_CUSTOMER, "Customer Id: " + customerId + " Account Id: " + accountId);
        return;
    }
    validateCurrency(currencyId);
    if (accountType.compareTo(ValidationAccountTypes.CUSTOMER) == 0) {
        if (!(account instanceof CustomerAccountBO)) {
            addValidationError(InvalidSaveCollectionSheetReason.ACCOUNT_NOT_A_CUSTOMER_ACCOUNT, "Customer Id: " + customerId + " Account Id: " + accountId);
        }
        return;
    }
    if (accountType.compareTo(ValidationAccountTypes.LOAN) == 0) {
        if (!(account instanceof LoanBO)) {
            addValidationError(InvalidSaveCollectionSheetReason.ACCOUNT_NOT_A_LOAN_ACCOUNT, "Customer Id: " + customerId + " Account Id: " + accountId);
        } else {
            if (!(validLoanAccountStates.contains(account.getState()))) {
                addValidationError(InvalidSaveCollectionSheetReason.INVALID_LOAN_ACCOUNT_STATUS, "Customer Id: " + customerId + " Account Id: " + accountId + " Account Status: " + account.getState().toString());
            }
        }
        return;
    }
    if ((accountType.compareTo(ValidationAccountTypes.SAVINGS) == 0) || (accountType.compareTo(ValidationAccountTypes.INDIVIDUAL_SAVINGS) == 0)) {
        if (!(account instanceof SavingsBO)) {
            addValidationError(InvalidSaveCollectionSheetReason.ACCOUNT_NOT_A_SAVINGS_ACCOUNT, "Customer Id: " + customerId + " Account Id: " + accountId);
        } else {
            if (!(validSavingsAccountStates.contains(account.getState()))) {
                addValidationError(InvalidSaveCollectionSheetReason.INVALID_SAVINGS_ACCOUNT_STATUS, "Customer Id: " + customerId + " Account Id: " + accountId + " Account Status: " + account.getState().toString());
            }
        }
        return;
    }
    throw new MifosRuntimeException("Account Type: " + accountType.toString() + " not recognised");
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)36 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)15 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)15 MeetingBO (org.mifos.application.meeting.business.MeetingBO)12 DateTime (org.joda.time.DateTime)11 LocalDate (org.joda.time.LocalDate)11 AccountBO (org.mifos.accounts.business.AccountBO)10 CenterBuilder (org.mifos.domain.builders.CenterBuilder)10 MeetingBuilder (org.mifos.domain.builders.MeetingBuilder)10 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)9 CenterBO (org.mifos.customers.center.business.CenterBO)8 CalendarEventBuilder (org.mifos.domain.builders.CalendarEventBuilder)8 MifosRuntimeException (org.mifos.core.MifosRuntimeException)7 GroupBO (org.mifos.customers.group.business.GroupBO)7 GroupBuilder (org.mifos.domain.builders.GroupBuilder)7 AccountException (org.mifos.accounts.exceptions.AccountException)6 LoanBO (org.mifos.accounts.loan.business.LoanBO)6 UserContext (org.mifos.security.util.UserContext)6 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)5