Updates to Charge services to filter charges based on currency used in loan/ savings products

This commit is contained in:
Vishwas Babu A J
2014-10-23 21:51:43 -07:00
parent 5c76d3d377
commit e61abec3de
12 changed files with 75 additions and 37 deletions
@@ -21,15 +21,30 @@ public interface ChargeReadPlatformService {
ChargeData retrieveNewChargeDetails();
/**
* Returns all charges applicable for loans
* Returns all Fees (excluding penalties) applicable for loans
*
* @return
*/
Collection<ChargeData> retrieveLoanApplicableFees();
/**
* Returns all charges applicable for a given loan account
*
* @param feeChargesOnly
* If set to "true", only fees are returned
* @param excludeChargeTimes
* Excludes Given List of Charge Types from the response
* @return
*/
Collection<ChargeData> retrieveLoanApplicableCharges(boolean feeChargesOnly, ChargeTimeType[] excludeChargeTimes);
Collection<ChargeData> retrieveLoanAccountApplicableCharges(final Long loanId, ChargeTimeType[] excludeChargeTimes);
/**
* Returns all charges applicable for a given loan product (filter based on
* Currency of Selected Loan Product)
*
* @param excludeChargeTimes
* Excludes Given List of Charge Types from the response
* @return
*/
Collection<ChargeData> retrieveLoanProductApplicableCharges(final Long loanProductId, ChargeTimeType[] excludeChargeTimes);
/**
* Returns all Penalties applicable for loans
@@ -62,14 +77,14 @@ public interface ChargeReadPlatformService {
* @param feeChargesOnly
* @return
*/
Collection<ChargeData> retrieveSavingsAccountApplicableCharges(boolean feeChargesOnly);
Collection<ChargeData> retrieveSavingsApplicableCharges(boolean feeChargesOnly);
/**
* Returns all penalties applicable for savings
*
* @return
*/
Collection<ChargeData> retrieveSavingsAccountApplicablePenalties();
Collection<ChargeData> retrieveSavingsApplicablePenalties();
/**
* Returns all charges applicable for a given savings product
@@ -124,10 +124,20 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService
}
@Override
public Collection<ChargeData> retrieveLoanApplicableCharges(final boolean feeChargesOnly, ChargeTimeType[] excludeChargeTimes) {
public Collection<ChargeData> retrieveLoanApplicableFees() {
final ChargeMapper rm = new ChargeMapper();
Object[] params = new Object[] { ChargeAppliesTo.LOAN.getValue() };
String sql = "select " + rm.chargeSchema()
+ " where c.is_deleted=0 and c.is_active=1 and c.is_penalty=0 and c.charge_applies_to_enum=? order by c.name ";
return this.jdbcTemplate.query(sql, rm, params);
}
@Override
public Collection<ChargeData> retrieveLoanAccountApplicableCharges(final Long loanId, ChargeTimeType[] excludeChargeTimes) {
final ChargeMapper rm = new ChargeMapper();
String excludeClause = "";
Object[] params = new Object[] { ChargeAppliesTo.LOAN.getValue() };
Object[] params = new Object[] { loanId, ChargeAppliesTo.LOAN.getValue() };
if (excludeChargeTimes != null && excludeChargeTimes.length > 0) {
excludeClause = " and c.charge_time_enum not in(?) ";
StringBuilder sb = new StringBuilder();
@@ -137,15 +147,32 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService
}
sb.append(excludeChargeTimes[i].getValue());
}
params = new Object[] { ChargeAppliesTo.LOAN.getValue(), sb.toString() };
params[2] = sb.toString();
}
String sql = "select " + rm.chargeSchema() + " where c.is_deleted=0 and c.is_active=1 and c.charge_applies_to_enum=?"
+ excludeClause + " order by c.name ";
if (feeChargesOnly) {
sql = "select " + rm.chargeSchema()
+ " where c.is_deleted=0 and c.is_active=1 and c.is_penalty=0 and c.charge_applies_to_enum=? " + excludeClause
+ "order by c.name ";
String sql = "select " + rm.chargeSchema() + " join m_loan la on la.currency_code = c.currency_code" + " where la.id=?"
+ " and c.is_deleted=0 and c.is_active=1 and c.charge_applies_to_enum=?" + excludeClause + " order by c.name ";
return this.jdbcTemplate.query(sql, rm, params);
}
@Override
public Collection<ChargeData> retrieveLoanProductApplicableCharges(final Long loanProductId, ChargeTimeType[] excludeChargeTimes) {
final ChargeMapper rm = new ChargeMapper();
String excludeClause = "";
Object[] params = new Object[] { loanProductId, ChargeAppliesTo.LOAN.getValue() };
if (excludeChargeTimes != null && excludeChargeTimes.length > 0) {
excludeClause = " and c.charge_time_enum not in(?) ";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < excludeChargeTimes.length; i++) {
if (i != 0) {
sb.append(",");
}
sb.append(excludeChargeTimes[i].getValue());
}
params[2] = sb.toString();
}
String sql = "select " + rm.chargeSchema() + " join m_product_loan lp on lp.currency_code = c.currency_code" + " where lp.id=?"
+ " and c.is_deleted=0 and c.is_active=1 and c.charge_applies_to_enum=?" + excludeClause + " order by c.name ";
return this.jdbcTemplate.query(sql, rm, params);
}
@@ -233,7 +260,7 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService
}
@Override
public Collection<ChargeData> retrieveSavingsAccountApplicableCharges(final boolean feeChargesOnly) {
public Collection<ChargeData> retrieveSavingsApplicableCharges(final boolean feeChargesOnly) {
final ChargeMapper rm = new ChargeMapper();
String sql = "select " + rm.chargeSchema()
@@ -247,7 +274,7 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService
}
@Override
public Collection<ChargeData> retrieveSavingsAccountApplicablePenalties() {
public Collection<ChargeData> retrieveSavingsApplicablePenalties() {
final ChargeMapper rm = new ChargeMapper();
final String sql = "select " + rm.chargeSchema()
@@ -97,12 +97,11 @@ public class LoanChargesApiResource {
@Path("template")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveTemplate(@Context final UriInfo uriInfo) {
public String retrieveTemplate(@PathParam("loanId") final Long loanId, @Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
final boolean feeChargesOnly = false;
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly,
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanAccountApplicableCharges(loanId,
new ChargeTimeType[] { ChargeTimeType.OVERDUE_INSTALLMENT });
final LoanChargeData loanChargeTemplate = LoanChargeData.template(chargeOptions);
@@ -440,8 +440,7 @@ public class LoansApiResource {
fundOptions = this.fundReadPlatformService.retrieveAllFunds();
repaymentStrategyOptions = this.dropdownReadPlatformService.retreiveTransactionProcessingStrategies();
final boolean feeChargesOnly = false;
chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly,
chargeOptions = this.chargeReadPlatformService.retrieveLoanAccountApplicableCharges(loanId,
new ChargeTimeType[] { ChargeTimeType.OVERDUE_INSTALLMENT });
chargeTemplate = this.loanChargeReadPlatformService.retrieveLoanChargeTemplate();
@@ -1241,8 +1241,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
final Collection<CodeValueData> loanPurposeOptions = this.codeValueReadPlatformService.retrieveCodeValuesByCode("LoanPurpose");
final Collection<CodeValueData> loanCollateralOptions = this.codeValueReadPlatformService
.retrieveCodeValuesByCode("LoanCollateral");
final boolean feeChargesOnly = false;
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly,
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanProductApplicableCharges(productId,
new ChargeTimeType[] { ChargeTimeType.OVERDUE_INSTALLMENT });
Integer loanCycleCounter = null;
if (loanProduct.useBorrowerCycle()) {
@@ -234,8 +234,7 @@ public class LoanProductsApiResource {
private LoanProductData handleTemplate(final LoanProductData productData) {
final boolean feeChargesOnly = true;
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly, null);
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableFees();
if (chargeOptions.isEmpty()) {
chargeOptions = null;
}
@@ -269,10 +269,10 @@ public class FixedDepositProductsApiResource {
// charges
final boolean feeChargesOnly = true;
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveSavingsAccountApplicableCharges(feeChargesOnly);
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveSavingsApplicableCharges(feeChargesOnly);
chargeOptions = CollectionUtils.isEmpty(chargeOptions) ? null : chargeOptions;
Collection<ChargeData> penaltyOptions = this.chargeReadPlatformService.retrieveSavingsAccountApplicablePenalties();
Collection<ChargeData> penaltyOptions = this.chargeReadPlatformService.retrieveSavingsApplicablePenalties();
penaltyOptions = CollectionUtils.isEmpty(penaltyOptions) ? null : penaltyOptions;
// interest rate chart template
@@ -265,10 +265,10 @@ public class RecurringDepositProductsApiResource {
// charges
final boolean feeChargesOnly = true;
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveSavingsAccountApplicableCharges(feeChargesOnly);
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveSavingsApplicableCharges(feeChargesOnly);
chargeOptions = CollectionUtils.isEmpty(chargeOptions) ? null : chargeOptions;
Collection<ChargeData> penaltyOptions = this.chargeReadPlatformService.retrieveSavingsAccountApplicablePenalties();
Collection<ChargeData> penaltyOptions = this.chargeReadPlatformService.retrieveSavingsApplicablePenalties();
penaltyOptions = CollectionUtils.isEmpty(penaltyOptions) ? null : penaltyOptions;
final Collection<EnumOptionData> periodFrequencyTypeOptions = this.dropdownReadPlatformService.retrievePeriodFrequencyTypeOptions();
@@ -105,7 +105,7 @@ public class SavingsAccountChargesApiResource {
this.context.authenticatedUser().validateHasReadPermission(SAVINGS_ACCOUNT_CHARGE_RESOURCE_NAME);
final boolean feeChargesOnly = false;
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveSavingsAccountApplicableCharges(feeChargesOnly);
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveSavingsApplicableCharges(feeChargesOnly);
final SavingsAccountChargeData savingsAccountChargeTemplate = SavingsAccountChargeData.template(chargeOptions);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
@@ -238,10 +238,10 @@ public class SavingsProductsApiResource {
// charges
final boolean feeChargesOnly = true;
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveSavingsAccountApplicableCharges(feeChargesOnly);
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveSavingsApplicableCharges(feeChargesOnly);
chargeOptions = CollectionUtils.isEmpty(chargeOptions) ? null : chargeOptions;
Collection<ChargeData> penaltyOptions = this.chargeReadPlatformService.retrieveSavingsAccountApplicablePenalties();
Collection<ChargeData> penaltyOptions = this.chargeReadPlatformService.retrieveSavingsApplicablePenalties();
penaltyOptions = CollectionUtils.isEmpty(penaltyOptions) ? null : penaltyOptions;
SavingsProductData savingsProductToReturn = null;
@@ -351,7 +351,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead
final boolean feeChargesOnly = false;
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService
.retrieveSavingsAccountApplicableCharges(feeChargesOnly);
.retrieveSavingsApplicableCharges(feeChargesOnly);
Collection<StaffData> fieldOfficerOptions = null;
@@ -428,7 +428,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead
final boolean feeChargesOnly = true;
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService
.retrieveSavingsAccountApplicableCharges(feeChargesOnly);
.retrieveSavingsApplicableCharges(feeChargesOnly);
if (depositAccountType.isFixedDeposit()) {
@@ -518,7 +518,7 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
final boolean feeChargesOnly = false;
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService
.retrieveSavingsAccountApplicableCharges(feeChargesOnly);
.retrieveSavingsApplicableCharges(feeChargesOnly);
Collection<StaffData> fieldOfficerOptions = null;
@@ -577,7 +577,7 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
final boolean feeChargesOnly = true;
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService
.retrieveSavingsAccountApplicableCharges(feeChargesOnly);
.retrieveSavingsApplicableCharges(feeChargesOnly);
template = SavingsAccountData.withTemplateOptions(template, productOptions, fieldOfficerOptions,
interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions,