From af3d917441ae9864905eec9220a203768ae3b598 Mon Sep 17 00:00:00 2001 From: Vishwas Babu AJ Date: Sat, 8 Jun 2013 09:40:29 +0530 Subject: [PATCH] optionally fetch all penalty options as part of loan product creation --- ...oGLAccountMappingWritePlatformServiceImpl.java | 1 + .../charge/service/ChargeReadPlatformService.java | 2 ++ .../service/ChargeReadPlatformServiceImpl.java | 12 ++++++++++++ .../loanproduct/api/LoanProductsApiResource.java | 12 +++++++++--- .../loanproduct/data/LoanProductData.java | 15 +++++++++------ 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingWritePlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingWritePlatformServiceImpl.java index cb6df514a..085c1e108 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingWritePlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingWritePlatformServiceImpl.java @@ -194,6 +194,7 @@ public class ProductToGLAccountMappingWritePlatformServiceImpl implements Produc loanProductToGLAccountMappingHelper.handleChangesToLoanProductToGLAccountMappings(loanProductId, changes, element, accountingRuleType); loanProductToGLAccountMappingHelper.updatePaymentChannelToFundSourceMappings(command, element, loanProductId, changes); + loanProductToGLAccountMappingHelper.updateChargesToIncomeAccountMappings(command, element, loanProductId, changes); } return changes; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeReadPlatformService.java index 1ffd4a1f7..802a54779 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeReadPlatformService.java @@ -19,5 +19,7 @@ public interface ChargeReadPlatformService { Collection retrieveLoanApplicableCharges(boolean feeChargesOnly); + Collection retrieveLoanApplicablePenalties(); + Collection retrieveLoanProductCharges(Long loanProductId); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeReadPlatformServiceImpl.java index 9a5d891f5..4031760b9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeReadPlatformServiceImpl.java @@ -111,6 +111,17 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService return this.jdbcTemplate.query(sql, rm, new Object[] { ChargeAppliesTo.LOAN.getValue() }); } + + @Override + public Collection retrieveLoanApplicablePenalties() { + this.context.authenticatedUser(); + + final ChargeMapper rm = new ChargeMapper(); + + String sql = "select " + rm.chargeSchema() + + " where c.is_deleted=0 and c.is_active=1 and c.is_penalty=1 and c.charge_applies_to_enum=? order by c.name "; + return this.jdbcTemplate.query(sql, rm, new Object[] { ChargeAppliesTo.LOAN.getValue() }); + } private static final class ChargeMapper implements RowMapper { @@ -157,4 +168,5 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService active); } } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/api/LoanProductsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/api/LoanProductsApiResource.java index 0cf9dfb2e..971624337 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/api/LoanProductsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/api/LoanProductsApiResource.java @@ -204,6 +204,11 @@ public class LoanProductsApiResource { chargeOptions = null; } + Collection penaltyOptions = this.chargeReadPlatformService.retrieveLoanApplicablePenalties(); + if (penaltyOptions.isEmpty()) { + penaltyOptions = null; + } + final Collection currencyOptions = currencyReadPlatformService.retrieveAllowedCurrencies(); final List amortizationTypeOptions = dropdownReadPlatformService.retrieveLoanAmortizationTypeOptions(); final List interestTypeOptions = dropdownReadPlatformService.retrieveLoanInterestTypeOptions(); @@ -227,8 +232,9 @@ public class LoanProductsApiResource { List accountingRuleTypeOptions = accountingDropdownReadPlatformService.retrieveAccountingRuleTypeOptions(); - return new LoanProductData(productData, chargeOptions, paymentTypeOptions, currencyOptions, amortizationTypeOptions, - interestTypeOptions, interestCalculationPeriodTypeOptions, repaymentFrequencyTypeOptions, interestRateFrequencyTypeOptions, - fundOptions, transactionProcessingStrategyOptions, accountOptions, accountingRuleTypeOptions); + return new LoanProductData(productData, chargeOptions, penaltyOptions, paymentTypeOptions, currencyOptions, + amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions, repaymentFrequencyTypeOptions, + interestRateFrequencyTypeOptions, fundOptions, transactionProcessingStrategyOptions, accountOptions, + accountingRuleTypeOptions); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/data/LoanProductData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/data/LoanProductData.java index 3069204f4..d228f65d9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/data/LoanProductData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/data/LoanProductData.java @@ -89,6 +89,8 @@ public class LoanProductData { private final Collection transactionProcessingStrategyOptions; private final Collection chargeOptions; @SuppressWarnings("unused") + private final Collection penaltyOptions; + @SuppressWarnings("unused") private final List accountingRuleOptions; @SuppressWarnings("unused") private final Map> accountingMappingOptions; @@ -269,6 +271,7 @@ public class LoanProductData { this.accountingRule = accountingType; this.chargeOptions = null; + this.penaltyOptions = null; this.paymentTypeOptions = null; this.currencyOptions = null; this.fundOptions = null; @@ -288,11 +291,11 @@ public class LoanProductData { } public LoanProductData(final LoanProductData productData, final Collection chargeOptions, - final Collection paymentTypeOptions, final Collection currencyOptions, - final List amortizationTypeOptions, final List interestTypeOptions, - final List interestCalculationPeriodTypeOptions, final List repaymentFrequencyTypeOptions, - final List interestRateFrequencyTypeOptions, final Collection fundOptions, - final Collection transactionStrategyOptions, + final Collection penaltyOptions, final Collection paymentTypeOptions, + final Collection currencyOptions, final List amortizationTypeOptions, + final List interestTypeOptions, final List interestCalculationPeriodTypeOptions, + final List repaymentFrequencyTypeOptions, final List interestRateFrequencyTypeOptions, + final Collection fundOptions, final Collection transactionStrategyOptions, final Map> accountingMappingOptions, final List accountingRuleOptions) { this.id = productData.id; this.name = productData.name; @@ -326,6 +329,7 @@ public class LoanProductData { this.penaltyToIncomeAccountMappings = productData.penaltyToIncomeAccountMappings; this.chargeOptions = chargeOptions; + this.penaltyOptions = penaltyOptions; this.paymentTypeOptions = paymentTypeOptions; this.currencyOptions = currencyOptions; this.currency = productData.currency; @@ -355,7 +359,6 @@ public class LoanProductData { this.accountingMappingOptions = accountingMappingOptions; this.accountingRuleOptions = accountingRuleOptions; - } private Collection nullIfEmpty(final Collection charges) {