diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm
index 0b138189b..ddb3cf574 100644
--- a/api-docs/apiLive.htm
+++ b/api-docs/apiLive.htm
@@ -7212,6 +7212,9 @@ An enumeration that indicates the type of transaction processing strategy to be
Integer mandatory
+
+ Optional Arguments
+
- productId
-
Integer optional
@@ -7224,7 +7227,12 @@ An enumeration that indicates the type of transaction processing strategy to be
Boolean optional
- Defaults to false if not provided. If staffInSelectedOfficeOnly=true only loan officers
- who are associated with the selected branch are returned.
+ who are associated with the selected branch are returned.
+ - activeOnly
+ -
+ Boolean optional
+
+ - Defaults to false if not provided. If activeOnly=true only active loan products are returned.
Example Requests:
loans/template?templateType=individual&clientId=1
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java
index 357958e01..b5737d282 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java
@@ -226,12 +226,13 @@ public class LoansApiResource {
public String template(@QueryParam("clientId") final Long clientId, @QueryParam("groupId") final Long groupId,
@QueryParam("productId") final Long productId, @QueryParam("templateType") final String templateType,
@DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly,
+ @DefaultValue("false") @QueryParam("activeOnly") final boolean onlyActive,
@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
// template
- final Collection productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup();
+ final Collection productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup(onlyActive);
// options
Collection allowedLoanOfficers = null;
@@ -512,7 +513,7 @@ public class LoansApiResource {
Collection overdueCharges = this.chargeReadPlatformService.retrieveLoanProductCharges(loanBasicDetails.loanProductId(),
ChargeTimeType.OVERDUE_INSTALLMENT);
-
+
paidInAdvanceTemplate = this.loanReadPlatformService.retrieveTotalPaidInAdvance(loanId);
final LoanAccountData loanAccount = LoanAccountData.associationsAndTemplate(loanBasicDetails, repaymentSchedule, loanRepayments,
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductReadPlatformService.java
index 7ae1d8cc6..1cbbdf65a 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductReadPlatformService.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductReadPlatformService.java
@@ -16,6 +16,8 @@ public interface LoanProductReadPlatformService {
Collection retrieveAllLoanProductsForLookup();
+ Collection retrieveAllLoanProductsForLookup(boolean activeOnly);
+
LoanProductData retrieveLoanProduct(Long productId);
LoanProductData retrieveNewLoanProductDetails();
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductReadPlatformServiceImpl.java
index 3f0a96398..817ca3d3b 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductReadPlatformServiceImpl.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductReadPlatformServiceImpl.java
@@ -85,7 +85,7 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
final LoanProductMapper rm = new LoanProductMapper(null, null);
String sql = "select " + rm.loanProductSchema();
-
+
// Check if branch specific products are enabled. If yes, fetch only products mapped to current user's office
String inClause = mifosEntityAccessUtil.
getSQLWhereClauseForProductIDsForUserOffice_ifGlobalConfigEnabled(
@@ -99,20 +99,33 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
@Override
public Collection retrieveAllLoanProductsForLookup() {
+ return retrieveAllLoanProductsForLookup(false);
+ }
+ @Override
+ public Collection retrieveAllLoanProductsForLookup(final boolean activeOnly) {
this.context.authenticatedUser();
final LoanProductLookupMapper rm = new LoanProductLookupMapper();
- String sql = "select " + rm.schema();
-
+ String sql = "select ";
+ if(activeOnly) {
+ sql += rm.activeOnlySchema();
+ } else {
+ sql += rm.schema();
+ }
+
// Check if branch specific products are enabled. If yes, fetch only products mapped to current user's office
String inClause = mifosEntityAccessUtil.
- getSQLWhereClauseForProductIDsForUserOffice_ifGlobalConfigEnabled(
- MifosEntityType.LOAN_PRODUCT);
- if ( (inClause != null) && (!(inClause.trim().isEmpty())) ) {
- sql += " where id in ( " + inClause + " ) ";
- }
+ getSQLWhereClauseForProductIDsForUserOffice_ifGlobalConfigEnabled(
+ MifosEntityType.LOAN_PRODUCT);
+ if ( (inClause != null) && (!(inClause.trim().isEmpty())) ) {
+ if(activeOnly) {
+ sql += " and id in ( " + inClause + " )";
+ } else {
+ sql += " where id in ( " + inClause + " ) ";
+ }
+ }
return this.jdbcTemplate.query(sql, rm, new Object[] {});
}
@@ -314,6 +327,10 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
return "lp.id as id, lp.name as name from m_product_loan lp";
}
+ public String activeOnlySchema() {
+ return schema() + " where (close_date is null or close_date >= CURDATE())";
+ }
+
public String productMixSchema() {
return "lp.id as id, lp.name as name FROM m_product_loan lp left join m_product_mix pm on pm.product_id=lp.id where lp.id not IN("
+ "select lp.id from m_product_loan lp inner join m_product_mix pm on pm.product_id=lp.id)";
@@ -372,7 +389,7 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
final LoanProductMapper rm = new LoanProductMapper(null, null);
String sql = "select " + rm.loanProductSchema() + " where lp.currency_code='" + currencyCode + "'";
-
+
// Check if branch specific products are enabled. If yes, fetch only products mapped to current user's office
String inClause = mifosEntityAccessUtil.
getSQLWhereClauseForProductIDsForUserOffice_ifGlobalConfigEnabled(
@@ -392,7 +409,7 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
final LoanProductLookupMapper rm = new LoanProductLookupMapper();
String sql = "Select " + rm.productMixSchema();
-
+
// Check if branch specific products are enabled. If yes, fetch only products mapped to current user's office
String inClause = mifosEntityAccessUtil.
getSQLWhereClauseForProductIDsForUserOffice_ifGlobalConfigEnabled(
@@ -419,10 +436,10 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
if ( (inClause1 != null) && (!(inClause1.trim().isEmpty())) ) {
sql += " and rp.id in ( " + inClause1 + " ) ";
}
-
+
sql += " UNION Select "
+ rm.derivedRestrictedProductsSchema() + " where pm.restricted_product_id=?";
-
+
// Check if branch specific products are enabled. If yes, fetch only products mapped to current user's office
String inClause2 = mifosEntityAccessUtil.
getSQLWhereClauseForProductIDsForUserOffice_ifGlobalConfigEnabled(
@@ -442,7 +459,7 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
final LoanProductLookupMapper rm = new LoanProductLookupMapper();
String sql = "Select " + rm.schema() + " where ";
-
+
// Check if branch specific products are enabled. If yes, fetch only products mapped to current user's office
String inClause = mifosEntityAccessUtil.
getSQLWhereClauseForProductIDsForUserOffice_ifGlobalConfigEnabled(
@@ -450,7 +467,7 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
if ( (inClause != null) && (!(inClause.trim().isEmpty())) ) {
sql += " lp.id in ( " + inClause + " ) and ";
}
-
+
sql += "lp.id not in ("
+ "Select pm.restricted_product_id from m_product_mix pm where pm.product_id=? " + "UNION "
+ "Select pm.product_id from m_product_mix pm where pm.restricted_product_id=?)";