MIFOSX-1739 Add option to show only active loan products

This commit is contained in:
Alex Ivanov
2014-12-19 00:32:59 +02:00
parent f72a5efb52
commit 9d07e9ad7a
4 changed files with 45 additions and 17 deletions
+8
View File
@@ -7212,6 +7212,9 @@ An enumeration that indicates the type of transaction processing strategy to be
<dd> <dd>
Integer <span>mandatory</span> Integer <span>mandatory</span>
</dd> </dd>
</dl>
<h5>Optional Arguments</h5>
<dl class="argument-list">
<dt>productId</dt> <dt>productId</dt>
<dd> <dd>
Integer <span>optional</span> Integer <span>optional</span>
@@ -7225,6 +7228,11 @@ An enumeration that indicates the type of transaction processing strategy to be
</dd> </dd>
<dd>Defaults to false if not provided. If <strong>staffInSelectedOfficeOnly=true</strong> only loan officers <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> </dl>
<p>Example Requests:</p> <p>Example Requests:</p>
<div class=apiClick>loans/template?templateType=individual&clientId=1</div> <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, public String template(@QueryParam("clientId") final Long clientId, @QueryParam("groupId") final Long groupId,
@QueryParam("productId") final Long productId, @QueryParam("templateType") final String templateType, @QueryParam("productId") final Long productId, @QueryParam("templateType") final String templateType,
@DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly, @DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly,
@DefaultValue("false") @QueryParam("activeOnly") final boolean onlyActive,
@Context final UriInfo uriInfo) { @Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions); this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
// template // template
final Collection<LoanProductData> productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup(); final Collection<LoanProductData> productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup(onlyActive);
// options // options
Collection<StaffData> allowedLoanOfficers = null; Collection<StaffData> allowedLoanOfficers = null;
@@ -16,6 +16,8 @@ public interface LoanProductReadPlatformService {
Collection<LoanProductData> retrieveAllLoanProductsForLookup(); Collection<LoanProductData> retrieveAllLoanProductsForLookup();
Collection<LoanProductData> retrieveAllLoanProductsForLookup(boolean activeOnly);
LoanProductData retrieveLoanProduct(Long productId); LoanProductData retrieveLoanProduct(Long productId);
LoanProductData retrieveNewLoanProductDetails(); LoanProductData retrieveNewLoanProductDetails();
@@ -99,20 +99,33 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
@Override @Override
public Collection<LoanProductData> retrieveAllLoanProductsForLookup() { public Collection<LoanProductData> retrieveAllLoanProductsForLookup() {
return retrieveAllLoanProductsForLookup(false);
}
@Override
public Collection<LoanProductData> retrieveAllLoanProductsForLookup(final boolean activeOnly) {
this.context.authenticatedUser(); this.context.authenticatedUser();
final LoanProductLookupMapper rm = new LoanProductLookupMapper(); 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 // Check if branch specific products are enabled. If yes, fetch only products mapped to current user's office
String inClause = mifosEntityAccessUtil. String inClause = mifosEntityAccessUtil.
getSQLWhereClauseForProductIDsForUserOffice_ifGlobalConfigEnabled( getSQLWhereClauseForProductIDsForUserOffice_ifGlobalConfigEnabled(
MifosEntityType.LOAN_PRODUCT); MifosEntityType.LOAN_PRODUCT);
if ( (inClause != null) && (!(inClause.trim().isEmpty())) ) { if ( (inClause != null) && (!(inClause.trim().isEmpty())) ) {
sql += " where id in ( " + inClause + " ) "; if(activeOnly) {
} sql += " and id in ( " + inClause + " )";
} else {
sql += " where id in ( " + inClause + " ) ";
}
}
return this.jdbcTemplate.query(sql, rm, new Object[] {}); 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"; 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() { 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(" 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)"; + "select lp.id from m_product_loan lp inner join m_product_mix pm on pm.product_id=lp.id)";