@Transactional
  @Override
  public Long handleFDAccountPreMatureClosure(
      final FixedDepositAccount account,
      final PaymentDetail paymentDetail,
      final AppUser user,
      final JsonCommand command,
      final LocalDate tenantsTodayDate,
      final Map<String, Object> changes) {

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd =
        this.configurationDomainService.isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth =
        this.configurationDomainService.retrieveFinancialYearBeginningMonth();

    boolean isAccountTransfer = false;
    boolean isRegularTransaction = false;
    final boolean isPreMatureClosure = true;
    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    updateExistingTransactionsDetails(
        account, existingTransactionIds, existingReversedTransactionIds);

    final LocalDate closedDate =
        command.localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName);
    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt =
        DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    Long savingsTransactionId = null;
    // post interest
    account.postPreMaturityInterest(
        closedDate,
        isPreMatureClosure,
        isSavingsInterestPostingAtCurrentPeriodEnd,
        financialYearBeginningMonth);

    final Integer closureTypeValue =
        command.integerValueOfParameterNamed(DepositsApiConstants.onAccountClosureIdParamName);
    DepositAccountOnClosureType closureType = DepositAccountOnClosureType.fromInt(closureTypeValue);

    if (closureType.isTransferToSavings()) {
      final boolean isExceptionForBalanceCheck = false;
      final Long toSavingsId = command.longValueOfParameterNamed(toSavingsAccountIdParamName);
      final String transferDescription =
          command.stringValueOfParameterNamed(transferDescriptionParamName);
      final SavingsAccount toSavingsAccount =
          this.depositAccountAssembler.assembleFrom(
              toSavingsId, DepositAccountType.SAVINGS_DEPOSIT);
      final AccountTransferDTO accountTransferDTO =
          new AccountTransferDTO(
              closedDate,
              account.getAccountBalance(),
              PortfolioAccountType.SAVINGS,
              PortfolioAccountType.SAVINGS,
              null,
              null,
              transferDescription,
              locale,
              fmt,
              null,
              null,
              null,
              null,
              null,
              AccountTransferType.ACCOUNT_TRANSFER.getValue(),
              null,
              null,
              null,
              null,
              toSavingsAccount,
              account,
              isRegularTransaction,
              isExceptionForBalanceCheck);
      this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO);
    } else {
      final SavingsAccountTransaction withdrawal =
          this.handleWithdrawal(
              account,
              fmt,
              closedDate,
              account.getAccountBalance(),
              paymentDetail,
              false,
              isRegularTransaction);
      savingsTransactionId = withdrawal.getId();
    }

    /** * Update account transactionIds for post journal entries. */
    updateExistingTransactionsDetails(
        account, existingTransactionIds, existingReversedTransactionIds);
    account.prematureClosure(user, command, tenantsTodayDate, changes);

    this.savingsAccountRepository.save(account);

    postJournalEntries(
        account, existingTransactionIds, existingReversedTransactionIds, isAccountTransfer);
    return savingsTransactionId;
  }
  @Transactional
  @Override
  public Long handleFDAccountClosure(
      final FixedDepositAccount account,
      final PaymentDetail paymentDetail,
      final AppUser user,
      final JsonCommand command,
      final LocalDate tenantsTodayDate,
      final Map<String, Object> changes) {

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd =
        this.configurationDomainService.isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth =
        this.configurationDomainService.retrieveFinancialYearBeginningMonth();

    boolean isRegularTransaction = false;
    boolean isAccountTransfer = false;
    final boolean isPreMatureClosure = false;
    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    updateExistingTransactionsDetails(
        account, existingTransactionIds, existingReversedTransactionIds);
    /*
     * <<<<<<< HEAD final SavingsAccountTransactionDTO transactionDTO = new
     * SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount,
     * paymentDetail, new Date()); final SavingsAccountTransaction deposit =
     * account.deposit(transactionDTO); boolean isInterestTransfer = false;
     * final MathContext mc = MathContext.DECIMAL64; if
     * (account.isBeforeLastPostingPeriod(transactionDate)) { final
     * LocalDate today = DateUtils.getLocalDateOfTenant();
     * account.postInterest(mc, today, isInterestTransfer); } else { final
     * LocalDate today = DateUtils.getLocalDateOfTenant();
     * account.calculateInterestUsing(mc, today, isInterestTransfer);
     * =======
     */
    final MathContext mc = MathContext.DECIMAL64;
    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt =
        DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate closedDate =
        command.localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName);
    Long savingsTransactionId = null;
    account.postMaturityInterest(
        isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);
    final Integer onAccountClosureId =
        command.integerValueOfParameterNamed(onAccountClosureIdParamName);
    final DepositAccountOnClosureType onClosureType =
        DepositAccountOnClosureType.fromInt(onAccountClosureId);
    if (onClosureType.isReinvest()) {
      FixedDepositAccount reinvestedDeposit = account.reInvest(account.getAccountBalance());
      this.depositAccountAssembler.assignSavingAccountHelpers(reinvestedDeposit);
      reinvestedDeposit.updateMaturityDateAndAmountBeforeAccountActivation(
          mc,
          isPreMatureClosure,
          isSavingsInterestPostingAtCurrentPeriodEnd,
          financialYearBeginningMonth);
      this.savingsAccountRepository.save(reinvestedDeposit);
      autoGenerateAccountNumber(reinvestedDeposit);
      final SavingsAccountTransaction withdrawal =
          this.handleWithdrawal(
              account,
              fmt,
              closedDate,
              account.getAccountBalance(),
              paymentDetail,
              false,
              isRegularTransaction);
      savingsTransactionId = withdrawal.getId();
    } else if (onClosureType.isTransferToSavings()) {
      final Long toSavingsId = command.longValueOfParameterNamed(toSavingsAccountIdParamName);
      final String transferDescription =
          command.stringValueOfParameterNamed(transferDescriptionParamName);
      final SavingsAccount toSavingsAccount =
          this.depositAccountAssembler.assembleFrom(
              toSavingsId, DepositAccountType.SAVINGS_DEPOSIT);
      final boolean isExceptionForBalanceCheck = false;
      final AccountTransferDTO accountTransferDTO =
          new AccountTransferDTO(
              closedDate,
              account.getAccountBalance(),
              PortfolioAccountType.SAVINGS,
              PortfolioAccountType.SAVINGS,
              null,
              null,
              transferDescription,
              locale,
              fmt,
              null,
              null,
              null,
              null,
              null,
              AccountTransferType.ACCOUNT_TRANSFER.getValue(),
              null,
              null,
              null,
              null,
              toSavingsAccount,
              account,
              isAccountTransfer,
              isExceptionForBalanceCheck);
      this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO);
    } else {
      final SavingsAccountTransaction withdrawal =
          this.handleWithdrawal(
              account,
              fmt,
              closedDate,
              account.getAccountBalance(),
              paymentDetail,
              false,
              isRegularTransaction);
      savingsTransactionId = withdrawal.getId();
    }

    /** * Update account transactionIds for post journal entries. */
    updateExistingTransactionsDetails(
        account, existingTransactionIds, existingReversedTransactionIds);
    account.close(user, command, tenantsTodayDate, changes);
    this.savingsAccountRepository.save(account);

    postJournalEntries(
        account, existingTransactionIds, existingReversedTransactionIds, isAccountTransfer);

    return savingsTransactionId;
  }