Advanced deposit products and accounts (FD & RD) with interest rate

extensions bug fixes
This commit is contained in:
Michael Duku-Kaakyire
2014-04-30 21:42:56 +00:00
parent d033ea22ca
commit 31a6e07e87
13 changed files with 97 additions and 35 deletions
@@ -8,17 +8,18 @@ package org.mifosplatform.accounting.producttoaccountmapping.service;
import java.util.Map;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.portfolio.savings.DepositAccountType;
public interface ProductToGLAccountMappingWritePlatformService {
void createLoanProductToGLAccountMapping(Long loanProductId, JsonCommand command);
void createSavingProductToGLAccountMapping(Long savingProductId, JsonCommand command);
void createSavingProductToGLAccountMapping(Long savingProductId, JsonCommand command, DepositAccountType accountType);
Map<String, Object> updateLoanProductToGLAccountMapping(Long loanProductId, JsonCommand command, boolean accountingRuleChanged,
int accountingRuleTypeId);
Map<String, Object> updateSavingsProductToGLAccountMapping(Long savingsProductId, JsonCommand command, boolean accountingRuleChanged,
int accountingRuleTypeId);
int accountingRuleTypeId, DepositAccountType accountType);
}
@@ -20,6 +20,7 @@ import org.mifosplatform.accounting.common.AccountingRuleType;
import org.mifosplatform.accounting.producttoaccountmapping.serialization.ProductToGLAccountMappingFromApiJsonDeserializer;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
import org.mifosplatform.portfolio.savings.DepositAccountType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -145,7 +146,7 @@ public class ProductToGLAccountMappingWritePlatformServiceImpl implements Produc
@Override
@Transactional
public void createSavingProductToGLAccountMapping(final Long savingProductId, final JsonCommand command) {
public void createSavingProductToGLAccountMapping(final Long savingProductId, final JsonCommand command, DepositAccountType accountType) {
final JsonElement element = this.fromApiJsonHelper.parse(command.json());
final Integer accountingRuleTypeId = this.fromApiJsonHelper.extractIntegerNamed(accountingRuleParamName, element,
Locale.getDefault());
@@ -159,9 +160,12 @@ public class ProductToGLAccountMappingWritePlatformServiceImpl implements Produc
this.savingsProductToGLAccountMappingHelper.saveSavingsToAssetAccountMapping(element,
SAVINGS_PRODUCT_ACCOUNTING_PARAMS.SAVINGS_REFERENCE.getValue(), savingProductId,
CASH_ACCOUNTS_FOR_SAVINGS.SAVINGS_REFERENCE.getValue());
this.savingsProductToGLAccountMappingHelper.saveSavingsToAssetAccountMapping(element,
if(!accountType.equals(DepositAccountType.RECURRING_DEPOSIT) && !accountType.equals(DepositAccountType.FIXED_DEPOSIT)) {
this.savingsProductToGLAccountMappingHelper.saveSavingsToAssetAccountMapping(element,
SAVINGS_PRODUCT_ACCOUNTING_PARAMS.OVERDRAFT_PORTFOLIO_CONTROL.getValue(), savingProductId,
CASH_ACCOUNTS_FOR_SAVINGS.OVERDRAFT_PORTFOLIO_CONTROL.getValue());
}
// income
this.savingsProductToGLAccountMappingHelper.saveSavingsToIncomeAccountMapping(element,
@@ -171,19 +175,23 @@ public class ProductToGLAccountMappingWritePlatformServiceImpl implements Produc
this.savingsProductToGLAccountMappingHelper.saveSavingsToIncomeAccountMapping(element,
SAVINGS_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_PENALTIES.getValue(), savingProductId,
CASH_ACCOUNTS_FOR_SAVINGS.INCOME_FROM_PENALTIES.getValue());
if(!accountType.equals(DepositAccountType.RECURRING_DEPOSIT) && !accountType.equals(DepositAccountType.FIXED_DEPOSIT)) {
this.savingsProductToGLAccountMappingHelper.saveSavingsToIncomeAccountMapping(element,
SAVINGS_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_INTEREST.getValue(), savingProductId,
CASH_ACCOUNTS_FOR_SAVINGS.INCOME_FROM_INTEREST.getValue());
}
// expenses
this.savingsProductToGLAccountMappingHelper.saveSavingsToExpenseAccountMapping(element,
SAVINGS_PRODUCT_ACCOUNTING_PARAMS.INTEREST_ON_SAVINGS.getValue(), savingProductId,
CASH_ACCOUNTS_FOR_SAVINGS.INTEREST_ON_SAVINGS.getValue());
if(!accountType.equals(DepositAccountType.RECURRING_DEPOSIT) && !accountType.equals(DepositAccountType.FIXED_DEPOSIT)) {
this.savingsProductToGLAccountMappingHelper.saveSavingsToExpenseAccountMapping(element,
SAVINGS_PRODUCT_ACCOUNTING_PARAMS.LOSSES_WRITTEN_OFF.getValue(), savingProductId,
CASH_ACCOUNTS_FOR_SAVINGS.LOSSES_WRITTEN_OFF.getValue());
CASH_ACCOUNTS_FOR_SAVINGS.LOSSES_WRITTEN_OFF.getValue());
}
// liability
this.savingsProductToGLAccountMappingHelper.saveSavingsToLiabilityAccountMapping(element,
@@ -237,7 +245,7 @@ public class ProductToGLAccountMappingWritePlatformServiceImpl implements Produc
@Override
public Map<String, Object> updateSavingsProductToGLAccountMapping(final Long savingsProductId, final JsonCommand command,
final boolean accountingRuleChanged, final int accountingRuleTypeId) {
final boolean accountingRuleChanged, final int accountingRuleTypeId, final DepositAccountType accountType) {
/***
* Variable tracks all accounting mapping properties that have been
* updated
@@ -253,7 +261,7 @@ public class ProductToGLAccountMappingWritePlatformServiceImpl implements Produc
if (accountingRuleChanged) {
this.deserializer.validateForSavingsProductCreate(command.json());
this.savingsProductToGLAccountMappingHelper.deleteSavingsProductToGLAccountMapping(savingsProductId);
createSavingProductToGLAccountMapping(savingsProductId, command);
createSavingProductToGLAccountMapping(savingsProductId, command, accountType);
changes = this.savingsProductToGLAccountMappingHelper.populateChangesForNewSavingsProductToGLAccountMappingCreation(element,
accountingRuleType);
}/*** else examine and update individual changes ***/
@@ -266,4 +274,4 @@ public class ProductToGLAccountMappingWritePlatformServiceImpl implements Produc
}
return changes;
}
}
}
@@ -212,6 +212,8 @@ public class InterestRateChartSlabFields {
}
public boolean isAmountBetween(final BigDecimal depositAmount){
if(depositAmount == null || amountRangeFrom == null || amountRangeTo == null)
return true;
return depositAmount.compareTo(amountRangeFrom) >= 0 && depositAmount.compareTo(amountRangeTo) <= 0;
}
}
@@ -213,9 +213,7 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi
}
this.savingsAccountRepository.save(account);
if (withdrawal != null) {
saveTransactionToGenerateTransactionId(withdrawal);
}
postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
return withdrawal;
@@ -8,6 +8,7 @@ package org.mifosplatform.portfolio.savings.domain;
import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositAmountParamName;
import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositPeriodFrequencyIdParamName;
import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositPeriodParamName;
import static org.mifosplatform.portfolio.savings.DepositsApiConstants.expectedFirstDepositOnDateParamName;
import java.math.BigDecimal;
import java.util.Date;
@@ -32,6 +33,7 @@ import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
import org.mifosplatform.organisation.monetary.domain.Money;
import org.mifosplatform.portfolio.savings.DepositAccountOnClosureType;
import org.mifosplatform.portfolio.savings.SavingsApiConstants;
import org.mifosplatform.portfolio.savings.SavingsPeriodFrequencyType;
import org.mifosplatform.portfolio.savings.service.SavingsEnumerations;
import org.springframework.data.jpa.domain.AbstractPersistable;
@@ -122,6 +124,18 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable<Long> {
actualChanges.put(depositPeriodFrequencyIdParamName, SavingsEnumerations.depositTermFrequencyType(newValue));
this.depositPeriodFrequency = newValue;
}
final String localeAsInput = command.locale();
final String dateFormat = command.dateFormat();
if (command.isChangeInLocalDateParameterNamed(expectedFirstDepositOnDateParamName, getExpectedFirstDepositOnDate())) {
final LocalDate newValue = command.localDateValueOfParameterNamed(expectedFirstDepositOnDateParamName);
final String newValueAsString = command.stringValueOfParameterNamed(expectedFirstDepositOnDateParamName);
actualChanges.put(expectedFirstDepositOnDateParamName, newValueAsString);
actualChanges.put(SavingsApiConstants.localeParamName, localeAsInput);
actualChanges.put(SavingsApiConstants.dateFormatParamName, dateFormat);
this.expectedFirstDepositOnDate = newValue.toDate();
}
if (this.preClosureDetail != null) {
actualChanges.putAll(this.preClosureDetail.update(command, baseDataValidator));
@@ -576,7 +576,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
LocalDate endOfBalanceDate = interestPostingUpToDate;
for (int i = accountTransactionsSorted.size() - 1; i >= 0; i--) {
final SavingsAccountTransaction transaction = accountTransactionsSorted.get(i);
if (transaction.isNotReversed()) {
if (transaction.isNotReversed() && !transaction.isInterestPostingAndNotReversed()) {
transaction.updateCumulativeBalanceAndDates(this.currency, endOfBalanceDate);
// this transactions transaction date is end of balance date for
@@ -19,6 +19,7 @@ import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityExce
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.charge.domain.Charge;
import org.mifosplatform.portfolio.interestratechart.service.InterestRateChartAssembler;
import org.mifosplatform.portfolio.savings.DepositAccountType;
import org.mifosplatform.portfolio.savings.data.DepositProductDataValidator;
import org.mifosplatform.portfolio.savings.domain.DepositProductAssembler;
import org.mifosplatform.portfolio.savings.domain.FixedDepositProduct;
@@ -70,7 +71,7 @@ public class FixedDepositProductWritePlatformServiceJpaRepositoryImpl implements
this.fixedDepositProductRepository.save(product);
// save accounting mappings
this.accountMappingWritePlatformService.createSavingProductToGLAccountMapping(product.getId(), command);
this.accountMappingWritePlatformService.createSavingProductToGLAccountMapping(product.getId(), command, DepositAccountType.FIXED_DEPOSIT);
return new CommandProcessingResultBuilder() //
.withEntityId(product.getId()) //
@@ -107,7 +108,7 @@ public class FixedDepositProductWritePlatformServiceJpaRepositoryImpl implements
// accounting related changes
final boolean accountingTypeChanged = changes.containsKey(accountingRuleParamName);
final Map<String, Object> accountingMappingChanges = this.accountMappingWritePlatformService
.updateSavingsProductToGLAccountMapping(product.getId(), command, accountingTypeChanged, product.getAccountingType());
.updateSavingsProductToGLAccountMapping(product.getId(), command, accountingTypeChanged, product.getAccountingType(), DepositAccountType.FIXED_DEPOSIT);
changes.putAll(accountingMappingChanges);
if (!changes.isEmpty()) {
@@ -19,6 +19,7 @@ import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityExce
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.charge.domain.Charge;
import org.mifosplatform.portfolio.interestratechart.service.InterestRateChartAssembler;
import org.mifosplatform.portfolio.savings.DepositAccountType;
import org.mifosplatform.portfolio.savings.data.DepositProductDataValidator;
import org.mifosplatform.portfolio.savings.domain.DepositProductAssembler;
import org.mifosplatform.portfolio.savings.domain.RecurringDepositProduct;
@@ -70,7 +71,7 @@ public class RecurringDepositProductWritePlatformServiceJpaRepositoryImpl implem
this.recurringDepositProductRepository.save(product);
// save accounting mappings
this.accountMappingWritePlatformService.createSavingProductToGLAccountMapping(product.getId(), command);
this.accountMappingWritePlatformService.createSavingProductToGLAccountMapping(product.getId(), command, DepositAccountType.RECURRING_DEPOSIT);
return new CommandProcessingResultBuilder() //
.withEntityId(product.getId()) //
@@ -107,7 +108,7 @@ public class RecurringDepositProductWritePlatformServiceJpaRepositoryImpl implem
// accounting related changes
final boolean accountingTypeChanged = changes.containsKey(accountingRuleParamName);
final Map<String, Object> accountingMappingChanges = this.accountMappingWritePlatformService
.updateSavingsProductToGLAccountMapping(product.getId(), command, accountingTypeChanged, product.getAccountingType());
.updateSavingsProductToGLAccountMapping(product.getId(), command, accountingTypeChanged, product.getAccountingType(), DepositAccountType.RECURRING_DEPOSIT);
changes.putAll(accountingMappingChanges);
if (!changes.isEmpty()) {
@@ -18,6 +18,7 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.charge.domain.Charge;
import org.mifosplatform.portfolio.savings.DepositAccountType;
import org.mifosplatform.portfolio.savings.data.SavingsProductDataValidator;
import org.mifosplatform.portfolio.savings.domain.SavingsProduct;
import org.mifosplatform.portfolio.savings.domain.SavingsProductAssembler;
@@ -93,7 +94,7 @@ public class SavingsProductWritePlatformServiceJpaRepositoryImpl implements Savi
this.savingProductRepository.save(product);
// save accounting mappings
this.accountMappingWritePlatformService.createSavingProductToGLAccountMapping(product.getId(), command);
this.accountMappingWritePlatformService.createSavingProductToGLAccountMapping(product.getId(), command, DepositAccountType.SAVINGS_DEPOSIT);
return new CommandProcessingResultBuilder() //
.withEntityId(product.getId()) //
@@ -129,7 +130,7 @@ public class SavingsProductWritePlatformServiceJpaRepositoryImpl implements Savi
// accounting related changes
final boolean accountingTypeChanged = changes.containsKey(accountingRuleParamName);
final Map<String, Object> accountingMappingChanges = this.accountMappingWritePlatformService
.updateSavingsProductToGLAccountMapping(product.getId(), command, accountingTypeChanged, product.getAccountingType());
.updateSavingsProductToGLAccountMapping(product.getId(), command, accountingTypeChanged, product.getAccountingType(), DepositAccountType.SAVINGS_DEPOSIT);
changes.putAll(accountingMappingChanges);
if (!changes.isEmpty()) {