use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class MeetingAction method update.
@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
MeetingActionForm actionForm = (MeetingActionForm) form;
MeetingBO meeting = createMeeting(actionForm);
CustomerBO customerInSession = (CustomerBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
MeetingDto meetingDto = null;
if (meeting != null) {
meetingDto = meeting.toDto();
}
meetingServiceFacade.updateCustomerMeeting(meetingDto, customerInSession.getCustomerId());
ActionForwards forward = forwardForUpdate(actionForm.getCustomerLevelValue());
return mapping.findForward(forward.toString());
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class SavingsAction method getPrdOfferings.
@TransactionDemarcate(saveToken = true)
public ActionForward getPrdOfferings(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
SavingsActionForm savingsActionForm = ((SavingsActionForm) form);
doCleanUp(savingsActionForm, request);
Integer customerId = Integer.valueOf(savingsActionForm.getCustomerId());
CustomerBO customer = this.customerDao.findCustomerById(customerId);
SessionUtils.setAttribute(SavingsConstants.CLIENT, customer, request);
List<PrdOfferingDto> savingPrds = this.savingsServiceFacade.retrieveApplicableSavingsProductsForCustomer(customerId);
SessionUtils.setCollectionAttribute(SavingsConstants.SAVINGS_PRD_OFFERINGS, savingPrds, request);
return mapping.findForward(AccountConstants.GET_PRDOFFERINGS_SUCCESS);
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class CustomerTagGenerator method buildLink.
private void buildLink(StringBuilder strBuilder, CustomerBO customer, CustomerBO originalCustomer, boolean selfLinkRequired, Object randomNum) {
if (customer == null) {
return;
}
try {
CustomerBO customerReloaded = new CustomerPersistence().getCustomer(customer.getCustomerId());
buildLink(strBuilder, customerReloaded.getParentCustomer(), originalCustomer, selfLinkRequired, randomNum);
strBuilder.append(" / ");
createCustomerLink(strBuilder, customer, originalCustomer, selfLinkRequired, randomNum);
} catch (PersistenceException e) {
throw new RuntimeException(e);
}
}
use of org.mifos.customers.business.CustomerBO 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.business.CustomerBO in project head by mifos.
the class XlsLoansAccountImporter method parse.
/**
* Parse input stream.
* @param is input stream containing loan accounts' data
* @return object containing successfully parsed rows and rows with errors
*/
public ParsedLoansDto parse(InputStream is) {
//prepare objects: result, lists for rows
ParsedLoansDto result = null;
List<String> errors = new ArrayList<String>();
//temporary list for new accounts numbers, currently not used
List<String> newAccountsNumbers = new ArrayList<String>();
List<ImportedLoanDetail> parsedLoanDetails = new ArrayList<ImportedLoanDetail>();
// open spreadsheet
try {
HSSFWorkbook workbook = new HSSFWorkbook(is);
HSSFSheet sheet = workbook.getSheetAt(0);
// check first row of data
HSSFRow row = sheet.getRow(XlsLoansImportTemplateConstants.FIRST_ROW_WITH_DATA.getValue());
if (row == null) {
throw new XlsParsingException(getMessage(XlsMessageConstants.NOT_ENOUGH_INPUT_ROW, null));
}
Iterator<Row> iterator = sheet.rowIterator();
// skip to rows with data
while (iterator.hasNext() && (iterator.next().getRowNum() < XlsLoansImportTemplateConstants.FIRST_ROW_WITH_DATA.getValue() - 1)) ;
// parse loan account's data
while (iterator.hasNext()) {
row = (HSSFRow) iterator.next();
List<Object> params = new ArrayList<Object>();
// setup the first cell
XlsLoansImportTemplateConstants currentCell = XlsLoansImportTemplateConstants.ACCOUNT_NUMBER;
try {
// account number
String accountNumber = getCellStringValue(row, currentCell);
// TODO: rewrite this account number validation to more universal and extract method
if (StringUtils.isBlank(accountNumber) && isEdit) {
//editing and account number is missing
throw new XlsParsingException(getCellError(XlsMessageConstants.MISSING_ACCOUNT_NUMBER, row, currentCell.getValue(), null));
} else //TODO: validation if account for edition exists
if (StringUtils.isBlank(accountNumber) && !isEdit) {
//not editing, adding with predefined account number and account number is not good
accountNumber = null;
} else //account number is good for creating new account with predefined account number...
if (!StringUtils.isBlank(accountNumber) && !isEdit) {
//...but it's duplicate
if (!validateAccountNumber(accountNumber, newAccountsNumbers)) {
params.clear();
params.add(accountNumber);
throw new XlsParsingException(getCellError(XlsMessageConstants.DUPLICATE_GLOBAL_NUM_ERROR, row, currentCell.getValue(), params));
}
}
//all good, account is either predefined from xls document or null and will be generated
//TODO: extract methods that can be shared between loans and savings
// customer global id
currentCell = XlsLoansImportTemplateConstants.CUSTOMER_GLOBAL_ID;
String customerGlobalId = getCellStringValue(row, currentCell);
if (customerGlobalId.isEmpty()) {
throw new XlsParsingException(getCellError(XlsMessageConstants.CUSTOMER_NOT_BLANK, row, currentCell.getValue(), params));
}
CustomerBO customerBO = null;
customerBO = validateCustomerGlobalId(customerGlobalId);
if (customerBO == null) {
params.clear();
params.add(customerGlobalId);
throw new XlsParsingException(getCellError(XlsMessageConstants.CUSTOMER_NOT_FOUND, row, currentCell.getValue(), params));
}
// product name
currentCell = XlsLoansImportTemplateConstants.PRODUCT_NAME;
String productName = getCellStringValue(row, currentCell);
LoanOfferingBO loanOfferingBO = null;
loanOfferingBO = validateProductName(productName, customerBO, row, currentCell.getValue());
//TODO: add support for backdated payments
LoanCreationLoanDetailsDto lcldd = loanAccountServiceFacade.retrieveLoanDetailsForLoanAccountCreation(customerBO.getCustomerId(), loanOfferingBO.getPrdOfferingId(), false);
// status name
currentCell = XlsLoansImportTemplateConstants.STATUS_NAME;
String statusName = getCellStringValue(row, currentCell);
XlsLoanSavingsAccountStatesConstants statusConstant = null;
statusConstant = validateStatusName(statusName, customerBO, this.isEdit, row, currentCell.getValue());
// status reason flag
currentCell = XlsLoansImportTemplateConstants.CANCEL_FlAG_REASON;
String cancelReason = getCellStringValue(row, currentCell);
XlsLoanSavingsFlagsConstants flagConstant = null;
flagConstant = validateStatusFlagReason(cancelReason, statusName, AccountTypes.LOAN_ACCOUNT, row, currentCell.getValue());
// loan amount
currentCell = XlsLoansImportTemplateConstants.LOAN_AMOUNT;
BigDecimal loanAmount = getCellDecimalValue(row, currentCell);
validateAmount(loanAmount, loanOfferingBO, customerBO, lcldd, row, currentCell.getValue());
// Interest rate
currentCell = XlsLoansImportTemplateConstants.INTEREST_RATE;
BigDecimal interestRate = getCellDecimalValue(row, currentCell);
validateInterestRate(interestRate, loanOfferingBO, customerBO, lcldd, row, currentCell.getValue());
// number of installments
currentCell = XlsLoansImportTemplateConstants.NO_OF_INSTALLMENTS;
Integer numberOfInstallments = getCellIntegerValue(row, currentCell);
validateNumberOfInstallments(numberOfInstallments, customerBO, loanOfferingBO, lcldd, row, currentCell.getValue());
// disbursal date
currentCell = XlsLoansImportTemplateConstants.DISBURLSAL_DATE;
Date disbursalDate = getCellDateValue(row, currentCell);
validateDisbursalDate(disbursalDate, customerBO, loanOfferingBO, currentCell.getValue(), row, statusName);
// grace period
currentCell = XlsLoansImportTemplateConstants.GRACE_PERIOD;
Integer gracePeriod = getCellIntegerValue(row, currentCell);
validateGracePeriod(gracePeriod, loanOfferingBO, customerBO, numberOfInstallments, row, currentCell.getValue());
// source of founds
currentCell = XlsLoansImportTemplateConstants.SOURCE_OF_FOUNDS;
List<FundDto> funds = lcldd.getFundDtos();
String sourceOfFund = getCellStringValue(row, currentCell);
Integer sourceOfFundId = null;
sourceOfFundId = validateSourceOfFund(sourceOfFund, funds, row, currentCell.getValue());
// purpose
List<ValueListElement> purposes = lcldd.getLoanPurposes();
currentCell = XlsLoansImportTemplateConstants.PURPOSE;
String loanPurpose = getCellStringValue(row, currentCell);
Integer loanPurposeId = null;
loanPurposeId = validateLoanPurposeId(loanPurpose, purposes, row, currentCell.getValue());
// collateral type
currentCell = XlsLoansImportTemplateConstants.COLLATERAL_TYPE;
Integer collateralTypeId = null;
String collateralType = getCellStringValue(row, currentCell);
Map<String, String> collaterals = lcldd.getCollateralOptions();
collateralTypeId = validateCollateralType(collateralType, collaterals, row, currentCell.getValue());
// collateral notes
currentCell = XlsLoansImportTemplateConstants.COLLATERAL_NOTES;
String collateralNotes = getCellStringValue(row, currentCell);
collateralNotes = StringUtils.isBlank(collateralNotes) ? null : collateralNotes;
// external id
currentCell = XlsLoansImportTemplateConstants.EXTERNAL_ID;
String externalId = getCellStringValue(row, currentCell);
externalId = StringUtils.isBlank(externalId) ? null : externalId;
//...will be used for editing/adding loans with predefined account numbers
if (accountNumber != null) {
newAccountsNumbers.add(accountNumber);
}
//create final objects
//TODO handle backdated payments
Short flagValue = flagConstant == null ? null : flagConstant.getFlag().getValue();
ImportedLoanDetail detail = new ImportedLoanDetail(accountNumber, customerBO.getCustomerId(), loanOfferingBO.getPrdOfferingId(), statusConstant.getState().getValue(), flagValue, loanAmount, interestRate, numberOfInstallments, disbursalDate, gracePeriod, sourceOfFundId, loanPurposeId, collateralTypeId, collateralNotes, externalId);
parsedLoanDetails.add(detail);
} catch (XlsParsingException xex) {
if (xex.isMultiple()) {
for (String msg : xex.getMessages()) {
errors.add(msg);
}
} else {
errors.add(xex.getMessage());
}
} catch (Exception cex) {
errors.add(cex.getMessage());
}
}
} catch (Exception ex) {
errors.add(ex.getMessage());
}
result = new ParsedLoansDto(errors, parsedLoanDetails);
return result;
}
Aggregations