diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/common/AccountingConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/common/AccountingConstants.java index 3091270f6..6aacb3cb0 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/common/AccountingConstants.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/common/AccountingConstants.java @@ -84,7 +84,7 @@ public class AccountingConstants { FUND_SOURCE("fundSourceAccountId"), LOAN_PORTFOLIO("loanPortfolioAccountId"), INTEREST_ON_LOANS("interestOnLoanAccountId"), INCOME_FROM_FEES( "incomeFromFeeAccountId"), INCOME_FROM_PENALTIES("incomeFromPenaltyAccountId"), LOSSES_WRITTEN_OFF("writeOffAccountId"), INTEREST_RECEIVABLE( "receivableInterestAccountId"), FEES_RECEIVABLE("receivableFeeAccountId"), PENALTIES_RECEIVABLE( - "receivablePenaltyAccountId"), PAYMENT_CHANNEL_FUND_SOURCE_MAPPING("paymentChannelFundSourceMappings"), PAYMENT_TYPE( + "receivablePenaltyAccountId"), PAYMENT_CHANNEL_FUND_SOURCE_MAPPING("paymentChannelToFundSourceMappings"), PAYMENT_TYPE( "paymentTypeId"); private final String value; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/data/PaymentTypeToGLAccountMapper.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/data/PaymentTypeToGLAccountMapper.java new file mode 100755 index 000000000..96e3afcd7 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/data/PaymentTypeToGLAccountMapper.java @@ -0,0 +1,15 @@ +package org.mifosplatform.accounting.producttoaccountmapping.data; + +public class PaymentTypeToGLAccountMapper { + + @SuppressWarnings("unused") + private final long paymentTypeId; + @SuppressWarnings("unused") + private final long fundSourceAccountId; + + public PaymentTypeToGLAccountMapper(long paymentTypeId, long fundSourceAccountId) { + this.paymentTypeId = paymentTypeId; + this.fundSourceAccountId = fundSourceAccountId; + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingReadPlatformService.java index 72473b67d..74ced327f 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingReadPlatformService.java @@ -5,11 +5,14 @@ */ package org.mifosplatform.accounting.producttoaccountmapping.service; +import java.util.List; import java.util.Map; +import org.mifosplatform.accounting.producttoaccountmapping.data.PaymentTypeToGLAccountMapper; + public interface ProductToGLAccountMappingReadPlatformService { Map fetchAccountMappingDetailsForLoanProduct(final Long loanProductId, final Integer accountingType); - Map fetchPaymentTypeToFundSourceMappingsForLoanProduct(final Long loanProductId); + List fetchPaymentTypeToFundSourceMappingsForLoanProduct(final Long loanProductId); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingReadPlatformServiceImpl.java index a016d49e5..e5e59f8e1 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingReadPlatformServiceImpl.java @@ -7,6 +7,7 @@ package org.mifosplatform.accounting.producttoaccountmapping.service; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -14,6 +15,7 @@ import java.util.Map; import org.mifosplatform.accounting.common.AccountingConstants.ACCRUAL_ACCOUNTS_FOR_LOAN; import org.mifosplatform.accounting.common.AccountingConstants.CASH_ACCOUNTS_FOR_LOAN; import org.mifosplatform.accounting.common.AccountingConstants.LOAN_PRODUCT_ACCOUNTING_PARAMS; +import org.mifosplatform.accounting.producttoaccountmapping.data.PaymentTypeToGLAccountMapper; import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource; import org.mifosplatform.portfolio.loanproduct.domain.AccountingRuleType; import org.springframework.beans.factory.annotation.Autowired; @@ -66,7 +68,7 @@ public class ProductToGLAccountMappingReadPlatformServiceImpl implements Product final Map accountMappingDetails = new LinkedHashMap(8); final LoanProductToGLAccountMappingMapper rm = new LoanProductToGLAccountMappingMapper(); - final String sql = "select " + rm.schema() + " and product_id = ?"; + final String sql = "select " + rm.schema() + " and product_id = ? and payment_type is null "; final List> listOfProductToGLAccountMaps = this.jdbcTemplate.query(sql, rm, new Object[] { loanProductId }); @@ -128,8 +130,8 @@ public class ProductToGLAccountMappingReadPlatformServiceImpl implements Product } @Override - public Map fetchPaymentTypeToFundSourceMappingsForLoanProduct(Long loanProductId) { - Map paymentTypeToFundSourceMappingDetails = null; + public List fetchPaymentTypeToFundSourceMappingsForLoanProduct(Long loanProductId) { + List paymentTypeToGLAccountMappers = null; final LoanProductToGLAccountMappingMapper rm = new LoanProductToGLAccountMappingMapper(); final String sql = "select " + rm.schema() + " and product_id = ? and payment_type is not null"; @@ -138,13 +140,14 @@ public class ProductToGLAccountMappingReadPlatformServiceImpl implements Product new Object[] { loanProductId }); for (final Map productToGLAccountMap : paymentTypeToFundSourceMappingsList) { - if (paymentTypeToFundSourceMappingDetails == null) { - paymentTypeToFundSourceMappingDetails = new LinkedHashMap(); + if (paymentTypeToGLAccountMappers == null) { + paymentTypeToGLAccountMappers = new ArrayList(); } final Long glAccountId = (Long) productToGLAccountMap.get("glAccountId"); final Long paymentTypeId = (Long) productToGLAccountMap.get("paymentTypeId"); - paymentTypeToFundSourceMappingDetails.put(paymentTypeId, glAccountId); + PaymentTypeToGLAccountMapper paymentTypeToGLAccountMapper = new PaymentTypeToGLAccountMapper(paymentTypeId, glAccountId); + paymentTypeToGLAccountMappers.add(paymentTypeToGLAccountMapper); } - return paymentTypeToFundSourceMappingDetails; + return paymentTypeToGLAccountMappers; } } \ No newline at end of file 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 42cfe6a30..aca8c9713 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 @@ -188,7 +188,7 @@ public class ProductToGLAccountMappingWritePlatformServiceImpl implements Produc } /** - * Finds + * * * @param command * @param element @@ -239,11 +239,11 @@ public class ProductToGLAccountMappingWritePlatformServiceImpl implements Produc **/ else { for (ProductToGLAccountMapping existingPaymentChannelToFundSourceMapping : existingPaymentChannelToFundSourceMappings) { - Long currentPaymentChannelId = existingPaymentChannelToFundSourceMapping.getId(); + Long currentPaymentChannelId = existingPaymentChannelToFundSourceMapping.getPaymentType().getId(); existingPaymentTypes.add(currentPaymentChannelId); // update existing mappings (if required) - if (inputPaymentChannelFundSourceMap.containsKey(existingPaymentChannelToFundSourceMapping.getId())) { - Long newGLAccountId = inputPaymentChannelFundSourceMap.get(existingPaymentChannelToFundSourceMapping.getId()); + if (inputPaymentChannelFundSourceMap.containsKey(currentPaymentChannelId)) { + Long newGLAccountId = inputPaymentChannelFundSourceMap.get(currentPaymentChannelId); if (newGLAccountId != existingPaymentChannelToFundSourceMapping.getGlAccount().getId()) { final GLAccount glAccount = getAccountByIdAndType(LOAN_PRODUCT_ACCOUNTING_PARAMS.FUND_SOURCE.getValue(), GLAccountType.ASSET, newGLAccountId); @@ -257,12 +257,12 @@ public class ProductToGLAccountMappingWritePlatformServiceImpl implements Produc } // create new mappings Set incomingPaymentTypes = inputPaymentChannelFundSourceMap.keySet(); - boolean newPaymentTypesAdded = incomingPaymentTypes.removeAll(existingPaymentTypes); - if (newPaymentTypesAdded) { - for (Long newPaymentType : incomingPaymentTypes) { - Long newGLAccountId = inputPaymentChannelFundSourceMap.get(newPaymentType); - savePaymentChannelToFundSourceMapping(productId, newPaymentType, newGLAccountId); - } + incomingPaymentTypes.removeAll(existingPaymentTypes); + // incomingPaymentTypes now only contains the newly added + // payment Type mappings + for (Long newPaymentType : incomingPaymentTypes) { + Long newGLAccountId = inputPaymentChannelFundSourceMap.get(newPaymentType); + savePaymentChannelToFundSourceMapping(productId, newPaymentType, newGLAccountId); } } } 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 c49f77f8c..dec4f9151 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 @@ -27,6 +27,7 @@ import javax.ws.rs.core.UriInfo; import org.mifosplatform.accounting.glaccount.data.GLAccountData; import org.mifosplatform.accounting.glaccount.domain.GLAccountType; import org.mifosplatform.accounting.glaccount.service.GLAccountReadPlatformService; +import org.mifosplatform.accounting.producttoaccountmapping.data.PaymentTypeToGLAccountMapper; import org.mifosplatform.accounting.producttoaccountmapping.service.ProductToGLAccountMappingReadPlatformService; import org.mifosplatform.commands.domain.CommandWrapper; import org.mifosplatform.commands.service.CommandWrapperBuilder; @@ -161,7 +162,7 @@ public class LoanProductsApiResource { LoanProductData loanProduct = this.loanProductReadPlatformService.retrieveLoanProduct(productId); Map accountingMappings = null; - Map paymentChannelToFundSourceMappings = null; + Collection paymentChannelToFundSourceMappings = null; if (loanProduct.hasAccountingEnabled()) { accountingMappings = accountMappingReadPlatformService.fetchAccountMappingDetailsForLoanProduct(productId, loanProduct .accountingRuleType().getId().intValue()); @@ -191,7 +192,7 @@ public class LoanProductsApiResource { } private LoanProductData handleTemplate(final LoanProductData productData, final Map accountingMappings, - final Map paymentChannelToFundSourceMappings) { + final Collection paymentChannelToFundSourceMappings) { final boolean feeChargesOnly = true; Collection chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly); 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 6b0efe4c1..e5ef5b9b6 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 @@ -12,6 +12,7 @@ import java.util.List; import java.util.Map; import org.mifosplatform.accounting.glaccount.data.GLAccountData; +import org.mifosplatform.accounting.producttoaccountmapping.data.PaymentTypeToGLAccountMapper; import org.mifosplatform.infrastructure.codes.data.CodeValueData; import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.organisation.monetary.data.CurrencyData; @@ -67,7 +68,7 @@ public class LoanProductData { @SuppressWarnings("unused") private final Map accountingMappings; @SuppressWarnings("unused") - private final Map paymentChannelToFundSourceMappings; + private final Collection paymentChannelToFundSourceMappings; // template related private final Collection fundOptions; @@ -191,7 +192,7 @@ public class LoanProductData { } public static LoanProductData withAccountingDetails(final LoanProductData productData, final Map accountingMappings, - final Map paymentChannelToFundSourceMappings) { + final Collection paymentChannelToFundSourceMappings) { return new LoanProductData(productData, productData.chargeOptions, productData.paymentTypeOptions, productData.currencyOptions, productData.amortizationTypeOptions, productData.interestTypeOptions, productData.interestCalculationPeriodTypeOptions, @@ -270,7 +271,7 @@ public class LoanProductData { final List interestRateFrequencyTypeOptions, final Collection fundOptions, final Collection transactionStrategyOptions, final Map> accountingMappingOptions, final List accountingRuleOptions, - final Map accountingMappings, final Map paymentChannelToFundSourceMappings) { + final Map accountingMappings, final Collection paymentChannelToFundSourceMappings) { this.id = productData.id; this.name = productData.name; this.description = productData.description; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/serialization/LoanProductCommandFromApiJsonDeserializer.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/serialization/LoanProductCommandFromApiJsonDeserializer.java index 5f5f93826..a62dd348e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/serialization/LoanProductCommandFromApiJsonDeserializer.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/serialization/LoanProductCommandFromApiJsonDeserializer.java @@ -483,7 +483,7 @@ public final class LoanProductCommandFromApiJsonDeserializer { if (fromApiJsonHelper.parameterExists(LOAN_PRODUCT_ACCOUNTING_PARAMS.PAYMENT_CHANNEL_FUND_SOURCE_MAPPING.getValue(), element)) { JsonArray paymentChannelMappingArray = fromApiJsonHelper.extractJsonArrayNamed( LOAN_PRODUCT_ACCOUNTING_PARAMS.PAYMENT_CHANNEL_FUND_SOURCE_MAPPING.getValue(), element); - if (paymentChannelMappingArray != null) { + if (paymentChannelMappingArray != null && paymentChannelMappingArray.size() > 0) { int i = 0; do { final JsonObject jsonObject = paymentChannelMappingArray.get(i).getAsJsonObject();