private void verifyWithdrawalTransaction()

in service/src/main/java/org/apache/fineract/cn/teller/service/rest/TellerOperationRestController.java [294:324]


  private void verifyWithdrawalTransaction(final TellerTransaction tellerTransaction,
                                           final ConfirmTellerTransactionCommand confirmTellerTransactionCommand) {
    final String transactionType = tellerTransaction.getTransactionType();

    if (transactionType.equals(ServiceConstants.TX_ACCOUNT_TRANSFER)
        || transactionType.equals(ServiceConstants.TX_CASH_WITHDRAWAL)
        || transactionType.equals(ServiceConstants.TX_CLOSE_ACCOUNT)) {

      final Account account = this.accountingService.findAccount(tellerTransaction.getCustomerAccountIdentifier())
          .orElseThrow(() -> ServiceException.notFound("Customer account {0} not found.",
              tellerTransaction.getCustomerAccountIdentifier()));

      final BigDecimal currentBalance = BigDecimal.valueOf(account.getBalance());

      final TellerTransactionCosts tellerTransactionCosts =
          this.tellerTransactionProcessor.getCosts(tellerTransaction);
      final BigDecimal transactionAmount = confirmTellerTransactionCommand.chargesIncluded()
          ? tellerTransaction.getAmount()
          : tellerTransactionCosts.getTotalAmount();

      if (transactionAmount.compareTo(currentBalance) > 0) {
        throw ServiceException.conflict("Account has not enough balance.");
      }

      if (transactionType.equals(ServiceConstants.TX_CLOSE_ACCOUNT)) {
        if (currentBalance.compareTo(transactionAmount) > 0) {
          throw ServiceException.conflict("Account has remaining balance.");
        }
      }
    }
  }