Merge pull request #1209 from MegaAlex/MIFOSX-1739

MIFOSX-1739 Add option to show only active loan products
This commit is contained in:
Vishwas Babu A J
2014-12-18 19:05:10 -08:00
4 changed files with 45 additions and 17 deletions
+9 -1
View File
@@ -7212,6 +7212,9 @@ An enumeration that indicates the type of transaction processing strategy to be
<dd>
Integer <span>mandatory</span>
</dd>
</dl>
<h5>Optional Arguments</h5>
<dl class="argument-list">
<dt>productId</dt>
<dd>
Integer <span>optional</span>
@@ -7224,7 +7227,12 @@ An enumeration that indicates the type of transaction processing strategy to be
Boolean <span>optional</span>
</dd>
<dd>Defaults to false if not provided. If <strong>staffInSelectedOfficeOnly=true</strong> only loan officers
who are associated with the selected branch are returned.</dd>
who are associated with the selected branch are returned.</dd>
<dt>activeOnly</dt>
<dd>
Boolean <span>optional</span>
</dd>
<dd>Defaults to false if not provided. If <strong>activeOnly=true</strong> only active loan products are returned.</dd>
</dl>
<p>Example Requests:</p>
<div class=apiClick>loans/template?templateType=individual&clientId=1</div>
@@ -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<LoanProductData> productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup();
final Collection<LoanProductData> productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup(onlyActive);
// options
Collection<StaffData> allowedLoanOfficers = null;
@@ -512,7 +513,7 @@ public class LoansApiResource {
Collection<ChargeData> overdueCharges = this.chargeReadPlatformService.retrieveLoanProductCharges(loanBasicDetails.loanProductId(),
ChargeTimeType.OVERDUE_INSTALLMENT);
paidInAdvanceTemplate = this.loanReadPlatformService.retrieveTotalPaidInAdvance(loanId);
final LoanAccountData loanAccount = LoanAccountData.associationsAndTemplate(loanBasicDetails, repaymentSchedule, loanRepayments,
@@ -16,6 +16,8 @@ public interface LoanProductReadPlatformService {
Collection<LoanProductData> retrieveAllLoanProductsForLookup();
Collection<LoanProductData> retrieveAllLoanProductsForLookup(boolean activeOnly);
LoanProductData retrieveLoanProduct(Long productId);
LoanProductData retrieveNewLoanProductDetails();
@@ -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<LoanProductData> retrieveAllLoanProductsForLookup() {
return retrieveAllLoanProductsForLookup(false);
}
@Override
public Collection<LoanProductData> 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=?)";