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(); 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 * @param excludeChargeTimes
* Excludes Given List of Charge Types from the response * Excludes Given List of Charge Types from the response
* @return * @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 * Returns all Penalties applicable for loans
@@ -62,14 +77,14 @@ public interface ChargeReadPlatformService {
* @param feeChargesOnly * @param feeChargesOnly
* @return * @return
*/ */
Collection<ChargeData> retrieveSavingsAccountApplicableCharges(boolean feeChargesOnly); Collection<ChargeData> retrieveSavingsApplicableCharges(boolean feeChargesOnly);
/** /**
* Returns all penalties applicable for savings * Returns all penalties applicable for savings
* *
* @return * @return
*/ */
Collection<ChargeData> retrieveSavingsAccountApplicablePenalties(); Collection<ChargeData> retrieveSavingsApplicablePenalties();
/** /**
* Returns all charges applicable for a given savings product * Returns all charges applicable for a given savings product
@@ -124,10 +124,20 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService
} }
@Override @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(); final ChargeMapper rm = new ChargeMapper();
String excludeClause = ""; String excludeClause = "";
Object[] params = new Object[] { ChargeAppliesTo.LOAN.getValue() }; Object[] params = new Object[] { loanId, ChargeAppliesTo.LOAN.getValue() };
if (excludeChargeTimes != null && excludeChargeTimes.length > 0) { if (excludeChargeTimes != null && excludeChargeTimes.length > 0) {
excludeClause = " and c.charge_time_enum not in(?) "; excludeClause = " and c.charge_time_enum not in(?) ";
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@@ -137,15 +147,32 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService
} }
sb.append(excludeChargeTimes[i].getValue()); 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=?" String sql = "select " + rm.chargeSchema() + " join m_loan la on la.currency_code = c.currency_code" + " where la.id=?"
+ excludeClause + " order by c.name "; + " and 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() return this.jdbcTemplate.query(sql, rm, params);
+ " 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 ";
@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); return this.jdbcTemplate.query(sql, rm, params);
} }
@@ -233,7 +260,7 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService
} }
@Override @Override
public Collection<ChargeData> retrieveSavingsAccountApplicableCharges(final boolean feeChargesOnly) { public Collection<ChargeData> retrieveSavingsApplicableCharges(final boolean feeChargesOnly) {
final ChargeMapper rm = new ChargeMapper(); final ChargeMapper rm = new ChargeMapper();
String sql = "select " + rm.chargeSchema() String sql = "select " + rm.chargeSchema()
@@ -247,7 +274,7 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService
} }
@Override @Override
public Collection<ChargeData> retrieveSavingsAccountApplicablePenalties() { public Collection<ChargeData> retrieveSavingsApplicablePenalties() {
final ChargeMapper rm = new ChargeMapper(); final ChargeMapper rm = new ChargeMapper();
final String sql = "select " + rm.chargeSchema() final String sql = "select " + rm.chargeSchema()
@@ -97,12 +97,11 @@ public class LoanChargesApiResource {
@Path("template") @Path("template")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ 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); this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
final boolean feeChargesOnly = false; final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanAccountApplicableCharges(loanId,
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly,
new ChargeTimeType[] { ChargeTimeType.OVERDUE_INSTALLMENT }); new ChargeTimeType[] { ChargeTimeType.OVERDUE_INSTALLMENT });
final LoanChargeData loanChargeTemplate = LoanChargeData.template(chargeOptions); final LoanChargeData loanChargeTemplate = LoanChargeData.template(chargeOptions);
@@ -440,8 +440,7 @@ public class LoansApiResource {
fundOptions = this.fundReadPlatformService.retrieveAllFunds(); fundOptions = this.fundReadPlatformService.retrieveAllFunds();
repaymentStrategyOptions = this.dropdownReadPlatformService.retreiveTransactionProcessingStrategies(); repaymentStrategyOptions = this.dropdownReadPlatformService.retreiveTransactionProcessingStrategies();
final boolean feeChargesOnly = false; chargeOptions = this.chargeReadPlatformService.retrieveLoanAccountApplicableCharges(loanId,
chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly,
new ChargeTimeType[] { ChargeTimeType.OVERDUE_INSTALLMENT }); new ChargeTimeType[] { ChargeTimeType.OVERDUE_INSTALLMENT });
chargeTemplate = this.loanChargeReadPlatformService.retrieveLoanChargeTemplate(); chargeTemplate = this.loanChargeReadPlatformService.retrieveLoanChargeTemplate();
@@ -1241,8 +1241,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
final Collection<CodeValueData> loanPurposeOptions = this.codeValueReadPlatformService.retrieveCodeValuesByCode("LoanPurpose"); final Collection<CodeValueData> loanPurposeOptions = this.codeValueReadPlatformService.retrieveCodeValuesByCode("LoanPurpose");
final Collection<CodeValueData> loanCollateralOptions = this.codeValueReadPlatformService final Collection<CodeValueData> loanCollateralOptions = this.codeValueReadPlatformService
.retrieveCodeValuesByCode("LoanCollateral"); .retrieveCodeValuesByCode("LoanCollateral");
final boolean feeChargesOnly = false; final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanProductApplicableCharges(productId,
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly,
new ChargeTimeType[] { ChargeTimeType.OVERDUE_INSTALLMENT }); new ChargeTimeType[] { ChargeTimeType.OVERDUE_INSTALLMENT });
Integer loanCycleCounter = null; Integer loanCycleCounter = null;
if (loanProduct.useBorrowerCycle()) { if (loanProduct.useBorrowerCycle()) {
@@ -234,8 +234,7 @@ public class LoanProductsApiResource {
private LoanProductData handleTemplate(final LoanProductData productData) { private LoanProductData handleTemplate(final LoanProductData productData) {
final boolean feeChargesOnly = true; Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableFees();
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly, null);
if (chargeOptions.isEmpty()) { if (chargeOptions.isEmpty()) {
chargeOptions = null; chargeOptions = null;
} }
@@ -269,10 +269,10 @@ public class FixedDepositProductsApiResource {
// charges // charges
final boolean feeChargesOnly = true; final boolean feeChargesOnly = true;
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveSavingsAccountApplicableCharges(feeChargesOnly); Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveSavingsApplicableCharges(feeChargesOnly);
chargeOptions = CollectionUtils.isEmpty(chargeOptions) ? null : chargeOptions; chargeOptions = CollectionUtils.isEmpty(chargeOptions) ? null : chargeOptions;
Collection<ChargeData> penaltyOptions = this.chargeReadPlatformService.retrieveSavingsAccountApplicablePenalties(); Collection<ChargeData> penaltyOptions = this.chargeReadPlatformService.retrieveSavingsApplicablePenalties();
penaltyOptions = CollectionUtils.isEmpty(penaltyOptions) ? null : penaltyOptions; penaltyOptions = CollectionUtils.isEmpty(penaltyOptions) ? null : penaltyOptions;
// interest rate chart template // interest rate chart template
@@ -265,10 +265,10 @@ public class RecurringDepositProductsApiResource {
// charges // charges
final boolean feeChargesOnly = true; final boolean feeChargesOnly = true;
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveSavingsAccountApplicableCharges(feeChargesOnly); Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveSavingsApplicableCharges(feeChargesOnly);
chargeOptions = CollectionUtils.isEmpty(chargeOptions) ? null : chargeOptions; chargeOptions = CollectionUtils.isEmpty(chargeOptions) ? null : chargeOptions;
Collection<ChargeData> penaltyOptions = this.chargeReadPlatformService.retrieveSavingsAccountApplicablePenalties(); Collection<ChargeData> penaltyOptions = this.chargeReadPlatformService.retrieveSavingsApplicablePenalties();
penaltyOptions = CollectionUtils.isEmpty(penaltyOptions) ? null : penaltyOptions; penaltyOptions = CollectionUtils.isEmpty(penaltyOptions) ? null : penaltyOptions;
final Collection<EnumOptionData> periodFrequencyTypeOptions = this.dropdownReadPlatformService.retrievePeriodFrequencyTypeOptions(); final Collection<EnumOptionData> periodFrequencyTypeOptions = this.dropdownReadPlatformService.retrievePeriodFrequencyTypeOptions();
@@ -105,7 +105,7 @@ public class SavingsAccountChargesApiResource {
this.context.authenticatedUser().validateHasReadPermission(SAVINGS_ACCOUNT_CHARGE_RESOURCE_NAME); this.context.authenticatedUser().validateHasReadPermission(SAVINGS_ACCOUNT_CHARGE_RESOURCE_NAME);
final boolean feeChargesOnly = false; 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 SavingsAccountChargeData savingsAccountChargeTemplate = SavingsAccountChargeData.template(chargeOptions);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
@@ -238,10 +238,10 @@ public class SavingsProductsApiResource {
// charges // charges
final boolean feeChargesOnly = true; final boolean feeChargesOnly = true;
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveSavingsAccountApplicableCharges(feeChargesOnly); Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveSavingsApplicableCharges(feeChargesOnly);
chargeOptions = CollectionUtils.isEmpty(chargeOptions) ? null : chargeOptions; chargeOptions = CollectionUtils.isEmpty(chargeOptions) ? null : chargeOptions;
Collection<ChargeData> penaltyOptions = this.chargeReadPlatformService.retrieveSavingsAccountApplicablePenalties(); Collection<ChargeData> penaltyOptions = this.chargeReadPlatformService.retrieveSavingsApplicablePenalties();
penaltyOptions = CollectionUtils.isEmpty(penaltyOptions) ? null : penaltyOptions; penaltyOptions = CollectionUtils.isEmpty(penaltyOptions) ? null : penaltyOptions;
SavingsProductData savingsProductToReturn = null; SavingsProductData savingsProductToReturn = null;
@@ -351,7 +351,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead
final boolean feeChargesOnly = false; final boolean feeChargesOnly = false;
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService
.retrieveSavingsAccountApplicableCharges(feeChargesOnly); .retrieveSavingsApplicableCharges(feeChargesOnly);
Collection<StaffData> fieldOfficerOptions = null; Collection<StaffData> fieldOfficerOptions = null;
@@ -428,7 +428,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead
final boolean feeChargesOnly = true; final boolean feeChargesOnly = true;
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService
.retrieveSavingsAccountApplicableCharges(feeChargesOnly); .retrieveSavingsApplicableCharges(feeChargesOnly);
if (depositAccountType.isFixedDeposit()) { if (depositAccountType.isFixedDeposit()) {
@@ -518,7 +518,7 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
final boolean feeChargesOnly = false; final boolean feeChargesOnly = false;
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService
.retrieveSavingsAccountApplicableCharges(feeChargesOnly); .retrieveSavingsApplicableCharges(feeChargesOnly);
Collection<StaffData> fieldOfficerOptions = null; Collection<StaffData> fieldOfficerOptions = null;
@@ -577,7 +577,7 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
final boolean feeChargesOnly = true; final boolean feeChargesOnly = true;
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService
.retrieveSavingsAccountApplicableCharges(feeChargesOnly); .retrieveSavingsApplicableCharges(feeChargesOnly);
template = SavingsAccountData.withTemplateOptions(template, productOptions, fieldOfficerOptions, template = SavingsAccountData.withTemplateOptions(template, productOptions, fieldOfficerOptions,
interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions,