class ChartOfAccountDetailService {

	public List<ChartOfAccountDetail> fetchRelated(List<ChartOfAccountDetail> chartofaccountdetails) {
		for (ChartOfAccountDetail chartOfAccountDetail : chartofaccountdetails) {
			// fetch related items
			chartOfAccountDetail.setTenantId(ApplicationThreadLocals.getTenantId().get());
			if (chartOfAccountDetail.getChartOfAccount() != null) {
				ChartOfAccount chartOfAccount = chartOfAccountRepository
						.findById(chartOfAccountDetail.getChartOfAccount());
				if (chartOfAccount == null) {
					throw new InvalidDataException("chartOfAccount", "chartOfAccount.invalid",
							" Invalid chartOfAccount");
				}
				chartOfAccountDetail.setChartOfAccount(chartOfAccount);
			}
			if (chartOfAccountDetail.getAccountDetailType() != null) {
				AccountDetailType accountDetailType = accountDetailTypeRepository
						.findById(chartOfAccountDetail.getAccountDetailType());
				if (accountDetailType == null) {
					throw new InvalidDataException("accountDetailType", "accountDetailType.invalid",
							" Invalid accountDetailType");
				}
				chartOfAccountDetail.setAccountDetailType(accountDetailType);
			}

		}

		return chartofaccountdetails;
	}

}