@Transactional
  @Override
  public SavingsAccountTransaction handleRDDeposit(
      final RecurringDepositAccount account,
      final DateTimeFormatter fmt,
      final LocalDate transactionDate,
      final BigDecimal transactionAmount,
      final PaymentDetail paymentDetail,
      final boolean isRegularTransaction) {

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

    boolean isAccountTransfer = false;
    final boolean isPreMatureClosure = false;
    final MathContext mc = MathContext.DECIMAL64;
    final SavingsAccountTransaction deposit =
        this.savingsAccountDomainService.handleDeposit(
            account,
            fmt,
            transactionDate,
            transactionAmount,
            paymentDetail,
            isAccountTransfer,
            isRegularTransaction);

    account.handleScheduleInstallments(deposit);
    account.updateMaturityDateAndAmount(
        mc,
        isPreMatureClosure,
        isSavingsInterestPostingAtCurrentPeriodEnd,
        financialYearBeginningMonth);
    account.updateOverduePayments(DateUtils.getLocalDateOfTenant());
    return deposit;
  }
  @Override
  public OfficeOpeningBalancesData retrieveOfficeOpeningBalances(
      final Long officeId, String currencyCode) {

    final FinancialActivityAccount financialActivityAccountId =
        this.financialActivityAccountRepositoryWrapper
            .findByFinancialActivityTypeWithNotFoundDetection(300);
    final Long contraId = financialActivityAccountId.getGlAccount().getId();
    if (contraId == null) {
      throw new GeneralPlatformDomainRuleException(
          "error.msg.financial.activity.mapping.opening.balance.contra.account.cannot.be.null",
          "office-opening-balances-contra-account value can not be null",
          "office-opening-balances-contra-account");
    }

    final JournalEntryAssociationParametersData associationParametersData =
        new JournalEntryAssociationParametersData();
    final GLAccountData contraAccount =
        this.glAccountReadPlatformService.retrieveGLAccountById(
            contraId, associationParametersData);
    if (!GLAccountType.fromInt(contraAccount.getTypeId()).isEquityType()) {
      throw new GeneralPlatformDomainRuleException(
          "error.msg.configuration.opening.balance.contra.account.value.is.invalid.account.type",
          "Global configuration 'office-opening-balances-contra-account' value is not an equity type account",
          contraId);
    }

    final OfficeData officeData = this.officeReadPlatformService.retrieveOffice(officeId);
    final List<JournalEntryData> allOpeningTransactions =
        populateAllTransactionsFromGLAccounts(contraId);
    final String contraTransactionId =
        retrieveContraAccountTransactionId(officeId, contraId, currencyCode);

    List<JournalEntryData> existingOpeningBalanceTransactions = new ArrayList<>();
    if (StringUtils.isNotBlank(contraTransactionId)) {
      existingOpeningBalanceTransactions =
          retrieveOfficeBalanceTransactions(officeId, contraTransactionId, currencyCode);
    }
    final List<JournalEntryData> transactions =
        populateOpeningBalances(existingOpeningBalanceTransactions, allOpeningTransactions);
    final List<JournalEntryData> assetAccountOpeningBalances = new ArrayList<>();
    final List<JournalEntryData> liabityAccountOpeningBalances = new ArrayList<>();
    final List<JournalEntryData> incomeAccountOpeningBalances = new ArrayList<>();
    final List<JournalEntryData> equityAccountOpeningBalances = new ArrayList<>();
    final List<JournalEntryData> expenseAccountOpeningBalances = new ArrayList<>();

    for (final JournalEntryData journalEntryData : transactions) {
      final GLAccountType type =
          GLAccountType.fromInt(journalEntryData.getGlAccountType().getId().intValue());
      if (type.isAssetType()) {
        assetAccountOpeningBalances.add(journalEntryData);
      } else if (type.isLiabilityType()) {
        liabityAccountOpeningBalances.add(journalEntryData);
      } else if (type.isEquityType()) {
        equityAccountOpeningBalances.add(journalEntryData);
      } else if (type.isIncomeType()) {
        incomeAccountOpeningBalances.add(journalEntryData);
      } else if (type.isExpenseType()) {
        expenseAccountOpeningBalances.add(journalEntryData);
      }
    }

    final LocalDate transactionDate = DateUtils.getLocalDateOfTenant();

    final OfficeOpeningBalancesData officeOpeningBalancesData =
        OfficeOpeningBalancesData.createNew(
            officeId,
            officeData.name(),
            transactionDate,
            contraAccount,
            assetAccountOpeningBalances,
            liabityAccountOpeningBalances,
            incomeAccountOpeningBalances,
            equityAccountOpeningBalances,
            expenseAccountOpeningBalances);
    return officeOpeningBalancesData;
  }