use of org.mifos.clientportfolio.newloan.applicationservice.CreateGlimLoanAccount in project head by mifos.
the class LoanAccountRESTController method createLoanAccount.
@RequestMapping(value = "/account/loan/create", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> createLoanAccount(@RequestBody String request) throws Throwable {
ObjectMapper om = createLoanAccountMapping();
Map<String, String> map = new HashMap<String, String>();
CreationLoanAccountDto creationDetails = null;
try {
creationDetails = om.readValue(request, CreationLoanAccountDto.class);
} catch (JsonMappingException e) {
e.getCause();
}
loanValidator(creationDetails);
List<QuestionGroupDetail> questionGroups = new ArrayList<QuestionGroupDetail>();
LoanCreationResultDto loanResult = null;
LoanBO loanInfo = null;
CreateLoanAccount loanAccount = createLoan(creationDetails);
if (creationDetails.getGlim()) {
List<GroupMemberAccountDto> memberAccounts = creationDetails.glimsAsGroupMemberAccountDto(creationDetails.getGlimAccounts());
CreateGlimLoanAccount createGroupLoanAccount = new CreateGlimLoanAccount(memberAccounts, creationDetails.getLoanAmount(), loanAccount);
loanResult = loanAccountServiceFacade.createGroupLoanWithIndividualMonitoring(createGroupLoanAccount, questionGroups, null);
List<LoanBO> individuals = loanDao.findIndividualLoans(loanResult.getAccountId());
for (int i = 0; i < individuals.size(); i++) {
map.put("individualCustomer[" + i + "]", individuals.get(i).getCustomer().getDisplayName());
map.put("individualAccount[" + i + "]", individuals.get(i).getGlobalAccountNum());
map.put("individualAmmount[" + i + "]", individuals.get(i).getLoanAmount().toString());
}
} else {
loanResult = loanAccountServiceFacade.createLoan(loanAccount, questionGroups, null);
}
loanInfo = loanDao.findByGlobalAccountNum(loanResult.getGlobalAccountNum());
map.put("status", "success");
map.put("accountNum", loanInfo.getGlobalAccountNum());
map.put("GLIM", creationDetails.getGlim().toString());
map.put("customer", loanInfo.getCustomer().getDisplayName());
map.put("loanAmmount", loanInfo.getLoanAmount().toString());
map.put("noOfInstallments", loanInfo.getNoOfInstallments().toString());
map.put("externalId", loanInfo.getExternalId());
return map;
}
use of org.mifos.clientportfolio.newloan.applicationservice.CreateGlimLoanAccount in project head by mifos.
the class LoanAccountController method submitLoanApplication.
private LoanCreationResultDto submitLoanApplication(Integer accountState, LoanAccountFormBean formBean, LoanAccountQuestionGroupFormBean loanAccountQuestionGroupFormBean, LoanAccountCashFlow loanAccountCashFlow, CashFlowSummaryFormBean cashFlowSummaryFormBean, LoanScheduleFormBean loanScheduleFormBean) {
LocalDate disbursementDate = LoanCreationHelper.translateDisbursementDateToLocalDate(formBean);
RecurringSchedule recurringSchedule = LoanCreationHelper.determineRecurringSchedule(formBean);
List<CreateAccountFeeDto> accountFees = LoanCreationHelper.translateToAccountFeeDtos(formBean);
List<CreateAccountFeeDto> additionalAccountFees = LoanCreationHelper.translateToAdditionalAccountFeeDtos(formBean);
List<CreateAccountPenaltyDto> accountPenalties = LoanCreationHelper.translateToAccountPenaltyDtos(formBean);
accountFees.addAll(additionalAccountFees);
BigDecimal loanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
BigDecimal minAllowedLoanAmount = BigDecimal.valueOf(formBean.getMinAllowedAmount().doubleValue());
BigDecimal maxAllowedLoanAmount = BigDecimal.valueOf(formBean.getMaxAllowedAmount().doubleValue());
CreateLoanAccount loanAccountDetails = new CreateLoanAccount(formBean.getCustomerId(), formBean.getProductId(), accountState, loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount, formBean.getInterestRate().doubleValue(), disbursementDate, null, formBean.getNumberOfInstallments().intValue(), formBean.getMinNumberOfInstallments().intValue(), formBean.getMaxNumberOfInstallments().intValue(), formBean.getGraceDuration().intValue(), formBean.getFundId(), formBean.getLoanPurposeId(), formBean.getCollateralTypeId(), formBean.getCollateralNotes(), formBean.getExternalId(), formBean.isRepaymentScheduleIndependentOfCustomerMeeting(), recurringSchedule, accountFees, accountPenalties);
LoanCreationResultDto loanCreationResultDto = null;
if (formBean.isGlimApplicable()) {
List<GroupMemberAccountDto> memberAccounts = createGroupMemberAccounts(formBean);
BigDecimal totalLoanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
CreateGlimLoanAccount createGroupLoanAccount = new CreateGlimLoanAccount(memberAccounts, totalLoanAmount, loanAccountDetails);
loanCreationResultDto = loanAccountServiceFacade.createGroupLoanWithIndividualMonitoring(createGroupLoanAccount, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow);
} else {
if (formBean.isVariableInstallmentsAllowed()) {
List<DateTime> installmentDates = cashFlowSummaryFormBean.getInstallments();
List<Number> totalInstallmentAmounts = cashFlowSummaryFormBean.getInstallmentAmounts();
if (installmentDates.isEmpty()) {
installmentDates = loanScheduleFormBean.getInstallments();
totalInstallmentAmounts = loanScheduleFormBean.getInstallmentAmounts();
}
// api for creating loan with premade loan schedule
loanCreationResultDto = loanAccountServiceFacade.createLoan(loanAccountDetails, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow, installmentDates, totalInstallmentAmounts);
} else {
loanCreationResultDto = loanAccountServiceFacade.createLoan(loanAccountDetails, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow);
}
}
List<CommonsMultipartFile> formFiles = formBean.getFiles();
List<UploadedFileDto> filesMetadata = formBean.getFilesMetadata();
for (int i = 0; i < formFiles.size(); i++) {
if (formFiles.get(i).getSize() != 0) {
InputStream inputStream;
try {
inputStream = formFiles.get(i).getInputStream();
} catch (IOException e) {
throw new MifosRuntimeException();
}
UploadedFileDto fileMetadata = filesMetadata.get(i);
loanAccountServiceFacade.uploadFile(loanCreationResultDto.getAccountId(), inputStream, fileMetadata);
}
}
return loanCreationResultDto;
}
use of org.mifos.clientportfolio.newloan.applicationservice.CreateGlimLoanAccount in project head by mifos.
the class LoanAccountController method submitLoanWithBackdatedPaymentsApplication.
private LoanCreationResultDto submitLoanWithBackdatedPaymentsApplication(Integer accountState, LoanAccountFormBean formBean, LoanAccountQuestionGroupFormBean loanAccountQuestionGroupFormBean, LoanAccountCashFlow loanAccountCashFlow, CashFlowSummaryFormBean cashFlowSummaryFormBean, LoanScheduleFormBean loanScheduleFormBean) {
LocalDate disbursementDate = LoanCreationHelper.translateDisbursementDateToLocalDate(formBean);
RecurringSchedule recurringSchedule = LoanCreationHelper.determineRecurringSchedule(formBean);
List<CreateAccountFeeDto> accountFees = LoanCreationHelper.translateToAccountFeeDtos(formBean);
List<CreateAccountPenaltyDto> accountPenalties = LoanCreationHelper.translateToAccountPenaltyDtos(formBean);
List<CreateAccountFeeDto> additionalAccountFees = LoanCreationHelper.translateToAdditionalAccountFeeDtos(formBean);
accountFees.addAll(additionalAccountFees);
BigDecimal loanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
BigDecimal minAllowedLoanAmount = BigDecimal.valueOf(formBean.getMinAllowedAmount().doubleValue());
BigDecimal maxAllowedLoanAmount = BigDecimal.valueOf(formBean.getMaxAllowedAmount().doubleValue());
CreateLoanAccount loanAccountDetails = new CreateLoanAccount(formBean.getCustomerId(), formBean.getProductId(), accountState, loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount, formBean.getInterestRate().doubleValue(), disbursementDate, formBean.getDisbursalPaymentTypeId(), formBean.getNumberOfInstallments().intValue(), formBean.getMinNumberOfInstallments().intValue(), formBean.getMaxNumberOfInstallments().intValue(), formBean.getGraceDuration().intValue(), formBean.getFundId(), formBean.getLoanPurposeId(), formBean.getCollateralTypeId(), formBean.getCollateralNotes(), formBean.getExternalId(), formBean.isRepaymentScheduleIndependentOfCustomerMeeting(), recurringSchedule, accountFees, accountPenalties);
List<LoanPaymentDto> backdatedLoanPayments = new ArrayList<LoanPaymentDto>();
int index = 0;
List<Number> actualPaymentAmountDetails = cashFlowSummaryFormBean.getActualPaymentAmounts();
if (actualPaymentAmountDetails.isEmpty()) {
actualPaymentAmountDetails = loanScheduleFormBean.getActualPaymentAmounts();
}
for (Number actualPaymentAmount : actualPaymentAmountDetails) {
if (actualPaymentAmount.doubleValue() > 0) {
LocalDate transactionDate = new LocalDate(loanScheduleFormBean.getActualPaymentDates().get(index));
backdatedLoanPayments.add(new LoanPaymentDto(actualPaymentAmount.toString(), transactionDate, loanScheduleFormBean.getActualPaymentTypes().get(index), null));
}
index++;
}
LoanCreationResultDto loanCreationResultDto = null;
if (formBean.isGlimApplicable()) {
List<GroupMemberAccountDto> memberAccounts = createGroupMemberAccounts(formBean);
BigDecimal totalLoanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
CreateGlimLoanAccount createGroupLoanAccount = new CreateGlimLoanAccount(memberAccounts, totalLoanAmount, loanAccountDetails);
loanCreationResultDto = loanAccountServiceFacade.createBackdatedGroupLoanWithIndividualMonitoring(createGroupLoanAccount, backdatedLoanPayments, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow);
} else if (formBean.isVariableInstallmentsAllowed()) {
List<DateTime> installmentDates = cashFlowSummaryFormBean.getInstallments();
List<Number> installmentPrincipalAmounts = cashFlowSummaryFormBean.getInstallmentAmounts();
if (installmentDates.isEmpty()) {
installmentDates = loanScheduleFormBean.getInstallments();
installmentPrincipalAmounts = loanScheduleFormBean.getInstallmentAmounts();
}
// api for creating loan with premade loan schedule
loanCreationResultDto = loanAccountServiceFacade.createBackdatedLoan(loanAccountDetails, backdatedLoanPayments, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow, installmentDates, installmentPrincipalAmounts);
} else {
loanCreationResultDto = loanAccountServiceFacade.createBackdatedLoan(loanAccountDetails, backdatedLoanPayments, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow);
}
return loanCreationResultDto;
}
Aggregations