From 6769fd18438cfad003c9a62900205a4dc6f5f48e Mon Sep 17 00:00:00 2001 From: Pramod Nuthakki Date: Thu, 5 Sep 2013 17:53:01 +0530 Subject: [PATCH 1/2] added transfer withdrawal fee configuration --- ..._transfer_withdrawal_fee_configuration.sql | 5 ++++ ...ountTransfersWritePlatformServiceImpl.java | 4 +-- .../savings/SavingsApiConstants.java | 27 +++++++++--------- .../savings/data/SavingsAccountData.java | 27 ++++++++++-------- .../data/SavingsAccountDataValidator.java | 13 +++++++++ .../savings/data/SavingsProductData.java | 28 +++++++++++-------- .../data/SavingsProductDataValidator.java | 13 +++++++++ .../savings/domain/SavingsAccount.java | 28 +++++++++++++++---- .../domain/SavingsAccountAssembler.java | 9 +++++- .../domain/SavingsAccountDomainService.java | 2 +- .../SavingsAccountDomainServiceJpa.java | 4 +-- .../savings/domain/SavingsProduct.java | 23 +++++++++++---- .../domain/SavingsProductAssembler.java | 10 +++++-- ...SavingsAccountReadPlatformServiceImpl.java | 16 +++++++---- ...WritePlatformServiceJpaRepositoryImpl.java | 4 +-- ...SavingsProductReadPlatformServiceImpl.java | 7 +++-- 16 files changed, 155 insertions(+), 65 deletions(-) create mode 100755 mifosng-db/migrations/core_db/V109__account_transfer_withdrawal_fee_configuration.sql diff --git a/mifosng-db/migrations/core_db/V109__account_transfer_withdrawal_fee_configuration.sql b/mifosng-db/migrations/core_db/V109__account_transfer_withdrawal_fee_configuration.sql new file mode 100755 index 000000000..7e50e1708 --- /dev/null +++ b/mifosng-db/migrations/core_db/V109__account_transfer_withdrawal_fee_configuration.sql @@ -0,0 +1,5 @@ +ALTER TABLE `m_savings_product` + ADD COLUMN `withdrawal_fee_for_transfer` TINYINT NULL DEFAULT '1' AFTER `withdrawal_fee_type_enum`; + +ALTER TABLE `m_savings_account` + ADD COLUMN `withdrawal_fee_for_transfer` TINYINT NULL DEFAULT '1' AFTER `withdrawal_fee_type_enum`; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/AccountTransfersWritePlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/AccountTransfersWritePlatformServiceImpl.java index fe70b7fc0..b23e20adc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/AccountTransfersWritePlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/AccountTransfersWritePlatformServiceImpl.java @@ -96,7 +96,7 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer final SavingsAccount fromSavingsAccount = this.savingsAccountAssembler.assembleFrom(fromSavingsAccountId); final SavingsAccountTransaction withdrawal = this.savingsAccountDomainService.handleWithdrawal(fromSavingsAccount, fmt, - transactionDate, transactionAmount, paymentDetail); + transactionDate, transactionAmount, paymentDetail, fromSavingsAccount.isWithdrawalFeeApplicableForTransfer()); final Long toSavingsId = command.longValueOfParameterNamed(toAccountIdParamName); final SavingsAccount toSavingsAccount = this.savingsAccountAssembler.assembleFrom(toSavingsId); @@ -115,7 +115,7 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer final SavingsAccount fromSavingsAccount = this.savingsAccountAssembler.assembleFrom(fromSavingsAccountId); final SavingsAccountTransaction withdrawal = this.savingsAccountDomainService.handleWithdrawal(fromSavingsAccount, fmt, - transactionDate, transactionAmount, paymentDetail); + transactionDate, transactionAmount, paymentDetail, fromSavingsAccount.isWithdrawalFeeApplicableForTransfer()); final Long toLoanAccountId = command.longValueOfParameterNamed(toAccountIdParamName); final Loan toLoanAccount = this.loanAccountAssembler.assembleFrom(toLoanAccountId); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/SavingsApiConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/SavingsApiConstants.java index b0452a62d..0e60dff4c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/SavingsApiConstants.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/SavingsApiConstants.java @@ -75,6 +75,7 @@ public class SavingsApiConstants { public static final String lockinPeriodFrequencyTypeParamName = "lockinPeriodFrequencyType"; public static final String withdrawalFeeAmountParamName = "withdrawalFeeAmount"; public static final String withdrawalFeeTypeParamName = "withdrawalFeeType"; + public static final String withdrawalFeeForTransfersParamName = "withdrawalFeeForTransfers"; public static final String annualFeeAmountParamName = "annualFeeAmount"; public static final String annualFeeOnMonthDayParamName = "annualFeeOnMonthDay"; public static final String accountingRuleParamName = "accountingRule"; @@ -92,7 +93,7 @@ public class SavingsApiConstants { public static final String runningBalanceParamName = "runningBalance"; public static final String reversedParamName = "reversed"; public static final String dateParamName = "date"; - + public static final String noteParamName = "note"; public static final Set SAVINGS_PRODUCT_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, @@ -100,8 +101,8 @@ public class SavingsApiConstants { inMultiplesOfParamName, nominalAnnualInterestRateParamName, interestCompoundingPeriodTypeParamName, interestPostingPeriodTypeParamName, interestCalculationTypeParamName, interestCalculationDaysInYearTypeParamName, minRequiredOpeningBalanceParamName, lockinPeriodFrequencyParamName, lockinPeriodFrequencyTypeParamName, - withdrawalFeeAmountParamName, withdrawalFeeTypeParamName, annualFeeAmountParamName, annualFeeOnMonthDayParamName, - accountingRuleParamName, SAVINGS_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_FEES.getValue(), + withdrawalFeeAmountParamName, withdrawalFeeTypeParamName, withdrawalFeeForTransfersParamName, annualFeeAmountParamName, + annualFeeOnMonthDayParamName, accountingRuleParamName, SAVINGS_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_FEES.getValue(), SAVINGS_PRODUCT_ACCOUNTING_PARAMS.INTEREST_ON_SAVINGS.getValue(), SAVINGS_PRODUCT_ACCOUNTING_PARAMS.PAYMENT_CHANNEL_FUND_SOURCE_MAPPING.getValue(), SAVINGS_PRODUCT_ACCOUNTING_PARAMS.SAVINGS_CONTROL.getValue(), SAVINGS_PRODUCT_ACCOUNTING_PARAMS.SAVINGS_REFERENCE.getValue())); @@ -116,17 +117,17 @@ public class SavingsApiConstants { nominalAnnualInterestRateParamName, interestCompoundingPeriodTypeParamName, interestPostingPeriodTypeParamName, interestCalculationTypeParamName, interestCalculationDaysInYearTypeParamName, minRequiredOpeningBalanceParamName, lockinPeriodFrequencyParamName, lockinPeriodFrequencyTypeParamName, withdrawalFeeAmountParamName, withdrawalFeeTypeParamName, - annualFeeAmountParamName, annualFeeOnMonthDayParamName, "currencyOptions", "interestCompoundingPeriodTypeOptions", - "interestPostingPeriodTypeOptions", "interestCalculationTypeOptions", "interestCalculationDaysInYearTypeOptions", - "lockinPeriodFrequencyTypeOptions", "withdrawalFeeTypeOptions")); + withdrawalFeeForTransfersParamName, annualFeeAmountParamName, annualFeeOnMonthDayParamName, "currencyOptions", + "interestCompoundingPeriodTypeOptions", "interestPostingPeriodTypeOptions", "interestCalculationTypeOptions", + "interestCalculationDaysInYearTypeOptions", "lockinPeriodFrequencyTypeOptions", "withdrawalFeeTypeOptions")); public static final Set SAVINGS_ACCOUNT_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, dateFormatParamName, monthDayFormatParamName, accountNoParamName, externalIdParamName, clientIdParamName, groupIdParamName, productIdParamName, fieldOfficerIdParamName, submittedOnDateParamName, nominalAnnualInterestRateParamName, interestCompoundingPeriodTypeParamName, interestPostingPeriodTypeParamName, interestCalculationTypeParamName, interestCalculationDaysInYearTypeParamName, minRequiredOpeningBalanceParamName, lockinPeriodFrequencyParamName, - lockinPeriodFrequencyTypeParamName, withdrawalFeeAmountParamName, withdrawalFeeTypeParamName, annualFeeAmountParamName, - annualFeeOnMonthDayParamName)); + lockinPeriodFrequencyTypeParamName, withdrawalFeeAmountParamName, withdrawalFeeTypeParamName, + withdrawalFeeForTransfersParamName, annualFeeAmountParamName, annualFeeOnMonthDayParamName)); /** * These parameters will match the class level parameters of @@ -138,10 +139,10 @@ public class SavingsApiConstants { groupIdParamName, "groupName", "savingsProductId", "savingsProductName", "currency", nominalAnnualInterestRateParamName, interestCompoundingPeriodTypeParamName, interestCalculationTypeParamName, interestCalculationDaysInYearTypeParamName, minRequiredOpeningBalanceParamName, lockinPeriodFrequencyParamName, lockinPeriodFrequencyTypeParamName, - withdrawalFeeAmountParamName, withdrawalFeeTypeParamName, annualFeeAmountParamName, annualFeeOnMonthDayParamName, "summary", - "transactions", "productOptions", "interestCompoundingPeriodTypeOptions", "interestPostingPeriodTypeOptions", - "interestCalculationTypeOptions", "interestCalculationDaysInYearTypeOptions", "lockinPeriodFrequencyTypeOptions", - "withdrawalFeeTypeOptions")); + withdrawalFeeAmountParamName, withdrawalFeeTypeParamName, withdrawalFeeForTransfersParamName, annualFeeAmountParamName, + annualFeeOnMonthDayParamName, "summary", "transactions", "productOptions", "interestCompoundingPeriodTypeOptions", + "interestPostingPeriodTypeOptions", "interestCalculationTypeOptions", "interestCalculationDaysInYearTypeOptions", + "lockinPeriodFrequencyTypeOptions", "withdrawalFeeTypeOptions")); public static final Set SAVINGS_ACCOUNT_TRANSACTION_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList( localeParamName, dateFormatParamName, transactionDateParamName, transactionAmountParamName, paymentTypeIdParamName, @@ -153,7 +154,7 @@ public class SavingsApiConstants { public static final Set SAVINGS_ACCOUNT_ACTIVATION_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, dateFormatParamName, activatedOnDateParamName)); - + public static final Set SAVINGS_ACCOUNT_CLOSE_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, dateFormatParamName, closedOnDateParamName, noteParamName)); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountData.java index e6da94bd1..e50eadff5 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountData.java @@ -45,6 +45,7 @@ public class SavingsAccountData { private final EnumOptionData lockinPeriodFrequencyType; private final BigDecimal withdrawalFeeAmount; private final EnumOptionData withdrawalFeeType; + private final boolean withdrawalFeeForTransfers; private final BigDecimal annualFeeAmount; private final MonthDay annualFeeOnMonthDay; private final LocalDate annualFeeNextDueDate; @@ -72,8 +73,8 @@ public class SavingsAccountData { final EnumOptionData interestCalculationType, final EnumOptionData interestCalculationDaysInYearType, final BigDecimal minRequiredOpeningBalance, final Integer lockinPeriodFrequency, final EnumOptionData lockinPeriodFrequencyType, final BigDecimal withdrawalFeeAmount, final EnumOptionData withdrawalFeeType, - final BigDecimal annualFeeAmount, final MonthDay annualFeeOnMonthDay, final LocalDate annualFeeNextDueDate, - final SavingsAccountSummaryData summary) { + boolean withdrawalFeeForTransfers, final BigDecimal annualFeeAmount, final MonthDay annualFeeOnMonthDay, + final LocalDate annualFeeNextDueDate, final SavingsAccountSummaryData summary) { final Collection productOptions = null; final Collection fieldOfficerOptions = null; @@ -89,8 +90,8 @@ public class SavingsAccountData { return new SavingsAccountData(id, accountNo, externalId, groupId, groupName, clientId, clientName, productId, productName, fieldOfficerId, fieldOfficerName, status, timeline, currency, interestRate, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, - lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, annualFeeAmount, - annualFeeOnMonthDay, annualFeeNextDueDate, summary, transactions, productOptions, fieldOfficerOptions, + lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, withdrawalFeeForTransfers, + annualFeeAmount, annualFeeOnMonthDay, annualFeeNextDueDate, summary, transactions, productOptions, fieldOfficerOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions); } @@ -109,7 +110,7 @@ public class SavingsAccountData { final Collection transactions = null; return new SavingsAccountData(accountId, accountNo, null, null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null, null, null, null, null, transactions, productOptions, + null, null, null, null, null, null, null, null, null, false, null, null, null, null, transactions, productOptions, fieldOfficerOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions); @@ -138,8 +139,8 @@ public class SavingsAccountData { account.fieldOfficerName, account.status, account.timeline, account.currency, account.nominalAnnualInterestRate, account.interestCompoundingPeriodType, account.interestPostingPeriodType, account.interestCalculationType, account.interestCalculationDaysInYearType, account.minRequiredOpeningBalance, account.lockinPeriodFrequency, - account.lockinPeriodFrequencyType, account.withdrawalFeeAmount, account.withdrawalFeeType, account.annualFeeAmount, - account.annualFeeOnMonthDay, account.annualFeeNextDueDate, account.summary, transactions, template.productOptions, + account.lockinPeriodFrequencyType, account.withdrawalFeeAmount, account.withdrawalFeeType, account.withdrawalFeeForTransfers, + account.annualFeeAmount, account.annualFeeOnMonthDay, account.annualFeeNextDueDate, account.summary, transactions, template.productOptions, template.fieldOfficerOptions, template.interestCompoundingPeriodTypeOptions, template.interestPostingPeriodTypeOptions, template.interestCalculationTypeOptions, template.interestCalculationDaysInYearTypeOptions, template.lockinPeriodFrequencyTypeOptions, template.withdrawalFeeTypeOptions); @@ -159,8 +160,8 @@ public class SavingsAccountData { account.fieldOfficerName, account.status, account.timeline, account.currency, account.nominalAnnualInterestRate, account.interestCompoundingPeriodType, account.interestPostingPeriodType, account.interestCalculationType, account.interestCalculationDaysInYearType, account.minRequiredOpeningBalance, account.lockinPeriodFrequency, - account.lockinPeriodFrequencyType, account.withdrawalFeeAmount, account.withdrawalFeeType, account.annualFeeAmount, - account.annualFeeOnMonthDay, account.annualFeeNextDueDate, account.summary, transactions, productOptions, + account.lockinPeriodFrequencyType, account.withdrawalFeeAmount, account.withdrawalFeeType,account.withdrawalFeeForTransfers, + account.annualFeeAmount, account.annualFeeOnMonthDay, account.annualFeeNextDueDate, account.summary, transactions, productOptions, fieldOfficerOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions); @@ -189,6 +190,7 @@ public class SavingsAccountData { final EnumOptionData lockinPeriodFrequencyType = null; final BigDecimal withdrawalFeeAmount = null; final EnumOptionData withdrawalFeeType = null; + final boolean withdrawalFeeForTransfers = false; final BigDecimal annualFeeAmount = null; final MonthDay annualFeeOnMonthDay = null; final LocalDate annualFeeNextDueDate = null; @@ -208,8 +210,8 @@ public class SavingsAccountData { return new SavingsAccountData(id, accountNo, externalId, groupId, groupName, clientId, clientName, productId, productName, fieldOfficerId, fieldOfficerName, status, timeline, currency, nominalAnnualInterestRate, interestPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, - lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, annualFeeAmount, - annualFeeOnMonthDay, annualFeeNextDueDate, summary, transactions, productOptions, fieldOfficerOptions, + lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType,withdrawalFeeForTransfers, + annualFeeAmount, annualFeeOnMonthDay, annualFeeNextDueDate, summary, transactions, productOptions, fieldOfficerOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions); } @@ -221,7 +223,7 @@ public class SavingsAccountData { final EnumOptionData interestPostingPeriodType, final EnumOptionData interestCalculationType, final EnumOptionData interestCalculationDaysInYearType, final BigDecimal minRequiredOpeningBalance, final Integer lockinPeriodFrequency, final EnumOptionData lockinPeriodFrequencyType, final BigDecimal withdrawalFeeAmount, - final EnumOptionData withdrawalFeeType, final BigDecimal annualFeeAmount, final MonthDay annualFeeOnMonthDay, + final EnumOptionData withdrawalFeeType,final boolean withdrawalFeeForTransfers, final BigDecimal annualFeeAmount, final MonthDay annualFeeOnMonthDay, final LocalDate annualFeeNextDueDate, final SavingsAccountSummaryData summary, final Collection transactions, final Collection productOptions, final Collection fieldOfficerOptions, final Collection interestCompoundingPeriodTypeOptions, @@ -253,6 +255,7 @@ public class SavingsAccountData { this.lockinPeriodFrequencyType = lockinPeriodFrequencyType; this.withdrawalFeeAmount = withdrawalFeeAmount; this.withdrawalFeeType = withdrawalFeeType; + this.withdrawalFeeForTransfers = withdrawalFeeForTransfers; this.annualFeeAmount = annualFeeAmount; this.annualFeeOnMonthDay = annualFeeOnMonthDay; this.annualFeeNextDueDate = annualFeeNextDueDate; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountDataValidator.java index 9fa0104fd..6ae84b284 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountDataValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountDataValidator.java @@ -24,6 +24,7 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.productIdP import static org.mifosplatform.portfolio.savings.SavingsApiConstants.submittedOnDateParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeAmountParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeTypeParamName; +import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeForTransfersParamName; import java.lang.reflect.Type; import java.math.BigDecimal; @@ -198,6 +199,12 @@ public class SavingsAccountDataValidator { .zeroOrPositiveAmount(); } } + + if(this.fromApiJsonHelper.parameterExists(withdrawalFeeForTransfersParamName, element)) { + final Boolean isWithdrawalFeeApplicableForTransfers = fromApiJsonHelper.extractBooleanNamed(withdrawalFeeForTransfersParamName, element); + baseDataValidator.reset().parameter(withdrawalFeeForTransfersParamName).value(isWithdrawalFeeApplicableForTransfers).ignoreIfNull() + .validateForBooleanValue(); + } if (this.fromApiJsonHelper.parameterExists(annualFeeAmountParamName, element)) { final BigDecimal annualFeeAmount = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(annualFeeAmountParamName, element); @@ -358,6 +365,12 @@ public class SavingsAccountDataValidator { baseDataValidator.reset().parameter(withdrawalFeeTypeParamName).value(withdrawalFeeType).ignoreIfNull() .isOneOfTheseValues(SavingsWithdrawalFeesType.integerValues()); } + + if(this.fromApiJsonHelper.parameterExists(withdrawalFeeForTransfersParamName, element)) { + final Boolean isWithdrawalFeeApplicableForTransfers = fromApiJsonHelper.extractBooleanNamed(withdrawalFeeForTransfersParamName, element); + baseDataValidator.reset().parameter(withdrawalFeeForTransfersParamName).value(isWithdrawalFeeApplicableForTransfers).ignoreIfNull() + .validateForBooleanValue(); + } if (this.fromApiJsonHelper.parameterExists(annualFeeAmountParamName, element)) { final BigDecimal annualFeeAmount = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(annualFeeAmountParamName, element); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsProductData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsProductData.java index 36aafbf09..721554a37 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsProductData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsProductData.java @@ -37,6 +37,7 @@ public class SavingsProductData { private final EnumOptionData lockinPeriodFrequencyType; private final BigDecimal withdrawalFeeAmount; private final EnumOptionData withdrawalFeeType; + private final boolean withdrawalFeeForTransfers; private final BigDecimal annualFeeAmount; private final MonthDay annualFeeOnMonthDay; @@ -87,6 +88,7 @@ public class SavingsProductData { final EnumOptionData lockinPeriodFrequencyType = null; final BigDecimal withdrawalFeeAmount = null; final EnumOptionData withdrawalFeeType = null; + final boolean withdrawalFeeForTransfers = false; final BigDecimal annualFeeAmount = null; final MonthDay annualFeeMonthDay = null; final Map accountingMappings = null; @@ -94,8 +96,8 @@ public class SavingsProductData { return new SavingsProductData(id, name, description, currency, nominalAnnualInterestRate, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, - lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, accountingRule, annualFeeAmount, - annualFeeMonthDay, accountingMappings, paymentChannelToFundSourceMappings, currencyOptions, + lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType,withdrawalFeeForTransfers, + accountingRule, annualFeeAmount, annualFeeMonthDay, accountingMappings, paymentChannelToFundSourceMappings, currencyOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions); @@ -119,7 +121,7 @@ public class SavingsProductData { existingProduct.interestPostingPeriodType, existingProduct.interestCalculationType, existingProduct.interestCalculationDaysInYearType, existingProduct.minRequiredOpeningBalance, existingProduct.lockinPeriodFrequency, existingProduct.lockinPeriodFrequencyType, existingProduct.withdrawalFeeAmount, - existingProduct.withdrawalFeeType, existingProduct.accountingRule, existingProduct.annualFeeAmount, + existingProduct.withdrawalFeeType,existingProduct.withdrawalFeeForTransfers, existingProduct.accountingRule, existingProduct.annualFeeAmount, existingProduct.annualFeeOnMonthDay, existingProduct.accountingMappings, existingProduct.paymentChannelToFundSourceMappings, currencyOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, @@ -146,7 +148,7 @@ public class SavingsProductData { existingProduct.interestPostingPeriodType, existingProduct.interestCalculationType, existingProduct.interestCalculationDaysInYearType, existingProduct.minRequiredOpeningBalance, existingProduct.lockinPeriodFrequency, existingProduct.lockinPeriodFrequencyType, existingProduct.withdrawalFeeAmount, - existingProduct.withdrawalFeeType, existingProduct.accountingRule, existingProduct.annualFeeAmount, + existingProduct.withdrawalFeeType,existingProduct.withdrawalFeeForTransfers, existingProduct.accountingRule, existingProduct.annualFeeAmount, existingProduct.annualFeeOnMonthDay, accountingMappings, paymentChannelToFundSourceMappings, currencyOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, @@ -158,8 +160,8 @@ public class SavingsProductData { final EnumOptionData interestPostingPeriodType, final EnumOptionData interestCalculationType, final EnumOptionData interestCalculationDaysInYearType, final BigDecimal minRequiredOpeningBalance, final Integer lockinPeriodFrequency, final EnumOptionData lockinPeriodFrequencyType, final BigDecimal withdrawalFeeAmount, - final EnumOptionData withdrawalFeeType, final BigDecimal annualFeeAmount, final MonthDay annualFeeOnMonthDay, - final EnumOptionData accountingType) { + final EnumOptionData withdrawalFeeType, boolean withdrawalFeeForTransfers, final BigDecimal annualFeeAmount, + final MonthDay annualFeeOnMonthDay, final EnumOptionData accountingType) { final Map accountingMappings = null; final Collection paymentChannelToFundSourceMappings = null; @@ -177,8 +179,8 @@ public class SavingsProductData { return new SavingsProductData(id, name, description, currency, nominalAnnualInterestRate, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, - lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, accountingType, annualFeeAmount, - annualFeeOnMonthDay, accountingMappings, paymentChannelToFundSourceMappings, currencyOptions, + lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType,withdrawalFeeForTransfers, accountingType, + annualFeeAmount, annualFeeOnMonthDay, accountingMappings, paymentChannelToFundSourceMappings, currencyOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions); @@ -198,6 +200,7 @@ public class SavingsProductData { final EnumOptionData lockinPeriodFrequencyType = null; final BigDecimal withdrawalFeeAmount = null; final EnumOptionData withdrawalFeeType = null; + final boolean withdrawalFeeForTransfers = false; final EnumOptionData accountingType = null; final BigDecimal annualFeeAmount = null; final MonthDay annualFeeMonthDay = null; @@ -217,8 +220,8 @@ public class SavingsProductData { return new SavingsProductData(id, name, description, currency, nominalAnnualInterestRate, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, - lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, accountingType, annualFeeAmount, - annualFeeMonthDay, accountingMappings, paymentChannelToFundSourceMappings, currencyOptions, + lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType,withdrawalFeeForTransfers, accountingType, + annualFeeAmount, annualFeeMonthDay, accountingMappings, paymentChannelToFundSourceMappings, currencyOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions); @@ -229,8 +232,8 @@ public class SavingsProductData { final EnumOptionData interestPostingPeriodType, final EnumOptionData interestCalculationType, final EnumOptionData interestCalculationDaysInYearType, final BigDecimal minRequiredOpeningBalance, final Integer lockinPeriodFrequency, final EnumOptionData lockinPeriodFrequencyType, final BigDecimal withdrawalFeeAmount, - final EnumOptionData withdrawalFeeType, final EnumOptionData accountingType, final BigDecimal annualFeeAmount, - final MonthDay annualFeeOnMonthDay, final Map accountingMappings, + final EnumOptionData withdrawalFeeType,final boolean withdrawalFeeForTransfers, final EnumOptionData accountingType, + final BigDecimal annualFeeAmount, final MonthDay annualFeeOnMonthDay, final Map accountingMappings, final Collection paymentChannelToFundSourceMappings, final Collection currencyOptions, final Collection interestCompoundingPeriodTypeOptions, final Collection interestPostingPeriodTypeOptions, @@ -254,6 +257,7 @@ public class SavingsProductData { this.lockinPeriodFrequencyType = lockinPeriodFrequencyType; this.withdrawalFeeAmount = withdrawalFeeAmount; this.withdrawalFeeType = withdrawalFeeType; + this.withdrawalFeeForTransfers = withdrawalFeeForTransfers; this.annualFeeAmount = annualFeeAmount; this.annualFeeOnMonthDay = annualFeeOnMonthDay; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsProductDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsProductDataValidator.java index 11f50fdfc..f2fba572e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsProductDataValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsProductDataValidator.java @@ -23,6 +23,7 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.minRequire import static org.mifosplatform.portfolio.savings.SavingsApiConstants.nameParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.nominalAnnualInterestRateParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeAmountParamName; +import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeForTransfersParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeTypeParamName; import java.lang.reflect.Type; @@ -173,6 +174,12 @@ public class SavingsProductDataValidator { .zeroOrPositiveAmount(); } } + + if(this.fromApiJsonHelper.parameterExists(withdrawalFeeForTransfersParamName, element)) { + final Boolean isWithdrawalFeeApplicableForTransfers = fromApiJsonHelper.extractBooleanNamed(withdrawalFeeForTransfersParamName, element); + baseDataValidator.reset().parameter(withdrawalFeeForTransfersParamName).value(isWithdrawalFeeApplicableForTransfers).ignoreIfNull() + .validateForBooleanValue(); + } if (this.fromApiJsonHelper.parameterExists(annualFeeAmountParamName, element)) { final BigDecimal annualFeeAmount = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(annualFeeAmountParamName, element); @@ -319,6 +326,12 @@ public class SavingsProductDataValidator { baseDataValidator.reset().parameter(withdrawalFeeTypeParamName).value(withdrawalFeeType).ignoreIfNull() .isOneOfTheseValues(1, 2); } + + if(this.fromApiJsonHelper.parameterExists(withdrawalFeeForTransfersParamName, element)) { + final Boolean isWithdrawalFeeApplicableForTransfers = fromApiJsonHelper.extractBooleanNamed(withdrawalFeeForTransfersParamName, element); + baseDataValidator.reset().parameter(withdrawalFeeForTransfersParamName).value(isWithdrawalFeeApplicableForTransfers).ignoreIfNull() + .validateForBooleanValue(); + } if (this.fromApiJsonHelper.parameterExists(annualFeeAmountParamName, element)) { final BigDecimal annualFeeAmount = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(annualFeeAmountParamName, element); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java index 447127344..86a788339 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java @@ -13,6 +13,7 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.lockinPeri import static org.mifosplatform.portfolio.savings.SavingsApiConstants.lockinPeriodFrequencyTypeParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeAmountParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeTypeParamName; +import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeForTransfersParamName; import java.math.BigDecimal; import java.math.MathContext; @@ -216,6 +217,9 @@ public class SavingsAccount extends AbstractPersistable { @Column(name = "withdrawal_fee_type_enum", nullable = true) private Integer withdrawalFeeType; + @Column(name = "withdrawal_fee_for_transfer", nullable = true) + private boolean withdrawalFeeApplicableForTransfer; + @Column(name = "annual_fee_amount", scale = 6, precision = 19, nullable = true) private BigDecimal annualFeeAmount; @@ -255,14 +259,14 @@ public class SavingsAccount extends AbstractPersistable { final SavingsPostingInterestPeriodType interestPostingPeriodType, final SavingsInterestCalculationType interestCalculationType, final SavingsInterestCalculationDaysInYearType interestCalculationDaysInYearType, final BigDecimal minRequiredOpeningBalance, final Integer lockinPeriodFrequency, final SavingsPeriodFrequencyType lockinPeriodFrequencyType, - final BigDecimal withdrawalFeeAmount, final SavingsWithdrawalFeesType withdrawalFeeType, final BigDecimal annualFeeAmount, - final MonthDay annualFeeOnMonthDay) { + final BigDecimal withdrawalFeeAmount, final SavingsWithdrawalFeesType withdrawalFeeType, boolean withdrawalFeeApplicableForTransfer, + final BigDecimal annualFeeAmount, final MonthDay annualFeeOnMonthDay) { final SavingsAccountStatusType status = SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL; return new SavingsAccount(client, group, product, fieldOfficer, accountNo, externalId, status, accountType, submittedOnDate, interestRate, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyType, - withdrawalFeeAmount, withdrawalFeeType, annualFeeAmount, annualFeeOnMonthDay); + withdrawalFeeAmount, withdrawalFeeType,withdrawalFeeApplicableForTransfer, annualFeeAmount, annualFeeOnMonthDay); } private SavingsAccount(final Client client, final Group group, final SavingsProduct product, final Staff fieldOfficer, @@ -272,7 +276,7 @@ public class SavingsAccount extends AbstractPersistable { final SavingsPostingInterestPeriodType interestPostingPeriodType, final SavingsInterestCalculationType interestCalculationType, final SavingsInterestCalculationDaysInYearType interestCalculationDaysInYearType, final BigDecimal minRequiredOpeningBalance, final Integer lockinPeriodFrequency, final SavingsPeriodFrequencyType lockinPeriodFrequencyType, - final BigDecimal withdrawalFeeAmount, final SavingsWithdrawalFeesType withdrawalFeeType, final BigDecimal annualFeeAmount, + final BigDecimal withdrawalFeeAmount, final SavingsWithdrawalFeesType withdrawalFeeType,final boolean withdrawalFeeApplicableForTransfer, final BigDecimal annualFeeAmount, final MonthDay annualFeeOnMonthDay) { this.client = client; this.group = group; @@ -303,6 +307,7 @@ public class SavingsAccount extends AbstractPersistable { if (withdrawalFeeType != null) { this.withdrawalFeeType = withdrawalFeeType.getValue(); } + this.withdrawalFeeApplicableForTransfer = withdrawalFeeApplicableForTransfer; this.annualFeeAmount = annualFeeAmount; if (annualFeeOnMonthDay != null) { @@ -600,7 +605,7 @@ public class SavingsAccount extends AbstractPersistable { public SavingsAccountTransaction withdraw(final DateTimeFormatter formatter, final LocalDate transactionDate, final BigDecimal transactionAmount, final List existingTransactionIds, final List existingReversedTransactionIds, - final PaymentDetail paymentDetail) { + final PaymentDetail paymentDetail,final boolean applyWithdrawFee) { if (isNotActive()) { @@ -659,7 +664,7 @@ public class SavingsAccount extends AbstractPersistable { transactionAmountMoney); this.transactions.add(transaction); - if (isAutomaticWithdrawalFee()) { + if (applyWithdrawFee && isAutomaticWithdrawalFee()) { SavingsAccountTransaction withdrawalFeeTransaction = null; Money feeAmount = Money.zero(this.currency); @@ -1030,6 +1035,12 @@ public class SavingsAccount extends AbstractPersistable { actualChanges.put(withdrawalFeeTypeParamName, newValue); this.withdrawalFeeType = newValue != null ? SavingsWithdrawalFeesType.fromInt(newValue).getValue() : newValue; } + + if(command.isChangeInBooleanParameterNamed(withdrawalFeeForTransfersParamName, this.withdrawalFeeApplicableForTransfer)){ + final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(withdrawalFeeForTransfersParamName); + actualChanges.put(withdrawalFeeForTransfersParamName, newValue); + this.withdrawalFeeApplicableForTransfer = newValue; + } // set period type to null if frequency is null if (this.withdrawalFeeAmount == null) { @@ -1747,4 +1758,9 @@ public class SavingsAccount extends AbstractPersistable { public Group group() { return this.group; } + + + public boolean isWithdrawalFeeApplicableForTransfer() { + return this.withdrawalFeeApplicableForTransfer; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java index bf58caf9b..6571dfbbf 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java @@ -24,6 +24,7 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.productIdP import static org.mifosplatform.portfolio.savings.SavingsApiConstants.submittedOnDateParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeAmountParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeTypeParamName; +import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeForTransfersParamName; import java.math.BigDecimal; @@ -211,6 +212,11 @@ public class SavingsAccountAssembler { } else { withdrawalFeeType = product.withdrawalFeeType(); } + + boolean iswithdrawalFeeApplicableForTransfer = false; + if(command.parameterExists(withdrawalFeeForTransfersParamName)){ + iswithdrawalFeeApplicableForTransfer = command.booleanPrimitiveValueOfParameterNamed(withdrawalFeeForTransfersParamName); + } BigDecimal annualFeeAmount = null; if (command.parameterExists(annualFeeAmountParamName)) { @@ -229,7 +235,8 @@ public class SavingsAccountAssembler { final SavingsAccount account = SavingsAccount.createNewApplicationForSubmittal(client, group, product, fieldOfficer, accountNo, externalId, accountType, submittedOnDate, interestRate, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, lockinPeriodFrequency, - lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, annualFeeAmount, monthDayOfAnnualFee); + lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, iswithdrawalFeeApplicableForTransfer, annualFeeAmount, + monthDayOfAnnualFee); account.setHelpers(this.savingsAccountTransactionSummaryWrapper, this.savingsHelper); account.validateNewApplicationState(DateUtils.getLocalDateOfTenant()); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountDomainService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountDomainService.java index 96ddfa376..30e0394ce 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountDomainService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountDomainService.java @@ -14,7 +14,7 @@ import org.mifosplatform.portfolio.paymentdetail.domain.PaymentDetail; public interface SavingsAccountDomainService { SavingsAccountTransaction handleWithdrawal(SavingsAccount account, DateTimeFormatter fmt, LocalDate transactionDate, - BigDecimal transactionAmount, PaymentDetail paymentDetail); + BigDecimal transactionAmount, PaymentDetail paymentDetail, boolean applyWithdrawFee); SavingsAccountTransaction handleDeposit(SavingsAccount account, DateTimeFormatter fmt, LocalDate transactionDate, BigDecimal transactionAmount, PaymentDetail paymentDetail); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountDomainServiceJpa.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountDomainServiceJpa.java index 286a28125..e5025ea04 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountDomainServiceJpa.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountDomainServiceJpa.java @@ -45,13 +45,13 @@ public class SavingsAccountDomainServiceJpa implements SavingsAccountDomainServi @Transactional @Override public SavingsAccountTransaction handleWithdrawal(final SavingsAccount account, final DateTimeFormatter fmt, - final LocalDate transactionDate, final BigDecimal transactionAmount, final PaymentDetail paymentDetail) { + final LocalDate transactionDate, final BigDecimal transactionAmount, final PaymentDetail paymentDetail, boolean applyWithdrawFee) { final List existingTransactionIds = new ArrayList(); final List existingReversedTransactionIds = new ArrayList(); final SavingsAccountTransaction withdrawal = account.withdraw(fmt, transactionDate, transactionAmount, existingTransactionIds, - existingReversedTransactionIds, paymentDetail); + existingReversedTransactionIds, paymentDetail, applyWithdrawFee); final MathContext mc = MathContext.DECIMAL64; if (account.isBeforeLastPostingPeriod(transactionDate)) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsProduct.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsProduct.java index 80b2f691e..2f9da549c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsProduct.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsProduct.java @@ -24,6 +24,7 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.minRequire import static org.mifosplatform.portfolio.savings.SavingsApiConstants.nameParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.nominalAnnualInterestRateParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeAmountParamName; +import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeForTransfersParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeTypeParamName; import java.math.BigDecimal; @@ -118,6 +119,10 @@ public class SavingsProduct extends AbstractPersistable { @Column(name = "withdrawal_fee_type_enum", nullable = true) private Integer withdrawalFeeType; + + @Column(name = "withdrawal_fee_for_transfer") + @SuppressWarnings("unused") + private boolean withdrawalFeeApplicableForTransfer; @Column(name = "annual_fee_amount", scale = 6, precision = 19, nullable = true) private BigDecimal annualFeeAmount; @@ -133,12 +138,13 @@ public class SavingsProduct extends AbstractPersistable { final SavingsPostingInterestPeriodType interestPostingPeriodType, final SavingsInterestCalculationType interestCalculationType, final SavingsInterestCalculationDaysInYearType interestCalculationDaysInYearType, final BigDecimal minRequiredOpeningBalance, final Integer lockinPeriodFrequency, final SavingsPeriodFrequencyType lockinPeriodFrequencyType, - final BigDecimal withdrawalFeeAmount, final SavingsWithdrawalFeesType withdrawalFeeType, final BigDecimal annualFeeAmount, - final MonthDay annualFeeOnMonthDay, final AccountingRuleType accountingRuleType) { + final BigDecimal withdrawalFeeAmount, final SavingsWithdrawalFeesType withdrawalFeeType, boolean withdrawalFeeApplicableForTransfer, + final BigDecimal annualFeeAmount, final MonthDay annualFeeOnMonthDay, final AccountingRuleType accountingRuleType) { return new SavingsProduct(name, description, currency, interestRate, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, lockinPeriodFrequency, - lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, annualFeeAmount, annualFeeOnMonthDay, accountingRuleType); + lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType,withdrawalFeeApplicableForTransfer, annualFeeAmount, + annualFeeOnMonthDay, accountingRuleType); } protected SavingsProduct() { @@ -151,8 +157,8 @@ public class SavingsProduct extends AbstractPersistable { final SavingsPostingInterestPeriodType interestPostingPeriodType, final SavingsInterestCalculationType interestCalculationType, final SavingsInterestCalculationDaysInYearType interestCalculationDaysInYearType, final BigDecimal minRequiredOpeningBalance, final Integer lockinPeriodFrequency, final SavingsPeriodFrequencyType lockinPeriodFrequencyType, - final BigDecimal withdrawalFeeAmount, final SavingsWithdrawalFeesType withdrawalFeeType, final BigDecimal annualFeeAmount, - final MonthDay annualFeeOnMonthDay, final AccountingRuleType accountingRuleType) { + final BigDecimal withdrawalFeeAmount, final SavingsWithdrawalFeesType withdrawalFeeType, final boolean withdrawalFeeApplicableForTransfer, + final BigDecimal annualFeeAmount, final MonthDay annualFeeOnMonthDay, final AccountingRuleType accountingRuleType) { this.name = name; this.description = description; @@ -177,6 +183,7 @@ public class SavingsProduct extends AbstractPersistable { if (withdrawalFeeAmount != null && withdrawalFeeType != null) { this.withdrawalFeeType = withdrawalFeeType.getValue(); } + this.withdrawalFeeApplicableForTransfer = withdrawalFeeApplicableForTransfer; this.annualFeeAmount = annualFeeAmount; if (annualFeeAmount != null && annualFeeOnMonthDay != null) { this.annualFeeOnMonth = annualFeeOnMonthDay.getMonthOfYear(); @@ -369,6 +376,12 @@ public class SavingsProduct extends AbstractPersistable { actualChanges.put(withdrawalFeeTypeParamName, newValue); this.withdrawalFeeType = newValue != null ? SavingsWithdrawalFeesType.fromInt(newValue).getValue() : newValue; } + + if(command.isChangeInBooleanParameterNamed(withdrawalFeeForTransfersParamName, this.withdrawalFeeApplicableForTransfer)){ + final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(withdrawalFeeForTransfersParamName); + actualChanges.put(withdrawalFeeForTransfersParamName, newValue); + this.withdrawalFeeApplicableForTransfer = newValue; + } // set period type to null if frequency is null if (this.withdrawalFeeAmount == null) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsProductAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsProductAssembler.java index d881b5a32..25348d780 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsProductAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsProductAssembler.java @@ -21,6 +21,7 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.minRequire import static org.mifosplatform.portfolio.savings.SavingsApiConstants.nameParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.nominalAnnualInterestRateParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeAmountParamName; +import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeForTransfersParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeTypeParamName; import java.math.BigDecimal; @@ -93,6 +94,11 @@ public class SavingsProductAssembler { if (withdrawalFeeTypeValue != null) { withdrawalFeeType = SavingsWithdrawalFeesType.fromInt(withdrawalFeeTypeValue); } + + boolean iswithdrawalFeeApplicableForTransfer = false; + if(command.parameterExists(withdrawalFeeForTransfersParamName)){ + iswithdrawalFeeApplicableForTransfer = command.booleanPrimitiveValueOfParameterNamed(withdrawalFeeForTransfersParamName); + } final BigDecimal annualFeeAmount = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero(annualFeeAmountParamName); final MonthDay monthDayOfAnnualFee = command.extractMonthDayNamed(annualFeeOnMonthDayParamName); @@ -100,7 +106,7 @@ public class SavingsProductAssembler { return SavingsProduct.createNew(name, description, currency, interestRate, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, - lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, annualFeeAmount, - monthDayOfAnnualFee, accountingRuleType); + lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, iswithdrawalFeeApplicableForTransfer, + annualFeeAmount, monthDayOfAnnualFee, accountingRuleType); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountReadPlatformServiceImpl.java index fcbe61f4b..3141c1420 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountReadPlatformServiceImpl.java @@ -218,6 +218,7 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead sqlBuilder.append("sa.lockin_period_frequency_enum as lockinPeriodFrequencyType, "); sqlBuilder.append("sa.withdrawal_fee_amount as withdrawalFeeAmount,"); sqlBuilder.append("sa.withdrawal_fee_type_enum as withdrawalFeeTypeEnum, "); + sqlBuilder.append("sa.withdrawal_fee_for_transfer as withdrawalFeeForTransfers, "); sqlBuilder.append("sa.annual_fee_amount as annualFeeAmount,"); sqlBuilder.append("sa.annual_fee_on_month as annualFeeOnMonth, "); sqlBuilder.append("sa.annual_fee_on_day as annualFeeOnDay, "); @@ -349,6 +350,8 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead if (withdrawalFeeTypeValue != null) { withdrawalFeeType = SavingsEnumerations.withdrawalFeeType(withdrawalFeeTypeValue); } + + final boolean withdrawalFeeForTransfers = rs.getBoolean("withdrawalFeeForTransfers"); final BigDecimal annualFeeAmount = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "annualFeeAmount"); @@ -376,8 +379,8 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead return SavingsAccountData.instance(id, accountNo, externalId, groupId, groupName, clientId, clientName, productId, productName, fieldOfficerId, fieldOfficerName, status, timeline, currency, nominalAnnualInterestRate, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, - lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, annualFeeAmount, - annualFeeOnMonthDay, annualFeeNextDueDate, summary); + lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, withdrawalFeeForTransfers, + annualFeeAmount, annualFeeOnMonthDay, annualFeeNextDueDate, summary); } } @@ -697,6 +700,7 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead sqlBuilder.append("sp.lockin_period_frequency_enum as lockinPeriodFrequencyType, "); sqlBuilder.append("sp.withdrawal_fee_amount as withdrawalFeeAmount,"); sqlBuilder.append("sp.withdrawal_fee_type_enum as withdrawalFeeTypeEnum, "); + sqlBuilder.append("sp.withdrawal_fee_for_transfer as withdrawalFeeForTransfers, "); sqlBuilder.append("sp.annual_fee_amount as annualFeeAmount,"); sqlBuilder.append("sp.annual_fee_on_month as annualFeeOnMonth, "); sqlBuilder.append("sp.annual_fee_on_day as annualFeeOnDay "); @@ -758,7 +762,9 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead if (withdrawalFeeTypeValue != null) { withdrawalFeeType = SavingsEnumerations.withdrawalFeeType(withdrawalFeeTypeValue); } - + + final boolean withdrawalFeeForTransfers = rs.getBoolean("withdrawalFeeForTransfers"); + final BigDecimal annualFeeAmount = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "annualFeeAmount"); MonthDay annualFeeOnMonthDay = null; @@ -793,8 +799,8 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead return SavingsAccountData.instance(null, null, null, groupId, groupName, clientId, clientName, productId, productName, fieldOfficerId, fieldOfficerName, status, timeline, currency, nominalAnnualIterestRate, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, - lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, annualFeeAmount, - annualFeeOnMonthDay, annualFeeNextDueDate, summary); + lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, withdrawalFeeForTransfers, + annualFeeAmount, annualFeeOnMonthDay, annualFeeNextDueDate, summary); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java index 15461dd34..d1c111b8b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java @@ -178,7 +178,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi checkClientOrGroupActive(account); SavingsAccountTransaction withdrawal = this.savingsAccountDomainService.handleWithdrawal(account, fmt, transactionDate, - transactionAmount, paymentDetail); + transactionAmount, paymentDetail, true); return new CommandProcessingResultBuilder() // .withEntityId(withdrawal.getId()) // @@ -351,7 +351,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi paymentDetail); } else { transaction = account.withdraw(fmt, transactionDate, transactionAmount, existingTransactionIds, existingReversedTransactionIds, - paymentDetail); + paymentDetail, true); } final Long newtransactionId = saveTransactionToGenerateTransactionId(transaction); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsProductReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsProductReadPlatformServiceImpl.java index 6cd36970b..371d9c315 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsProductReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsProductReadPlatformServiceImpl.java @@ -89,6 +89,7 @@ public class SavingsProductReadPlatformServiceImpl implements SavingsProductRead sqlBuilder.append("sp.lockin_period_frequency_enum as lockinPeriodFrequencyType, "); sqlBuilder.append("sp.withdrawal_fee_amount as withdrawalFeeAmount,"); sqlBuilder.append("sp.withdrawal_fee_type_enum as withdrawalFeeTypeEnum, "); + sqlBuilder.append("sp.withdrawal_fee_for_transfer as withdrawalFeeForTransfers, "); sqlBuilder.append("sp.annual_fee_amount as annualFeeAmount,"); sqlBuilder.append("sp.annual_fee_on_month as annualFeeOnMonth, "); sqlBuilder.append("sp.annual_fee_on_day as annualFeeOnDay, "); @@ -156,6 +157,8 @@ public class SavingsProductReadPlatformServiceImpl implements SavingsProductRead if (withdrawalFeeTypeValue != null) { withdrawalFeeType = SavingsEnumerations.withdrawalFeeType(withdrawalFeeTypeValue); } + + final boolean withdrawalFeeForTransfers = rs.getBoolean("withdrawalFeeForTransfers"); final BigDecimal annualFeeAmount = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "annualFeeAmount"); @@ -168,8 +171,8 @@ public class SavingsProductReadPlatformServiceImpl implements SavingsProductRead return SavingsProductData.instance(id, name, description, currency, nominalAnnualInterestRate, compoundingInterestPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, - lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, annualFeeAmount, - annualFeeOnMonthDay, accountingRuleType); + lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, withdrawalFeeForTransfers, + annualFeeAmount, annualFeeOnMonthDay, accountingRuleType); } } From 1b7e2df3eee4d91d3d6961025c1169548d7f5cfb Mon Sep 17 00:00:00 2001 From: Pramod Nuthakki Date: Thu, 5 Sep 2013 18:39:17 +0530 Subject: [PATCH 2/2] api doc changes added for transfer withdrawal fee configuration --- api-docs/apiLive.htm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 7d358af1d..a260fcd9f 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -11408,6 +11408,9 @@ Content-Type: application/json withdrawalFeeType Optional: If provided, used along with withdrawalFeeAmount to indicate the amount to be charged on the account for withdrawing. 1=Flat, 2=% of Amount, e.g. 5 Flat or 5 % of Amount + withdrawalFeeForTransfers + Optional: Used along with withdrawalFeeAmount to indicate whether the withdrawal fee should be applied on the account for account transfers . + annualFeeAmount Optional: If provided, used along with annualFeeOnMonthDay to indicate the amount to be charged on the account annually on a given day of month. e.g. 10 on 10 May. monthDayFormat indicates day and month formatting used e.g. "dd MMM" for 10 May @@ -11937,7 +11940,7 @@ Content-Type: application/json
- +
Optional Fields
minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, annualFeeAmount, annualFeeOnMonthDay, monthDayFormat, paymentChannelToFundSourceMappings
minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType,withdrawalFeeForTransfers, annualFeeAmount, annualFeeOnMonthDay, monthDayFormat, paymentChannelToFundSourceMappings
@@ -11985,6 +11988,7 @@ Request Body: "lockinPeriodFrequencyType": "1", "withdrawalFeeAmount": "12", "withdrawalFeeType": "1", + "withdrawalFeeForTransfers":false, "monthDayFormat": "dd MMM", "annualFeeAmount": "12", "annualFeeOnMonthDay": "01 May", @@ -12069,6 +12073,7 @@ Request Body: "code": "savingsWithdrawalFeesType.flat", "value": "Flat" }, + "withdrawalFeeForTransfers":true, "annualFeeAmount": 100.000000, "annualFeeOnMonthDay": [ 5, @@ -12295,6 +12300,9 @@ Content-Type: application/json withdrawalFeeType Optional: If provided, used along with withdrawalFeeAmount to indicate the amount to be charged on the account for withdrawing. 1=Flat, 2=% of Amount, e.g. 5 Flat or 5 % of Amount + withdrawalFeeForTransfers + Optional: Used along with withdrawalFeeAmount to indicate whether the withdrawal fee should be applied on the account for account transfers . + annualFeeAmount Optional: If provided, used along with annualFeeOnMonthDay to indicate the amount to be charged on the account annually on a given day of month. e.g. 10 on 10 May. monthDayFormat indicates day and month formatting used e.g. "dd MMM" for 10 May @@ -12521,7 +12529,7 @@ Content-Type: application/json
- +
Inherited from Product (if not provided)
nominalAnnualInterestRate, interestCompoundingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType, annualFeeAmount, annualFeeOnMonthDay
nominalAnnualInterestRate, interestCompoundingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeAmount, withdrawalFeeType,withdrawalFeeForTransfers, annualFeeAmount, annualFeeOnMonthDay