support submit new loan application and delete loan capabilities through api.
This commit is contained in:
@@ -1,16 +1,10 @@
|
||||
package org.mifosng.ui;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosng.data.EntityIdentifier;
|
||||
import org.mifosng.data.LoanProductData;
|
||||
import org.mifosng.data.LoanRepaymentData;
|
||||
import org.mifosng.data.LoanSchedule;
|
||||
import org.mifosng.data.command.AdjustLoanTransactionCommand;
|
||||
import org.mifosng.data.command.CalculateLoanScheduleCommand;
|
||||
import org.mifosng.data.command.LoanStateTransitionCommand;
|
||||
import org.mifosng.data.command.LoanTransactionCommand;
|
||||
import org.mifosng.data.command.SubmitLoanApplicationCommand;
|
||||
import org.mifosng.data.command.UndoLoanApprovalCommand;
|
||||
import org.mifosng.data.command.UndoLoanDisbursalCommand;
|
||||
import org.springframework.security.oauth.consumer.ProtectedResourceDetails;
|
||||
@@ -21,12 +15,6 @@ public interface CommonRestOperations {
|
||||
|
||||
void updateProtectedResource(ProtectedResourceDetails loadProtectedResourceDetailsById);
|
||||
|
||||
Collection<LoanProductData> retrieveAllLoanProducts();
|
||||
|
||||
LoanSchedule calculateLoanSchedule(CalculateLoanScheduleCommand command);
|
||||
|
||||
Long submitLoanApplication(SubmitLoanApplicationCommand command);
|
||||
|
||||
EntityIdentifier deleteLoan(Long loanId);
|
||||
|
||||
EntityIdentifier approveLoan(LoanStateTransitionCommand command);
|
||||
|
||||
-75
@@ -2,7 +2,6 @@ package org.mifosng.ui;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.mifosng.configuration.ApplicationConfigurationService;
|
||||
@@ -10,15 +9,10 @@ import org.mifosng.data.ClientList;
|
||||
import org.mifosng.data.EntityIdentifier;
|
||||
import org.mifosng.data.ErrorResponse;
|
||||
import org.mifosng.data.ErrorResponseList;
|
||||
import org.mifosng.data.LoanProductData;
|
||||
import org.mifosng.data.LoanProductList;
|
||||
import org.mifosng.data.LoanRepaymentData;
|
||||
import org.mifosng.data.LoanSchedule;
|
||||
import org.mifosng.data.command.AdjustLoanTransactionCommand;
|
||||
import org.mifosng.data.command.CalculateLoanScheduleCommand;
|
||||
import org.mifosng.data.command.LoanStateTransitionCommand;
|
||||
import org.mifosng.data.command.LoanTransactionCommand;
|
||||
import org.mifosng.data.command.SubmitLoanApplicationCommand;
|
||||
import org.mifosng.data.command.UndoLoanApprovalCommand;
|
||||
import org.mifosng.data.command.UndoLoanDisbursalCommand;
|
||||
import org.mifosng.ui.loanproduct.ClientValidationException;
|
||||
@@ -81,18 +75,6 @@ public class CommonRestOperationsImpl implements CommonRestOperations {
|
||||
return requestEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<LoanProductData> retrieveAllLoanProducts() {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/product/loan/all"));
|
||||
|
||||
ResponseEntity<LoanProductList> s = this.oauthRestServiceTemplate
|
||||
.exchange(restUri, HttpMethod.GET, emptyRequest(),
|
||||
LoanProductList.class);
|
||||
|
||||
return s.getBody().getProducts();
|
||||
}
|
||||
|
||||
private ErrorResponseList parseErrors(HttpStatusCodeException e) {
|
||||
|
||||
XStream xstream = new XStream();
|
||||
@@ -118,43 +100,6 @@ public class CommonRestOperationsImpl implements CommonRestOperations {
|
||||
return errorList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoanSchedule calculateLoanSchedule(
|
||||
final CalculateLoanScheduleCommand command) {
|
||||
try {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/loan/calculate"));
|
||||
|
||||
ResponseEntity<LoanSchedule> s = this.oauthRestServiceTemplate
|
||||
.exchange(restUri, HttpMethod.POST,
|
||||
calculateLoanRepaymentScheduleRequest(command),
|
||||
LoanSchedule.class);
|
||||
|
||||
return s.getBody();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
ErrorResponseList errorList = parseErrors(e);
|
||||
throw new ClientValidationException(errorList.getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long submitLoanApplication(final SubmitLoanApplicationCommand command) {
|
||||
try {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/loan/new"));
|
||||
|
||||
ResponseEntity<EntityIdentifier> s = this.oauthRestServiceTemplate
|
||||
.postForEntity(restUri,
|
||||
submitLoanApplicationRequest(command),
|
||||
EntityIdentifier.class);
|
||||
|
||||
return s.getBody().getEntityId();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
ErrorResponseList errorList = parseErrors(e);
|
||||
throw new ClientValidationException(errorList.getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityIdentifier deleteLoan(Long loanId) {
|
||||
try {
|
||||
@@ -437,24 +382,4 @@ public class CommonRestOperationsImpl implements CommonRestOperations {
|
||||
return new HttpEntity<LoanStateTransitionCommand>(command,
|
||||
requestHeaders);
|
||||
}
|
||||
|
||||
private HttpEntity<SubmitLoanApplicationCommand> submitLoanApplicationRequest(
|
||||
final SubmitLoanApplicationCommand command) {
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
requestHeaders.set("Accept", "application/xml");
|
||||
requestHeaders.set("Content-Type", "application/xml");
|
||||
|
||||
return new HttpEntity<SubmitLoanApplicationCommand>(command,
|
||||
requestHeaders);
|
||||
}
|
||||
|
||||
private HttpEntity<CalculateLoanScheduleCommand> calculateLoanRepaymentScheduleRequest(
|
||||
final CalculateLoanScheduleCommand command) {
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
requestHeaders.set("Accept", "application/xml");
|
||||
requestHeaders.set("Content-Type", "application/xml");
|
||||
|
||||
return new HttpEntity<CalculateLoanScheduleCommand>(command,
|
||||
requestHeaders);
|
||||
}
|
||||
}
|
||||
+4
@@ -13,6 +13,10 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
/**
|
||||
* @deprecated - some initial work around cashflow for CreoCore that can be deleted later.
|
||||
*/
|
||||
@Deprecated
|
||||
@Controller
|
||||
public class CashflowController {
|
||||
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
package org.mifosng.ui.loan;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.mifosng.data.EntityIdentifier;
|
||||
import org.mifosng.data.ErrorResponse;
|
||||
import org.mifosng.data.LoanSchedule;
|
||||
import org.mifosng.data.command.CalculateLoanScheduleCommand;
|
||||
import org.mifosng.data.command.SubmitLoanApplicationCommand;
|
||||
import org.mifosng.ui.CommonRestOperations;
|
||||
import org.mifosng.ui.loanproduct.ClientValidationException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
public class LoanController {
|
||||
|
||||
private final CommonRestOperations commonRestOperations;
|
||||
|
||||
@Autowired
|
||||
public LoanController(final CommonRestOperations commonRestOperations) {
|
||||
this.commonRestOperations = commonRestOperations;
|
||||
}
|
||||
|
||||
@ExceptionHandler(AccessDeniedException.class)
|
||||
public String accessDeniedException() {
|
||||
return "unAuthorizedAction";
|
||||
}
|
||||
|
||||
@ExceptionHandler(ClientValidationException.class)
|
||||
public @ResponseBody Collection<ErrorResponse> validationException(ClientValidationException ex, HttpServletResponse response) {
|
||||
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
response.setContentType("application/json");
|
||||
|
||||
return ex.getValidationErrors();
|
||||
}
|
||||
|
||||
private LocalDate parseStringToLocalDate(String eventDate, String dateFieldIdentifier) {
|
||||
LocalDate eventLocalDate = null;
|
||||
if (StringUtils.isNotBlank(eventDate)) {
|
||||
try {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
eventLocalDate = DateTimeFormat.forPattern("dd MMMM yyyy").withLocale(locale).parseLocalDate(eventDate.toLowerCase(locale));
|
||||
} catch (IllegalArgumentException e) {
|
||||
List<ErrorResponse> validationErrors = new ArrayList<ErrorResponse>();
|
||||
validationErrors.add(new ErrorResponse("validation.msg.invalid.date.format", dateFieldIdentifier, eventDate));
|
||||
throw new ClientValidationException(validationErrors);
|
||||
}
|
||||
}
|
||||
|
||||
return eventLocalDate;
|
||||
}
|
||||
|
||||
private BigDecimal parseStringToBigDecimal(String source) {
|
||||
try {
|
||||
BigDecimal number = null;
|
||||
|
||||
if (StringUtils.isNotBlank(source)) {
|
||||
String sourceWithoutSpaces = source.replaceAll(" ", "");
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
NumberFormat format = NumberFormat.getNumberInstance(locale);
|
||||
Number parsedNumber = format.parse(sourceWithoutSpaces);
|
||||
number = BigDecimal.valueOf(Double.valueOf(parsedNumber
|
||||
.doubleValue()));
|
||||
}
|
||||
|
||||
return number;
|
||||
} catch (ParseException e) {
|
||||
List<ErrorResponse> validationErrors = new ArrayList<ErrorResponse>();
|
||||
validationErrors.add(new ErrorResponse("validation.msg.invalid.number.format", "amount", source));
|
||||
throw new ClientValidationException(validationErrors);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/x-www-form-urlencoded", produces="application/json", value = "/portfolio/client/{clientId}/loan/new", method = RequestMethod.POST)
|
||||
public @ResponseBody EntityIdentifier submitNewLoanApplication(
|
||||
@RequestParam(value="clientId", required=false) Long applicantId,
|
||||
@RequestParam(value="productId", required=false) Long productId,
|
||||
@RequestParam(value="submittedOnDate", required=false) String submittedOnDateStr,
|
||||
@RequestParam(value="submittedOnNote", required=false) String submittedOnNote,
|
||||
@RequestParam(value="currencyCode", required=false) String currencyCode,
|
||||
@RequestParam(value="digitsAfterDecimal", required=false) Integer digitsAfterDecimal,
|
||||
@RequestParam(value="principalMoney", required=false) String principalMoney,
|
||||
@RequestParam(value="repaidEvery", required=false) Integer repaymentEvery,
|
||||
@RequestParam(value="selectedRepaymentFrequencyOption", required=false) Integer repaymentFrequency,
|
||||
@RequestParam(value="numberOfRepayments", required=false) Integer numberOfRepayments,
|
||||
@RequestParam(value="selectedAmortizationMethodOption", required=false) Integer amortizationMethod,
|
||||
@RequestParam(value="inArrearsTolerance", required=false) String inArrearsTolerance,
|
||||
@RequestParam(value="nominalInterestRate", required=false) String nominalInterestRate,
|
||||
@RequestParam(value="selectedInterestFrequencyOption", required=false) Integer interestRateFrequencyMethod,
|
||||
@RequestParam(value="selectedInterestMethodOption", required=false) Integer interestMethod,
|
||||
@RequestParam(value="interestRateCalculatedInPeriod", required=false) Integer interestRateCalculatedInPeriod,
|
||||
@RequestParam(value="expectedDisbursementDate", required=false) String expectedDisbursementDateStr,
|
||||
@RequestParam(value="repaymentsStartingFromDate", required=false) String repaymentsStartingFromDateStr,
|
||||
@RequestParam(value="interestCalculatedFromDate", required=false) String interestCalculatedFromDateStr
|
||||
) {
|
||||
|
||||
final LocalDate submittedOnDate = parseStringToLocalDate(submittedOnDateStr, "submittedOnDate");
|
||||
final Number toleranceAmount = parseStringToBigDecimal(inArrearsTolerance);
|
||||
|
||||
final Number principal = parseStringToBigDecimal(principalMoney);
|
||||
final Number interestRatePerPeriod = parseStringToBigDecimal(nominalInterestRate);
|
||||
final boolean flexibleRepaymentSchedule = false;
|
||||
final boolean interestRebateAllowed = false;
|
||||
|
||||
final LocalDate expectedDisbursementDate = parseStringToLocalDate(expectedDisbursementDateStr, "expectedDisbursementDate");
|
||||
final LocalDate repaymentsStartingFromDate = parseStringToLocalDate(repaymentsStartingFromDateStr, "repaymentsStartingFromDate");
|
||||
final LocalDate interestCalculatedFromDate = parseStringToLocalDate(interestCalculatedFromDateStr, "interestCalculatedFromDate");
|
||||
|
||||
CalculateLoanScheduleCommand calculateLoanScheduleCommand = new CalculateLoanScheduleCommand(currencyCode, digitsAfterDecimal, principal, interestRatePerPeriod,
|
||||
interestRateFrequencyMethod, interestMethod, interestRateCalculatedInPeriod, repaymentEvery, repaymentFrequency, numberOfRepayments, amortizationMethod,
|
||||
flexibleRepaymentSchedule, interestRebateAllowed, expectedDisbursementDate, repaymentsStartingFromDate, interestCalculatedFromDate);
|
||||
|
||||
LoanSchedule loanSchedule = this.commonRestOperations.calculateLoanSchedule(calculateLoanScheduleCommand);
|
||||
|
||||
SubmitLoanApplicationCommand command = new SubmitLoanApplicationCommand(applicantId, productId,
|
||||
submittedOnDate, submittedOnNote, expectedDisbursementDate, repaymentsStartingFromDate, interestCalculatedFromDate,
|
||||
loanSchedule, currencyCode, digitsAfterDecimal, principal,
|
||||
interestRatePerPeriod, interestRateFrequencyMethod, interestMethod, interestRateCalculatedInPeriod,
|
||||
repaymentEvery, repaymentFrequency, numberOfRepayments, amortizationMethod,
|
||||
toleranceAmount, flexibleRepaymentSchedule, interestRebateAllowed);
|
||||
|
||||
Long identifier = this.commonRestOperations.submitLoanApplication(command);
|
||||
|
||||
return new EntityIdentifier(identifier);
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/x-www-form-urlencoded", produces="application/json", value = "/portfolio/loanschedule/calculate", method = RequestMethod.POST)
|
||||
public @ResponseBody LoanSchedule calculateLoanSchedule(
|
||||
@RequestParam(value="currencyCode", required=false) String currencyCode,
|
||||
@RequestParam(value="digitsAfterDecimal", required=false) Integer digitsAfterDecimal,
|
||||
@RequestParam(value="principalMoney", required=false) String principalMoney,
|
||||
@RequestParam(value="repaidEvery", required=false) Integer repaymentEvery,
|
||||
@RequestParam(value="selectedRepaymentFrequencyOption", required=false) Integer repaymentFrequency,
|
||||
@RequestParam(value="numberOfRepayments", required=false) Integer numberOfRepayments,
|
||||
@RequestParam(value="selectedAmortizationMethodOption", required=false) Integer amortizationMethod,
|
||||
@RequestParam(value="nominalInterestRate", required=false) String nominalInterestRate,
|
||||
@RequestParam(value="selectedInterestFrequencyOption", required=false) Integer interestRateFrequencyMethod,
|
||||
@RequestParam(value="selectedInterestMethodOption", required=false) Integer interestMethod,
|
||||
@RequestParam(value="interestRateCalculatedInPeriod", required=false) Integer interestRateCalculatedInPeriod,
|
||||
@RequestParam(value="expectedDisbursementDate", required=false) String expectedDisbursementDateStr,
|
||||
@RequestParam(value="repaymentsStartingFromDate", required=false) String repaymentsStartingFromDateStr,
|
||||
@RequestParam(value="interestCalculatedFromDate", required=false) String interestCalculatedFromDateStr
|
||||
) {
|
||||
|
||||
final Number principal = parseStringToBigDecimal(principalMoney);
|
||||
final Number interestRatePerPeriod = parseStringToBigDecimal(nominalInterestRate);
|
||||
final boolean flexibleRepaymentSchedule = false;
|
||||
final boolean interestRebateAllowed = false;
|
||||
final LocalDate expectedDisbursementDate = parseStringToLocalDate(expectedDisbursementDateStr, "expectedDisbursementDate");
|
||||
final LocalDate repaymentsStartingFromDate = parseStringToLocalDate(repaymentsStartingFromDateStr, "repaymentsStartingFromDate");
|
||||
final LocalDate interestCalculatedFromDate = parseStringToLocalDate(interestCalculatedFromDateStr, "interestCalculatedFromDate");
|
||||
|
||||
CalculateLoanScheduleCommand command = new CalculateLoanScheduleCommand(currencyCode, digitsAfterDecimal, principal, interestRatePerPeriod,
|
||||
interestRateFrequencyMethod, interestMethod, interestRateCalculatedInPeriod, repaymentEvery, repaymentFrequency, numberOfRepayments, amortizationMethod,
|
||||
flexibleRepaymentSchedule, interestRebateAllowed, expectedDisbursementDate, repaymentsStartingFromDate, interestCalculatedFromDate);
|
||||
|
||||
return this.commonRestOperations.calculateLoanSchedule(command);
|
||||
}
|
||||
}
|
||||
+91
-88
@@ -206,7 +206,7 @@ $(document).ready(function() {
|
||||
return o;
|
||||
};
|
||||
|
||||
function popupConfirmationDialogAndPost(url, titleCode, width, height, tabIndex, redirectUrl) {
|
||||
function popupConfirmationDialogAndPost(url, submitType, titleCode, width, height, tabIndex, redirectUrl) {
|
||||
var dialogDiv = $("<div id='dialog-form'><div id='formerrors'></div>" + jQuery.i18n.prop('text.confirmation.required') + "</div>");
|
||||
|
||||
var confirmButton = jQuery.i18n.prop('dialog.button.confirm');
|
||||
@@ -216,7 +216,9 @@ $(document).ready(function() {
|
||||
buttonsOpts[confirmButton] = function() {
|
||||
var jqxhr = $.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
type: submitType,
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
dialogDiv.dialog("close");
|
||||
if (tabIndex > 0) {
|
||||
@@ -322,70 +324,70 @@ $(document).ready(function() {
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
console.log(data);
|
||||
var formHtml = $(templateSelector).render(data);
|
||||
|
||||
dialogDiv.append(formHtml);
|
||||
|
||||
var saveButton = jQuery.i18n.prop('dialog.button.save');
|
||||
var cancelButton = jQuery.i18n.prop('dialog.button.cancel');
|
||||
|
||||
var buttonsOpts = {};
|
||||
buttonsOpts[saveButton] = function() {
|
||||
console.log(data);
|
||||
var formHtml = $(templateSelector).render(data);
|
||||
|
||||
$('#notSelectedItems option').each(function(i) {
|
||||
dialogDiv.append(formHtml);
|
||||
|
||||
var saveButton = jQuery.i18n.prop('dialog.button.save');
|
||||
var cancelButton = jQuery.i18n.prop('dialog.button.cancel');
|
||||
|
||||
var buttonsOpts = {};
|
||||
buttonsOpts[saveButton] = function() {
|
||||
|
||||
$('#notSelectedItems option').each(function(i) {
|
||||
$(this).attr("selected", "selected");
|
||||
});
|
||||
|
||||
$('#selectedItems option').each(function(i) {
|
||||
$(this).attr("selected", "selected");
|
||||
});
|
||||
|
||||
$('#selectedItems option').each(function(i) {
|
||||
$(this).attr("selected", "selected");
|
||||
});
|
||||
|
||||
var newFormData = JSON.stringify($('#entityform').serializeObject());
|
||||
console.log(newFormData);
|
||||
|
||||
var jqxhr = $.ajax({
|
||||
url: postUrl,
|
||||
type: submitType,
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
data: newFormData,
|
||||
success: saveSuccessFunction,
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
buttonsOpts[cancelButton] = function() {$(this).dialog( "close" );};
|
||||
|
||||
dialogDiv.dialog({
|
||||
title: jQuery.i18n.prop(titleCode),
|
||||
width: width,
|
||||
height: height,
|
||||
modal: true,
|
||||
buttons: buttonsOpts,
|
||||
close: function() {
|
||||
// if i dont do this, theres a problem with errors being appended to dialog view second time round
|
||||
$(this).remove();
|
||||
},
|
||||
open: function (event, ui) {
|
||||
|
||||
$('#add').click(function() {
|
||||
return !$('#notSelectedItems option:selected').remove().appendTo('#selectedItems');
|
||||
});
|
||||
|
||||
$('#remove').click(function() {
|
||||
return !$('#selectedItems option:selected').remove().appendTo('#notSelectedItems');
|
||||
});
|
||||
|
||||
$('.datepickerfield').datepicker({constrainInput: true, maxDate: 0, dateFormat: 'dd MM yy'});
|
||||
|
||||
$("#entityform textarea").first().focus();
|
||||
$('#entityform input').first().focus();
|
||||
}
|
||||
}).dialog('open');
|
||||
}
|
||||
});
|
||||
|
||||
var newFormData = JSON.stringify($('#entityform').serializeObject());
|
||||
console.log(newFormData);
|
||||
|
||||
var jqxhr = $.ajax({
|
||||
url: postUrl,
|
||||
type: submitType,
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
data: newFormData,
|
||||
success: saveSuccessFunction,
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
buttonsOpts[cancelButton] = function() {$(this).dialog( "close" );};
|
||||
|
||||
dialogDiv.dialog({
|
||||
title: jQuery.i18n.prop(titleCode),
|
||||
width: width,
|
||||
height: height,
|
||||
modal: true,
|
||||
buttons: buttonsOpts,
|
||||
close: function() {
|
||||
// if i dont do this, theres a problem with errors being appended to dialog view second time round
|
||||
$(this).remove();
|
||||
},
|
||||
open: function (event, ui) {
|
||||
|
||||
$('#add').click(function() {
|
||||
return !$('#notSelectedItems option:selected').remove().appendTo('#selectedItems');
|
||||
});
|
||||
|
||||
$('#remove').click(function() {
|
||||
return !$('#selectedItems option:selected').remove().appendTo('#notSelectedItems');
|
||||
});
|
||||
|
||||
$('.datepickerfield').datepicker({constrainInput: true, maxDate: 0, dateFormat: 'dd MM yy'});
|
||||
|
||||
$("#entityform textarea").first().focus();
|
||||
$('#entityform input').first().focus();
|
||||
}
|
||||
}).dialog('open');
|
||||
}
|
||||
});
|
||||
|
||||
jqxhr.error(function(jqXHR, textStatus, errorThrown) {
|
||||
@@ -435,19 +437,6 @@ $(document).ready(function() {
|
||||
// retrieve accounts summary info
|
||||
refreshLoanSummaryInfo();
|
||||
|
||||
// retrieve additional info
|
||||
var additionalFieldsParams = {
|
||||
url: "http://localhost:8080/mifosng-provider/",
|
||||
datasetType: "portfolio_client",
|
||||
datasetPKValue: data.id,
|
||||
datasetTypeDiv: "clientadditionaldata",
|
||||
headingPrefix: "",
|
||||
headingClass: "",
|
||||
labelClass: "longrowlabel",
|
||||
valueClass: "rowvalue"
|
||||
};
|
||||
jQuery.stretchyData.displayAllExtraData(additionalFieldsParams);
|
||||
|
||||
// bind click listeners to buttons.
|
||||
$('.casflowbtn').button().click(function(e) {
|
||||
var linkId = this.id;
|
||||
@@ -489,24 +478,25 @@ $(document).ready(function() {
|
||||
|
||||
refreshNoteWidget();
|
||||
|
||||
} else {
|
||||
|
||||
var tableHtml = $("#loanDataTabTemplate").render(data);
|
||||
|
||||
var currentTab = $("#newtabs").children(".ui-tabs-panel").not(".ui-tabs-hide");
|
||||
currentTab.html(tableHtml);
|
||||
|
||||
// retrieve additional info
|
||||
var additionalFieldsParams = {
|
||||
url: "http://localhost:8080/mifosng-provider/",
|
||||
datasetType: "portfolio_loan",
|
||||
datasetType: "portfolio_client",
|
||||
datasetPKValue: data.id,
|
||||
datasetTypeDiv: "loanadditionaldata" + data.id,
|
||||
datasetTypeDiv: "clientadditionaldata",
|
||||
headingPrefix: "",
|
||||
headingClass: "",
|
||||
labelClass: "longrowlabel",
|
||||
valueClass: "rowvalue"
|
||||
};
|
||||
jQuery.stretchyData.displayAllExtraData(additionalFieldsParams);
|
||||
|
||||
} else {
|
||||
|
||||
var tableHtml = $("#loanDataTabTemplate").render(data);
|
||||
|
||||
var currentTab = $("#newtabs").children(".ui-tabs-panel").not(".ui-tabs-hide");
|
||||
currentTab.html(tableHtml);
|
||||
|
||||
var curTabID = currentTab.prop("id")
|
||||
|
||||
@@ -560,13 +550,13 @@ $(document).ready(function() {
|
||||
|
||||
var linkId = this.id;
|
||||
var loanId = linkId.replace("deletebtn", "");
|
||||
var url = '${rootContext}portfolio/loan/' + loanId + '/delete';
|
||||
var url = 'http://localhost:8080/mifosng-provider/api/v1/loans/' + loanId;
|
||||
var width = 400;
|
||||
var height = 225;
|
||||
|
||||
var redirectUrl = '${clientUrl}';
|
||||
|
||||
popupConfirmationDialogAndPost(url, 'dialog.title.confirmation.required', width, height, 0, redirectUrl);
|
||||
popupConfirmationDialogAndPost(url, 'DELETE', 'dialog.title.confirmation.required', width, height, 0, redirectUrl);
|
||||
e.preventDefault();
|
||||
});
|
||||
$('button.deleteloan span').text(jQuery.i18n.prop('dialog.button.delete.loan'));
|
||||
@@ -660,6 +650,19 @@ $(document).ready(function() {
|
||||
var curTabID = curTab.prop("id")
|
||||
}
|
||||
});
|
||||
|
||||
// additional data
|
||||
var additionalFieldsParams = {
|
||||
url: "http://localhost:8080/mifosng-provider/",
|
||||
datasetType: "portfolio_loan",
|
||||
datasetPKValue: data.id,
|
||||
datasetTypeDiv: "loanadditionaldata" + data.id,
|
||||
headingPrefix: "",
|
||||
headingClass: "",
|
||||
labelClass: "longrowlabel",
|
||||
valueClass: "rowvalue"
|
||||
};
|
||||
jQuery.stretchyData.displayAllExtraData(additionalFieldsParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+31
-26
@@ -173,13 +173,13 @@ $.views.registerHelpers({
|
||||
};
|
||||
|
||||
function calculateAnnualPercentageRate() {
|
||||
var periodInterestRate = parseFloat($('#nominalInterestRate').val());
|
||||
var periodInterestRate = parseFloat($('#interestRatePerPeriodFormatted').val());
|
||||
if (isNaN(periodInterestRate)) {
|
||||
periodInterestRate = 0;
|
||||
}
|
||||
|
||||
var periodsInYear = 12;
|
||||
var periodType = $('#selectedInterestFrequencyOption').val();
|
||||
var periodType = $('#interestRateFrequencyMethod').val();
|
||||
if (periodType == 3) {
|
||||
periodsInYear = 1;
|
||||
} else if (periodType == 2) {
|
||||
@@ -220,15 +220,15 @@ $.views.registerHelpers({
|
||||
calculateLoanSchedule();
|
||||
|
||||
// change detection
|
||||
$('#principalMoney').change(function() {
|
||||
$('#principalFormatted').change(function() {
|
||||
calculateLoanSchedule();
|
||||
});
|
||||
|
||||
$('#repaidEvery').change(function() {
|
||||
$('#repaymentEvery').change(function() {
|
||||
calculateLoanSchedule();
|
||||
});
|
||||
|
||||
$('#selectedRepaymentFrequencyOption').change(function() {
|
||||
$('#repaymentFrequency').change(function() {
|
||||
calculateLoanSchedule();
|
||||
});
|
||||
|
||||
@@ -236,37 +236,37 @@ $.views.registerHelpers({
|
||||
calculateLoanSchedule();
|
||||
});
|
||||
|
||||
$('#expectedDisbursementDate').change(function() {
|
||||
$('#expectedDisbursementDateFormatted').change(function() {
|
||||
calculateLoanSchedule();
|
||||
});
|
||||
|
||||
$('#repaymentsStartingFromDate').change(function() {
|
||||
$('#repaymentsStartingFromDateFormatted').change(function() {
|
||||
calculateLoanSchedule();
|
||||
});
|
||||
|
||||
$('#nominalInterestRate').change(function() {
|
||||
$('#interestRatePerPeriodFormatted').change(function() {
|
||||
calculateAnnualPercentageRate();
|
||||
calculateLoanSchedule();
|
||||
});
|
||||
|
||||
$('#selectedInterestFrequencyOption').change(function() {
|
||||
$('#interestRateFrequencyMethod').change(function() {
|
||||
calculateAnnualPercentageRate();
|
||||
calculateLoanSchedule();
|
||||
});
|
||||
|
||||
$('#selectedAmortizationMethodOption').change(function() {
|
||||
$('#amortizationMethod').change(function() {
|
||||
calculateLoanSchedule();
|
||||
});
|
||||
|
||||
$('#selectedInterestMethodOption').change(function() {
|
||||
$('#interestMethod').change(function() {
|
||||
calculateLoanSchedule();
|
||||
});
|
||||
|
||||
$('#interestRateCalculatedInPeriod').change(function() {
|
||||
$('#interestCalculationPeriodMethod').change(function() {
|
||||
calculateLoanSchedule();
|
||||
});
|
||||
|
||||
$('#interestCalculatedFromDate').change(function() {
|
||||
$('#interestCalculatedFromDateFormatted').change(function() {
|
||||
calculateLoanSchedule();
|
||||
});
|
||||
|
||||
@@ -291,14 +291,17 @@ $.views.registerHelpers({
|
||||
}
|
||||
|
||||
function calculateLoanSchedule() {
|
||||
var calculateLoanScheduleurl = '${rootContext}portfolio/loanschedule/calculate';
|
||||
var calculateLoanScheduleurl = 'http://localhost:8080/mifosng-provider/api/v1/loans?command=calculateLoanSchedule';
|
||||
|
||||
var form_data = $('#entityform').serialize();
|
||||
|
||||
var newFormData = JSON.stringify($('#entityform').serializeObject());
|
||||
console.log(newFormData);
|
||||
|
||||
var jqxhr2 = $.ajax({
|
||||
url: calculateLoanScheduleurl,
|
||||
type: 'POST',
|
||||
data: form_data,
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
data: newFormData,
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
removeErrors("#formerrors");
|
||||
var loanScheduleHtml = $("#newLoanScheduleTemplate").render(data);
|
||||
@@ -313,17 +316,20 @@ $.views.registerHelpers({
|
||||
}
|
||||
|
||||
function submitLoanApplication() {
|
||||
var submitLoanApplicationUrl = '${rootContext}portfolio/client/${clientId}/loan/new';
|
||||
var submitLoanApplicationUrl = 'http://localhost:8080/mifosng-provider/api/v1/loans';
|
||||
|
||||
var form_data = $('#entityform').serialize();
|
||||
|
||||
var newFormData = JSON.stringify($('#entityform').serializeObject());
|
||||
console.log(newFormData);
|
||||
|
||||
var jqxhr2 = $.ajax({
|
||||
url: submitLoanApplicationUrl,
|
||||
type: 'POST',
|
||||
data: form_data,
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
data: newFormData,
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
var url = '${rootContext}portfolio/client/${clientId}';
|
||||
window.location.href = url;
|
||||
var localAppUrlToSwitchToClientPage = '${rootContext}portfolio/client/${clientId}';
|
||||
window.location.href = localAppUrlToSwitchToClientPage;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -331,9 +337,8 @@ $.views.registerHelpers({
|
||||
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// on page load
|
||||
var jqxhr = $.ajax({
|
||||
url: 'http://localhost:8080/mifosng-provider/api/v1/loans/template?clientId=${clientId}',
|
||||
type: 'GET',
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
<form id="entityform">
|
||||
<div id="formerrors"></div>
|
||||
|
||||
<input type="hidden" id="clientId" name="clientId" value="{{=clientId}}" />
|
||||
<input type="hidden" id="applicantId" name="applicantId" value="{{=clientId}}" />
|
||||
<input type="hidden" id="currencyCode" name="currencyCode" value="{{=selectedProduct.principalMoney.currencyCode}}" />
|
||||
<input type="hidden" id="digitsAfterDecimal" name="digitsAfterDecimal" value="{{=$ctx.number(selectedProduct.principalMoney.currencyDigitsAfterDecimal)}}" />
|
||||
|
||||
@@ -103,16 +103,16 @@
|
||||
<tr>
|
||||
<td><spring:message code="form.label.loan.product.loan.amount"/></td>
|
||||
<td>
|
||||
<input id="principalMoney" name="principalMoney" title="" type="text" value="{{=$ctx.money(selectedProduct.principalMoney)}}" style="width: 125px;" />
|
||||
<input id="principalMoney.currencyCode" name="principalMoney.currencyCode" title="" type="text" value="{{=selectedProduct.principalMoney.displaySymbol}}" style="width: 40px;" disabled="disabled" />
|
||||
<input id="principalFormatted" name="principalFormatted" title="" type="text" value="{{=$ctx.money(selectedProduct.principalMoney)}}" style="width: 125px;" />
|
||||
<input id="principalCurrencyCode" name="principalCurrencyCode" title="" type="text" value="{{=selectedProduct.principalMoney.displaySymbol}}" style="width: 40px;" disabled="disabled" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><spring:message code="form.label.loan.product.repaidevery"/></td>
|
||||
<td>
|
||||
<input id="repaidEvery" name="repaidEvery" title="" type="text" value="{{=$ctx.number(selectedProduct.repaidEvery)}}" style="width: 50px;" />
|
||||
<input id="repaymentEvery" name="repaymentEvery" title="" type="text" value="{{=$ctx.number(selectedProduct.repaidEvery)}}" style="width: 50px;" />
|
||||
|
||||
<select name="selectedRepaymentFrequencyOption" id="selectedRepaymentFrequencyOption" title="" style="width: 121px;">
|
||||
<select name="repaymentFrequency" id="repaymentFrequency" title="" style="width: 121px;">
|
||||
{{#each selectedProduct.repaymentFrequencyOptions}}
|
||||
{{#if $ctx.number($parent.parent.data.selectedProduct.repaymentPeriodFrequency)===$ctx.number(id)}}
|
||||
<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
|
||||
@@ -149,9 +149,9 @@
|
||||
<tr>
|
||||
<td><spring:message code="form.label.loan.product.nominal.interestrate"/></td>
|
||||
<td>
|
||||
<input id="nominalInterestRate" name="nominalInterestRate" title="" type="text" value="{{=$ctx.decimal(selectedProduct.interestRatePerPeriod, 4)}}" style="width: 60px;" />
|
||||
<input id="interestRatePerPeriodFormatted" name="interestRatePerPeriodFormatted" title="" type="text" value="{{=$ctx.decimal(selectedProduct.interestRatePerPeriod, 4)}}" style="width: 60px;" />
|
||||
|
||||
<select name="selectedInterestFrequencyOption" id="selectedInterestFrequencyOption" title="" style="width: 115px;">
|
||||
<select name="interestRateFrequencyMethod" id="interestRateFrequencyMethod" title="" style="width: 115px;">
|
||||
{{#each selectedProduct.interestFrequencyOptions}}
|
||||
{{#if $ctx.number($parent.parent.data.selectedProduct.interestRatePeriod)===$ctx.number(id)}}
|
||||
<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
|
||||
@@ -171,7 +171,7 @@
|
||||
<tr>
|
||||
<td><spring:message code="form.label.loan.product.amortization"/></td>
|
||||
<td>
|
||||
<select name="selectedAmortizationMethodOption" id="selectedAmortizationMethodOption" title="" style="width: 178px;">
|
||||
<select name="amortizationMethod" id="amortizationMethod" title="" style="width: 178px;">
|
||||
{{#each selectedProduct.possibleAmortizationOptions}}
|
||||
{{#if $ctx.number($parent.parent.data.selectedProduct.amortizationMethod)===$ctx.number(id)}}
|
||||
<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
|
||||
@@ -185,7 +185,7 @@
|
||||
<tr>
|
||||
<td><spring:message code="form.label.loan.product.interest.method"/></td>
|
||||
<td>
|
||||
<select name="selectedInterestMethodOption" id="selectedInterestMethodOption" title="" style="width: 180px;">
|
||||
<select name="interestMethod" id="interestMethod" title="" style="width: 180px;">
|
||||
{{#each selectedProduct.possibleInterestOptions}}
|
||||
{{#if $ctx.number($parent.parent.data.selectedProduct.interestMethod)===$ctx.number(id)}}
|
||||
<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
|
||||
@@ -199,7 +199,7 @@
|
||||
<tr>
|
||||
<td><spring:message code="form.label.loan.product.interest.rate.calcutated.in.period"/></td>
|
||||
<td>
|
||||
<select id="interestRateCalculatedInPeriod" name="interestRateCalculatedInPeriod" title="" style="width: 220px;">
|
||||
<select id="interestCalculationPeriodMethod" name="interestCalculationPeriodMethod" title="" style="width: 220px;">
|
||||
{{#each selectedProduct.possibleInterestRateCalculatedInPeriodOptions}}
|
||||
{{#if $ctx.number($parent.parent.data.selectedProduct.interestRateCalculatedInPeriod)===$ctx.number(id)}}
|
||||
<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
|
||||
@@ -213,14 +213,14 @@
|
||||
<tr>
|
||||
<td><spring:message code="form.label.loan.interest.charged.from"/></td>
|
||||
<td>
|
||||
<input id="interestCalculatedFromDate" name="interestCalculatedFromDate" title="" type="text" class="datepickerfield" value="{{=$ctx.globalDate(interestCalculatedFromDate)}}" style="width:172px;"/>
|
||||
<input id="interestCalculatedFromDateFormatted" name="interestCalculatedFromDateFormatted" title="" type="text" class="datepickerfield" value="{{=$ctx.globalDate(interestCalculatedFromDate)}}" style="width:172px;"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><spring:message code="form.label.loan.product.arrears.tolerance"/></td>
|
||||
<td>
|
||||
<input id="inArrearsTolerance" name="inArrearsTolerance" title="" type="text" value="{{=$ctx.money(selectedProduct.inArrearsTolerance)}}" style="width: 125px;" />
|
||||
<input id="inArrearsTolerance.currencyCode" name="inArrearsTolerance.currencyCode" title="" type="text" value="{{=selectedProduct.inArrearsTolerance.displaySymbol}}" style="width: 40px;" disabled="disabled" />
|
||||
<input id="inArrearsToleranceAmountFormatted" name="inArrearsToleranceAmountFormatted" title="" type="text" value="{{=$ctx.money(selectedProduct.inArrearsTolerance)}}" style="width: 125px;" />
|
||||
<input id="inArrearsCurrencyCode" name="inArrearsCurrencyCode" title="" type="text" value="{{=selectedProduct.inArrearsTolerance.displaySymbol}}" style="width: 40px;" disabled="disabled" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user