private static bool ShouldKeepAccount(AccountScreenRow accountRowData, ICollection <int> hideIfZeroBalanceTypeIds) { return(!hideIfZeroBalanceTypeIds.Contains(accountRowData.AccountTypeId) || (hideIfZeroBalanceTypeIds.Contains(accountRowData.AccountTypeId) && accountRowData.Balance != 0)); }
public IEnumerable <AccountScreenRow> GetAccountScreenRows(AccountScreen accountScreen, WorkPeriod currentWorkPeriod) { var rows = new List <AccountScreenRow>(); var detailedTemplateNames = accountScreen.AccountScreenValues.Where(x => x.DisplayDetails).Select(x => x.AccountTypeId); _accountDao.GetAccountBalances(detailedTemplateNames.ToList(), GetFilter(accountScreen, currentWorkPeriod)).ToList().ForEach(x => rows.Add(AccountScreenRow.Create(x, _cacheService.GetCurrencySymbol(x.Key.ForeignCurrencyId), GetGroupKey(accountScreen, x.Key.AccountTypeId)))); var templateTotals = accountScreen.AccountScreenValues.Where(x => !x.DisplayDetails).Select(x => x.AccountTypeId); _accountDao.GetAccountTypeBalances(templateTotals.ToList(), GetFilter(accountScreen, currentWorkPeriod)).ToList().ForEach(x => rows.Add(AccountScreenRow.Create(x, GetGroupKey(accountScreen, x.Key.Id)))); var hideIfZeroBalanceTypeIds = accountScreen.AccountScreenValues.Where(x => x.HideZeroBalanceAccounts).Select(x => x.AccountTypeId).ToList(); var accounts = rows.Where(x => ShouldKeepAccount(x, hideIfZeroBalanceTypeIds)) .OrderBy(x => GetSortOrder(accountScreen.AccountScreenValues, x.AccountTypeId)) .ThenBy(x => x.Name) .ToList(); return(accounts); }