use of org.mifos.accounts.productdefinition.business.LoanOfferingFeesEntity in project head by mifos.
the class LoanPrdPersistence method getLoanOffering.
public LoanOfferingBO getLoanOffering(final Short loanOfferingId, final Short localeId) throws PersistenceException {
LoanOfferingBO loanOffering = getPersistentObject(LoanOfferingBO.class, loanOfferingId);
Hibernate.initialize(loanOffering);
Hibernate.initialize(loanOffering.getCurrency());
loanOffering.getPrdCategory().getProductCategoryName();
loanOffering.getPrincipalGLcode().getGlcode();
loanOffering.getInterestGLcode().getGlcode();
if (loanOffering.getLoanOfferingFunds() != null && loanOffering.getLoanOfferingFunds().size() > 0) {
for (LoanOfferingFundEntity loanOfferingFund : loanOffering.getLoanOfferingFunds()) {
loanOfferingFund.getFund().getFundName();
}
}
if (loanOffering.getLoanOfferingFees() != null && loanOffering.getLoanOfferingFees().size() > 0) {
for (LoanOfferingFeesEntity prdOfferingFees : loanOffering.getLoanOfferingFees()) {
prdOfferingFees.getFees().getFeeName();
}
}
return loanOffering;
}
use of org.mifos.accounts.productdefinition.business.LoanOfferingFeesEntity in project head by mifos.
the class LoanAccountServiceFacadeWebTier method createMultipleLoans.
@Override
public List<String> createMultipleLoans(List<CreateLoanRequest> multipleLoans) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
List<String> createdLoanAccountNumbers = new ArrayList<String>();
for (CreateLoanRequest loanDetail : multipleLoans) {
CustomerBO center = this.customerDao.findCustomerById(loanDetail.getCenterId());
Short loanProductId = loanDetail.getLoanProductId();
LoanOfferingBO loanProduct = this.loanProductDao.findById(loanProductId.intValue());
List<QuestionGroupDetail> questionGroups = new ArrayList<QuestionGroupDetail>();
LoanAccountCashFlow loanAccountCashFlow = null;
BigDecimal loanAmount = BigDecimal.valueOf(Double.valueOf(loanDetail.getLoanAmount()));
BigDecimal minAllowedLoanAmount = BigDecimal.valueOf(Double.valueOf(loanDetail.getMinLoanAmount()));
BigDecimal maxAllowedLoanAmount = BigDecimal.valueOf(Double.valueOf(loanDetail.getMaxLoanAmount()));
Double interestRate = loanProduct.getDefInterestRate();
LocalDate disbursementDate = new LocalDate(center.getCustomerAccount().getNextMeetingDate());
int numberOfInstallments = loanDetail.getDefaultNoOfInstall();
int minAllowedNumberOfInstallments = loanDetail.getMinNoOfInstall();
int maxAllowedNumberOfInstallments = loanDetail.getMaxNoOfInstall();
int graceDuration = loanProduct.getGracePeriodDuration();
boolean isRepaymentIndepOfMeetingEnabled = new ConfigurationBusinessService().isRepaymentIndepOfMeetingEnabled();
Integer sourceOfFundId = null;
Integer loanPurposeId = loanDetail.getLoanPurpose();
Integer collateralTypeId = null;
String collateralNotes = null;
String externalId = null;
List<CreateAccountFeeDto> accountFees = new ArrayList<CreateAccountFeeDto>();
for (LoanOfferingFeesEntity loanOfferingFeesEntity : loanProduct.getLoanOfferingFees()) {
FeeBO feeBO = loanOfferingFeesEntity.getFees();
FeeDto feeDto = feeBO.toDto();
String amountOrRate = feeDto.getAmountOrRate().toString();
accountFees.add(new CreateAccountFeeDto(feeBO.getFeeId().intValue(), amountOrRate));
}
RecurringSchedule recurringSchedule = null;
if (isRepaymentIndepOfMeetingEnabled) {
MeetingBO meetingBO = loanProduct.getLoanOfferingMeetingValue();
MeetingDetailsEntity meetingDetailsEntity = meetingBO.getMeetingDetails();
Integer recursEvery = meetingDetailsEntity.getRecurAfter().intValue();
Short dayOfMonth = meetingDetailsEntity.getDayNumber();
RankOfDay weekOfMonth = meetingDetailsEntity.getWeekRank();
WeekDay dayOfWeek = meetingDetailsEntity.getWeekDay();
MeetingDetailsEntity customerMeetingDetailsEntity = center.getCustomerAccount().getMeetingForAccount().getMeetingDetails();
Short customerRecurrenceType = customerMeetingDetailsEntity.getRecurrenceType().getRecurrenceId();
if (meetingDetailsEntity.getRecurrenceType().getRecurrenceId().equals(customerRecurrenceType)) {
dayOfMonth = customerMeetingDetailsEntity.getDayNumber();
weekOfMonth = customerMeetingDetailsEntity.getWeekRank();
dayOfWeek = customerMeetingDetailsEntity.getWeekDay();
}
if (meetingBO.isMonthly()) {
if (meetingBO.isMonthlyOnDate()) {
recurringSchedule = new MonthlyOnDayOfMonthSchedule(recursEvery, dayOfMonth.intValue());
} else {
recurringSchedule = new MonthlyOnWeekOfMonthSchedule(recursEvery, weekOfMonth.getValue().intValue(), dayOfWeek.getValue().intValue());
}
} else if (meetingBO.isWeekly()) {
recurringSchedule = new WeeklySchedule(recursEvery, dayOfWeek.getValue().intValue());
}
}
CreateLoanAccount loanAccountInfo = new CreateLoanAccount(loanDetail.getClientId(), loanDetail.getLoanProductId().intValue(), loanDetail.getAccountStateId().intValue(), loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount, interestRate, disbursementDate, null, numberOfInstallments, minAllowedNumberOfInstallments, maxAllowedNumberOfInstallments, graceDuration, sourceOfFundId, loanPurposeId, collateralTypeId, collateralNotes, externalId, isRepaymentIndepOfMeetingEnabled, recurringSchedule, accountFees, new ArrayList<CreateAccountPenaltyDto>());
LoanCreationResultDto result = this.createLoan(loanAccountInfo, questionGroups, loanAccountCashFlow);
createdLoanAccountNumbers.add(result.getGlobalAccountNum());
// try {
// CustomerBO center = this.customerDao.findCustomerById(loanDetail.getCenterId());
//
// Short loanProductId = loanDetail.getLoanProductId();
// LoanOfferingBO loanProduct = this.loanProductDao.findById(loanProductId.intValue());
// CustomerBO client = this.customerDao.findCustomerById(loanDetail.getClientId());
//
// AccountState accountState = AccountState.fromShort(loanDetail.getAccountStateId());
// Money loanAmount = new Money(loanProduct.getCurrency(), loanDetail.getLoanAmount());
// Short defaultNumOfInstallments = loanDetail.getDefaultNoOfInstall();
// Date disbursementDate = center.getCustomerAccount().getNextMeetingDate();
// boolean interestDeductedAtDisbursement = loanProduct.isIntDedDisbursement();
// boolean isRepaymentIndepOfMeetingEnabled = new ConfigurationBusinessService().isRepaymentIndepOfMeetingEnabled();
//
// MeetingBO newMeetingForRepaymentDay = null;
// if (isRepaymentIndepOfMeetingEnabled) {
// MeetingBO meeting = center.getCustomerAccount().getMeetingForAccount();
// LoanAccountMeetingDto loanAccountMeetingDto = null;
//
// if (meeting.isWeekly()) {
// loanAccountMeetingDto = new LoanAccountMeetingDto(RecurrenceType.WEEKLY.getValue().toString(),
// meeting.getMeetingDetails().getWeekDay().getValue().toString(),
// meeting.getMeetingDetails().getRecurAfter().toString(),
// null, null, null, null, null, null);
// } else if (meeting.isMonthly()) {
// if (meeting.isMonthlyOnDate()) {
// loanAccountMeetingDto = new LoanAccountMeetingDto(RecurrenceType.MONTHLY.getValue().toString(),
// null, null, "1",
// meeting.getMeetingDetails().getDayNumber().toString(),
// meeting.getMeetingDetails().getRecurAfter().toString(),
// null, null, null);
// } else {
// loanAccountMeetingDto = new LoanAccountMeetingDto(RecurrenceType.MONTHLY.getValue().toString(),
// null, null, "2", null, null,
// meeting.getMeetingDetails().getWeekDay().getValue().toString(),
// meeting.getMeetingDetails().getRecurAfter().toString(),
// meeting.getMeetingDetails().getWeekRank().getValue().toString());
// }
// }
//
// newMeetingForRepaymentDay = this.createNewMeetingForRepaymentDay(new LocalDate(disbursementDate), loanAccountMeetingDto, client);
// }
//
// checkPermissionForCreate(accountState.getValue(), userContext, userContext.getBranchId(), userContext.getId());
//
// List<FeeDto> additionalFees = new ArrayList<FeeDto>();
// List<FeeDto> defaultFees = new ArrayList<FeeDto>();
//
// new LoanProductService().getDefaultAndAdditionalFees(loanProductId, userContext, defaultFees, additionalFees);
//
// FundBO fund = null;
// List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
// boolean isRedone = false;
//
// // FIXME - keithw - tidy up constructor and use domain concepts rather than primitives, e.g. money v double, loanpurpose v integer.
//
// LoanBO loan = new LoanBO(userContext, loanProduct, client, accountState, loanAmount, defaultNumOfInstallments,
// disbursementDate, interestDeductedAtDisbursement, interestRate, gracePeriodDuration, fund, defaultFees,
// customFields, isRedone, maxLoanAmount, minLoanAmount,
// loanProduct.getMaxInterestRate(), loanProduct.getMinInterestRate(),
// maxNoOfInstall, minNoOfInstall, isRepaymentIndepOfMeetingEnabled, newMeetingForRepaymentDay);
// loan.setBusinessActivityId(loanDetail.getLoanPurpose());
//
// PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
// AccountStateEntity newAccountState = new AccountStateEntity(accountState);
// AccountStatusChangeHistoryEntity statusChange = new AccountStatusChangeHistoryEntity(null, newAccountState, loggedInUser, loan);
//
// this.transactionHelper.startTransaction();
// loan.addAccountStatusChangeHistory(statusChange);
// this.loanDao.save(loan);
// this.transactionHelper.flushSession();
// String globalAccountNum = loan.generateId(userContext.getBranchGlobalNum());
// loan.setGlobalAccountNum(globalAccountNum);
// this.loanDao.save(loan);
// this.transactionHelper.commitTransaction();
//
// createdLoanAccountNumbers.add(loan.getGlobalAccountNum());
// } catch (ServiceException e) {
// this.transactionHelper.rollbackTransaction();
// throw new MifosRuntimeException(e);
// } catch (PersistenceException e) {
// this.transactionHelper.rollbackTransaction();
// throw new MifosRuntimeException(e);
// } catch (AccountException e) {
// this.transactionHelper.rollbackTransaction();
// throw new BusinessRuleException(e.getKey(), e);
// }
}
return createdLoanAccountNumbers;
}
use of org.mifos.accounts.productdefinition.business.LoanOfferingFeesEntity in project head by mifos.
the class InterceptHelper method hibernateMeta.
public Map hibernateMeta(Object object, String state) {
logger.debug("object : " + object);
ClassMetadata customMeta = StaticHibernateUtil.getSessionFactory().getClassMetadata(object.getClass());
Object[] propertyValues = customMeta.getPropertyValues(object, EntityMode.POJO);
String[] propertyNames = customMeta.getPropertyNames();
Type[] propertyTypes = customMeta.getPropertyTypes();
if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
// locale=((BusinessObject)object).getUserContext().getMfiLocale();
locale = ((AbstractBusinessObject) object).getUserContext().getCurrentLocale();
// localeId=((BusinessObject)object).getUserContext().getMfiLocaleId();
localeId = ((AbstractBusinessObject) object).getUserContext().getLocaleId();
logger.debug("initial path class: " + AuditConfiguration.getEntityToClassPath(object.getClass().getName()));
entityName = AuditConfiguration.getEntityToClassPath(object.getClass().getName());
entityId = Integer.valueOf(customMeta.getIdentifier(object, EntityMode.POJO).toString());
}
setPrimaryKeyValues(customMeta, object, customMeta.getIdentifierPropertyName(), state);
for (int i = 0; i < propertyNames.length; i++) {
if (!propertyTypes[i].isEntityType() && !propertyTypes[i].isCollectionType() && !propertyTypes[i].isComponentType()) {
if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
String name = propertyNames[i];
if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name, propertyValues[i], localeId);
initialValues.put(propertyNames[i], value);
} else {
if (propertyValues[i] instanceof Calendar && propertyValues[i] != null) {
initialValues.put(propertyNames[i], ((Calendar) propertyValues[i]).getTime());
} else if (propertyValues[i] instanceof byte[] && propertyValues[i] != null) {
initialValues.put(propertyNames[i], new String((byte[]) propertyValues[i]));
} else if (propertyValues[i] instanceof Date && propertyValues[i] != null) {
try {
Date date = (Date) propertyValues[i];
initialValues.put(propertyNames[i], DateUtils.getUserLocaleDate(locale, new java.sql.Date(date.getTime()).toString()));
} catch (Exception e) {
initialValues.put(propertyNames[i], propertyValues[i].toString());
}
} else {
initialValues.put(propertyNames[i], propertyValues[i]);
}
}
String columnName = AuditConfiguration.getColumnNameForPropertyName(entityName, name);
if (columnName != null && !columnName.equals("")) {
columnNames.put(propertyNames[i], columnName);
} else {
columnNames.put(propertyNames[i], propertyNames[i]);
}
} else {
String name = propertyNames[i];
logger.debug("c hibernateMeta " + name + " : " + propertyValues[i]);
if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name, propertyValues[i], localeId);
changedValues.put(propertyNames[i], value);
} else {
if (propertyValues[i] instanceof Calendar && propertyValues[i] != null) {
changedValues.put(propertyNames[i], ((Calendar) propertyValues[i]).getTime());
} else if (propertyValues[i] instanceof byte[] && propertyValues[i] != null) {
changedValues.put(propertyNames[i], new String((byte[]) propertyValues[i]));
} else if (propertyValues[i] instanceof Date && propertyValues[i] != null) {
try {
Date date = (Date) propertyValues[i];
changedValues.put(propertyNames[i], DateUtils.getUserLocaleDate(locale, new java.sql.Date(date.getTime()).toString()));
} catch (Exception e) {
changedValues.put(propertyNames[i], propertyValues[i].toString());
}
} else {
changedValues.put(propertyNames[i], propertyValues[i]);
}
}
String columnName = AuditConfiguration.getColumnNameForPropertyName(entityName, name);
if (columnName != null && !columnName.equals("")) {
columnNames.put(propertyNames[i], columnName);
} else {
columnNames.put(propertyNames[i], propertyNames[i]);
}
}
}
if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType() && propertyValues[i] instanceof MasterDataEntity && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], null)) {
String personnelStatusName = AuditConstants.PERSONNELSTATUSPATH;
String personnelLevelName = AuditConstants.PERSONNELLEVELPATH;
if (propertyValues[i].getClass().getName().startsWith(personnelStatusName)) {
Short id = ((PersonnelStatusEntity) propertyValues[i]).getId();
populateValueForObjectsOfTypeMasterDataEntity(id, state, propertyNames[i]);
} else if (propertyValues[i].getClass().getName().startsWith(personnelLevelName)) {
Short id = ((PersonnelLevelEntity) propertyValues[i]).getId();
populateValueForObjectsOfTypeMasterDataEntity(id, state, propertyNames[i]);
} else {
populateValueForObjectsOfTypeMasterDataEntity(propertyValues[i], state, propertyNames[i]);
}
}
// Reading Collection Types
if (propertyTypes[i].isCollectionType() && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], null) && AuditConfiguration.isObjectPropertiesToBeMerged(entityName, propertyNames[i], null)) {
populateAndMergeCollectionTypes(state, propertyValues[i], propertyNames[i], null);
}
if (propertyTypes[i].isCollectionType() && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], null) && !AuditConfiguration.isObjectPropertiesToBeMerged(entityName, propertyNames[i], null)) {
Iterator iterator = ((Set) propertyValues[i]).iterator();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj != null) {
if (obj instanceof LoanOfferingFeesEntity) {
LoanOfferingFeesEntity loanOfferingFeesEntity = (LoanOfferingFeesEntity) obj;
if (propertyNames[i].equalsIgnoreCase("loanOfferingFees") && loanOfferingFeesEntity.getPrdOfferingFeeId() != null) {
readLoanOfferingFeesCollection(loanOfferingFeesEntity, state);
} else {
readFurtherMetaForCollectionType(obj, propertyNames[i], state);
}
} else {
readFurtherMetaForCollectionType(obj, propertyNames[i], state);
}
}
}
}
if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType() && !(propertyValues[i] instanceof MasterDataEntity) && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], null)) {
Object obj = propertyValues[i];
if (obj != null) {
readFurtherMeta(obj, propertyNames[i], state);
}
}
// Reading further Money type
if (!propertyTypes[i].isEntityType() && propertyTypes[i].isComponentType() && !(propertyValues[i] instanceof MasterDataEntity) && (propertyValues[i] instanceof Money)) {
Object obj1 = propertyValues[i];
if (obj1 != null) {
readFurtherMoneyType(obj1, propertyNames[i], state);
}
}
// Reading further component type
if (!propertyTypes[i].isEntityType() && propertyTypes[i].isComponentType() && !(propertyValues[i] instanceof MasterDataEntity) && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], null)) {
Object obj1 = propertyValues[i];
if (obj1 != null) {
readFurtherComponenetMeta(obj1, propertyNames[i], state, propertyTypes[i]);
}
}
}
if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
return initialValues;
} else {
return changedValues;
}
}
use of org.mifos.accounts.productdefinition.business.LoanOfferingFeesEntity in project head by mifos.
the class LoanPrdAction method getFeesSelected.
private List<FeeDto> getFeesSelected(HttpServletRequest request, LoanOfferingBO loanOffering) {
List<FeeDto> feeSelected = new ArrayList<FeeDto>();
for (LoanOfferingFeesEntity prdOfferingFees : loanOffering.getLoanOfferingFees()) {
FeeBO fee = prdOfferingFees.getFees();
fee = feeDao.initializeAndUnproxy(feeDao.findById(fee.getFeeId()));
feeSelected.add(new FeeDto(getUserContext(request), fee));
}
return feeSelected;
}
Aggregations