Search in sources :

Example 1 with CustomerHistoricalDataEntity

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

the class GroupServiceFacadeWebTier method retrieveCustomerHistoricalData.

@Override
public CustomerHistoricalDataDto retrieveCustomerHistoricalData(String globalCustNum) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    CustomerBO customer = this.customerDao.findCustomerBySystemId(globalCustNum);
    boolean client = false;
    boolean group = false;
    if (customer.isClient()) {
        client = true;
    } else if (customer.isGroup()) {
        group = true;
    }
    CustomerHistoricalDataEntity customerHistoricalDataEntity = customer.getHistoricalData();
    if (customerHistoricalDataEntity == null) {
        customerHistoricalDataEntity = new CustomerHistoricalDataEntity(customer);
    }
    try {
        String currentDate = DateUtils.getCurrentDate(userContext.getPreferredLocale());
        java.sql.Date mfiJoiningDate = null;
        if (customerHistoricalDataEntity.getMfiJoiningDate() == null) {
            mfiJoiningDate = DateUtils.getLocaleDate(userContext.getPreferredLocale(), currentDate);
        } else {
            mfiJoiningDate = new Date(customerHistoricalDataEntity.getMfiJoiningDate().getTime());
        }
        return new CustomerHistoricalDataDto(client, group, mfiJoiningDate);
    } catch (InvalidDateException e) {
        throw new BusinessRuleException(e.getMessage(), e);
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerHistoricalDataDto(org.mifos.dto.screen.CustomerHistoricalDataDto) UserContext(org.mifos.security.util.UserContext) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) CustomerHistoricalDataEntity(org.mifos.customers.business.CustomerHistoricalDataEntity) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) Date(java.sql.Date) Date(java.sql.Date)

Example 2 with CustomerHistoricalDataEntity

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

the class GroupServiceFacadeWebTier method updateCustomerHistoricalData.

@Override
public void updateCustomerHistoricalData(String globalCustNum, CustomerHistoricalDataUpdateRequest historicalData) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    CustomerBO customerBO = this.customerDao.findCustomerBySystemId(globalCustNum);
    customerBO.updateDetails(userContext);
    try {
        CustomerHistoricalDataEntity customerHistoricalDataEntity = customerBO.getHistoricalData();
        if (customerBO.getPersonnel() != null) {
            checkPermissionForAddingHistoricalData(customerBO.getLevel(), userContext, customerBO.getOffice().getOfficeId(), customerBO.getPersonnel().getPersonnelId());
        } else {
            checkPermissionForAddingHistoricalData(customerBO.getLevel(), userContext, customerBO.getOffice().getOfficeId(), userContext.getId());
        }
        // Integer oldLoanCycleNo = 0;
        if (customerHistoricalDataEntity == null) {
            customerHistoricalDataEntity = new CustomerHistoricalDataEntity(customerBO);
            customerHistoricalDataEntity.setCreatedBy(customerBO.getUserContext().getId());
            customerHistoricalDataEntity.setCreatedDate(new DateTimeService().getCurrentJavaDateTime());
        } else {
            // oldLoanCycleNo =
            // customerHistoricalDataEntity.getLoanCycleNumber();
            customerHistoricalDataEntity.setUpdatedDate(new DateTimeService().getCurrentJavaDateTime());
            customerHistoricalDataEntity.setUpdatedBy(customerBO.getUserContext().getId());
        }
        customerHistoricalDataEntity.setInterestPaid(StringUtils.isBlank(historicalData.getInterestPaid()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getInterestPaid()));
        customerHistoricalDataEntity.setLoanAmount(StringUtils.isBlank(historicalData.getLoanAmount()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getLoanAmount()));
        customerHistoricalDataEntity.setLoanCycleNumber(historicalData.getLoanCycleNumber());
        customerHistoricalDataEntity.setMissedPaymentsCount(historicalData.getMissedPaymentsCount());
        customerHistoricalDataEntity.setNotes(historicalData.getNotes());
        customerHistoricalDataEntity.setProductName(historicalData.getProductName());
        customerHistoricalDataEntity.setTotalAmountPaid(StringUtils.isBlank(historicalData.getTotalAmountPaid()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getTotalAmountPaid()));
        customerHistoricalDataEntity.setTotalPaymentsCount(historicalData.getTotalPaymentsCount());
        customerHistoricalDataEntity.setMfiJoiningDate(historicalData.getMfiJoiningDate());
        this.transactionHelper.startTransaction();
        this.transactionHelper.beginAuditLoggingFor(customerBO);
        customerBO.updateHistoricalData(customerHistoricalDataEntity);
        this.customerDao.save(customerBO);
        this.transactionHelper.commitTransaction();
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) UserContext(org.mifos.security.util.UserContext) CustomerHistoricalDataEntity(org.mifos.customers.business.CustomerHistoricalDataEntity) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 3 with CustomerHistoricalDataEntity

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

the class CustHistoricalDataAction method getHistoricalData.

@TransactionDemarcate(saveToken = true)
public ActionForward getHistoricalData(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    CustHistoricalDataActionForm actionForm = (CustHistoricalDataActionForm) form;
    String globalCustNum = request.getParameter(CustomerConstants.GLOBAL_CUST_NUM);
    CustomerHistoricalDataDto historicalData = this.groupServiceFacade.retrieveCustomerHistoricalData(globalCustNum);
    CustomerBO customer = this.customerDao.findCustomerBySystemId(globalCustNum);
    UserContext userContext = getUserContext(request);
    customer.updateDetails(userContext);
    if (historicalData.isClient()) {
        actionForm.setType("Client");
    } else if (historicalData.isGroup()) {
        actionForm.setType("Group");
    }
    CustomerHistoricalDataEntity customerHistoricalDataEntity = customer.getHistoricalData();
    if (customerHistoricalDataEntity == null) {
        customerHistoricalDataEntity = new CustomerHistoricalDataEntity(customer);
    }
    SessionUtils.removeAttribute(Constants.BUSINESS_KEY, request);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, customer, request);
    SessionUtils.setAttribute(CustomerConstants.MFIJOININGDATE, historicalData.getMfiJoiningDate(), request);
    SessionUtils.setAttribute(CustomerConstants.CUSTOMER_HISTORICAL_DATA, customerHistoricalDataEntity, request);
    return mapping.findForward(ActionForwards.getHistoricalData_success.toString());
}
Also used : CustomerHistoricalDataDto(org.mifos.dto.screen.CustomerHistoricalDataDto) UserContext(org.mifos.security.util.UserContext) CustomerHistoricalDataEntity(org.mifos.customers.business.CustomerHistoricalDataEntity) CustHistoricalDataActionForm(org.mifos.customers.struts.actionforms.CustHistoricalDataActionForm) CustomerBO(org.mifos.customers.business.CustomerBO) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 4 with CustomerHistoricalDataEntity

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

the class CustHistoricalDataAction method loadHistoricalData.

@TransactionDemarcate(joinToken = true)
public ActionForward loadHistoricalData(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    CustHistoricalDataActionForm historicalActionForm = (CustHistoricalDataActionForm) form;
    UserContext userContext = getUserContext(request);
    CustomerHistoricalDataEntity customerHistoricalDataEntity = (CustomerHistoricalDataEntity) SessionUtils.getAttribute(CustomerConstants.CUSTOMER_HISTORICAL_DATA, request);
    historicalActionForm.setInterestPaid(getStringValue(customerHistoricalDataEntity.getInterestPaid()));
    historicalActionForm.setLoanAmount(getStringValue(customerHistoricalDataEntity.getLoanAmount()));
    historicalActionForm.setLoanCycleNumber(getStringValue(customerHistoricalDataEntity.getLoanCycleNumber()));
    historicalActionForm.setMissedPaymentsCount(getStringValue(customerHistoricalDataEntity.getMissedPaymentsCount()));
    historicalActionForm.setCommentNotes(customerHistoricalDataEntity.getNotes());
    historicalActionForm.setProductName(customerHistoricalDataEntity.getProductName());
    historicalActionForm.setTotalAmountPaid(getStringValue(customerHistoricalDataEntity.getTotalAmountPaid()));
    historicalActionForm.setTotalPaymentsCount(getStringValue(customerHistoricalDataEntity.getTotalPaymentsCount()));
    String mfiJoiningDate = SessionUtils.getAttribute(CustomerConstants.MFIJOININGDATE, request).toString();
    historicalActionForm.setMfiJoiningDate(DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), mfiJoiningDate));
    return mapping.findForward(ActionForwards.loadHistoricalData_success.toString());
}
Also used : UserContext(org.mifos.security.util.UserContext) CustomerHistoricalDataEntity(org.mifos.customers.business.CustomerHistoricalDataEntity) CustHistoricalDataActionForm(org.mifos.customers.struts.actionforms.CustHistoricalDataActionForm) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 5 with CustomerHistoricalDataEntity

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

the class CustHistoricalDataActionStrutsTest method testGetHistoricalDataWhenCustHistoricalDataIsNotNull.

@Test
public void testGetHistoricalDataWhenCustHistoricalDataIsNotNull() throws Exception {
    createInitialObjects();
    CustomerHistoricalDataEntity customerHistoricalDataEntity = new CustomerHistoricalDataEntity(group);
    customerHistoricalDataEntity.setMfiJoiningDate(offSetCurrentDate(10));
    Date mfiDate = new Date(customerHistoricalDataEntity.getMfiJoiningDate().getTime());
    group.updateHistoricalData(customerHistoricalDataEntity);
    group.update();
    StaticHibernateUtil.flushSession();
    Assert.assertEquals(mfiDate, new Date(group.getMfiJoiningDate().getTime()));
    setRequestPathInfo("/custHistoricalDataAction.do");
    addRequestParameter("method", "getHistoricalData");
    addRequestParameter("globalCustNum", group.getGlobalCustNum());
    getRequest().getSession().setAttribute("security_param", "Group");
    actionPerform();
    verifyForward(ActionForwards.getHistoricalData_success.toString());
    verifyNoActionErrors();
    verifyNoActionMessages();
    Assert.assertEquals(new java.sql.Date(DateUtils.getDateWithoutTimeStamp(mfiDate.getTime()).getTime()).toString(), SessionUtils.getAttribute(CustomerConstants.MFIJOININGDATE, request).toString());
}
Also used : CustomerHistoricalDataEntity(org.mifos.customers.business.CustomerHistoricalDataEntity) Date(java.sql.Date) Test(org.junit.Test)

Aggregations

CustomerHistoricalDataEntity (org.mifos.customers.business.CustomerHistoricalDataEntity)6 UserContext (org.mifos.security.util.UserContext)5 CustomerBO (org.mifos.customers.business.CustomerBO)3 MifosUser (org.mifos.security.MifosUser)3 Date (java.sql.Date)2 Test (org.junit.Test)2 CustHistoricalDataActionForm (org.mifos.customers.struts.actionforms.CustHistoricalDataActionForm)2 CustomerHistoricalDataDto (org.mifos.dto.screen.CustomerHistoricalDataDto)2 Money (org.mifos.framework.util.helpers.Money)2 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)1 MifosUserBuilder (org.mifos.builders.MifosUserBuilder)1 ApplicationException (org.mifos.framework.exceptions.ApplicationException)1 DateTimeService (org.mifos.framework.util.DateTimeService)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)1