diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountTermAndPreClosure.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountTermAndPreClosure.java index 09e8584d2..e315ac03d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountTermAndPreClosure.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountTermAndPreClosure.java @@ -49,7 +49,7 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable { @Temporal(TemporalType.DATE) @Column(name = "maturity_date", nullable = true) private Date maturityDate; - + @Temporal(TemporalType.DATE) @Column(name = "expected_firstdepositon_date") private Date expectedFirstDepositOnDate; @@ -179,14 +179,14 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable { } return maturityLocalDate; } - + public LocalDate getExpectedFirstDepositOnDate() { - LocalDate expectedFirstDepositOnLocalDate = null; + LocalDate expectedFirstDepositOnLocalDate = null; if (this.expectedFirstDepositOnDate != null) { - expectedFirstDepositOnLocalDate = new LocalDate(this.expectedFirstDepositOnDate); + expectedFirstDepositOnLocalDate = new LocalDate(this.expectedFirstDepositOnDate); } return expectedFirstDepositOnLocalDate; - } + } public boolean isPreClosurePenalApplicable() { if (this.preClosureDetail != null) { return this.preClosureDetail.preClosurePenalApplicable(); } @@ -195,10 +195,9 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable { public Integer getActualDepositPeriod(final LocalDate interestPostingUpToDate, final SavingsPeriodFrequencyType periodFrequencyType) { LocalDate depositFromDate = getExpectedFirstDepositOnDate(); - - if(depositFromDate == null) - depositFromDate = this.account.accountSubmittedOrActivationDate(); - + + if (depositFromDate == null) depositFromDate = this.account.accountSubmittedOrActivationDate(); + Integer actualDepositPeriod = this.depositPeriod; if (depositFromDate == null || getMaturityLocalDate() == null || interestPostingUpToDate.isEqual(getMaturityLocalDate())) { return actualDepositPeriod; } @@ -234,7 +233,7 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable { public boolean isReinvestOnClosure() { return DepositAccountOnClosureType.fromInt(this.onAccountClosureType).isReinvest(); } - + public boolean isTransferToSavingsOnClosure() { return DepositAccountOnClosureType.fromInt(this.onAccountClosureType).isTransferToSavings(); } @@ -249,12 +248,12 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable { final DepositPreClosureDetail preClosureDetail = this.preClosureDetail.copy(); final DepositTermDetail depositTermDetail = this.depositTermDetail.copy(); final LocalDate expectedFirstDepositOnDate = null; - + final DepositAccountOnClosureType accountOnClosureType = null; return DepositAccountTermAndPreClosure.createNew(preClosureDetail, depositTermDetail, account, actualDepositAmount, maturityAmount, maturityDate, depositPeriod, depositPeriodFrequency, expectedFirstDepositOnDate, accountOnClosureType); } - + public void updateExpectedFirstDepositDate(final LocalDate expectedFirstDepositOnDate) { this.expectedFirstDepositOnDate = expectedFirstDepositOnDate.toDate(); } 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 97d956970..d1634e1b1 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 @@ -99,10 +99,10 @@ public class RecurringDepositAccount extends SavingsAccount { lockinPeriodFrequencyType, withdrawalFeeApplicableForTransfer, savingsAccountCharges, accountTermAndPreClosure, recurringDetail, chart, allowOverdraft, overdraftLimit); } - - public static RecurringDepositAccount createNewActivatedAccount(final Client client, final Group group, - final SavingsProduct product, final Staff fieldOfficer, final String accountNo, final String externalId, - final AccountType accountType, final LocalDate submittedOnDate, final AppUser submittedBy, final BigDecimal interestRate, + + public static RecurringDepositAccount createNewActivatedAccount(final Client client, final Group group, final SavingsProduct product, + final Staff fieldOfficer, final String accountNo, final String externalId, final AccountType accountType, + final LocalDate submittedOnDate, final AppUser submittedBy, final BigDecimal interestRate, final SavingsCompoundingInterestPeriodType interestCompoundingPeriodType, final SavingsPostingInterestPeriodType interestPostingPeriodType, final SavingsInterestCalculationType interestCalculationType, final SavingsInterestCalculationDaysInYearType interestCalculationDaysInYearType, final BigDecimal minRequiredOpeningBalance, @@ -272,8 +272,8 @@ public class RecurringDepositAccount extends SavingsAccount { final SavingsInterestCalculationDaysInYearType daysInYearType = SavingsInterestCalculationDaysInYearType .fromInt(this.interestCalculationDaysInYearType); - final List postingPeriodIntervals = this.savingsHelper.determineInterestPostingPeriods( - depositStartDate(), maturityDate, postingPeriodType); + final List postingPeriodIntervals = this.savingsHelper.determineInterestPostingPeriods(depositStartDate(), + maturityDate, postingPeriodType); final List allPostingPeriods = new ArrayList(); @@ -380,8 +380,7 @@ public class RecurringDepositAccount extends SavingsAccount { // TODO: Support to add deposit start date which can be a date after // account activation date. final LocalDate depositStartDate = accountTermAndPreClosure.getExpectedFirstDepositOnDate(); - if(depositStartDate == null) - return accountSubmittedOrActivationDate(); + if (depositStartDate == null) return accountSubmittedOrActivationDate(); return depositStartDate; } @@ -460,19 +459,19 @@ public class RecurringDepositAccount extends SavingsAccount { } @Override - protected void processAccountUponActivation(final DateTimeFormatter fmt) { + protected void processAccountUponActivation(final DateTimeFormatter fmt) { final Money minRequiredOpeningBalance = Money.of(this.currency, this.minRequiredOpeningBalance); - + if (minRequiredOpeningBalance.isGreaterThanZero()) { final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, getActivationLocalDate(), minRequiredOpeningBalance.getAmount(), null, new Date()); deposit(transactionDTO); - + // update existing transactions so derived balance fields are // correct. recalculateDailyBalances(Money.zero(this.currency), DateUtils.getLocalDateOfTenant()); } - + } public SavingsAccountTransaction close(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate, @@ -803,23 +802,26 @@ public class RecurringDepositAccount extends SavingsAccount { if (!chartInterval.contains(accountSubmittedOrActivationDate())) { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("no.valid.interest.rate.slab.available.for.date.range"); } - + final boolean firstDepositDateBeforeMaturityAndOnOrAfterActivationDate = firstDepositDateBeforeMaturityAndOnOrAfterActivationDate(); - - if(!firstDepositDateBeforeMaturityAndOnOrAfterActivationDate) { - baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("expected.first.deposit.date.is.not.between.maturity.date.and.activation.or.submitted.date"); + + if (!firstDepositDateBeforeMaturityAndOnOrAfterActivationDate) { + baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( + "expected.first.deposit.date.is.not.between.maturity.date.and.activation.or.submitted.date"); } - + final BigDecimal recurringDepositAmount = recurringDetail.recurringDepositAmount(); - BigDecimal applicableInterestRate = this.chart.getApplicableInterestRate(recurringDepositAmount, depositStartDate(), calculateMaturityDate()); - - if(applicableInterestRate.equals(BigDecimal.ZERO)) { - baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("no.applicable.interest.rate.is.found.based.on.amount.and.deposit.period"); + BigDecimal applicableInterestRate = this.chart.getApplicableInterestRate(recurringDepositAmount, depositStartDate(), + calculateMaturityDate()); + + if (applicableInterestRate.equals(BigDecimal.ZERO)) { + baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( + "no.applicable.interest.rate.is.found.based.on.amount.and.deposit.period"); } - + final boolean recurringFrequencyBeforeDepositPeriod = recurringFrequencyBeforeDepositPeriod(); - - if(!recurringFrequencyBeforeDepositPeriod) { + + if (!recurringFrequencyBeforeDepositPeriod) { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("recurring.frequency.not.before.deposit.period"); } } @@ -854,33 +856,35 @@ public class RecurringDepositAccount extends SavingsAccount { final SavingsPeriodFrequencyType lockinPeriodFrequencyType = SavingsPeriodFrequencyType.fromInt(this.lockinPeriodFrequencyType); final Integer lockinPeriodFrequency = this.lockinPeriodFrequency; final boolean withdrawalFeeApplicableForTransfer = false; - + LocalDate now = LocalDate.now(); - + newAccountTermAndPreClosure.updateExpectedFirstDepositDate(now); - RecurringDepositAccount rdAccount = RecurringDepositAccount.createNewActivatedAccount(client, group, product, fieldOfficer, accountNumber, externalId, - accountType, getClosedOnDate(), closedBy, interestRate, compoundingPeriodType, postingPeriodType, interestCalculationType, - daysInYearType, minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyType, - withdrawalFeeApplicableForTransfer, savingsAccountCharges, newAccountTermAndPreClosure, recurringDetail, newChart); - - rdAccount.setDatesFrom(now); - newAccountTermAndPreClosure.updateAccountReference(rdAccount); + RecurringDepositAccount rdAccount = RecurringDepositAccount.createNewActivatedAccount(client, group, product, fieldOfficer, + accountNumber, externalId, accountType, getClosedOnDate(), closedBy, interestRate, compoundingPeriodType, + postingPeriodType, interestCalculationType, daysInYearType, minRequiredOpeningBalance, lockinPeriodFrequency, + lockinPeriodFrequencyType, withdrawalFeeApplicableForTransfer, savingsAccountCharges, newAccountTermAndPreClosure, + recurringDetail, newChart); + + rdAccount.setDatesFrom(now); + newAccountTermAndPreClosure.updateAccountReference(rdAccount); recurringDetail.updateAccountReference(rdAccount); - + return rdAccount; } - + private boolean firstDepositDateBeforeMaturityAndOnOrAfterActivationDate() { LocalDate expectedFirstDepositLocalDate = accountTermAndPreClosure.getExpectedFirstDepositOnDate(); LocalDate maturityLocalDate = calculateMaturityDate(); LocalDate activateOnSubmittedLocalDate = accountSubmittedOrActivationDate(); - - return expectedFirstDepositLocalDate.isBefore(maturityLocalDate) && - (activateOnSubmittedLocalDate.isEqual(expectedFirstDepositLocalDate) || activateOnSubmittedLocalDate.isBefore(expectedFirstDepositLocalDate)); + if (expectedFirstDepositLocalDate != null) { return expectedFirstDepositLocalDate.isBefore(maturityLocalDate) + && (activateOnSubmittedLocalDate.isEqual(expectedFirstDepositLocalDate) || activateOnSubmittedLocalDate + .isBefore(expectedFirstDepositLocalDate)); } + return true; } - + public void setDatesFrom(final LocalDate now) { this.rejectedOnDate = null; this.rejectedBy = null; @@ -888,11 +892,11 @@ public class RecurringDepositAccount extends SavingsAccount { this.withdrawnBy = null; this.closedOnDate = null; this.closedBy = null; - + this.activatedBy = null; this.lockedInUntilDate = null; - - this.activatedOnDate = now.toDate(); + + this.activatedOnDate = now.toDate(); } private boolean recurringFrequencyBeforeDepositPeriod() { @@ -921,5 +925,5 @@ public class RecurringDepositAccount extends SavingsAccount { } return endDateWithFirstRecurringFrequency != null && endDateWithFirstRecurringFrequency.isBefore(calculateMaturityDate()); - } + } } \ No newline at end of file