Exemplo n.º 1
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var profiles = new FinancialScheduledTransactionService().Queryable();

            SortProperty sortProperty = rGridGivingProfile.SortProperty;

            if (dtpGivingProfileDate.SelectedDateTime.HasValue)
            {
                profiles = profiles.Where(GivingProfile => GivingProfile.StartDate >= dtpGivingProfileDate.SelectedDateTime);
            }

            if (sortProperty != null)
            {
                rGridGivingProfile.DataSource = profiles.Sort(sortProperty).ToList();
            }
            else
            {
                rGridGivingProfile.DataSource = profiles.OrderBy(b => b.AuthorizedPersonId).ToList();
            }

            rGridGivingProfile.DataBind();
        }
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid(bool isExporting = false)
        {
            int?personId      = null;
            int?givingGroupId = null;

            bool validRequest = false;

            if (TargetPerson != null)
            {
                personId      = TargetPerson.Id;
                givingGroupId = TargetPerson.GivingGroupId;
                validRequest  = true;
            }
            else
            {
                int personEntityTypeId = EntityTypeCache.Read("Rock.Model.Person").Id;
                if (!ContextTypesRequired.Any(e => e.Id == personEntityTypeId))
                {
                    validRequest = true;
                }
            }

            if (validRequest)
            {
                var rockContext = new RockContext();
                var qry         = new FinancialScheduledTransactionService(rockContext)
                                  .Queryable("ScheduledTransactionDetails,FinancialPaymentDetail.CurrencyTypeValue,FinancialPaymentDetail.CreditCardTypeValue")
                                  .AsNoTracking();

                // Valid Accounts
                var accountGuids = GetAttributeValue("Accounts").SplitDelimitedValues().AsGuidList();
                if (accountGuids.Any())
                {
                    qry = qry.Where(t => t.ScheduledTransactionDetails.Any(d => accountGuids.Contains(d.Account.Guid)));
                }

                // Amount Range
                var nre = new NumberRangeEditor();
                nre.DelimitedValues = gfSettings.GetUserPreference("Amount");
                if (nre.LowerValue.HasValue)
                {
                    qry = qry.Where(t => t.ScheduledTransactionDetails.Sum(d => d.Amount) >= nre.LowerValue.Value);
                }

                if (nre.UpperValue.HasValue)
                {
                    qry = qry.Where(t => t.ScheduledTransactionDetails.Sum(d => d.Amount) <= nre.UpperValue.Value);
                }

                // Frequency
                int?frequencyTypeId = gfSettings.GetUserPreference("Frequency").AsIntegerOrNull();
                if (frequencyTypeId.HasValue)
                {
                    qry = qry.Where(t => t.TransactionFrequencyValueId == frequencyTypeId.Value);
                }

                // Date Range
                var drp = new DateRangePicker();
                drp.DelimitedValues = gfSettings.GetUserPreference("Created");
                if (drp.LowerValue.HasValue)
                {
                    qry = qry.Where(t => t.CreatedDateTime >= drp.LowerValue.Value);
                }

                if (drp.UpperValue.HasValue)
                {
                    DateTime upperDate = drp.UpperValue.Value.Date.AddDays(1);
                    qry = qry.Where(t => t.CreatedDateTime < upperDate);
                }

                // Account Id
                int accountId = int.MinValue;
                if (int.TryParse(gfSettings.GetUserPreference("Account"), out accountId) && ddlAccount.Visible)
                {
                    qry = qry.Where(t => t.ScheduledTransactionDetails.Any(d => d.AccountId == accountId));
                }

                // Active only (no filter)
                if (string.IsNullOrWhiteSpace(gfSettings.GetUserPreference("Include Inactive")))
                {
                    qry = qry.Where(t => t.IsActive);
                }

                if (givingGroupId.HasValue)
                {
                    //  Person contributes with family
                    qry = qry.Where(t => t.AuthorizedPersonAlias.Person.GivingGroupId == givingGroupId);
                }
                else if (personId.HasValue)
                {
                    // Person contributes individually
                    qry = qry.Where(t => t.AuthorizedPersonAlias.PersonId == personId);
                }

                SortProperty sortProperty = gList.SortProperty;
                if (sortProperty != null)
                {
                    if (sortProperty.Property == "Amount")
                    {
                        if (sortProperty.Direction == SortDirection.Ascending)
                        {
                            qry = qry.OrderBy(t => t.ScheduledTransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.00M);
                        }
                        else
                        {
                            qry = qry.OrderByDescending(t => t.ScheduledTransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.0M);
                        }
                    }
                    else
                    {
                        qry = qry.Sort(sortProperty);
                    }
                }
                else
                {
                    qry = qry
                          .OrderBy(t => t.AuthorizedPersonAlias.Person.LastName)
                          .ThenBy(t => t.AuthorizedPersonAlias.Person.NickName)
                          .ThenByDescending(t => t.IsActive)
                          .ThenByDescending(t => t.StartDate);
                }

                _isExporting = isExporting;

                gList.SetLinqDataSource <FinancialScheduledTransaction>(qry);
                gList.DataBind();

                _isExporting = false;
            }
        }