diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/RecurringDepositTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/RecurringDepositTest.java index 2fd36553d..c5fde08b5 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/RecurringDepositTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/RecurringDepositTest.java @@ -975,6 +975,7 @@ public class RecurringDepositTest { DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); Assert.assertNotNull(transactionIdForDeposit); + currentDate = currentDate - 1; interestPerMonth = (float) (interestPerDay * principal * currentDate); System.out.println("IPM = " + interestPerMonth); principal += interestPerMonth; @@ -1101,6 +1102,7 @@ public class RecurringDepositTest { DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); Assert.assertNotNull(transactionIdForDeposit); + currentDate = currentDate - 1; interestPerMonth = (float) (interestPerDay * principal * currentDate); System.out.println("IPM = " + interestPerMonth); principal += interestPerMonth; @@ -1230,6 +1232,7 @@ public class RecurringDepositTest { DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); Assert.assertNotNull(transactionIdForDeposit); + currentDate = currentDate - 1; interestPerMonth = (float) (interestPerDay * principal * currentDate); System.out.println("IPM = " + interestPerMonth); principal += interestPerMonth; @@ -1364,6 +1367,7 @@ public class RecurringDepositTest { DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); Assert.assertNotNull(newTransactionIdForDeposit); + currentDate = currentDate - 1; interestPerMonth = (float) (interestPerDay * principal * currentDate); System.out.println("IPM = " + interestPerMonth); principal += interestPerMonth; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartSlabDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartSlabDataValidator.java index 9ee79b909..1a39e8bfa 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartSlabDataValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartSlabDataValidator.java @@ -148,7 +148,7 @@ public class InterestRateChartSlabDataValidator { if (this.fromApiJsonHelper.parameterExists(descriptionParamName, element)) { final String description = this.fromApiJsonHelper.extractStringNamed(descriptionParamName, element); - baseDataValidator.reset().parameter(descriptionParamName).value(description).notNull(); + baseDataValidator.reset().parameter(descriptionParamName).value(description).ignoreIfNull(); } if (this.fromApiJsonHelper.parameterExists(periodTypeParamName, element)) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountDomainServiceJpa.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountDomainServiceJpa.java index 320186b4e..aad499950 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountDomainServiceJpa.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountDomainServiceJpa.java @@ -117,12 +117,13 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi public SavingsAccountTransaction handleRDDeposit(final RecurringDepositAccount account, final DateTimeFormatter fmt, final LocalDate transactionDate, final BigDecimal transactionAmount, final PaymentDetail paymentDetail) { boolean isAccountTransfer = false; + final boolean isPreMatureClosure = false; final MathContext mc = MathContext.DECIMAL64; final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(account, fmt, transactionDate, transactionAmount, paymentDetail, isAccountTransfer); account.handleScheduleInstallments(deposit); - account.updateMaturityDateAndAmount(mc); + account.updateMaturityDateAndAmount(mc, isPreMatureClosure); account.updateOverduePayments(DateUtils.getLocalDateOfTenant()); return deposit; } @@ -132,6 +133,7 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi public Long handleFDAccountClosure(final FixedDepositAccount account, final PaymentDetail paymentDetail, final AppUser user, final JsonCommand command, final LocalDate tenantsTodayDate, final Map changes) { boolean isAccountTransfer = false; + final boolean isPreMatureClosure = false; final Set existingTransactionIds = new HashSet(); final Set existingReversedTransactionIds = new HashSet(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); @@ -157,7 +159,7 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi if (account.isReinvestOnClosure()) { FixedDepositAccount reinvestedDeposit = account.reInvest(account.getAccountBalance()); this.depositAccountAssembler.assignSavingAccountHelpers(reinvestedDeposit); - reinvestedDeposit.updateMaturityDateAndAmountBeforeAccountActivation(mc); + reinvestedDeposit.updateMaturityDateAndAmountBeforeAccountActivation(mc,isPreMatureClosure); this.savingsAccountRepository.save(reinvestedDeposit); autoGenerateAccountNumber(reinvestedDeposit); final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate, account.getAccountBalance(), @@ -192,6 +194,7 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi public Long handleRDAccountClosure(final RecurringDepositAccount account, final PaymentDetail paymentDetail, final AppUser user, final JsonCommand command, final LocalDate tenantsTodayDate, final Map changes) { boolean isAccountTransfer = false; + final boolean isPreMatureClosure = false; final Set existingTransactionIds = new HashSet(); final Set existingReversedTransactionIds = new HashSet(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); @@ -206,9 +209,9 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi if (account.isReinvestOnClosure()) { RecurringDepositAccount reinvestedDeposit = account.reInvest(transactionAmount); depositAccountAssembler.assignSavingAccountHelpers(reinvestedDeposit); - reinvestedDeposit.updateMaturityDateAndAmount(mc); + reinvestedDeposit.updateMaturityDateAndAmount(mc, isPreMatureClosure); reinvestedDeposit.processAccountUponActivation(fmt); - reinvestedDeposit.updateMaturityDateAndAmount(mc); + reinvestedDeposit.updateMaturityDateAndAmount(mc, isPreMatureClosure); this.savingsAccountRepository.save(reinvestedDeposit); Money amountForDeposit = reinvestedDeposit.activateWithBalance(); @@ -216,7 +219,7 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi handleRDDeposit(reinvestedDeposit, fmt, reinvestedDeposit.getActivationLocalDate(), amountForDeposit.getAmount(), paymentDetail); } - reinvestedDeposit.updateMaturityDateAndAmount(mc); + reinvestedDeposit.updateMaturityDateAndAmount(mc, isPreMatureClosure); this.savingsAccountRepository.save(reinvestedDeposit); autoGenerateAccountNumber(reinvestedDeposit); @@ -263,6 +266,7 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi public Long handleFDAccountPreMatureClosure(final FixedDepositAccount account, final PaymentDetail paymentDetail, final AppUser user, final JsonCommand command, final LocalDate tenantsTodayDate, final Map changes) { boolean isAccountTransfer = false; + final boolean isPreMatureClosure = true; final Set existingTransactionIds = new HashSet(); final Set existingReversedTransactionIds = new HashSet(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); @@ -272,7 +276,7 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); Long savingsTransactionId = null; // post interest - account.postPreMaturityInterest(closedDate); + account.postPreMaturityInterest(closedDate, isPreMatureClosure); final Integer closureTypeValue = command.integerValueOfParameterNamed(DepositsApiConstants.onAccountClosureIdParamName); DepositAccountOnClosureType closureType = DepositAccountOnClosureType.fromInt(closureTypeValue); @@ -306,6 +310,7 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi public Long handleRDAccountPreMatureClosure(final RecurringDepositAccount account, final PaymentDetail paymentDetail, final AppUser user, final JsonCommand command, final LocalDate tenantsTodayDate, final Map changes) { boolean isAccountTransfer = false; + final boolean isPreMatureClosure = true; final Set existingTransactionIds = new HashSet(); final Set existingReversedTransactionIds = new HashSet(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); @@ -315,7 +320,7 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); Long savingsTransactionId = null; // post interest - account.postPreMaturityInterest(closedDate); + account.postPreMaturityInterest(closedDate, isPreMatureClosure); final Integer closureTypeValue = command.integerValueOfParameterNamed(DepositsApiConstants.onAccountClosureIdParamName); DepositAccountOnClosureType closureType = DepositAccountOnClosureType.fromInt(closureTypeValue); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/FixedDepositAccount.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/FixedDepositAccount.java index 3074ec707..e8c1d54d9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/FixedDepositAccount.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/FixedDepositAccount.java @@ -131,14 +131,13 @@ public class FixedDepositAccount extends SavingsAccount { if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } - @Override - protected BigDecimal getEffectiveInterestRateAsFraction(final MathContext mc, final LocalDate interestPostingUpToDate) { + protected BigDecimal getEffectiveInterestRateAsFraction(final MathContext mc, final LocalDate interestPostingUpToDate, + final boolean isPreMatureClosure) { // default it to nominalAnnualInterst rate. interest chart overrrides // this value. BigDecimal applicableInterestRate = this.nominalAnnualInterestRate; if (this.chart != null) { - final boolean isPreMatureClosure = SavingsAccountStatusType.fromInt(this.status).isPreMatureClosure(); boolean applyPreMaturePenalty = false; BigDecimal penalInterest = BigDecimal.ZERO; LocalDate depositCloseDate = calculateMaturityDate(); @@ -170,7 +169,7 @@ public class FixedDepositAccount extends SavingsAccount { return applicableInterestRate.divide(BigDecimal.valueOf(100l), mc); } - public void updateMaturityDateAndAmountBeforeAccountActivation(final MathContext mc) { + public void updateMaturityDateAndAmountBeforeAccountActivation(final MathContext mc, final boolean isPreMatureClosure) { List allTransactions = new ArrayList(); final Money transactionAmountMoney = Money.of(getCurrency(), this.accountTermAndPreClosure.depositAmount()); final SavingsAccountTransaction transaction = SavingsAccountTransaction.deposit(null, office(), null, @@ -178,14 +177,15 @@ public class FixedDepositAccount extends SavingsAccount { transaction.updateRunningBalance(transactionAmountMoney); transaction.updateCumulativeBalanceAndDates(this.getCurrency(), interestCalculatedUpto()); allTransactions.add(transaction); - updateMaturityDateAndAmount(mc, allTransactions); + updateMaturityDateAndAmount(mc, allTransactions, isPreMatureClosure); } - public void updateMaturityDateAndAmount(final MathContext mc) { - updateMaturityDateAndAmount(mc, retreiveOrderedNonInterestPostingTransactions()); + public void updateMaturityDateAndAmount(final MathContext mc, final boolean isPreMatureClosure) { + updateMaturityDateAndAmount(mc, retreiveOrderedNonInterestPostingTransactions(), isPreMatureClosure); } - public void updateMaturityDateAndAmount(final MathContext mc, final List transactions) { + public void updateMaturityDateAndAmount(final MathContext mc, final List transactions, + final boolean isPreMatureClosure) { final LocalDate maturityDate = calculateMaturityDate(); final LocalDate interestCalculationUpto = maturityDate.minusDays(1); @@ -193,7 +193,7 @@ public class FixedDepositAccount extends SavingsAccount { // calculation this.resetAccountTransactionsEndOfDayBalances(transactions, maturityDate); - final List postingPeriods = calculateInterestPayable(mc, interestCalculationUpto, transactions); + final List postingPeriods = calculateInterestPayable(mc, interestCalculationUpto, transactions, isPreMatureClosure); // reset end of day balance back to today's date this.resetAccountTransactionsEndOfDayBalances(transactions, DateUtils.getLocalDateOfTenant()); @@ -253,7 +253,7 @@ public class FixedDepositAccount extends SavingsAccount { } private List calculateInterestPayable(final MathContext mc, final LocalDate maturityDate, - final List transactions) { + final List transactions, final boolean isPreMatureClosure) { final SavingsPostingInterestPeriodType postingPeriodType = SavingsPostingInterestPeriodType.fromInt(this.interestPostingPeriodType); @@ -271,7 +271,7 @@ public class FixedDepositAccount extends SavingsAccount { Money periodStartingBalance = Money.zero(currency); final SavingsInterestCalculationType interestCalculationType = SavingsInterestCalculationType.fromInt(this.interestCalculationType); - final BigDecimal interestRateAsFraction = getEffectiveInterestRateAsFraction(mc, maturityDate); + final BigDecimal interestRateAsFraction = getEffectiveInterestRateAsFraction(mc, maturityDate, isPreMatureClosure); final Collection interestPostTransactions = this.savingsHelper.fetchPostInterestTransactionIds(getId()); boolean isInterestTransfer = false; for (final LocalDateInterval periodInterval : postingPeriodIntervals) { @@ -496,10 +496,10 @@ public class FixedDepositAccount extends SavingsAccount { this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions); } - public void postPreMaturityInterest(final LocalDate accountCloseDate) { + public void postPreMaturityInterest(final LocalDate accountCloseDate, final boolean isPreMatureClosure) { Money interestPostedToDate = totalInterestPosted(); - final Money interestOnMaturity = calculatePreMatureInterest(accountCloseDate, retreiveOrderedNonInterestPostingTransactions()); + final Money interestOnMaturity = calculatePreMatureInterest(accountCloseDate, retreiveOrderedNonInterestPostingTransactions(), isPreMatureClosure); boolean recalucateDailyBalance = false; // post remaining interest @@ -521,11 +521,12 @@ public class FixedDepositAccount extends SavingsAccount { } - public BigDecimal calculatePreMatureAmount(final LocalDate preMatureDate) { + public BigDecimal calculatePreMatureAmount(final LocalDate preMatureDate, final boolean isPreMatureClosure) { final Money interestPostedToDate = totalInterestPosted().copy(); - final Money interestEarnedTillDate = calculatePreMatureInterest(preMatureDate, retreiveOrderedNonInterestPostingTransactions()); + final Money interestEarnedTillDate = calculatePreMatureInterest(preMatureDate, retreiveOrderedNonInterestPostingTransactions(), + isPreMatureClosure); final Money accountBalance = Money.of(getCurrency(), getAccountBalance()); final Money maturityAmount = accountBalance.minus(interestPostedToDate).plus(interestEarnedTillDate); @@ -533,9 +534,10 @@ public class FixedDepositAccount extends SavingsAccount { return maturityAmount.getAmount(); } - private Money calculatePreMatureInterest(final LocalDate preMatureDate, final List transactions) { + private Money calculatePreMatureInterest(final LocalDate preMatureDate, final List transactions, + final boolean isPreMatureClosure) { final MathContext mc = MathContext.DECIMAL64; - final List postingPeriods = calculateInterestPayable(mc, preMatureDate, transactions); + final List postingPeriods = calculateInterestPayable(mc, preMatureDate, transactions, isPreMatureClosure); Money interestOnMaturity = Money.zero(this.currency); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/RecurringDepositAccount.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/RecurringDepositAccount.java index a8d43f6ff..df4a80f7a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/RecurringDepositAccount.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/RecurringDepositAccount.java @@ -164,10 +164,9 @@ public class RecurringDepositAccount extends SavingsAccount { if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } - @Override - protected BigDecimal getEffectiveInterestRateAsFraction(final MathContext mc, final LocalDate interestPostingUpToDate) { + protected BigDecimal getEffectiveInterestRateAsFraction(final MathContext mc, final LocalDate interestPostingUpToDate, + final boolean isPreMatureClosure) { - final boolean isPreMatureClosure = SavingsAccountStatusType.fromInt(this.status).isPreMatureClosure(); boolean applyPreMaturePenalty = false; BigDecimal penalInterest = BigDecimal.ZERO; LocalDate depositCloseDate = calculateMaturityDate(); @@ -199,12 +198,13 @@ public class RecurringDepositAccount extends SavingsAccount { return applicableInterestRate.divide(BigDecimal.valueOf(100l), mc); } - public void updateMaturityDateAndAmount(final MathContext mc) { + public void updateMaturityDateAndAmount(final MathContext mc, final boolean isPreMatureClosure) { final LocalDate maturityDate = calculateMaturityDate(); final LocalDate interestCalculationUpto = maturityDate.minusDays(1); final List allTransactions = generateIncludingFutureTransactions(interestCalculationUpto); - final List postingPeriods = calculateInterestPayable(mc, interestCalculationUpto, allTransactions); + final List postingPeriods = calculateInterestPayable(mc, interestCalculationUpto, allTransactions, + isPreMatureClosure); Money totalInterestPayable = Money.zero(getCurrency()); Money totalDepositAmount = Money.zero(getCurrency()); for (PostingPeriod postingPeriod : postingPeriods) { @@ -260,7 +260,7 @@ public class RecurringDepositAccount extends SavingsAccount { } private List calculateInterestPayable(final MathContext mc, final LocalDate maturityDate, - final List transactions) { + final List transactions, final boolean isPreMatureClosure) { // 1. default to calculate interest based on entire history OR // 2. determine latest 'posting period' and find interest credited to @@ -283,7 +283,7 @@ public class RecurringDepositAccount extends SavingsAccount { Money periodStartingBalance = Money.zero(currency); final SavingsInterestCalculationType interestCalculationType = SavingsInterestCalculationType.fromInt(this.interestCalculationType); - final BigDecimal interestRateAsFraction = getEffectiveInterestRateAsFraction(mc, maturityDate); + final BigDecimal interestRateAsFraction = getEffectiveInterestRateAsFraction(mc, maturityDate, isPreMatureClosure); final Collection interestPostTransactions = this.savingsHelper.fetchPostInterestTransactionIds(getId()); boolean isInterestTransfer = false; for (final LocalDateInterval periodInterval : postingPeriodIntervals) { @@ -597,10 +597,10 @@ public class RecurringDepositAccount extends SavingsAccount { this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions); } - public void postPreMaturityInterest(final LocalDate accountCloseDate) { + public void postPreMaturityInterest(final LocalDate accountCloseDate, final boolean isPreMatureClosure) { final Money interestPostedToDate = totalInterestPosted(); - final Money interestOnMaturity = calculatePreMatureInterest(accountCloseDate, retreiveOrderedNonInterestPostingTransactions()); + final Money interestOnMaturity = calculatePreMatureInterest(accountCloseDate, retreiveOrderedNonInterestPostingTransactions(), isPreMatureClosure); boolean recalucateDailyBalance = false; @@ -623,11 +623,12 @@ public class RecurringDepositAccount extends SavingsAccount { this.accountTermAndPreClosure.updateMaturityDetails(this.getAccountBalance(), accountCloseDate); } - public BigDecimal calculatePreMatureAmount(final LocalDate preMatureDate) { + public BigDecimal calculatePreMatureAmount(final LocalDate preMatureDate, final boolean isPreMatureClosure) { final Money interestPostedToDate = totalInterestPosted().copy(); - final Money interestEarnedTillDate = calculatePreMatureInterest(preMatureDate, retreiveOrderedNonInterestPostingTransactions()); + final Money interestEarnedTillDate = calculatePreMatureInterest(preMatureDate, retreiveOrderedNonInterestPostingTransactions(), + isPreMatureClosure); final Money accountBalance = Money.of(getCurrency(), getAccountBalance()); final Money maturityAmount = accountBalance.minus(interestPostedToDate).plus(interestEarnedTillDate); @@ -635,9 +636,10 @@ public class RecurringDepositAccount extends SavingsAccount { return maturityAmount.getAmount(); } - private Money calculatePreMatureInterest(final LocalDate preMatureDate, final List transactions) { + private Money calculatePreMatureInterest(final LocalDate preMatureDate, final List transactions, + final boolean isPreMatureClosure) { final MathContext mc = MathContext.DECIMAL64; - final List postingPeriods = calculateInterestPayable(mc, preMatureDate, transactions); + final List postingPeriods = calculateInterestPayable(mc, preMatureDate, transactions, isPreMatureClosure); Money interestOnMaturity = Money.zero(this.currency); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountPreMatureCalculationPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountPreMatureCalculationPlatformServiceImpl.java index 635e35e14..f5b5955b6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountPreMatureCalculationPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountPreMatureCalculationPlatformServiceImpl.java @@ -71,15 +71,18 @@ public class DepositAccountPreMatureCalculationPlatformServiceImpl implements De account.clientId(), DepositAccountType.SAVINGS_DEPOSIT); final JsonElement element = this.fromJsonHelper.parse(query.json()); final LocalDate preMaturityDate = this.fromJsonHelper.extractLocalDateNamed(closedOnDateParamName, element); + final boolean isPreMatureClosure = true; if (depositAccountType.isFixedDeposit()) { final FixedDepositAccount fd = (FixedDepositAccount) account; - accountData = FixedDepositAccountData.preClosureDetails(account.getId(), fd.calculatePreMatureAmount(preMaturityDate), - onAccountClosureOptions, paymentTypeOptions, savingsAccountDatas); + accountData = FixedDepositAccountData.preClosureDetails(account.getId(), + fd.calculatePreMatureAmount(preMaturityDate, isPreMatureClosure), onAccountClosureOptions, paymentTypeOptions, + savingsAccountDatas); } else if (depositAccountType.isRecurringDeposit()) { final RecurringDepositAccount rd = (RecurringDepositAccount) account; - accountData = RecurringDepositAccountData.preClosureDetails(account.getId(), rd.calculatePreMatureAmount(preMaturityDate), - onAccountClosureOptions, paymentTypeOptions, savingsAccountDatas); + accountData = RecurringDepositAccountData.preClosureDetails(account.getId(), + rd.calculatePreMatureAmount(preMaturityDate, isPreMatureClosure), onAccountClosureOptions, paymentTypeOptions, + savingsAccountDatas); } return accountData; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java index 1181eac67..131516cc3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java @@ -215,7 +215,8 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); } - account.updateMaturityDateAndAmount(mc); + final boolean isPreMatureClosure = false; + account.updateMaturityDateAndAmount(mc, isPreMatureClosure); account.validateAccountBalanceDoesNotBecomeNegative(SavingsAccountTransactionType.PAY_CHARGE.name()); this.savingAccountRepository.save(account); } @@ -276,6 +277,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo // submitted and activation date are different then recalculate // maturity date and schedule if (!account.accountSubmittedAndActivationOnSameDate()) { + final boolean isPreMatureClosure = false; final CalendarInstance calendarInstance = this.calendarInstanceRepository.findByEntityIdAndEntityTypeIdAndCalendarTypeId( savingsId, CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue()); @@ -284,7 +286,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence()); frequency = frequency == -1 ? 1 : frequency; account.generateSchedule(frequencyType, frequency); - account.updateMaturityDateAndAmount(mc); + account.updateMaturityDateAndAmount(mc, isPreMatureClosure); } final LocalDate overdueUptoDate = account.maturityDate().isAfter(DateUtils.getLocalDateOfTenant()) ? DateUtils @@ -517,7 +519,8 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo } account.validateAccountBalanceDoesNotBecomeNegative(SavingsApiConstants.undoTransactionAction); // account.activateAccountBasedOnBalance(); - account.updateMaturityDateAndAmount(mc); + final boolean isPreMatureClosure = false; + account.updateMaturityDateAndAmount(mc, isPreMatureClosure); final LocalDate overdueUptoDate = account.maturityDate().isAfter(DateUtils.getLocalDateOfTenant()) ? DateUtils .getLocalDateOfTenant() : account.maturityDate(); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java index 9040ea04d..8b27097af 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java @@ -172,8 +172,9 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl DepositAccountType.FIXED_DEPOSIT); final MathContext mc = MathContext.DECIMAL64; + final boolean isPreMatureClosure = false; - account.updateMaturityDateAndAmountBeforeAccountActivation(mc); + account.updateMaturityDateAndAmountBeforeAccountActivation(mc, isPreMatureClosure); this.fixedDepositAccountRepository.save(account); if (account.isAccountNumberRequiresAutoGeneration()) { @@ -240,7 +241,8 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence()); frequency = frequency == -1 ? 1 : frequency; account.generateSchedule(frequencyType, frequency); - account.updateMaturityDateAndAmount(mc); + final boolean isPreMatureClosure = false; + account.updateMaturityDateAndAmount(mc, isPreMatureClosure); account.validateApplicableInterestRate(); this.savingAccountRepository.save(account); @@ -328,7 +330,8 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl if (!changes.isEmpty()) { updateFDAndRDCommonChanges(changes, command, account); final MathContext mc = MathContext.DECIMAL64; - account.updateMaturityDateAndAmountBeforeAccountActivation(mc); + final boolean isPreMatureClosure = false; + account.updateMaturityDateAndAmountBeforeAccountActivation(mc, isPreMatureClosure); this.savingAccountRepository.save(account); } @@ -371,7 +374,8 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence()); frequency = frequency == -1 ? 1 : frequency; account.generateSchedule(frequencyType, frequency); - account.updateMaturityDateAndAmount(mc); + final boolean isPreMatureClosure = false; + account.updateMaturityDateAndAmount(mc, isPreMatureClosure); account.validateApplicableInterestRate(); this.savingAccountRepository.save(account); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java index 2eb027959..16ee5d617 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java @@ -453,6 +453,9 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl Money amountForDeposit = account.activateWithBalance(); boolean isAccountTransfer = false; if (amountForDeposit.isGreaterThanZero()) { + // save account entity before performing deposit transaction, as + // accountId is required for persist transaction entity. + this.savingAccountRepository.save(account); this.savingsAccountDomainService.handleDeposit(account, savingsAccountDataDTO.getFmt(), account.getActivationLocalDate(), amountForDeposit.getAmount(), null, isAccountTransfer); }