use of org.mifos.clientportfolio.loan.service.MonthlyOnWeekOfMonthSchedule 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.clientportfolio.loan.service.MonthlyOnWeekOfMonthSchedule in project head by mifos.
the class ImportLoansSavingsFacadeWebTier method saveLoans.
@Override
public ParsedLoansDto saveLoans(ParsedLoansDto parsedLoansDto) {
List<CreateAccountFeeDto> defaultAccountFees = new ArrayList<CreateAccountFeeDto>();
List<QuestionGroupDetail> questionGroupDetails = new ArrayList<QuestionGroupDetail>();
List<CreateAccountPenaltyDto> defaultPenalties = new ArrayList<CreateAccountPenaltyDto>();
for (ImportedLoanDetail detail : parsedLoansDto.getSuccessfullyParsedRows()) {
LoanCreationLoanDetailsDto lcldd = loanAccountServiceFacade.retrieveLoanDetailsForLoanAccountCreation(detail.getCustomerId(), detail.getPrdOfferingId(), false);
RecurringSchedule recurringSchedule = null;
MeetingDto meetingDto = lcldd.getCustomerMeetingDetail();
int meetingEvery = (lcldd.isRepaymentIndependentOfMeetingEnabled()) ? lcldd.getLoanOfferingMeetingDetail().getMeetingDetailsDto().getEvery() : meetingDto.getMeetingDetailsDto().getEvery();
int loanRecurrenceTypeId = (lcldd.isRepaymentIndependentOfMeetingEnabled()) ? lcldd.getLoanOfferingMeetingDetail().getMeetingDetailsDto().getRecurrenceTypeId() : meetingDto.getMeetingDetailsDto().getRecurrenceTypeId();
if (loanRecurrenceTypeId == 1) {
recurringSchedule = new WeeklySchedule(meetingEvery, meetingDto.getMeetingDetailsDto().getRecurrenceDetails().getDayOfWeek());
} else if (loanRecurrenceTypeId == 2) {
if (meetingDto.getMeetingDetailsDto().getRecurrenceDetails().getWeekOfMonth().equals(0)) {
recurringSchedule = new MonthlyOnDayOfMonthSchedule(meetingEvery, meetingDto.getMeetingDetailsDto().getRecurrenceDetails().getDayNumber());
} else {
recurringSchedule = new MonthlyOnWeekOfMonthSchedule(meetingEvery, meetingDto.getMeetingDetailsDto().getRecurrenceDetails().getWeekOfMonth(), meetingDto.getMeetingDetailsDto().getRecurrenceDetails().getDayOfWeek());
}
} else if (loanRecurrenceTypeId == 3) {
recurringSchedule = new DailySchedule(meetingEvery);
}
CreateLoanAccount cla = new CreateLoanAccount(detail.getCustomerId(), new Integer(detail.getPrdOfferingId()), new Integer(detail.getStatus()), detail.getLoanAmount(), lcldd.getMinLoanAmount(), lcldd.getMaxLoanAmount(), detail.getInterestRate().doubleValue(), new LocalDate(detail.getDisbursalDate().getTime()), null, detail.getNumberOfInstallments(), lcldd.getMinNumberOfInstallments(), lcldd.getMaxNumberOfInstallments(), detail.getGracePeriod(), detail.getSourceOfFundId(), detail.getLoanPurposeId(), detail.getCollateralTypeId(), detail.getCollateralNotes(), detail.getExternalId(), lcldd.isRepaymentIndependentOfMeetingEnabled(), recurringSchedule, defaultAccountFees, defaultPenalties);
cla.setPredefinedAccountNumber(detail.getAccountNumber());
cla.setFlagId(detail.getFlag());
this.loanAccountServiceFacade.createLoan(cla, questionGroupDetails, null);
}
return null;
}
Aggregations