public List fetchJournalEntries()

in service/src/main/java/org/apache/fineract/cn/accounting/service/internal/service/JournalEntryService.java [59:103]


  public List<JournalEntry> fetchJournalEntries(final DateRange range, final String accountNumber, final BigDecimal amount) {
    final List<JournalEntryEntity> journalEntryEntities =
        this.journalEntryRepository.fetchJournalEntries(range);

    if (journalEntryEntities != null) {

      final List<JournalEntryEntity> filteredList =
          journalEntryEntities
              .stream()
              .filter(journalEntryEntity ->
                  accountNumber == null
                      || journalEntryEntity.getDebtors().stream()
                          .anyMatch(debtorType -> debtorType.getAccountNumber().equals(accountNumber))
                      || journalEntryEntity.getCreditors().stream()
                          .anyMatch(creditorType -> creditorType.getAccountNumber().equals(accountNumber))
              )
              .filter(journalEntryEntity ->
                  amount == null
                      || amount.compareTo(
                          BigDecimal.valueOf(
                              journalEntryEntity.getDebtors().stream().mapToDouble(DebtorType::getAmount).sum()
                          )
                  ) == 0
              )
              .sorted(Comparator.comparing(JournalEntryEntity::getTransactionDate))
              .collect(Collectors.toList());

      final List<TransactionTypeEntity> transactionTypes = this.transactionTypeRepository.findAll();
      final HashMap<String, String> mappedTransactionTypes = new HashMap<>(transactionTypes.size());
      transactionTypes.forEach(transactionTypeEntity ->
          mappedTransactionTypes.put(transactionTypeEntity.getIdentifier(), transactionTypeEntity.getName())
      );

      return filteredList
          .stream()
          .map(journalEntryEntity -> {
            final JournalEntry journalEntry = JournalEntryMapper.map(journalEntryEntity);
            journalEntry.setTransactionType(mappedTransactionTypes.get(journalEntry.getTransactionType()));
            return journalEntry;
          })
          .collect(Collectors.toList());
    } else {
      return Collections.emptyList();
    }
  }