diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositAccount.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositAccount.java index f46c41345..853e83b05 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositAccount.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositAccount.java @@ -79,7 +79,6 @@ public class DepositAccount extends AbstractAuditableCustom { @Column(name = "matures_on_date") private Date maturesOnDate; - @SuppressWarnings("unused") @Column(name = "projected_interest_accrued_on_maturity", scale = 6, precision = 19, nullable = false) private BigDecimal projectedInterestAccruedOnMaturity; @@ -638,4 +637,12 @@ public class DepositAccount extends AbstractAuditableCustom { this.renewalAllowed=renewalAllowed; this.isInterestWithdrawable=isInterestWithdrawable; } + + public boolean isSubmittedAndPendingApproval() { + return DepositAccountStatus.fromInt(this.depositStatus).isSubmittedAndPendingApproval(); + } + + public boolean isActive() { + return DepositAccountStatus.fromInt(this.depositStatus).isActive(); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java index 298f1792d..ab73d7937 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java @@ -55,8 +55,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo final DepositAccountRepository depositAccountRepository, final DepositAccountAssembler depositAccountAssembler, final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator, - final NoteRepository noteRepository - ) { + final NoteRepository noteRepository) { this.context=context; this.depositAccountRepository = depositAccountRepository; this.depositAccountAssembler = depositAccountAssembler; @@ -369,12 +368,8 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo && (new LocalDate().isAfter(account.maturesOnDate()) || new LocalDate() .isEqual(account.maturesOnDate()))) { - // FIXME - KW - rather than getting the status from account and then checking, - // add isActive behaviour on account so all places that use account dont have to repeat this type of checking. - if (account.getDepositStatus().equals( - DepositAccountStatus.ACTIVE.getValue())) { - final DepositAccount renewedAccount = this.depositAccountAssembler - .assembleFrom(account, command); + if (account.isActive()) { + final DepositAccount renewedAccount = this.depositAccountAssembler.assembleFrom(account, command); this.depositAccountRepository.save(renewedAccount); account.closeDepositAccount(defaultDepositLifecycleStateMachine()); this.depositAccountRepository.save(account); @@ -396,14 +391,17 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo DepositAccountCommandValidator validator = new DepositAccountCommandValidator(command); validator.validateForUpdate(); - DepositAccount account = this.depositAccountRepository.findOne(command.getId()); + final DepositAccount account = this.depositAccountRepository.findOne(command.getId()); if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.getId()); } - if(account.getDepositStatus() == 100) - this.depositAccountAssembler.assembleUpdatedDepositAccount(account,command); - else if(account.getDepositStatus() == 300) - this.depositAccountAssembler.updateApprovedDepositAccount(account,command); + + if (account.isSubmittedAndPendingApproval()) { + this.depositAccountAssembler.assembleUpdatedDepositAccount(account, command); + } else if (account.isActive()) { + this.depositAccountAssembler.updateApprovedDepositAccount(account, command); + } + this.depositAccountRepository.save(account); return new EntityIdentifier(account.getId()); @@ -411,7 +409,5 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo handleDataIntegrityIssues(command, dve); return new EntityIdentifier(Long.valueOf(-1)); } - - } } \ No newline at end of file