Esempio n. 1
0
        /// <inheritdoc/>
        public override IOrderedQueryable <object> SearchQuery(string searchTerm)
        {
            var rockContext             = new RockContext();
            var financialAccountService = new FinancialAccountService(rockContext);
            var qry = financialAccountService.GetAccountsBySearchTerm(searchTerm);

            return(qry
                   .OrderBy(p => p.PublicName.IsNullOrWhiteSpace() ? p.Name : p.PublicName));
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a list of matching financial accounts
        /// </summary>
        /// <param name="searchTerm"></param>
        /// <returns></returns>
        public override IQueryable <string> Search(string searchTerm)
        {
            var rockContext             = new RockContext();
            var financialAccountService = new FinancialAccountService(rockContext);

            var qry = financialAccountService.GetAccountsBySearchTerm(searchTerm)
                      .Select(v => (v.PublicName == null || v.PublicName.Length == 0 ? v.Name : v.PublicName) + (v.GlCode == null || v.GlCode.Length == 0 ? "" : " (" + v.GlCode + ")"));

            return(qry);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the search term data.
        /// </summary>
        /// <param name="activeOnly">if set to <c>true</c> [active only].</param>
        /// <param name="displayPublicName">if set to <c>true</c> [display public name].</param>
        /// <param name="searchTerm">The search term.</param>
        /// <returns>IQueryable&lt;AccountTreeViewItem&gt;.</returns>
        private IQueryable <AccountTreeViewItem> GetSearchTermData(bool activeOnly, bool displayPublicName, string searchTerm)
        {
            IQueryable <FinancialAccount> qry;

            if (searchTerm.IsNullOrWhiteSpace())
            {
                return(null);
            }

            var financialAccountService = new FinancialAccountService(new Data.RockContext());

            qry = financialAccountService.GetAccountsBySearchTerm(searchTerm);

            if (activeOnly)
            {
                qry = qry
                      .Where(f => f.IsActive == activeOnly);
            }

            var accountList = qry
                              .OrderBy(f => f.Order)
                              .ThenBy(f => f.Name)
                              .ToList();

            var accountTreeViewItems = accountList
                                       .Select(a => new AccountTreeViewItem
            {
                Id       = a.Id.ToString(),
                Name     = HttpUtility.HtmlEncode(displayPublicName ? a.PublicName : a.Name),
                GlCode   = a.GlCode,
                IsActive = a.IsActive,
                ParentId = a.ParentAccountId.GetValueOrDefault(0).ToString(),
                Path     = financialAccountService.GetDelimitedAccountHierarchy(a, FinancialAccountService.AccountHierarchyDirection.CurrentAccountToParent)
            }).ToList();

            var resultIds = accountList.Select(f => f.Id).ToList();

            var childrenList = Get()
                               .Where(f =>
                                      f.ParentAccountId.HasValue &&
                                      resultIds.Contains(f.ParentAccountId.Value))
                               .Select(f => f.ParentAccountId.Value)
                               .ToList();

            foreach (var accountTreeViewItem in accountTreeViewItems)
            {
                int accountId     = int.Parse(accountTreeViewItem.Id);
                int childrenCount = (childrenList?.Count(v => v == accountId)).GetValueOrDefault(0);

                accountTreeViewItem.HasChildren = childrenCount > 0;
                var lastChildId = (childrenList?.LastOrDefault()).GetValueOrDefault(0);

                if (accountTreeViewItem.HasChildren)
                {
                    accountTreeViewItem.CountInfo = childrenCount;
                }

                accountTreeViewItem.IconCssClass = "fa fa-file-o";
            }

            return(accountTreeViewItems.AsQueryable());
        }
Esempio n. 4
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            string searchTerm = PageParameter("SearchTerm");

            var accountService = new FinancialAccountService(new RockContext());
            var accounts       = new List <FinancialAccount>();

            var glCodeStart = searchTerm.LastIndexOf('(');

            if (glCodeStart > -1)
            {
                searchTerm = searchTerm.Substring(glCodeStart).Replace("(", "").Replace(")", "");
            }

            searchTerm = searchTerm.Trim();

            accounts = accountService.GetAccountsBySearchTerm(searchTerm)?.ToList();

            if (accounts?.Count == 1)
            {
                var pageService = new PageService(new RockContext());

                var queryParams = new Dictionary <string, string>();

                var accountId = accounts.First().Id;
                var parentIds = accountService.GetAllAncestorIds(accountId).Reverse()?.ToList();
                if (parentIds == null)
                {
                    parentIds = new List <int>();
                }
                queryParams.Add("AccountId", accountId.ToString());
                queryParams.Add("ExpandedIds", parentIds.Select(v => v.ToString()).JoinStrings(","));
                NavigateToPage(Rock.SystemGuid.Page.ACCOUNTS.AsGuid(), queryParams);
            }
            else
            {
                gAccounts.EntityTypeId = EntityTypeCache.Get <FinancialAccount>().Id;
                gAccounts.DataSource   = accounts?
                                         .Select(act => new
                {
                    act.Id,
                    Name        = act.Name,
                    PublicName  = act.PublicName.IsNullOrWhiteSpace() ? "" : act.PublicName,
                    GlCode      = act.GlCode,
                    AccountType = act.AccountTypeValue?.Value,
                    Description = act.Description,
                    Path        = accountService.GetDelimitedAccountHierarchy(act, FinancialAccountService.AccountHierarchyDirection.CurrentAccountToParent)?.Replace("^", " > ")
                })
                                         .ToList();

                gAccounts.DataBind();

                foreach (DataControlField dcf in gAccounts.Columns)
                {
                    var rtf = dcf as RockTemplateField;
                    var rtfAccountDescription = dcf as RockTemplateField;

                    if (rtf != null)
                    {
                        if (rtf.ID == "rtfAccountType")
                        {
                            rtf.Visible = this.GetAttributeValue(AttributeKey.ShowAccountType).AsBoolean();
                        }
                    }

                    if (rtfAccountDescription != null)
                    {
                        if (rtfAccountDescription.ID == "rtfAccountDescription")
                        {
                            rtfAccountDescription.Visible = this.GetAttributeValue(AttributeKey.ShowAccountDescription).AsBoolean();
                        }
                    }
                }
            }
        }