@Transactional @Override public EntityIdentifier withdrawDepositAccountInterestMoney( DepositAccountWithdrawInterestCommand command) { context.authenticatedUser(); WithDrawDepositAccountInterestCommandValidator validator = new WithDrawDepositAccountInterestCommandValidator(command); validator.validate(); DepositAccount account = this.depositAccountRepository.findOne(command.getAccountId()); if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.getAccountId()); } if (account.isInterestWithdrawable() && !account.isInterestCompoundingAllowed()) { // BigDecimal totalAvailableInterestForWithdrawal = // getTotalWithdrawableInterestAvailable(account); // BigDecimal interestPaid = account.getInterstPaid(); BigDecimal remainInterestForWithdrawal = account .getAvailableInterest(); // totalAvailableInterestForWithdrawal.subtract(interestPaid); if (remainInterestForWithdrawal.doubleValue() > 0) { if (remainInterestForWithdrawal.doubleValue() >= command.getWithdrawInterest().doubleValue() && command.getWithdrawInterest().doubleValue() > 0) { account.withdrawInterest( Money.of(account.getDeposit().getCurrency(), command.getWithdrawInterest())); this.depositAccountRepository.save(account); } else { throw new DepositAccountTransactionsException( "deposit.transaction.interest.withdrawal.exceed", "You can Withdraw " + remainInterestForWithdrawal + " only"); } } else { throw new DepositAccountTransactionsException( "deposit.transaction.interest.withdrawal.insufficient.amount", "You don't have enough money for withdrawal"); } } else { throw new DepositAccountTransactionsException( "deposit.transaction.interest.withdrawal.cannot.withdraw", "You can not withdraw interst for this account"); } return new EntityIdentifier(account.getId()); }