tidy up new loan data returned for submit loan flow and ensure locale is posted for forms with numbers and monetary values in them.

This commit is contained in:
Keith Woodlock
2012-05-31 13:39:30 +01:00
parent 7a62b37210
commit 9d597e2add
6 changed files with 46 additions and 155 deletions
@@ -30,6 +30,7 @@ public class ApplicationPagesRoutesController {
BasicAuthUserDetails userDetails = (BasicAuthUserDetails) authentication.getPrincipal();
model.addAttribute("basicAuthKey", userDetails.getBasicAuthenticationKey());
model.addAttribute("baseApiUrl", userDetails.getFullApiUrl());
model.addAttribute("currentLocale", LocaleContextHolder.getLocale().toString());
return "redirect:/home";
}
@@ -40,6 +41,7 @@ public class ApplicationPagesRoutesController {
BasicAuthUserDetails userDetails = (BasicAuthUserDetails) authentication.getPrincipal();
model.addAttribute("basicAuthKey", userDetails.getBasicAuthenticationKey());
model.addAttribute("baseApiUrl", userDetails.getFullApiUrl());
model.addAttribute("currentLocale", LocaleContextHolder.getLocale().toString());
return new ModelAndView("/home");
}
@@ -56,6 +58,7 @@ public class ApplicationPagesRoutesController {
model.addAttribute("basicAuthKey", userDetails.getBasicAuthenticationKey());
model.addAttribute("baseApiUrl", userDetails.getFullApiUrl());
model.addAttribute("clientId", clientId);
model.addAttribute("currentLocale", LocaleContextHolder.getLocale().toString());
return "client/viewClientAccount";
}
@@ -75,6 +78,9 @@ public class ApplicationPagesRoutesController {
BasicAuthUserDetails userDetails = (BasicAuthUserDetails) authentication.getPrincipal();
model.addAttribute("basicAuthKey", userDetails.getBasicAuthenticationKey());
model.addAttribute("baseApiUrl", userDetails.getFullApiUrl());
model.addAttribute("currentLocale", LocaleContextHolder.getLocale().toString());
return "admin/userhome";
}
@@ -84,6 +90,9 @@ public class ApplicationPagesRoutesController {
model.addAttribute("basicAuthKey", userDetails.getBasicAuthenticationKey());
model.addAttribute("baseApiUrl", userDetails.getFullApiUrl());
model.addAttribute("userId", userDetails.getUserId());
model.addAttribute("currentLocale", LocaleContextHolder.getLocale().toString());
return "admin/accountsettings";
}
@@ -95,6 +104,8 @@ public class ApplicationPagesRoutesController {
model.addAttribute("baseApiUrl", userDetails.getFullApiUrl());
model.addAttribute("clientId", clientId);
model.addAttribute("currentLocale", LocaleContextHolder.getLocale().toString());
return "newloanapplication";
}
@@ -105,6 +116,8 @@ public class ApplicationPagesRoutesController {
model.addAttribute("basicAuthKey", userDetails.getBasicAuthenticationKey());
model.addAttribute("baseApiUrl", userDetails.getFullApiUrl());
model.addAttribute("currentLocale", LocaleContextHolder.getLocale().toString());
return "reports/flexireport";
}
}
@@ -27,7 +27,9 @@ $(document).ready(function() {
// these helpers are registered for the jsViews and jsRender functionality to fix bug with display zero!
$.views.registerHelpers({
currentLocale: function() {
return "${currentLocale}";
},
money: function(monetaryObj) {
Globalize.culture().numberFormat.currency.symbol = monetaryObj.displaySymbol;
@@ -57,7 +57,7 @@ $(document).ready(function() {
},
globalDate: function(dateParts) {
try {
if (dateParts === 'undefined' || dateParts === undefined) return "";
if (dateParts === null || dateParts === '') return "";
var year = dateParts[0];
@@ -69,7 +69,7 @@ $(document).ready(function() {
return Globalize.format(d,"dd MMMM yyyy");
} catch(e) {
return "??";
return dateParts + " ??";
}
},
globalDateAsISOString: function(localDateAsISOString) {
@@ -57,6 +57,8 @@
<input type="hidden" id="clientId" name="clientId" value="{{=clientId}}" />
<input type="hidden" id="currencyCode" name="currencyCode" value="{{=selectedProduct.principal.currencyCode}}" />
<input type="hidden" id="digitsAfterDecimal" name="digitsAfterDecimal" value="{{=$ctx.number(selectedProduct.principal.digitsAfterDecimal)}}" />
<input type="hidden" id="dateFormat" name="dateFormat" value="dd MMMM yyyy" />
<input type="hidden" id="locale" name="locale" value="${currentLocale}" />
<fieldset>
<legend><spring:message code="form.legend.loan.information"/></legend>
@@ -83,7 +85,6 @@
</td>
<td style="text-align:right;vertical-align:bottom;width:50px;">&nbsp;</td>
<td valign="top">
<input type="hidden" id="dateFormat" name="dateFormat" value="dd MMMM yyyy" />
<label for="submittedOnDate"><spring:message code="form.label.loan.submitted.on"/></label>
<input id="submittedOnDate" name="submittedOnDate" title="" type="text" class="datepickerfield" value="{{=$ctx.globalDate(submittedOnDate)}}" />
@@ -826,6 +827,8 @@
<div id="formerrors"></div>
<input type="hidden" id="dateFormat" name="dateFormat" value="dd MMMM yyyy" />
<input type="hidden" id="locale" name="locale" value="{{=$ctx.currentLocale()}}" />
<label for="transactionDate"><spring:message code="label.loan.transaction.on"/></label>
<input id="transactionDate" name="transactionDate" class="text ui-widget-content ui-corner-all datepickerfield" title=""d value="{{=$ctx.globalDate(date)}}"/>
@@ -4,63 +4,30 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonFilter;
import org.joda.time.LocalDate;
import org.mifosng.data.LoanSchedule;
@JsonIgnoreProperties({ "organisationId", "organisationName" })
@JsonFilter("myFilter")
public class NewLoanData implements Serializable {
private Long organisationId;
private String organisationName;
private Long clientId;
private String clientName;
private Long productId;
private String productName;
private List<LoanProductLookup> allowedProducts = new ArrayList<LoanProductLookup>();
// extra
private String dateFormat;
private String submittedOnDateFormatted;
private LocalDate submittedOnDate;
private String submittedOnNote = "";
private String expectedDisbursementDateFormatted;
private LocalDate expectedDisbursementDate = new LocalDate();
private String repaymentsStartingFromDateFormatted;
private LocalDate repaymentsStartingFromDate;
private String interestCalculatedFromDateFormatted;
private LocalDate interestCalculatedFromDate;
private LoanProductData selectedProduct;
private LocalDate expectedDisbursementDate;
private LoanSchedule repaymentSchedule;
private LoanProductData selectedProduct;
private List<LoanProductLookup> allowedProducts = new ArrayList<LoanProductLookup>();
public NewLoanData() {
//
}
public Long getOrganisationId() {
return organisationId;
}
public void setOrganisationId(Long organisationId) {
this.organisationId = organisationId;
}
public String getOrganisationName() {
return organisationName;
}
public void setOrganisationName(String organisationName) {
this.organisationName = organisationName;
}
public Long getClientId() {
return clientId;
}
@@ -101,22 +68,6 @@ public class NewLoanData implements Serializable {
this.allowedProducts = allowedProducts;
}
public LocalDate getSubmittedOnDate() {
return submittedOnDate;
}
public void setSubmittedOnDate(LocalDate submittedOnDate) {
this.submittedOnDate = submittedOnDate;
}
public String getSubmittedOnNote() {
return submittedOnNote;
}
public void setSubmittedOnNote(String submittedOnNote) {
this.submittedOnNote = submittedOnNote;
}
public LoanProductData getSelectedProduct() {
return selectedProduct;
}
@@ -125,32 +76,6 @@ public class NewLoanData implements Serializable {
this.selectedProduct = selectedProduct;
}
public LocalDate getExpectedDisbursementDate() {
return expectedDisbursementDate;
}
public void setExpectedDisbursementDate(LocalDate expectedDisbursementDate) {
this.expectedDisbursementDate = expectedDisbursementDate;
}
public LocalDate getRepaymentsStartingFromDate() {
return repaymentsStartingFromDate;
}
public void setRepaymentsStartingFromDate(
LocalDate repaymentsStartingFromDate) {
this.repaymentsStartingFromDate = repaymentsStartingFromDate;
}
public LocalDate getInterestCalculatedFromDate() {
return interestCalculatedFromDate;
}
public void setInterestCalculatedFromDate(
LocalDate interestCalculatedFromDate) {
this.interestCalculatedFromDate = interestCalculatedFromDate;
}
public LoanSchedule getRepaymentSchedule() {
return repaymentSchedule;
}
@@ -159,46 +84,11 @@ public class NewLoanData implements Serializable {
this.repaymentSchedule = repaymentSchedule;
}
public String getDateFormat() {
return dateFormat;
public LocalDate getExpectedDisbursementDate() {
return expectedDisbursementDate;
}
public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
}
public String getSubmittedOnDateFormatted() {
return submittedOnDateFormatted;
}
public void setSubmittedOnDateFormatted(String submittedOnDateFormatted) {
this.submittedOnDateFormatted = submittedOnDateFormatted;
}
public String getExpectedDisbursementDateFormatted() {
return expectedDisbursementDateFormatted;
}
public void setExpectedDisbursementDateFormatted(
String expectedDisbursementDateFormatted) {
this.expectedDisbursementDateFormatted = expectedDisbursementDateFormatted;
}
public String getRepaymentsStartingFromDateFormatted() {
return repaymentsStartingFromDateFormatted;
}
public void setRepaymentsStartingFromDateFormatted(
String repaymentsStartingFromDateFormatted) {
this.repaymentsStartingFromDateFormatted = repaymentsStartingFromDateFormatted;
}
public String getInterestCalculatedFromDateFormatted() {
return interestCalculatedFromDateFormatted;
}
public void setInterestCalculatedFromDateFormatted(
String interestCalculatedFromDateFormatted) {
this.interestCalculatedFromDateFormatted = interestCalculatedFromDateFormatted;
public void setExpectedDisbursementDate(LocalDate expectedDisbursementDate) {
this.expectedDisbursementDate = expectedDisbursementDate;
}
}
@@ -22,7 +22,6 @@ import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository;
import org.mifosng.platform.currency.domain.Money;
import org.mifosng.platform.exceptions.CurrencyNotFoundException;
import org.mifosng.platform.exceptions.LoanNotFoundException;
import org.mifosng.platform.exceptions.LoanProductNotFoundException;
import org.mifosng.platform.exceptions.LoanTransactionNotFoundException;
import org.mifosng.platform.loan.domain.Loan;
import org.mifosng.platform.loan.domain.LoanRepository;
@@ -176,60 +175,44 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
}
@Override
public NewLoanData retrieveClientAndProductDetails(final Long clientId,
final Long productId) {
public NewLoanData retrieveClientAndProductDetails(final Long clientId, final Long productId) {
AppUser currentUser = context.authenticatedUser();
context.authenticatedUser();
NewLoanData workflowData = new NewLoanData();
workflowData.setOrganisationId(currentUser.getOrganisation().getId());
workflowData.setOrganisationName(currentUser.getOrganisation()
.getName());
Collection<LoanProductLookup> loanProducts = this.loanProductReadPlatformService
.retrieveAllLoanProductsForLookup();
workflowData.setAllowedProducts(new ArrayList<LoanProductLookup>(
loanProducts));
Collection<LoanProductLookup> loanProducts = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup();
workflowData.setAllowedProducts(new ArrayList<LoanProductLookup>(loanProducts));
if (loanProducts.size() == 1) {
Long allowedProductId = workflowData.getAllowedProducts().get(0)
.getId();
LoanProductData selectedProduct = this.loanProductReadPlatformService
.retrieveLoanProduct(allowedProductId);
if (selectedProduct == null) {
throw new LoanProductNotFoundException(allowedProductId);
}
Long allowedProductId = workflowData.getAllowedProducts().get(0).getId();
LoanProductData selectedProduct = this.loanProductReadPlatformService.retrieveLoanProduct(allowedProductId);
workflowData.setProductId(selectedProduct.getId());
workflowData.setProductName(selectedProduct.getName());
workflowData.setSelectedProduct(selectedProduct);
} else {
LoanProductData selectedProduct = findLoanProductById(loanProducts,
productId);
if (selectedProduct == null) {
throw new LoanProductNotFoundException(productId);
}
LoanProductData selectedProduct = findLoanProductById(loanProducts, productId);
workflowData.setProductId(selectedProduct.getId());
workflowData.setProductName(selectedProduct.getName());
workflowData.setSelectedProduct(selectedProduct);
}
ClientData clientAccount = this.clientReadPlatformService
.retrieveIndividualClient(clientId);
ClientData clientAccount = this.clientReadPlatformService.retrieveIndividualClient(clientId);
workflowData.setClientId(clientAccount.getId());
workflowData.setClientName(clientAccount.getDisplayName());
workflowData.setExpectedDisbursementDate(new LocalDate());
return workflowData;
}
private LoanProductData findLoanProductById(
Collection<LoanProductLookup> loanProducts, Long productId) {
LoanProductData match = this.loanProductReadPlatformService
.retrieveNewLoanProductDetails();
private LoanProductData findLoanProductById(Collection<LoanProductLookup> loanProducts, Long productId) {
LoanProductData match = this.loanProductReadPlatformService.retrieveNewLoanProductDetails();
for (LoanProductLookup loanProductLookup : loanProducts) {
if (loanProductLookup.getId().equals(productId)) {
match = this.loanProductReadPlatformService
.retrieveLoanProduct(loanProductLookup.getId());
match = this.loanProductReadPlatformService.retrieveLoanProduct(loanProductLookup.getId());
break;
}
}