class ChartOfAccountService {

	public List<ChartOfAccount> fetchRelated(List<ChartOfAccount> chartofaccounts) {
		for (ChartOfAccount chartOfAccount : chartofaccounts) {
			// fetch related items
			chartOfAccount.setTenantId(ApplicationThreadLocals.getTenantId().get());
			if (chartOfAccount.getAccountCodePurpose() != null) {
				AccountCodePurpose accountCodePurpose = accountCodePurposeRepository
						.findById(chartOfAccount.getAccountCodePurpose());
				if (accountCodePurpose == null) {
					throw new InvalidDataException("accountCodePurpose", "accountCodePurpose.invalid",
							" Invalid accountCodePurpose");
				}
				chartOfAccount.setAccountCodePurpose(accountCodePurpose);
			}
			if (chartOfAccount.getParentId() != null) {
				ChartOfAccount parentId = chartOfAccountRepository.findById(chartOfAccount.getParentId());
				if (parentId == null) {
					throw new InvalidDataException("parentId", "parentId.invalid", " Invalid parentId");
				}
				chartOfAccount.setParentId(parentId);
			}

		}

		return chartofaccounts;
	}

}