use of org.mifos.application.meeting.business.MeetingDetailsEntity in project head by mifos.
the class LoanAccountAction method manage.
@TransactionDemarcate(joinToken = true)
public ActionForward manage(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
LoanAccountActionForm loanActionForm = (LoanAccountActionForm) form;
String globalAccountNum = request.getParameter(GLOBAL_ACCOUNT_NUM);
CustomerBO customer = getCustomerFromRequest(request);
if (isGlimEnabled() || isNewGlimEnabled()) {
populateGlimAttributes(request, loanActionForm, globalAccountNum, customer);
}
String recurMonth = customer.getCustomerMeeting().getMeeting().getMeetingDetails().getRecurAfter().toString();
handleRepaymentsIndependentOfMeetingIfConfigured(request, loanActionForm, recurMonth);
LoanBO loanBO = new LoanDaoHibernate(new GenericDaoHibernate()).findByGlobalAccountNum(globalAccountNum);
UserContext userContext = getUserContext(request);
loanBO.setUserContext(userContext);
SessionUtils.setAttribute(PROPOSED_DISBURSAL_DATE, loanBO.getDisbursementDate(), request);
SessionUtils.removeAttribute(LOANOFFERING, request);
LoanOfferingBO loanOffering = getLoanOffering(loanBO.getLoanOffering().getPrdOfferingId(), userContext.getLocaleId());
loanActionForm.setInstallmentRange(loanBO.getMaxMinNoOfInstall());
loanActionForm.setLoanAmountRange(loanBO.getMaxMinLoanAmount());
MaxMinInterestRate interestRateRange = loanBO.getMaxMinInterestRate();
loanActionForm.setMaxInterestRate(interestRateRange.getMaxLoanAmount());
loanActionForm.setMinInterestRate(interestRateRange.getMinLoanAmount());
loanActionForm.setExternalId(loanBO.getExternalId());
if (null != loanBO.getFund()) {
loanActionForm.setLoanOfferingFund(loanBO.getFund().getFundId().toString());
}
if (configService.isRepaymentIndepOfMeetingEnabled()) {
MeetingDetailsEntity meetingDetail = loanBO.getLoanMeeting().getMeetingDetails();
loanActionForm.setMonthDay("");
loanActionForm.setMonthWeek("0");
loanActionForm.setMonthRank("0");
if (meetingDetail.getRecurrenceTypeEnum() == RecurrenceType.MONTHLY) {
setMonthlySchedule(loanActionForm, meetingDetail);
} else {
setWeeklySchedule(loanActionForm, meetingDetail);
}
}
setSessionAtributeForGLIM(request, loanBO);
SessionUtils.setAttribute(LOANOFFERING, loanOffering, request);
// Retrieve and set into the session all collateral types from the
// lookup_value_locale table associated with the current user context
// locale
SessionUtils.setCollectionAttribute(MasterConstants.COLLATERAL_TYPES, legacyMasterDao.getLookUpEntity(MasterConstants.COLLATERAL_TYPES).getCustomValueListElements(), request);
SessionUtils.setCollectionAttribute(MasterConstants.BUSINESS_ACTIVITIES, legacyMasterDao.findValueListElements(MasterConstants.LOAN_PURPOSES), request);
SessionUtils.setCollectionAttribute(CUSTOM_FIELDS, new ArrayList<CustomFieldDefinitionEntity>(), request);
SessionUtils.setAttribute(RECURRENCEID, loanBO.getLoanMeeting().getMeetingDetails().getRecurrenceTypeEnum().getValue(), request);
SessionUtils.setAttribute(RECURRENCENAME, loanBO.getLoanMeeting().getMeetingDetails().getRecurrenceType().getRecurrenceName(), request);
SessionUtils.setCollectionAttribute(LOANFUNDS, getFunds(loanOffering), request);
setRequestAttributesForEditPage(request, loanBO);
InformationOrderServiceFacade informationOrderServiceFacade = ApplicationContextProvider.getBean(InformationOrderServiceFacade.class);
SessionUtils.setCollectionAttribute("detailsInformationOrder", informationOrderServiceFacade.getInformationOrder("CreateLoan"), request);
setFormAttributes(loanBO, form, request);
return mapping.findForward(ActionForwards.manage_success.toString());
}
use of org.mifos.application.meeting.business.MeetingDetailsEntity 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.application.meeting.business.MeetingDetailsEntity in project head by mifos.
the class MeetingBuilder method build.
public MeetingBO build() {
LocalDate localStartDate = new LocalDate(startDate);
final MeetingBO meeting = new MeetingBO(meetingType, localStartDate.toDateTimeAtStartOfDay().toDate(), meetingLocation);
final MeetingDetailsEntity meetingDetailsEntity = new MeetingDetailsEntity(meeting, recurrenceType, recurAfter);
final MeetingRecurrenceEntity meetingRecurrenceEntity = new MeetingRecurrenceEntity(weekDay, meetingDetailsEntity);
meetingRecurrenceEntity.setDayNumber(dayNumber);
if (weekRank != null) {
meetingRecurrenceEntity.setRankOfDays(weekRank);
}
meetingDetailsEntity.setMeetingRecurrence(meetingRecurrenceEntity);
meeting.setMeetingDetails(meetingDetailsEntity);
return meeting;
}
use of org.mifos.application.meeting.business.MeetingDetailsEntity in project head by mifos.
the class LoanPrdActionFormTest method shouldAllowPeriodicFeeForNonVariableInstallmentLoanProduct.
@Test
public void shouldAllowPeriodicFeeForNonVariableInstallmentLoanProduct() {
String PERIODIC_FEE_2 = "2";
String NON_PERIODIC_FEE = "3";
final FeeDto feeDto = Mockito.mock(FeeDto.class);
loanPrdActionForm = new LoanPrdActionForm() {
@Override
FeeDto getFeeDto(@SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") FeeBO fee) {
return feeDto;
}
};
FeeFrequencyEntity feeFrequencyEntity = Mockito.mock(FeeFrequencyEntity.class);
MeetingBO meetingBo = Mockito.mock(MeetingBO.class);
MeetingDetailsEntity meetingDetailsEntity = Mockito.mock(MeetingDetailsEntity.class);
when(periodicFeeRate.isPeriodic()).thenReturn(true);
when(periodicFeeRate.getFeeType()).thenReturn(RateAmountFlag.RATE);
when(periodicFeeRate.getFeeId()).thenReturn(Short.valueOf(PERIODIC_FEE_2));
when(periodicFeeRate.getFeeName()).thenReturn("periodic fee2");
when((periodicFeeRate).getFeeFormula()).thenReturn(feeFormulaEntity);
when(feeFormulaEntity.getFeeFormula()).thenReturn(FeeFormula.INTEREST);
when(periodicFeeRate.getFeeFrequency()).thenReturn(feeFrequencyEntity);
when(nonPeriodicFeeRate.isPeriodic()).thenReturn(false);
when(nonPeriodicFeeRate.getFeeType()).thenReturn(RateAmountFlag.RATE);
when(nonPeriodicFeeRate.getFeeId()).thenReturn(Short.valueOf(NON_PERIODIC_FEE));
when(nonPeriodicFeeRate.getFeeName()).thenReturn("non Periodic fee");
when(((RateFeeBO) nonPeriodicFeeRate).getFeeFormula()).thenReturn(feeFormulaEntity);
when(feeFormulaEntity.getFeeFormula()).thenReturn(FeeFormula.INTEREST);
List<FeeBO> allPrdFees = new ArrayList<FeeBO>();
allPrdFees.add(periodicFeeRate);
allPrdFees.add(nonPeriodicFeeRate);
when(request.getAttribute(Constants.CURRENTFLOWKEY)).thenReturn(FLOW_KEY);
when(request.getSession()).thenReturn(session);
when(session.getAttribute(Constants.FLOWMANAGER)).thenReturn(flowManager);
when(session.getAttribute(ProductDefinitionConstants.LOANPRDFEE)).thenReturn(allPrdFees);
Flow flow = new Flow();
try {
when(flowManager.getFromFlow(Mockito.anyString(), Mockito.anyString())).thenReturn(allPrdFees);
when(flowManager.getFlowWithValidation(FLOW_KEY)).thenReturn(flow);
} catch (PageExpiredException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
loanPrdActionForm.setCanConfigureVariableInstallments(false);
loanPrdActionForm.setPrdOfferinFees(new String[] { PERIODIC_FEE_2, NON_PERIODIC_FEE });
loanPrdActionForm.validateSelectedFeeForVariableInstallment(request, errors);
Mockito.verifyZeroInteractions(errors);
}
Aggregations