add state transitions around loan to api.
This commit is contained in:
@@ -5,7 +5,6 @@ import org.mifosng.data.LoanRepaymentData;
|
||||
import org.mifosng.data.command.AdjustLoanTransactionCommand;
|
||||
import org.mifosng.data.command.LoanStateTransitionCommand;
|
||||
import org.mifosng.data.command.LoanTransactionCommand;
|
||||
import org.mifosng.data.command.UndoLoanApprovalCommand;
|
||||
import org.mifosng.data.command.UndoLoanDisbursalCommand;
|
||||
import org.springframework.security.oauth.consumer.ProtectedResourceDetails;
|
||||
|
||||
@@ -15,16 +14,6 @@ public interface CommonRestOperations {
|
||||
|
||||
void updateProtectedResource(ProtectedResourceDetails loadProtectedResourceDetailsById);
|
||||
|
||||
EntityIdentifier deleteLoan(Long loanId);
|
||||
|
||||
EntityIdentifier approveLoan(LoanStateTransitionCommand command);
|
||||
|
||||
EntityIdentifier undoLoanApproval(UndoLoanApprovalCommand command);
|
||||
|
||||
EntityIdentifier rejectLoan(LoanStateTransitionCommand command);
|
||||
|
||||
EntityIdentifier withdrawLoan(LoanStateTransitionCommand command);
|
||||
|
||||
EntityIdentifier disburseLoan(LoanStateTransitionCommand command);
|
||||
|
||||
EntityIdentifier undloLoanDisbursal(UndoLoanDisbursalCommand command);
|
||||
|
||||
+1
-91
@@ -99,97 +99,7 @@ public class CommonRestOperationsImpl implements CommonRestOperations {
|
||||
}
|
||||
return errorList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityIdentifier deleteLoan(Long loanId) {
|
||||
try {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/loan/").concat(loanId.toString()));
|
||||
|
||||
ResponseEntity<EntityIdentifier> s = this.oauthRestServiceTemplate
|
||||
.exchange(restUri, HttpMethod.DELETE, null,
|
||||
EntityIdentifier.class);
|
||||
|
||||
return s.getBody();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
ErrorResponseList errorList = parseErrors(e);
|
||||
throw new ClientValidationException(errorList.getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityIdentifier approveLoan(final LoanStateTransitionCommand command) {
|
||||
try {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/loan/approve"));
|
||||
|
||||
ResponseEntity<EntityIdentifier> s = this.oauthRestServiceTemplate
|
||||
.postForEntity(restUri,
|
||||
loanStateTransitionApplicationRequest(command),
|
||||
EntityIdentifier.class);
|
||||
|
||||
return s.getBody();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
ErrorResponseList errorList = parseErrors(e);
|
||||
throw new ClientValidationException(errorList.getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityIdentifier undoLoanApproval(
|
||||
final UndoLoanApprovalCommand command) {
|
||||
try {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/loan/undoapproval"));
|
||||
|
||||
ResponseEntity<EntityIdentifier> s = this.oauthRestServiceTemplate
|
||||
.postForEntity(restUri, undoLoanApprovalRequest(command),
|
||||
EntityIdentifier.class);
|
||||
|
||||
return s.getBody();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
ErrorResponseList errorList = parseErrors(e);
|
||||
throw new ClientValidationException(errorList.getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityIdentifier rejectLoan(final LoanStateTransitionCommand command) {
|
||||
try {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/loan/reject"));
|
||||
|
||||
ResponseEntity<EntityIdentifier> s = this.oauthRestServiceTemplate
|
||||
.postForEntity(restUri,
|
||||
loanStateTransitionApplicationRequest(command),
|
||||
EntityIdentifier.class);
|
||||
|
||||
return s.getBody();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
ErrorResponseList errorList = parseErrors(e);
|
||||
throw new ClientValidationException(errorList.getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityIdentifier withdrawLoan(
|
||||
final LoanStateTransitionCommand command) {
|
||||
try {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/loan/withdraw"));
|
||||
|
||||
ResponseEntity<EntityIdentifier> s = this.oauthRestServiceTemplate
|
||||
.postForEntity(restUri,
|
||||
loanStateTransitionApplicationRequest(command),
|
||||
EntityIdentifier.class);
|
||||
|
||||
return s.getBody();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
ErrorResponseList errorList = parseErrors(e);
|
||||
throw new ClientValidationException(errorList.getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EntityIdentifier disburseLoan(
|
||||
final LoanStateTransitionCommand command) {
|
||||
|
||||
-60
@@ -19,7 +19,6 @@ import org.mifosng.data.LoanRepaymentData;
|
||||
import org.mifosng.data.command.AdjustLoanTransactionCommand;
|
||||
import org.mifosng.data.command.LoanStateTransitionCommand;
|
||||
import org.mifosng.data.command.LoanTransactionCommand;
|
||||
import org.mifosng.data.command.UndoLoanApprovalCommand;
|
||||
import org.mifosng.data.command.UndoLoanDisbursalCommand;
|
||||
import org.mifosng.ui.CommonRestOperations;
|
||||
import org.mifosng.ui.loanproduct.ClientValidationException;
|
||||
@@ -97,65 +96,6 @@ public class LoanTransactionController {
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/portfolio/loan/{loanId}/delete", method = RequestMethod.POST)
|
||||
public @ResponseBody EntityIdentifier deleteLoan(@PathVariable("loanId") final Long loanId) {
|
||||
|
||||
return this.commonRestOperations.deleteLoan(loanId);
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/x-www-form-urlencoded", produces="application/json", value = "/portfolio/loan/{loanId}/approve", method = RequestMethod.POST)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public @ResponseBody EntityIdentifier approveLoan(
|
||||
@PathVariable("loanId") final Long loanId,
|
||||
@RequestParam(value="eventDate", required=false) String eventDate,
|
||||
@RequestParam(value="comment", required=false) String comment) {
|
||||
|
||||
LocalDate approvalDate = parseStringToLocalDate(eventDate, "eventDate");
|
||||
|
||||
LoanStateTransitionCommand command = new LoanStateTransitionCommand(loanId, approvalDate, comment);
|
||||
|
||||
return this.commonRestOperations.approveLoan(command);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/portfolio/loan/{loanId}/undoapproval", method = RequestMethod.POST)
|
||||
public String undoLoanApproval(@PathVariable("loanId") final Long loanId) {
|
||||
|
||||
UndoLoanApprovalCommand command = new UndoLoanApprovalCommand(loanId);
|
||||
|
||||
EntityIdentifier clientAccountId = this.commonRestOperations
|
||||
.undoLoanApproval(command);
|
||||
|
||||
return "redirect:/portfolio/client/" + clientAccountId.getEntityId();
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/x-www-form-urlencoded", produces="application/json", value = "/portfolio/loan/{loanId}/reject", method = RequestMethod.POST)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public @ResponseBody EntityIdentifier rejectLoan(
|
||||
@PathVariable("loanId") final Long loanId,
|
||||
@RequestParam(value="eventDate", required=false) String eventDate,
|
||||
@RequestParam(value="comment", required=false) String comment) {
|
||||
|
||||
LocalDate rejectionDate = parseStringToLocalDate(eventDate, "eventDate");
|
||||
|
||||
LoanStateTransitionCommand command = new LoanStateTransitionCommand(loanId, rejectionDate, comment);
|
||||
|
||||
return this.commonRestOperations.rejectLoan(command);
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/x-www-form-urlencoded", produces="application/json", value = "/portfolio/loan/{loanId}/withdraw", method = RequestMethod.POST)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public @ResponseBody EntityIdentifier loanWithdrawnByClient(
|
||||
@PathVariable("loanId") final Long loanId,
|
||||
@RequestParam(value="eventDate", required=false) String eventDate,
|
||||
@RequestParam(value="comment", required=false) String comment) {
|
||||
|
||||
LocalDate withdrawnOnDate = parseStringToLocalDate(eventDate, "eventDate");
|
||||
|
||||
LoanStateTransitionCommand command = new LoanStateTransitionCommand(loanId, withdrawnOnDate, comment);
|
||||
|
||||
return this.commonRestOperations.withdrawLoan(command);
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/x-www-form-urlencoded", produces="application/json", value = "/portfolio/loan/{loanId}/disburse", method = RequestMethod.POST)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public @ResponseBody EntityIdentifier disburseLoan(
|
||||
|
||||
+27
-25
@@ -251,7 +251,7 @@ $(document).ready(function() {
|
||||
}).dialog('open');
|
||||
}
|
||||
|
||||
function popupDialogWithPostOnlyFormView(url, titleCode, templateSelector, width, height, tabIndex, minOffset, defaultOffset, maxOffset) {
|
||||
function popupDialogWithPostOnlyFormView(postUrl, titleCode, templateSelector, width, height, tabIndex, minOffset, defaultOffset, maxOffset) {
|
||||
var dialogDiv = $("<div id='dialog-form'></div>");
|
||||
|
||||
var data = new Object();
|
||||
@@ -267,13 +267,17 @@ $(document).ready(function() {
|
||||
$('.multiSelectedItems option').each(function(i) {
|
||||
$(this).attr("selected", "selected");
|
||||
});
|
||||
|
||||
var form_data = $('#entityform').serialize();
|
||||
|
||||
|
||||
var newFormData = JSON.stringify($('#entityform').serializeObject());
|
||||
console.log(newFormData);
|
||||
|
||||
var jqxhr = $.ajax({
|
||||
url: url,
|
||||
url: postUrl,
|
||||
type: 'POST',
|
||||
data: form_data,
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
data: newFormData,
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
dialogDiv.dialog("close");
|
||||
$newtabs.tabs('load', tabIndex);
|
||||
@@ -505,29 +509,27 @@ $(document).ready(function() {
|
||||
offsetToDisbursalDate = data.maxDisbursedOnOffsetFromToday;
|
||||
|
||||
$('.rejectloan').button().click(function(e) {
|
||||
|
||||
var linkId = this.id;
|
||||
var loanId = linkId.replace("rejectbtn", "");
|
||||
var url = '${rootContext}portfolio/loan/' + loanId + '/reject';
|
||||
var templateSelector = "#rejectLoanFormTemplate";
|
||||
var postUrl = 'http://localhost:8080/mifosng-provider/api/v1/loans/' + loanId + '?command=reject';
|
||||
var templateSelector = "#stateTransitionLoanFormTemplate";
|
||||
var width = 500;
|
||||
var height = 350;
|
||||
var defaultOffset = offsetToSubmittedDate;
|
||||
popupDialogWithPostOnlyFormView(url, 'dialog.title.reject.loan', templateSelector, width, height, currentTabIndex, offsetToSubmittedDate, defaultOffset, maxOffset);
|
||||
popupDialogWithPostOnlyFormView(postUrl, 'dialog.title.reject.loan', templateSelector, width, height, currentTabIndex, offsetToSubmittedDate, defaultOffset, maxOffset);
|
||||
e.preventDefault();
|
||||
});
|
||||
$('button.rejectloan span').text(jQuery.i18n.prop('dialog.button.reject.loan'));
|
||||
|
||||
$('.withdrawnbyapplicantloan').button().click(function(e) {
|
||||
|
||||
var linkId = this.id;
|
||||
var loanId = linkId.replace("withdrawnbyapplicantloanbtn", "");
|
||||
var url = '${rootContext}portfolio/loan/' + loanId + '/withdraw';
|
||||
var templateSelector = "#withdrawnByClientLoanFormTemplate";
|
||||
var postUrl = 'http://localhost:8080/mifosng-provider/api/v1/loans/' + loanId + '?command=withdrewbyclient';
|
||||
var templateSelector = "#stateTransitionLoanFormTemplate";
|
||||
var width = 500;
|
||||
var height = 350;
|
||||
var defaultOffset = offsetToSubmittedDate;
|
||||
popupDialogWithPostOnlyFormView(url, 'dialog.title.loan.withdrawn.by.client', templateSelector, width, height, currentTabIndex, offsetToSubmittedDate, defaultOffset, maxOffset)
|
||||
popupDialogWithPostOnlyFormView(postUrl, 'dialog.title.loan.withdrawn.by.client', templateSelector, width, height, currentTabIndex, offsetToSubmittedDate, defaultOffset, maxOffset)
|
||||
e.preventDefault();
|
||||
});
|
||||
$('button.withdrawnbyapplicantloan span').text(jQuery.i18n.prop('dialog.button.withdrawn.by.client.loan'));
|
||||
@@ -536,12 +538,12 @@ $(document).ready(function() {
|
||||
|
||||
var linkId = this.id;
|
||||
var loanId = linkId.replace("approvebtn", "");
|
||||
var url = '${rootContext}portfolio/loan/' + loanId + '/approve';
|
||||
var templateSelector = "#approveLoanFormTemplate";
|
||||
var postUrl = 'http://localhost:8080/mifosng-provider/api/v1/loans/' + loanId + '?command=approve';
|
||||
var templateSelector = "#stateTransitionLoanFormTemplate";
|
||||
var width = 500;
|
||||
var height = 350;
|
||||
var defaultOffset = offsetToSubmittedDate;
|
||||
popupDialogWithPostOnlyFormView(url, 'dialog.title.approve.loan', templateSelector, width, height, currentTabIndex, offsetToSubmittedDate, defaultOffset, maxOffset)
|
||||
popupDialogWithPostOnlyFormView(postUrl, 'dialog.title.approve.loan', templateSelector, width, height, currentTabIndex, offsetToSubmittedDate, defaultOffset, maxOffset)
|
||||
e.preventDefault();
|
||||
});
|
||||
$('button.approveloan span').text(jQuery.i18n.prop('dialog.button.approve.loan'));
|
||||
@@ -565,10 +567,10 @@ $(document).ready(function() {
|
||||
|
||||
var linkId = this.id;
|
||||
var loanId = linkId.replace("undoapprovebtn", "");
|
||||
var url = '${rootContext}portfolio/loan/' + loanId + '/undoapproval';
|
||||
var postUrl = 'http://localhost:8080/mifosng-provider/api/v1/loans/' + loanId + '/undo?command=undoapproval';
|
||||
var width = 400;
|
||||
var height = 225;
|
||||
popupConfirmationDialogAndPost(url, 'dialog.title.undo.loan.approval', width, height, currentTabIndex);
|
||||
popupConfirmationDialogAndPost(postUrl, 'POST', 'dialog.title.undo.loan.approval', width, height, currentTabIndex);
|
||||
e.preventDefault();
|
||||
});
|
||||
$('button.undoapproveloan span').text(jQuery.i18n.prop('dialog.button.undo.loan.approval'));
|
||||
@@ -577,10 +579,10 @@ $(document).ready(function() {
|
||||
|
||||
var linkId = this.id;
|
||||
var loanId = linkId.replace("undodisbursalbtn", "");
|
||||
var url = '${rootContext}portfolio/loan/' + loanId + '/undodisbursal';
|
||||
var postUrl = 'http://localhost:8080/mifosng-provider/api/v1/loans/' + loanId + '?command=undodisbursal';
|
||||
var width = 400;
|
||||
var height = 150;
|
||||
popupConfirmationDialogAndPost(url, 'dialog.title.undo.loan.disbursal', width, height, currentTabIndex);
|
||||
popupConfirmationDialogAndPost(postUrl, 'POST', 'dialog.title.undo.loan.disbursal', width, height, currentTabIndex);
|
||||
e.preventDefault();
|
||||
});
|
||||
$('button.undodisbursalloan span').text(jQuery.i18n.prop('dialog.button.undo.loan.disbursal'));
|
||||
@@ -589,12 +591,12 @@ $(document).ready(function() {
|
||||
|
||||
var linkId = this.id;
|
||||
var loanId = linkId.replace("disbursebtn", "");
|
||||
var url = '${rootContext}portfolio/loan/' + loanId + '/disburse';
|
||||
var templateSelector = "#disburseLoanFormTemplate";
|
||||
var postUrl = 'http://localhost:8080/mifosng-provider/api/v1/loans/' + loanId + '?command=disburse';
|
||||
var templateSelector = "#stateTransitionLoanFormTemplate";
|
||||
var width = 500;
|
||||
var height = 350;
|
||||
var defaultOffset = offsetToApprovalDate;
|
||||
popupDialogWithPostOnlyFormView(url, 'dialog.title.disburse.loan', templateSelector, width, height, currentTabIndex, offsetToSubmittedDate, defaultOffset, maxOffset)
|
||||
popupDialogWithPostOnlyFormView(postUrl, 'dialog.title.disburse.loan', templateSelector, width, height, currentTabIndex, offsetToSubmittedDate, defaultOffset, maxOffset)
|
||||
e.preventDefault();
|
||||
});
|
||||
$('button.disburseloan span').text(jQuery.i18n.prop('dialog.button.disburse.loan'));
|
||||
@@ -603,7 +605,7 @@ $(document).ready(function() {
|
||||
|
||||
var linkId = this.id;
|
||||
var loanId = linkId.replace("repaymentbtn", "");
|
||||
var url = '${rootContext}portfolio/loan/' + loanId + '/repayment';
|
||||
var url = 'http://localhost:8080/mifosng-provider/api/v1/loans/' + loanId;
|
||||
var templateSelector = "#transactionLoanFormTemplate";
|
||||
var width = 500;
|
||||
var height = 350;
|
||||
|
||||
@@ -799,51 +799,16 @@
|
||||
</sec:authorize>
|
||||
</script>
|
||||
|
||||
<script id="rejectLoanFormTemplate" type="text/x-jquery-tmpl">
|
||||
<script id="stateTransitionLoanFormTemplate" type="text/x-jquery-tmpl">
|
||||
<form id="entityform">
|
||||
<div id="formerrors"></div>
|
||||
|
||||
<label for="eventDate"><spring:message code="label.loan.rejected.on"/></label>
|
||||
<input id="eventDate" name="eventDate" cssClass="text ui-widget-content ui-corner-all" title="" class="datepickerfield" />
|
||||
<input type="hidden" id="dateFormat" name="dateFormat" value="dd MMMM yyyy" />
|
||||
<label for="eventDateFormatted"><spring:message code="label.loan.rejected.on"/></label>
|
||||
<input id="eventDateFormatted" name="eventDateFormatted" title="" class="datepickerfield" />
|
||||
|
||||
<label for="comment"><spring:message code="label.loan.action.note"/></label>
|
||||
<textarea rows="3" cols="53" id="comment" name="comment" cssClass="text ui-widget-content ui-corner-all"></textarea>
|
||||
</form>
|
||||
</script>
|
||||
|
||||
<script id="withdrawnByClientLoanFormTemplate" type="text/x-jquery-tmpl">
|
||||
<form id="entityform">
|
||||
<div id="formerrors"></div>
|
||||
|
||||
<label for="eventDate"><spring:message code="label.loan.withdrawn.by.client.on"/></label>
|
||||
<input id="eventDate" name="eventDate" cssClass="text ui-widget-content ui-corner-all" title="" class="datepickerfield" />
|
||||
|
||||
<label for="comment"><spring:message code="label.loan.action.note"/></label>
|
||||
<textarea rows="3" cols="53" id="comment" name="comment" cssClass="text ui-widget-content ui-corner-all"></textarea>
|
||||
</form>
|
||||
</script>
|
||||
|
||||
<script id="approveLoanFormTemplate" type="text/x-jquery-tmpl">
|
||||
<form id="entityform">
|
||||
<div id="formerrors"></div>
|
||||
|
||||
<label for="eventDate"><spring:message code="label.loan.approved.on"/></label>
|
||||
<input id="eventDate" name="eventDate" cssClass="text ui-widget-content ui-corner-all" title="" class="datepickerfield" />
|
||||
|
||||
<label for="comment"><spring:message code="label.loan.action.note"/></label>
|
||||
<textarea rows="3" cols="53" id="comment" name="comment" cssClass="text ui-widget-content ui-corner-all"></textarea>
|
||||
</form>
|
||||
</script>
|
||||
|
||||
<script id="disburseLoanFormTemplate" type="text/x-jquery-tmpl">
|
||||
<form id="entityform">
|
||||
<div id="formerrors"></div>
|
||||
|
||||
<label for="eventDate"><spring:message code="label.loan.disbursed.on"/></label>
|
||||
<input id="eventDate" name="eventDate" cssClass="text ui-widget-content ui-corner-all" title="" class="datepickerfield" />
|
||||
|
||||
<label for="comment"><spring:message code="label.loan.action.note"/></label>
|
||||
<textarea rows="3" cols="53" id="comment" name="comment" cssClass="text ui-widget-content ui-corner-all"></textarea>
|
||||
<textarea rows="3" cols="53" id="comment" name="comment"></textarea>
|
||||
</form>
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user