use of org.mifos.customers.util.helpers.CustomerStatus in project head by mifos.
the class CenterServiceFacadeWebTier method retrieveCustomerStatusDetails.
@Override
public CustomerStatusDetailDto retrieveCustomerStatusDetails(Short newStatusId, Short flagIdValue, Short customerLevelId) {
CustomerLevel customerLevel = CustomerLevel.getLevel(customerLevelId);
CustomerStatus customerStatus = CustomerStatus.fromInt(newStatusId);
CustomerStatusFlag statusFlag = null;
if (customerStatus.isCustomerCancelledOrClosed()) {
statusFlag = CustomerStatusFlag.getStatusFlag(flagIdValue);
}
String statusName = AccountStateMachines.getInstance().getCustomerStatusName(customerStatus, customerLevel);
String flagName = AccountStateMachines.getInstance().getCustomerFlagName(statusFlag, customerLevel);
return new CustomerStatusDetailDto(statusName, flagName);
}
use of org.mifos.customers.util.helpers.CustomerStatus in project head by mifos.
the class ImportClientsServiceFacadeWebTier method save.
@Override
public ParsedClientsDto save(ParsedClientsDto parsedClientsDto) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
DateTimeService dateTimeService = new DateTimeService();
/* Construct ClientBO objects */
List<NewClientDto> newClients = new ArrayList<NewClientDto>();
for (ImportedClientDetail importedClient : parsedClientsDto.getSuccessfullyParsedRows()) {
String secondMiddleName = null;
ClientCreationDetail clientCreationDetail = importedClient.getClientCreationDetail();
PersonnelBO formedBy = null;
/* Client name details */
ClientNameDetailDto clientNameDetails = clientCreationDetail.getClientNameDetailDto();
ClientNameDetailEntity clientNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, clientNameDetails);
ClientDetailEntity clientDetailEntity = new ClientDetailEntity();
clientDetailEntity.updateClientDetails(clientCreationDetail.getClientPersonalDetailDto());
String clientFirstName = clientNameDetails.getFirstName();
String clientLastName = clientNameDetails.getLastName();
String secondLastName = clientNameDetails.getSecondLastName();
/* Spouse/father name details */
ClientNameDetailEntity spouseFatherNameDetailEntity = null;
if (clientCreationDetail.getSpouseFatherName() != null) {
spouseFatherNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, clientCreationDetail.getSpouseFatherName());
}
/* Data conversion */
DateTime dateOfBirth = new DateTime(clientCreationDetail.getDateOfBirth());
DateTime mfiJoiningDate = new DateTime(clientCreationDetail.getMfiJoiningDate());
DateTime trainedDateTime = null;
if (clientCreationDetail.getTrainedDate() != null) {
trainedDateTime = new DateTime(clientCreationDetail.getTrainedDate());
}
/* Status */
CustomerStatus clientStatus = CustomerStatus.fromInt(clientCreationDetail.getClientStatus());
CustomerStatus finalStatus = clientStatus;
if (clientStatus == CustomerStatus.CLIENT_ACTIVE && clientCreationDetail.getActivationDate() == null) {
clientStatus = CustomerStatus.CLIENT_PENDING;
}
/* Address */
Address address = null;
if (clientCreationDetail.getAddress() != null) {
AddressDto dto = clientCreationDetail.getAddress();
address = new Address(dto.getLine1(), dto.getLine2(), dto.getLine3(), dto.getCity(), dto.getState(), dto.getCountry(), dto.getZip(), dto.getPhoneNumber());
}
// empty list
List<ClientInitialSavingsOfferingEntity> associatedOfferings = new ArrayList<ClientInitialSavingsOfferingEntity>();
// client object
ClientBO client;
if (clientCreationDetail.getGroupFlag() == 1) {
CustomerBO group = customerDao.findCustomerBySystemId(clientCreationDetail.getParentGroupId());
if (clientCreationDetail.getFormedBy() != null) {
formedBy = this.personnelDao.findPersonnelById(clientCreationDetail.getFormedBy());
} else {
formedBy = group.getPersonnel();
}
client = ClientBO.createNewInGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, mfiJoiningDate, group, formedBy, clientNameDetailEntity, dateOfBirth, clientCreationDetail.getGovernmentId(), clientCreationDetail.isTrained(), trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, associatedOfferings, clientCreationDetail.getExternalId(), address, clientCreationDetail.getActivationDate());
} else {
Short officeId = clientCreationDetail.getOfficeId();
Short officerId = clientCreationDetail.getLoanOfficerId();
PersonnelBO loanOfficer = personnelDao.findPersonnelById(officerId);
OfficeBO office = this.officeDao.findOfficeById(officeId);
if (clientCreationDetail.getFormedBy() != null) {
formedBy = this.personnelDao.findPersonnelById(clientCreationDetail.getFormedBy());
} else {
formedBy = loanOfficer;
}
int lastSearchIdCustomerValue = customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(officeId);
/* meeting */
final MeetingDto meetingDto = importedClient.getMeeting();
MeetingBO clientMeeting = null;
if (meetingDto != null) {
clientMeeting = new MeetingFactory().create(meetingDto);
clientMeeting.setUserContext(userContext);
}
client = ClientBO.createNewOutOfGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, mfiJoiningDate, office, loanOfficer, clientMeeting, formedBy, clientNameDetailEntity, dateOfBirth, clientCreationDetail.getGovernmentId(), clientCreationDetail.isTrained(), trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, associatedOfferings, clientCreationDetail.getExternalId(), address, lastSearchIdCustomerValue);
if (clientCreationDetail.getActivationDate() != null) {
client.setCustomerActivationDate(clientCreationDetail.getActivationDate().toDateMidnight().toDate());
}
}
// global id
if (importedClient.getClientGlobalNum() != null) {
client.setGlobalCustNum(importedClient.getClientGlobalNum());
}
NewClientDto newClient = new NewClientDto(client, finalStatus);
newClients.add(newClient);
}
/* Validate client data */
for (NewClientDto newClient : newClients) {
ClientBO client = newClient.getClientBO();
try {
client.validate();
customerDao.validateClientForDuplicateNameOrGovtId(client.getDisplayName(), client.getDateOfBirth(), client.getGovernmentId());
} catch (CustomerException ex) {
throw new MifosRuntimeException(ex);
}
}
/* Save clients */
// empty list
List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>();
try {
hibernateTransactionHelper.startTransaction();
for (NewClientDto newClient : newClients) {
ClientBO client = newClient.getClientBO();
CustomerStatus finalStatus = newClient.getCustomerStatus();
// status to pending approval if active
MeetingBO meeting = client.getCustomerMeetingValue();
customerDao.save(client);
hibernateTransactionHelper.flushSession();
CalendarEvent applicableCalendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(client.getOfficeId());
CustomerAccountBO customerAccount = customerAccountFactory.create(client, accountFees, meeting, applicableCalendarEvents);
client.addAccount(customerAccount);
customerDao.save(client);
hibernateTransactionHelper.flushSession();
if (client.getParentCustomer() != null) {
customerDao.save(client.getParentCustomer());
}
if (client.getGlobalCustNum() == null) {
client.generateGlobalCustomerNumber();
}
client.generateSearchId();
customerDao.save(client);
hibernateTransactionHelper.flushSession();
if (client.getParentCustomer() != null) {
customerDao.save(client.getParentCustomer());
}
/* activate client */
if (finalStatus == CustomerStatus.CLIENT_ACTIVE) {
hibernateTransactionHelper.flushSession();
hibernateTransactionHelper.beginAuditLoggingFor(client);
client.clearCustomerFlagsIfApplicable(client.getStatus(), finalStatus);
client.updateCustomerStatus(finalStatus);
// changeStatus(client, oldStatus, newStatus);
if (client.getParentCustomer() != null) {
CustomerHierarchyEntity hierarchy = new CustomerHierarchyEntity(client, client.getParentCustomer());
client.addCustomerHierarchy(hierarchy);
}
if (client.getCustomerActivationDate() != null) {
client.setCustomerActivationDate(client.getCustomerActivationDate());
} else {
client.setCustomerActivationDate(dateTimeService.getCurrentJavaDateTime());
}
customerAccount.createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer(client, accountFees, meeting, applicableCalendarEvents, new DateTime(client.getCustomerActivationDate()));
customerDao.save(client);
}
}
hibernateTransactionHelper.commitTransaction();
} catch (Exception ex) {
hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(ex);
}
return parsedClientsDto;
}
use of org.mifos.customers.util.helpers.CustomerStatus in project head by mifos.
the class XlsClientsImporter method validateGroupStatus.
private void validateGroupStatus(final String globalGroupNum, final Short customerStatusId) throws RowException {
final CustomerStatus groupStatus = customerDao.findGroupBySystemId(globalGroupNum).getStatus();
final CustomerStatus clientStatus = CustomerStatus.fromInt(customerStatusId);
if (isGroupStatusLower(clientStatus, groupStatus)) {
throw new RowException(getMessage(XlsMessageConstants.GROUP_BAD_STATUS));
}
}
use of org.mifos.customers.util.helpers.CustomerStatus in project head by mifos.
the class XlsClientsImporter method validateGroup.
private void validateGroup(final String globalGroupNum) throws CellException {
if (StringUtils.isBlank(globalGroupNum)) {
return;
}
final GroupBO group = customerDao.findGroupBySystemId(globalGroupNum);
if (group == null) {
throw new CellException(getMessage(XlsMessageConstants.GROUP_NOT_FOUND_ERROR, globalGroupNum));
}
final CustomerStatus groupStatus = group.getStatus();
if (groupStatus == CustomerStatus.GROUP_CANCELLED) {
throw new CellException(getMessage(XlsMessageConstants.GROUP_CANCELED, globalGroupNum));
} else if (groupStatus == CustomerStatus.GROUP_CLOSED) {
throw new CellException(getMessage(XlsMessageConstants.GROUP_CLOSED, globalGroupNum));
}
}
use of org.mifos.customers.util.helpers.CustomerStatus in project head by mifos.
the class GroupServiceFacadeWebTier method createNewGroup.
@Override
public CustomerDetailsDto createNewGroup(GroupCreationDetail groupCreationDetail, MeetingDto meetingDto) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
GroupBO group;
try {
List<AccountFeesEntity> feesForCustomerAccount = convertFeeViewsToAccountFeeEntities(groupCreationDetail.getFeesToApply());
PersonnelBO formedBy = this.personnelDao.findPersonnelById(groupCreationDetail.getLoanOfficerId());
Short officeId;
String groupName = groupCreationDetail.getDisplayName();
CustomerStatus customerStatus = CustomerStatus.fromInt(groupCreationDetail.getCustomerStatus());
String externalId = groupCreationDetail.getExternalId();
boolean trained = groupCreationDetail.isTrained();
DateTime trainedOn = groupCreationDetail.getTrainedOn();
DateTime mfiJoiningDate = groupCreationDetail.getMfiJoiningDate();
DateTime activationDate = groupCreationDetail.getActivationDate();
AddressDto dto = groupCreationDetail.getAddressDto();
Address address = null;
if (dto != null) {
address = new Address(dto.getLine1(), dto.getLine2(), dto.getLine3(), dto.getCity(), dto.getState(), dto.getCountry(), dto.getZip(), dto.getPhoneNumber());
}
MeetingBO groupMeeting = null;
if (meetingDto != null) {
groupMeeting = new MeetingFactory().create(meetingDto);
groupMeeting.setUserContext(userContext);
}
if (ClientRules.getCenterHierarchyExists()) {
CenterBO parentCustomer = this.customerDao.findCenterBySystemId(groupCreationDetail.getParentSystemId());
// loanOfficerId = parentCustomer.getPersonnel().getPersonnelId();
officeId = parentCustomer.getOffice().getOfficeId();
groupMeeting = parentCustomer.getCustomerMeetingValue();
group = GroupBO.createGroupWithCenterAsParent(userContext, groupName, formedBy, parentCustomer, address, externalId, trained, trainedOn, customerStatus, mfiJoiningDate, activationDate);
} else {
// create group without center as parent
Short loanOfficerId = groupCreationDetail.getLoanOfficerId() != null ? groupCreationDetail.getLoanOfficerId() : userContext.getId();
officeId = groupCreationDetail.getOfficeId();
OfficeBO office = this.officeDao.findOfficeById(groupCreationDetail.getOfficeId());
PersonnelBO loanOfficer = this.personnelDao.findPersonnelById(loanOfficerId);
int numberOfCustomersInOfficeAlready = customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(officeId);
group = GroupBO.createGroupAsTopOfCustomerHierarchy(userContext, groupName, formedBy, groupMeeting, loanOfficer, office, address, externalId, trained, trainedOn, customerStatus, numberOfCustomersInOfficeAlready, mfiJoiningDate, activationDate);
}
try {
personnelDao.checkAccessPermission(userContext, group.getOfficeId(), group.getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
this.customerService.createGroup(group, groupMeeting, feesForCustomerAccount);
return new CustomerDetailsDto(group.getCustomerId(), group.getGlobalCustNum());
} catch (CustomerException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
Aggregations