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);
}
}
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);
}
}
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());
}
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());
}
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());
}
Aggregations