in service/src/main/java/org/apache/fineract/cn/accounting/service/internal/service/ChartOfAccountsService.java [70:98]
private void traverseHierarchy(final List<ChartOfAccountEntry> chartOfAccountEntries, final int level, final LedgerEntity ledgerEntity) {
if (ledgerEntity.getShowAccountsInChart()) {
final List<AccountEntity> accountEntities = this.accountRepository.findByLedger(ledgerEntity);
accountEntities.sort(Comparator.comparing(AccountEntity::getIdentifier));
accountEntities.forEach(accountEntity -> {
final ChartOfAccountEntry chartOfAccountEntry = new ChartOfAccountEntry();
chartOfAccountEntries.add(chartOfAccountEntry);
chartOfAccountEntry.setCode(accountEntity.getIdentifier());
chartOfAccountEntry.setName(accountEntity.getName());
chartOfAccountEntry.setType(accountEntity.getType());
chartOfAccountEntry.setLevel(level);
});
}
final List<LedgerEntity> subLedgers = this.ledgerRepository.findByParentLedgerOrderByIdentifier(ledgerEntity);
if (subLedgers != null && subLedgers.size() > 0) {
subLedgers.sort(Comparator.comparing(LedgerEntity::getIdentifier));
subLedgers.forEach(subLedger -> {
final ChartOfAccountEntry chartOfAccountEntry = new ChartOfAccountEntry();
chartOfAccountEntries.add(chartOfAccountEntry);
chartOfAccountEntry.setCode(subLedger.getIdentifier());
chartOfAccountEntry.setName(subLedger.getName());
chartOfAccountEntry.setType(subLedger.getType());
chartOfAccountEntry.setLevel(level);
final int nextLevel = level + 1;
this.traverseHierarchy(chartOfAccountEntries, nextLevel, subLedger);
});
}
}