Esempio n. 1
0
        /// <summary>
        /// Returns the field's current value(s)
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="value">Information about the value</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
        /// <returns></returns>
        public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed)
        {
            string formattedValue = string.Empty;

            if (!string.IsNullOrWhiteSpace(value))
            {
                bool displayPublicName = true;

                if (configurationValues != null &&
                    configurationValues.ContainsKey(DISPLAY_PUBLIC_NAME))
                {
                    displayPublicName = configurationValues[DISPLAY_PUBLIC_NAME].Value.AsBoolean();
                }

                var guids = value.SplitDelimitedValues();

                using (var rockContext = new RockContext())
                {
                    var accounts = new FinancialAccountService(rockContext).Queryable().AsNoTracking().Where(a => guids.Contains(a.Guid.ToString()));
                    if (accounts.Any())
                    {
                        formattedValue = string.Join(", ", (from account in accounts select displayPublicName && account.PublicName != null && account.PublicName != string.Empty ? account.PublicName : account.Name).ToArray());
                    }
                }
            }

            return(base.FormatValue(parentControl, formattedValue, null, condensed));
        }
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection(Type entityType, Control[] controls)
        {
            SelectionConfig selectionConfig = new SelectionConfig();

            var    accountIdList = (controls[0] as AccountPicker).SelectedValuesAsInt().ToList();
            string accountGuids  = string.Empty;
            var    accounts      = new FinancialAccountService(new RockContext()).GetByIds(accountIdList);

            if (accounts != null && accounts.Any())
            {
                selectionConfig.AccountGuids = accounts.Select(a => a.Guid).ToList();
            }

            SlidingDateRangePicker slidingDateRangePicker = controls[1] as SlidingDateRangePicker;

            selectionConfig.StartDate         = slidingDateRangePicker.DateRangeModeStart;
            selectionConfig.EndDate           = slidingDateRangePicker.DateRangeModeEnd;
            selectionConfig.DateRangeMode     = slidingDateRangePicker.SlidingDateRangeMode;
            selectionConfig.TimeUnit          = slidingDateRangePicker.TimeUnit;
            selectionConfig.NumberOfTimeUnits = slidingDateRangePicker.NumberOfTimeUnits;

            selectionConfig.UseSundayDate = (controls[2] as RockCheckBox).Checked;

            return(selectionConfig.ToJson());
        }
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection(Control[] controls)
        {
            string  comparisonType = (( DropDownList )controls[0]).SelectedValue;
            decimal?amount         = (controls[1] as CurrencyBox).Text.AsDecimal();

            var    accountIdList = (controls[2] as AccountPicker).SelectedValuesAsInt().ToList();
            string accountGuids  = string.Empty;
            var    accounts      = new FinancialAccountService(new RockContext()).GetByIds(accountIdList);

            if (accounts != null && accounts.Any())
            {
                accountGuids = accounts.Select(a => a.Guid).ToList().AsDelimited(",");
            }

            SlidingDateRangePicker slidingDateRangePicker = controls[3] as SlidingDateRangePicker;

            // convert pipe to comma delimited
            var delimitedValues = slidingDateRangePicker.DelimitedValues.Replace("|", ",");

            RockCheckBox cbCombineGiving = controls[4] as RockCheckBox;
            RockCheckBox cbUseAnalytics  = controls[5] as RockCheckBox;

            // {2} and {3} used to store the DateRange before, but now we using the SlidingDateRangePicker
            return($"{comparisonType}|{amount}|||{accountGuids}|{cbCombineGiving.Checked}|{delimitedValues}|{cbUseAnalytics.Checked}");
        }
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection(Type entityType, Control[] controls, string selection)
        {
            string[] selectionValues = selection.Split('|');
            if (selectionValues.Length >= 3)
            {
                var accountPicker          = controls[0] as AccountPicker;
                var slidingDateRangePicker = controls[1] as SlidingDateRangePicker;

                if (selectionValues.Length >= 4)
                {
                    // convert comma delimited to pipe
                    slidingDateRangePicker.DelimitedValues = selectionValues[3].Replace(',', '|');
                }
                else
                {
                    // if converting from a previous version of the selection
                    var lowerValue = selectionValues[0].AsDateTime();
                    var upperValue = selectionValues[1].AsDateTime();

                    slidingDateRangePicker.SlidingDateRangeMode = SlidingDateRangePicker.SlidingDateRangeType.DateRange;
                    slidingDateRangePicker.SetDateRangeModeValue(new DateRange(lowerValue, upperValue));
                }

                var accountGuids = selectionValues[2].Split(',').Select(a => a.AsGuid()).ToList();
                var accounts     = new FinancialAccountService(new RockContext()).GetByGuids(accountGuids);
                if (accounts != null && accounts.Any())
                {
                    accountPicker.SetValues(accounts);
                }
            }
        }
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection(Control[] controls, string selection)
        {
            string[] selectionValues = selection.Split('|');
            if (selectionValues.Length >= 4)
            {
                var comparisonControl = controls[0] as DropDownList;
                var numberBox         = controls[1] as CurrencyBox;
                var accountPicker     = controls[2] as AccountPicker;
                SlidingDateRangePicker slidingDateRangePicker = controls[3] as SlidingDateRangePicker;
                var cbCombineGiving = controls[4] as RockCheckBox;
                var cbUseAnalytics  = controls[5] as RockCheckBox;

                comparisonControl.SetValue(selectionValues[0]);
                decimal?amount = selectionValues[1].AsDecimal();
                if (amount.HasValue)
                {
                    numberBox.Text = amount.Value.ToString("F2");
                }
                else
                {
                    numberBox.Text = string.Empty;
                }


                if (selectionValues.Length >= 7)
                {
                    // convert comma delimited to pipe
                    slidingDateRangePicker.DelimitedValues = selectionValues[6].Replace(',', '|');
                }
                else
                {
                    // if converting from a previous version of the selection
                    var lowerValue = selectionValues[2].AsDateTime();
                    var upperValue = selectionValues[3].AsDateTime();

                    slidingDateRangePicker.SlidingDateRangeMode = SlidingDateRangePicker.SlidingDateRangeType.DateRange;
                    slidingDateRangePicker.SetDateRangeModeValue(new DateRange(lowerValue, upperValue));
                }

                if (selectionValues.Length >= 5)
                {
                    var accountGuids = selectionValues[4].Split(',').Select(a => a.AsGuid()).ToList();
                    var accounts     = new FinancialAccountService(new RockContext()).GetByGuids(accountGuids);
                    if (accounts != null && accounts.Any())
                    {
                        accountPicker.SetValues(accounts);
                    }
                }

                if (selectionValues.Length >= 6)
                {
                    cbCombineGiving.Checked = selectionValues[5].AsBooleanOrNull() ?? false;
                }

                if (selectionValues.Length >= 8)
                {
                    cbUseAnalytics.Checked = selectionValues[7].AsBooleanOrNull() ?? false;
                }
            }
        }
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection)
        {
            var rockContext = (RockContext)serviceInstance.Context;

            string[] selectionValues = selection.Split('|');
            if (selectionValues.Length < 3)
            {
                return(null);
            }

            DateTime?startDate     = selectionValues[0].AsDateTime();
            DateTime?endDate       = selectionValues[1].AsDateTime();
            var      accountGuids  = selectionValues[2].Split(',').Select(a => a.AsGuid()).ToList();
            var      accountIdList = new FinancialAccountService((RockContext)serviceInstance.Context).GetByGuids(accountGuids).Select(a => a.Id).ToList();

            int transactionTypeContributionId = Rock.Web.Cache.DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION.AsGuid()).Id;

            var financialTransactionsQry = new FinancialTransactionService(rockContext).Queryable()
                                           .Where(xx => xx.TransactionTypeValueId == transactionTypeContributionId);

            if (accountIdList.Any())
            {
                if (accountIdList.Count == 1)
                {
                    int accountId = accountIdList.First();
                    financialTransactionsQry = financialTransactionsQry.Where(xx => xx.TransactionDetails.Any(a => a.AccountId == accountId));
                }
                else
                {
                    financialTransactionsQry = financialTransactionsQry.Where(xx => xx.TransactionDetails.Any(a => accountIdList.Contains(a.AccountId)));
                }
            }

            var firstContributionDateQry = financialTransactionsQry
                                           .GroupBy(xx => xx.AuthorizedPersonAlias.PersonId)
                                           .Select(ss => new
            {
                PersonId = ss.Key,
                FirstTransactionSundayDate = ss.Min(a => a.SundayDate)
            });

            if (startDate.HasValue)
            {
                firstContributionDateQry = firstContributionDateQry.Where(xx => xx.FirstTransactionSundayDate >= startDate.Value);
            }

            if (endDate.HasValue)
            {
                firstContributionDateQry = firstContributionDateQry.Where(xx => xx.FirstTransactionSundayDate < endDate);
            }

            var innerQry = firstContributionDateQry.Select(xx => xx.PersonId).AsQueryable();

            var qry = new PersonService(rockContext).Queryable()
                      .Where(p => innerQry.Any(xx => xx == p.Id));

            Expression extractedFilterExpression = FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p");

            return(extractedFilterExpression);
        }
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection)
        {
            var rockContext = (RockContext)serviceInstance.Context;

            SelectionConfig selectionConfig = SelectionConfig.Parse(selection);

            if (selectionConfig == null)
            {
                return(null);
            }

            DateRange dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues(selectionConfig.DelimitedValues);

            int transactionTypeContributionId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION.AsGuid()).Id;
            var financialTransactionsQry      = new FinancialTransactionService(rockContext)
                                                .Queryable()
                                                .Where(xx => xx.TransactionTypeValueId == transactionTypeContributionId);

            var accountIdList = new FinancialAccountService(( RockContext )serviceInstance.Context).GetByGuids(selectionConfig.AccountGuids).Select(a => a.Id).ToList();

            if (accountIdList.Any())
            {
                if (accountIdList.Count == 1)
                {
                    int accountId = accountIdList.First();
                    financialTransactionsQry = financialTransactionsQry.Where(xx => xx.TransactionDetails.Any(a => a.AccountId == accountId));
                }
                else
                {
                    financialTransactionsQry = financialTransactionsQry.Where(xx => xx.TransactionDetails.Any(a => accountIdList.Contains(a.AccountId)));
                }
            }

            var firstContributionDateQry = financialTransactionsQry
                                           .GroupBy(xx => xx.AuthorizedPersonAlias.PersonId)
                                           .Select(ss => new
            {
                PersonId             = ss.Key,
                FirstTransactionDate = ss.Min(a => selectionConfig.UseSundayDate == true ? a.SundayDate : a.TransactionDateTime)
            });

            if (dateRange.Start.HasValue)
            {
                firstContributionDateQry = firstContributionDateQry.Where(xx => xx.FirstTransactionDate >= dateRange.Start.Value);
            }

            if (dateRange.End.HasValue)
            {
                firstContributionDateQry = firstContributionDateQry.Where(xx => xx.FirstTransactionDate < dateRange.End.Value);
            }

            var innerQry = firstContributionDateQry.Select(xx => xx.PersonId).AsQueryable();
            var qry      = new PersonService(rockContext).Queryable().Where(p => innerQry.Any(xx => xx == p.Id));

            return(FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p"));
        }
Esempio n. 8
0
 /// <summary>
 /// Sets the selection.
 /// </summary>
 /// <param name="entityType">Type of the entity.</param>
 /// <param name="controls">The controls.</param>
 /// <param name="selection">The selection.</param>
 public override void SetSelection(Type entityType, Control[] controls, string selection)
 {
     string[] selectionValues = selection.Split('|');
     if (selectionValues.Length >= 1)
     {
         var accountGuids = selectionValues[0].Split(',').Select(a => a.AsGuid()).ToList();
         var accounts     = new FinancialAccountService(new RockContext()).GetByGuids(accountGuids);
         if (accounts != null && accounts.Any())
         {
             (controls[0] as AccountPicker).SetValues(accounts);
         }
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection(Type entityType, Control[] controls)
        {
            var    accountIdList = (controls[0] as AccountPicker).SelectedValuesAsInt().ToList();
            string accountGuids  = string.Empty;
            var    accounts      = new FinancialAccountService(new RockContext()).GetByIds(accountIdList);

            if (accounts != null && accounts.Any())
            {
                accountGuids = accounts.Select(a => a.Guid).ToList().AsDelimited(",");
            }

            return(accountGuids);
        }
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection(Type entityType, Control[] controls)
        {
            var    accountIdList = (controls[0] as AccountPicker).SelectedValuesAsInt().ToList();
            string accountGuids  = string.Empty;
            var    accounts      = new FinancialAccountService(new RockContext()).GetByIds(accountIdList);

            if (accounts != null && accounts.Any())
            {
                accountGuids = accounts.Select(a => a.Guid).ToList().AsDelimited(",");
            }

            DateRangePicker dateRangePicker = controls[1] as DateRangePicker;

            return(string.Format("{0}|{1}|{2}", dateRangePicker.LowerValue, dateRangePicker.UpperValue, accountGuids));
        }
Esempio n. 11
0
        /// <summary>
        /// Returns the field's current value(s)
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="value">Information about the value</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
        /// <returns></returns>
        public override string FormatValue( Control parentControl, string value, Dictionary<string, ConfigurationValue> configurationValues, bool condensed )
        {
            string formattedValue = string.Empty;

            if ( !string.IsNullOrWhiteSpace( value ) )
            {
                var guids = value.SplitDelimitedValues();
                var accounts = new FinancialAccountService().Queryable().Where( a => guids.Contains( a.Guid.ToString() ) );
                if ( accounts.Any() )
                {
                    formattedValue = string.Join( ", ", ( from account in accounts select account.PublicName ).ToArray() );
                }
            }

            return base.FormatValue( parentControl, formattedValue, null, condensed );
        }
Esempio n. 12
0
        /// <summary>
        /// Returns the field's current value(s)
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="value">Information about the value</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
        /// <returns></returns>
        public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed)
        {
            string formattedValue = string.Empty;

            if (!string.IsNullOrWhiteSpace(value))
            {
                var guids    = value.SplitDelimitedValues();
                var accounts = new FinancialAccountService().Queryable().Where(a => guids.Contains(a.Guid.ToString()));
                if (accounts.Any())
                {
                    formattedValue = string.Join(", ", (from account in accounts select account.PublicName).ToArray());
                }
            }

            return(base.FormatValue(parentControl, formattedValue, null, condensed));
        }
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection(Type entityType, Control[] controls, string selection)
        {
            string[] selectionValues = selection.Split('|');
            if (selectionValues.Length >= 3)
            {
                var accountPicker   = controls[0] as AccountPicker;
                var dateRangePicker = controls[1] as DateRangePicker;

                dateRangePicker.LowerValue = selectionValues[0].AsDateTime();
                dateRangePicker.UpperValue = selectionValues[1].AsDateTime();

                var accountGuids = selectionValues[2].Split(',').Select(a => a.AsGuid()).ToList();
                var accounts     = new FinancialAccountService(new RockContext()).GetByGuids(accountGuids);
                if (accounts != null && accounts.Any())
                {
                    accountPicker.SetValues(accounts);
                }
            }
        }
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection(Type entityType, Control[] controls)
        {
            var    accountIdList = (controls[0] as AccountPicker).SelectedValuesAsInt().ToList();
            string accountGuids  = string.Empty;
            var    accounts      = new FinancialAccountService(new RockContext()).GetByIds(accountIdList);

            if (accounts != null && accounts.Any())
            {
                accountGuids = accounts.Select(a => a.Guid).ToList().AsDelimited(",");
            }

            SlidingDateRangePicker slidingDateRangePicker = controls[1] as SlidingDateRangePicker;

            // convert pipe to comma delimited
            var delimitedValues = slidingDateRangePicker.DelimitedValues.Replace("|", ",");

            // {1} and {2} used to store the DateRange before, but now we using the SlidingDateRangePicker
            return(string.Format("{0}|{1}|{2}|{3}", string.Empty, string.Empty, accountGuids, delimitedValues));
        }
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection(Type entityType, Control[] controls, string selection)
        {
            SelectionConfig selectionConfig = SelectionConfig.Parse(selection);

            var accountPicker = controls[0] as AccountPicker;
            var accounts      = new FinancialAccountService(new RockContext()).GetByGuids(selectionConfig.AccountGuids);

            if (accounts != null && accounts.Any())
            {
                accountPicker.SetValues(accounts);
            }

            var slidingDateRangePicker = controls[1] as SlidingDateRangePicker;

            slidingDateRangePicker.DelimitedValues = selectionConfig.DelimitedValues;

            var cbUseSundayDate = controls[2] as RockCheckBox;

            cbUseSundayDate.Checked = selectionConfig.UseSundayDate;
        }
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection(Control[] controls)
        {
            string  comparisonType = ((DropDownList)controls[0]).SelectedValue;
            decimal?amount         = (controls[1] as NumberBox).Text.AsDecimal();

            var    accountIdList = (controls[2] as AccountPicker).SelectedValuesAsInt().ToList();
            string accountGuids  = string.Empty;
            var    accounts      = new FinancialAccountService(new RockContext()).GetByIds(accountIdList);

            if (accounts != null && accounts.Any())
            {
                accountGuids = accounts.Select(a => a.Guid).ToList().AsDelimited(",");
            }

            DateRangePicker dateRangePicker = controls[3] as DateRangePicker;

            RockCheckBox cbCombineGiving = controls[4] as RockCheckBox;

            return(string.Format("{0}|{1}|{2}|{3}|{4}|{5}", comparisonType, amount, dateRangePicker.LowerValue, dateRangePicker.UpperValue, accountGuids, cbCombineGiving.Checked));
        }
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection(Control[] controls, string selection)
        {
            string[] selectionValues = selection.Split('|');
            if (selectionValues.Length >= 4)
            {
                var comparisonControl = controls[0] as DropDownList;
                var numberBox         = controls[1] as NumberBox;
                var accountPicker     = controls[2] as AccountPicker;
                var dateRangePicker   = controls[3] as DateRangePicker;
                var cbCombineGiving   = controls[4] as RockCheckBox;

                comparisonControl.SetValue(selectionValues[0]);
                decimal?amount = selectionValues[1].AsDecimal();
                if (amount.HasValue)
                {
                    numberBox.Text = amount.Value.ToString("F2");
                }
                else
                {
                    numberBox.Text = string.Empty;
                }

                dateRangePicker.LowerValue = selectionValues[2].AsDateTime();
                dateRangePicker.UpperValue = selectionValues[3].AsDateTime();

                if (selectionValues.Length >= 5)
                {
                    var accountGuids = selectionValues[4].Split(',').Select(a => a.AsGuid()).ToList();
                    var accounts     = new FinancialAccountService(new RockContext()).GetByGuids(accountGuids);
                    if (accounts != null && accounts.Any())
                    {
                        accountPicker.SetValues(accounts);
                    }
                }

                if (selectionValues.Length >= 6)
                {
                    cbCombineGiving.Checked = selectionValues[5].AsBooleanOrNull() ?? false;
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection(Type entityType, Control[] controls)
        {
            var comparisonControl        = controls[0] as DropDownList;
            var numberBoxAmount          = controls[1] as CurrencyBox;
            var accountPicker            = controls[2] as AccountPicker;
            var cbIncludeChildAccounts   = controls[3] as RockCheckBox;
            var cbIgnoreInactiveAccounts = controls[4] as RockCheckBox;
            var slidingDateRangePicker   = controls[5] as SlidingDateRangePicker;
            var cbCombineGiving          = controls[6] as RockCheckBox;
            var cbUseAnalyticsTables     = controls[7] as RockCheckBox;

            var     comparisonType = comparisonControl.SelectedValue.ConvertToEnum <ComparisonType>();
            decimal?amount         = numberBoxAmount.Text.AsDecimal();

            var         accountIdList = accountPicker.SelectedValuesAsInt().ToList();
            List <Guid> accountGuids;
            var         accounts = new FinancialAccountService(new RockContext()).GetByIds(accountIdList);

            if (accounts != null && accounts.Any())
            {
                accountGuids = accounts.Select(a => a.Guid).ToList();
            }
            else
            {
                accountGuids = null;
            }

            var selectionConfig = new SelectionConfig
            {
                ComparisonType         = comparisonType,
                Amount                 = amount,
                AccountGuids           = accountGuids,
                IncludeChildAccounts   = cbIncludeChildAccounts.Checked,
                IgnoreInactiveAccounts = cbIgnoreInactiveAccounts.Checked,
                CombineGiving          = cbCombineGiving.Checked,
                SlidingDateRangePickerDelimitedValues = slidingDateRangePicker.DelimitedValues,
                UseAnalyticsModels = cbUseAnalyticsTables.Checked,
            };

            return(selectionConfig.ToJson());
        }
Esempio n. 19
0
        /// <summary>
        /// Reads new values entered by the user for the field
        /// </summary>
        /// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <returns></returns>
        public override string GetEditValue(Control control, Dictionary <string, ConfigurationValue> configurationValues)
        {
            var    picker = control as AccountPicker;
            string result = null;

            if (picker != null)
            {
                var guids    = new List <Guid>();
                var ids      = picker.SelectedValuesAsInt();
                var accounts = new FinancialAccountService().Queryable().Where(a => ids.Contains(a.Id));

                if (accounts.Any())
                {
                    guids = accounts.Select(a => a.Guid).ToList();
                }

                result = string.Join(",", guids);
            }

            return(result);
        }
Esempio n. 20
0
        /// <summary>
        /// Reads new values entered by the user for the field
        /// </summary>
        /// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <returns></returns>
        public override string GetEditValue( Control control, Dictionary<string, ConfigurationValue> configurationValues )
        {
            var picker = control as AccountPicker;
            string result = null;

            if ( picker != null )
            {
                var guids = new List<Guid>();
                var ids = picker.SelectedValuesAsInt();
                var accounts = new FinancialAccountService().Queryable().Where( a => ids.Contains( a.Id ) );

                if ( accounts.Any() )
                {
                    guids = accounts.Select( a => a.Guid ).ToList();
                }

                result = string.Join( ",", guids );
            }

            return result;
        }
Esempio n. 21
0
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection(Type entityType, Control[] controls)
        {
            string  comparisonType = (( DropDownList )controls[0]).SelectedValue;
            decimal?amount         = (controls[1] as NumberBox).Text.AsDecimal();

            var    accountIdList = (controls[2] as AccountPicker).SelectedValuesAsInt().ToList();
            string accountGuids  = string.Empty;
            var    accounts      = new FinancialAccountService(new RockContext()).GetByIds(accountIdList);

            if (accounts != null && accounts.Any())
            {
                accountGuids = accounts.Select(a => a.Guid).ToList().AsDelimited(",");
            }

            SlidingDateRangePicker slidingDateRangePicker = controls[3] as SlidingDateRangePicker;

            // convert pipe to comma delimited
            var delimitedValues = slidingDateRangePicker.DelimitedValues.Replace("|", ",");

            RockCheckBox cbCombineGiving = controls[4] as RockCheckBox;

            return(string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}", comparisonType, amount, string.Empty, string.Empty, accountGuids, cbCombineGiving.Checked, delimitedValues));
        }
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression( Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection )
        {
            var rockContext = (RockContext)serviceInstance.Context;

            string[] selectionValues = selection.Split( '|' );
            if ( selectionValues.Length < 3 )
            {
                return null;
            }

            DateTime? startDate = selectionValues[0].AsDateTime();
            DateTime? endDate = selectionValues[1].AsDateTime();
            var accountGuids = selectionValues[2].Split( ',' ).Select( a => a.AsGuid() ).ToList();
            var accountIdList = new FinancialAccountService( (RockContext)serviceInstance.Context ).GetByGuids( accountGuids ).Select( a => a.Id ).ToList();

            int transactionTypeContributionId = Rock.Web.Cache.DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION.AsGuid() ).Id;

            var financialTransactionsQry = new FinancialTransactionService( rockContext ).Queryable()
                .Where( xx => xx.TransactionTypeValueId == transactionTypeContributionId );

            if ( accountIdList.Any() )
            {
                if ( accountIdList.Count == 1 )
                {
                    int accountId = accountIdList.First();
                    financialTransactionsQry = financialTransactionsQry.Where( xx => xx.TransactionDetails.Any( a => a.AccountId == accountId ) );
                }
                else
                {
                    financialTransactionsQry = financialTransactionsQry.Where( xx => xx.TransactionDetails.Any( a => accountIdList.Contains( a.AccountId ) ) );
                }
            }

            var firstContributionDateQry = financialTransactionsQry
                .GroupBy( xx => xx.AuthorizedPersonAlias.PersonId )
                .Select( ss => new
                {
                    PersonId = ss.Key,
                    FirstTransactionDateTime = ss.Min( a => a.TransactionDateTime )
                } );

            if ( startDate.HasValue )
            {
                firstContributionDateQry = firstContributionDateQry.Where( xx => xx.FirstTransactionDateTime >= startDate.Value );
            }

            if ( endDate.HasValue )
            {
                firstContributionDateQry = firstContributionDateQry.Where( xx => xx.FirstTransactionDateTime < endDate );
            }

            var innerQry = firstContributionDateQry.Select( xx => xx.PersonId ).AsQueryable();

            var qry = new PersonService( rockContext ).Queryable()
                .Where( p => innerQry.Any( xx => xx == p.Id ) );

            Expression extractedFilterExpression = FilterExpressionExtractor.Extract<Rock.Model.Person>( qry, parameterExpression, "p" );

            return extractedFilterExpression;
        }
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection( Type entityType, Control[] controls, string selection )
        {
            string[] selectionValues = selection.Split( '|' );
            if ( selectionValues.Length >= 3 )
            {
                var accountPicker = controls[0] as AccountPicker;
                var slidingDateRangePicker = controls[1] as SlidingDateRangePicker;

                if ( selectionValues.Length >= 4 )
                {
                    // convert comma delimited to pipe
                    slidingDateRangePicker.DelimitedValues = selectionValues[3].Replace( ',', '|' );
                }
                else
                {
                    // if converting from a previous version of the selection
                    var lowerValue = selectionValues[0].AsDateTime();
                    var upperValue = selectionValues[1].AsDateTime();

                    slidingDateRangePicker.SlidingDateRangeMode = SlidingDateRangePicker.SlidingDateRangeType.DateRange;
                    slidingDateRangePicker.SetDateRangeModeValue( new DateRange( lowerValue, upperValue ) );
                }

                var accountGuids = selectionValues[2].Split( ',' ).Select( a => a.AsGuid() ).ToList();
                var accounts = new FinancialAccountService( new RockContext() ).GetByGuids( accountGuids );
                if ( accounts != null && accounts.Any() )
                {
                    accountPicker.SetValues( accounts );
                }
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection( Control[] controls )
        {
            string comparisonType = ( (DropDownList)controls[0] ).SelectedValue;
            decimal? amount = ( controls[1] as NumberBox ).Text.AsDecimal();

            var accountIdList = ( controls[2] as AccountPicker ).SelectedValuesAsInt().ToList();
            string accountGuids = string.Empty;
            var accounts = new FinancialAccountService( new RockContext() ).GetByIds( accountIdList );
            if ( accounts != null && accounts.Any() )
            {
                accountGuids = accounts.Select( a => a.Guid ).ToList().AsDelimited( "," );
            }

            SlidingDateRangePicker slidingDateRangePicker = controls[3] as SlidingDateRangePicker;

            // convert pipe to comma delimited
            var delimitedValues = slidingDateRangePicker.DelimitedValues.Replace( "|", "," );

            RockCheckBox cbCombineGiving = controls[4] as RockCheckBox;

            // {2} and {3} used to store the DateRange before, but now we using the SlidingDateRangePicker
            return string.Format( "{0}|{1}|{2}|{3}|{4}|{5}|{6}", comparisonType, amount, string.Empty, string.Empty, accountGuids, cbCombineGiving.Checked, delimitedValues );
        }
Esempio n. 25
0
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection( Control[] controls, string selection )
        {
            string[] selectionValues = selection.Split( '|' );
            if ( selectionValues.Length >= 4 )
            {
                var comparisonControl = controls[0] as DropDownList;
                var numberBox = controls[1] as NumberBox;
                var accountPicker = controls[2] as AccountPicker;
                SlidingDateRangePicker slidingDateRangePicker = controls[3] as SlidingDateRangePicker;
                var cbCombineGiving = controls[4] as RockCheckBox;

                comparisonControl.SetValue( selectionValues[0] );
                decimal? amount = selectionValues[1].AsDecimal();
                if ( amount.HasValue )
                {
                    numberBox.Text = amount.Value.ToString( "F2" );
                }
                else
                {
                    numberBox.Text = string.Empty;
                }

                if ( selectionValues.Length >= 7 )
                {
                    // convert comma delimited to pipe
                    slidingDateRangePicker.DelimitedValues = selectionValues[6].Replace( ',', '|' );
                }
                else
                {
                    // if converting from a previous version of the selection
                    var lowerValue = selectionValues[2].AsDateTime();
                    var upperValue = selectionValues[3].AsDateTime();

                    slidingDateRangePicker.SlidingDateRangeMode = SlidingDateRangePicker.SlidingDateRangeType.DateRange;
                    slidingDateRangePicker.SetDateRangeModeValue( new DateRange( lowerValue, upperValue ) );
                }

                if ( selectionValues.Length >= 5 )
                {
                    var accountGuids = selectionValues[4].Split( ',' ).Select( a => a.AsGuid() ).ToList();
                    var accounts = new FinancialAccountService( new RockContext() ).GetByGuids( accountGuids );
                    if ( accounts != null && accounts.Any() )
                    {
                        accountPicker.SetValues( accounts );
                    }
                }

                if ( selectionValues.Length >= 6 )
                {
                    cbCombineGiving.Checked = selectionValues[5].AsBooleanOrNull() ?? false;
                }
            }
        }
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection( Control[] controls, string selection )
        {
            string[] selectionValues = selection.Split( '|' );
            if ( selectionValues.Length >= 4 )
            {
                var comparisonControl = controls[0] as DropDownList;
                var numberBox = controls[1] as NumberBox;
                var accountPicker = controls[2] as AccountPicker;
                var dateRangePicker = controls[3] as DateRangePicker;
                var cbCombineGiving = controls[4] as RockCheckBox;

                comparisonControl.SetValue( selectionValues[0] );
                decimal? amount = selectionValues[1].AsDecimal();
                if ( amount.HasValue )
                {
                    numberBox.Text = amount.Value.ToString( "F2" );
                }
                else
                {
                    numberBox.Text = string.Empty;
                }

                dateRangePicker.LowerValue = selectionValues[2].AsDateTime();
                dateRangePicker.UpperValue = selectionValues[3].AsDateTime();

                if ( selectionValues.Length >= 5 )
                {
                    var accountGuids = selectionValues[4].Split( ',' ).Select( a => a.AsGuid() ).ToList();
                    var accounts = new FinancialAccountService( new RockContext() ).GetByGuids( accountGuids );
                    if ( accounts != null && accounts.Any() )
                    {
                        accountPicker.SetValues( accounts );
                    }
                }

                if ( selectionValues.Length >= 6 )
                {
                    cbCombineGiving.Checked = selectionValues[5].AsBooleanOrNull() ?? false;
                }
            }
        }
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection( Type entityType, Control[] controls )
        {
            var accountIdList = ( controls[0] as AccountPicker ).SelectedValuesAsInt().ToList();
            string accountGuids = string.Empty;
            var accounts = new FinancialAccountService( new RockContext() ).GetByIds( accountIdList );
            if ( accounts != null && accounts.Any() )
            {
                accountGuids = accounts.Select( a => a.Guid ).ToList().AsDelimited( "," );
            }

            SlidingDateRangePicker slidingDateRangePicker = controls[1] as SlidingDateRangePicker;

            // convert pipe to comma delimited
            var delimitedValues = slidingDateRangePicker.DelimitedValues.Replace( "|", "," );

            // {1} and {2} used to store the DateRange before, but now we using the SlidingDateRangePicker
            return string.Format( "{0}|{1}|{2}|{3}", string.Empty, string.Empty, accountGuids, delimitedValues );
        }
Esempio n. 28
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var rockContext = new RockContext();
            var pledgeService = new FinancialPledgeService( rockContext );
            var sortProperty = gPledges.SortProperty;
            var pledges = pledgeService.Queryable();

            Person person = null;
            if ( TargetPerson != null )
            {
                person = TargetPerson;
            }
            else
            {
                int? personId = gfPledges.GetUserPreference( "Person" ).AsIntegerOrNull();
                if ( personId.HasValue && ppFilterPerson.Visible )
                {
                    person = new PersonService( rockContext ).Get( personId.Value );
                }
            }

            if ( person != null )
            {
                // if a person is specified, get pledges for that person ( and also anybody in their GivingUnit )
                pledges = pledges.Where( p => p.PersonAlias.Person.GivingId == person.GivingId );
            }

            // get the accounts and make sure they still exist by checking the database
            var accountIds = gfPledges.GetUserPreference( "Accounts" ).Split( ',' ).AsIntegerList();
            accountIds = new FinancialAccountService( rockContext ).GetByIds( accountIds ).Select( a => a.Id ).ToList();

            if ( accountIds.Any() && apFilterAccount.Visible )
            {
                pledges = pledges.Where( p => p.AccountId.HasValue && accountIds.Contains( p.AccountId.Value ) );
            }

            // Date Range
            var drp = new DateRangePicker();
            drp.DelimitedValues = gfPledges.GetUserPreference( "Date Range" );
            var filterStartDate = drp.LowerValue ?? DateTime.MinValue;
            var filterEndDate = drp.UpperValue ?? DateTime.MaxValue;

            if (filterEndDate != DateTime.MaxValue)
            {
                filterEndDate = filterEndDate.AddDays( 1 );
            }

            /****
             * Include any pledges whose Start/EndDates overlap with the Filtered Date Range
             *
             * * Pledge1 Range 1/1/2011 - 12/31/2011
             * * Pledge2 Range 1/1/0000 - 1/1/9999
             * * Pledge3 Range 6/1/2011 - 6/1/2012
             *
             * Filter1 Range 1/1/2010 - 1/1/2013
             * * * All Pledges should show
             * Filter1 Range 1/1/2012 - 1/1/2013
             * * * Pledge2 and Pledge3 should show
             * Filter2 Range 5/1/2012 - 5/2/2012
             * * * Pledge2 and Pledge3 should show
             * Filter3 Range 5/1/2012 - 1/1/9999
             * * * Pledge2 and Pledge3 should show
             * Filter4 Range 5/1/2010 - 5/1/2010
             * * * Pledge2 should show
             ***/

            // exclude pledges that start after the filter's end date or end before the filter's start date
            if ( drpDates.Visible )
            {
                pledges = pledges.Where( p => !(p.StartDate > filterEndDate) && !(p.EndDate < filterStartDate) );
            }

            // Last Modified
            drp.DelimitedValues = gfPledges.GetUserPreference( "Last Modified" );
            filterStartDate = drp.LowerValue ?? DateTime.MinValue;
            filterEndDate = drp.UpperValue ?? DateTime.MaxValue;

            if (filterEndDate != DateTime.MaxValue)
            {
                filterEndDate = filterEndDate.AddDays( 1 );
            }

            if ( drpLastModifiedDates.Visible )
            {
                pledges = pledges.Where( p => !(p.ModifiedDateTime >= filterEndDate) && !(p.ModifiedDateTime <= filterStartDate) );
            }

            gPledges.DataSource = sortProperty != null ? pledges.Sort( sortProperty ).ToList() : pledges.OrderBy( p => p.AccountId ).ToList();
            gPledges.DataBind();
        }
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection( Type entityType, Control[] controls )
        {
            var accountIdList = ( controls[0] as AccountPicker ).SelectedValuesAsInt().ToList();
            string accountGuids = string.Empty;
            var accounts = new FinancialAccountService( new RockContext() ).GetByIds( accountIdList );
            if ( accounts != null && accounts.Any() )
            {
                accountGuids = accounts.Select( a => a.Guid ).ToList().AsDelimited( "," );
            }

            DateRangePicker dateRangePicker = controls[1] as DateRangePicker;
            return string.Format( "{0}|{1}|{2}", dateRangePicker.LowerValue, dateRangePicker.UpperValue, accountGuids );
        }
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection( Type entityType, Control[] controls, string selection )
        {
            string[] selectionValues = selection.Split( '|' );
            if ( selectionValues.Length >= 3 )
            {
                var accountPicker = controls[0] as AccountPicker;
                var dateRangePicker = controls[1] as DateRangePicker;

                dateRangePicker.LowerValue = selectionValues[0].AsDateTime();
                dateRangePicker.UpperValue = selectionValues[1].AsDateTime();

                var accountGuids = selectionValues[2].Split( ',' ).Select( a => a.AsGuid() ).ToList();
                var accounts = new FinancialAccountService( new RockContext() ).GetByGuids( accountGuids );
                if ( accounts != null && accounts.Any() )
                {
                    accountPicker.SetValues( accounts );
                }
            }
        }
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection( Control[] controls )
        {
            string comparisonType = ( (DropDownList)controls[0] ).SelectedValue;
            decimal? amount = ( controls[1] as NumberBox ).Text.AsDecimal();

            var accountIdList = ( controls[2] as AccountPicker ).SelectedValuesAsInt().ToList();
            string accountGuids = string.Empty;
            var accounts = new FinancialAccountService( new RockContext() ).GetByIds( accountIdList );
            if ( accounts != null && accounts.Any() )
            {
                accountGuids = accounts.Select( a => a.Guid ).ToList().AsDelimited( "," );
            }

            DateRangePicker dateRangePicker = controls[3] as DateRangePicker;

            RockCheckBox cbCombineGiving = controls[4] as RockCheckBox;

            return string.Format( "{0}|{1}|{2}|{3}|{4}|{5}", comparisonType, amount, dateRangePicker.LowerValue, dateRangePicker.UpperValue, accountGuids, cbCombineGiving.Checked );
        }
Esempio n. 32
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var rockContext   = new RockContext();
            var pledgeService = new FinancialPledgeService(rockContext);
            var sortProperty  = gPledges.SortProperty;
            var pledges       = pledgeService.Queryable();

            Person person = null;

            if (TargetPerson != null)
            {
                person = TargetPerson;
            }
            else
            {
                int?personId = gfPledges.GetUserPreference("Person").AsIntegerOrNull();
                if (personId.HasValue && ppFilterPerson.Visible)
                {
                    person = new PersonService(rockContext).Get(personId.Value);
                }
            }

            if (person != null)
            {
                // if a person is specified, get pledges for that person ( and also anybody in their GivingUnit )
                pledges = pledges.Where(p => p.PersonAlias.Person.GivingId == person.GivingId);
            }

            // Filter by configured limit accounts if specified.
            var accountGuids = GetAttributeValue("Accounts").SplitDelimitedValues().AsGuidList();

            if (accountGuids.Any())
            {
                pledges = pledges.Where(p => accountGuids.Contains(p.Account.Guid));
            }

            // get the accounts and make sure they still exist by checking the database
            var accountIds = gfPledges.GetUserPreference("Accounts").Split(',').AsIntegerList();

            accountIds = new FinancialAccountService(rockContext).GetByIds(accountIds).Select(a => a.Id).ToList();

            if (accountIds.Any() && apFilterAccount.Visible)
            {
                pledges = pledges.Where(p => p.AccountId.HasValue && accountIds.Contains(p.AccountId.Value));
            }

            // Date Range
            DateRange filterDateRange = DateRangePicker.CalculateDateRangeFromDelimitedValues(gfPledges.GetUserPreference("Date Range"));
            var       filterStartDate = filterDateRange.Start ?? DateTime.MinValue;
            var       filterEndDate   = filterDateRange.End ?? DateTime.MaxValue;

            /****
             * Include any pledges whose Start/EndDates overlap with the Filtered Date Range
             *
             * * Pledge1 Range 1/1/2011 - 12/31/2011
             * * Pledge2 Range 1/1/0000 - 1/1/9999
             * * Pledge3 Range 6/1/2011 - 6/1/2012
             *
             * Filter1 Range 1/1/2010 - 1/1/2013
             * * * All Pledges should show
             * Filter1 Range 1/1/2012 - 1/1/2013
             * * * Pledge2 and Pledge3 should show
             * Filter2 Range 5/1/2012 - 5/2/2012
             * * * Pledge2 and Pledge3 should show
             * Filter3 Range 5/1/2012 - 1/1/9999
             * * * Pledge2 and Pledge3 should show
             * Filter4 Range 5/1/2010 - 5/1/2010
             * * * Pledge2 should show
             ***/

            // exclude pledges that start after the filter's end date or end before the filter's start date
            if (drpDates.Visible && (filterDateRange.Start.HasValue || filterDateRange.End.HasValue))
            {
                pledges = pledges.Where(p => !(p.StartDate > filterEndDate) && !(p.EndDate < filterStartDate));
            }

            // Last Modified
            DateRange filterModifiedDateRange = DateRangePicker.CalculateDateRangeFromDelimitedValues(gfPledges.GetUserPreference("Last Modified"));
            var       filterModifiedStartDate = filterModifiedDateRange.Start ?? DateTime.MinValue;
            var       filterModifiedEndDate   = filterModifiedDateRange.End ?? DateTime.MaxValue;

            if (drpLastModifiedDates.Visible && (filterModifiedDateRange.Start.HasValue || filterModifiedDateRange.End.HasValue))
            {
                pledges = pledges.Where(p => !(p.ModifiedDateTime >= filterModifiedEndDate) && !(p.ModifiedDateTime <= filterModifiedStartDate));
            }

            gPledges.DataSource = sortProperty != null?pledges.Sort(sortProperty).ToList() : pledges.OrderBy(p => p.AccountId).ToList();

            gPledges.DataBind();

            var showAccountSummary = this.GetAttributeValue("ShowAccountSummary").AsBoolean();

            if (showAccountSummary || TargetPerson == null)
            {
                pnlSummary.Visible = true;

                var summaryList = pledges
                                  .GroupBy(a => a.AccountId)
                                  .Select(a => new AccountSummaryRow
                {
                    AccountId   = a.Key.Value,
                    TotalAmount = a.Sum(x => x.TotalAmount),
                    Name        = a.Select(p => p.Account.Name).FirstOrDefault(),
                    Order       = a.Select(p => p.Account.Order).FirstOrDefault()
                }).ToList();

                var grandTotalAmount = (summaryList.Count > 0) ? summaryList.Sum(a => a.TotalAmount) : 0;
                lGrandTotal.Text             = grandTotalAmount.FormatAsCurrency();
                rptAccountSummary.DataSource = summaryList.Select(a => new { a.Name, TotalAmount = a.TotalAmount.FormatAsCurrency() }).ToList();
                rptAccountSummary.DataBind();
            }
            else
            {
                pnlSummary.Visible = false;
            }
        }
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection)
        {
            var rockContext = (RockContext)serviceInstance.Context;

            string[] selectionValues = selection.Split('|');
            if (selectionValues.Length < 3)
            {
                return(null);
            }

            DateRange dateRange;

            if (selectionValues.Length >= 4)
            {
                string slidingDelimitedValues = selectionValues[3].Replace(',', '|');
                dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues(slidingDelimitedValues);
            }
            else
            {
                // if converting from a previous version of the selection
                DateTime?startDate = selectionValues[0].AsDateTime();
                DateTime?endDate   = selectionValues[1].AsDateTime();
                dateRange = new DateRange(startDate, endDate);

                if (dateRange.End.HasValue)
                {
                    // the DateRange picker doesn't automatically add a full day to the end date
                    dateRange.End.Value.AddDays(1);
                }
            }

            var accountGuids  = selectionValues[2].Split(',').Select(a => a.AsGuid()).ToList();
            var accountIdList = new FinancialAccountService((RockContext)serviceInstance.Context).GetByGuids(accountGuids).Select(a => a.Id).ToList();

            int transactionTypeContributionId = Rock.Web.Cache.DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION.AsGuid()).Id;

            var financialTransactionsQry = new FinancialTransactionService(rockContext).Queryable()
                                           .Where(xx => xx.TransactionTypeValueId == transactionTypeContributionId);

            if (accountIdList.Any())
            {
                if (accountIdList.Count == 1)
                {
                    int accountId = accountIdList.First();
                    financialTransactionsQry = financialTransactionsQry.Where(xx => xx.TransactionDetails.Any(a => a.AccountId == accountId));
                }
                else
                {
                    financialTransactionsQry = financialTransactionsQry.Where(xx => xx.TransactionDetails.Any(a => accountIdList.Contains(a.AccountId)));
                }
            }

            var firstContributionDateQry = financialTransactionsQry
                                           .GroupBy(xx => xx.AuthorizedPersonAlias.PersonId)
                                           .Select(ss => new
            {
                PersonId = ss.Key,
                FirstTransactionSundayDate = ss.Min(a => a.SundayDate)
            });

            if (dateRange.Start.HasValue)
            {
                firstContributionDateQry = firstContributionDateQry.Where(xx => xx.FirstTransactionSundayDate >= dateRange.Start.Value);
            }

            if (dateRange.End.HasValue)
            {
                firstContributionDateQry = firstContributionDateQry.Where(xx => xx.FirstTransactionSundayDate < dateRange.End.Value);
            }

            var innerQry = firstContributionDateQry.Select(xx => xx.PersonId).AsQueryable();

            var qry = new PersonService(rockContext).Queryable()
                      .Where(p => innerQry.Any(xx => xx == p.Id));

            Expression extractedFilterExpression = FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p");

            return(extractedFilterExpression);
        }
Esempio n. 34
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var rockContext   = new RockContext();
            var pledgeService = new FinancialPledgeService(rockContext);
            var sortProperty  = gPledges.SortProperty;
            var pledges       = pledgeService.Queryable();

            Person person = null;

            if (TargetPerson != null)
            {
                person = TargetPerson;
            }
            else
            {
                int?personId = gfPledges.GetUserPreference("Person").AsIntegerOrNull();
                if (personId.HasValue)
                {
                    person = new PersonService(rockContext).Get(personId.Value);
                }
            }

            if (person != null)
            {
                // if a person is specified, get pledges for that person ( and also anybody in their GivingUnit )
                pledges = pledges.Where(p => p.PersonAlias.Person.GivingId == person.GivingId);
            }

            // get the accounts and make sure they still exist by checking the database
            var accountIds = gfPledges.GetUserPreference("Accounts").Split(',').AsIntegerList();

            accountIds = new FinancialAccountService(rockContext).GetByIds(accountIds).Select(a => a.Id).ToList();

            if (accountIds.Any())
            {
                pledges = pledges.Where(p => p.AccountId.HasValue && accountIds.Contains(p.AccountId.Value));
            }

            // Date Range
            var drp = new DateRangePicker();

            drp.DelimitedValues = gfPledges.GetUserPreference("Date Range");
            var filterStartDate = drp.LowerValue ?? DateTime.MinValue;
            var filterEndDate   = drp.UpperValue ?? DateTime.MaxValue;

            /****
             * Include any pledges whose Start/EndDates overlap with the Filtered Date Range
             *
             * * Pledge1 Range 1/1/2011 - 12/31/2011
             * * Pledge2 Range 1/1/0000 - 1/1/9999
             * * Pledge3 Range 6/1/2011 - 6/1/2012
             *
             * Filter1 Range 1/1/2010 - 1/1/2013
             * * * All Pledges should show
             * Filter1 Range 1/1/2012 - 1/1/2013
             * * * Pledge2 and Pledge3 should show
             * Filter2 Range 5/1/2012 - 5/2/2012
             * * * Pledge2 and Pledge3 should show
             * Filter3 Range 5/1/2012 - 1/1/9999
             * * * Pledge2 and Pledge3 should show
             * Filter4 Range 5/1/2010 - 5/1/2010
             * * * Pledge2 should show
             ***/

            // exclude pledges that start after the filter's end date or end before the filter's start date
            pledges = pledges.Where(p => !(p.StartDate > filterEndDate) && !(p.EndDate < filterStartDate));

            gPledges.DataSource = sortProperty != null?pledges.Sort(sortProperty).ToList() : pledges.OrderBy(p => p.AccountId).ToList();

            gPledges.DataBind();
        }
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression( Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection )
        {
            var rockContext = (RockContext)serviceInstance.Context;

            string[] selectionValues = selection.Split( '|' );
            if ( selectionValues.Length < 3 )
            {
                return null;
            }

            DateRange dateRange;

            if ( selectionValues.Length >= 4 )
            {
                string slidingDelimitedValues = selectionValues[3].Replace( ',', '|' );
                dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues( slidingDelimitedValues );
            }
            else
            {
                // if converting from a previous version of the selection
                DateTime? startDate = selectionValues[0].AsDateTime();
                DateTime? endDate = selectionValues[1].AsDateTime();
                dateRange = new DateRange( startDate, endDate );

                if ( dateRange.End.HasValue )
                {
                    // the DateRange picker doesn't automatically add a full day to the end date
                    dateRange.End.Value.AddDays( 1 );
                }
            }

            var accountGuids = selectionValues[2].Split( ',' ).Select( a => a.AsGuid() ).ToList();
            var accountIdList = new FinancialAccountService( (RockContext)serviceInstance.Context ).GetByGuids( accountGuids ).Select( a => a.Id ).ToList();

            int transactionTypeContributionId = Rock.Web.Cache.DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION.AsGuid() ).Id;

            var financialTransactionsQry = new FinancialTransactionService( rockContext ).Queryable()
                .Where( xx => xx.TransactionTypeValueId == transactionTypeContributionId );

            if ( accountIdList.Any() )
            {
                if ( accountIdList.Count == 1 )
                {
                    int accountId = accountIdList.First();
                    financialTransactionsQry = financialTransactionsQry.Where( xx => xx.TransactionDetails.Any( a => a.AccountId == accountId ) );
                }
                else
                {
                    financialTransactionsQry = financialTransactionsQry.Where( xx => xx.TransactionDetails.Any( a => accountIdList.Contains( a.AccountId ) ) );
                }
            }

            var firstContributionDateQry = financialTransactionsQry
                .GroupBy( xx => xx.AuthorizedPersonAlias.PersonId )
                .Select( ss => new
                {
                    PersonId = ss.Key,
                    FirstTransactionSundayDate = ss.Min( a => a.SundayDate )
                } );

            if ( dateRange.Start.HasValue )
            {
                firstContributionDateQry = firstContributionDateQry.Where( xx => xx.FirstTransactionSundayDate >= dateRange.Start.Value );
            }

            if ( dateRange.End.HasValue )
            {
                firstContributionDateQry = firstContributionDateQry.Where( xx => xx.FirstTransactionSundayDate < dateRange.End.Value );
            }

            var innerQry = firstContributionDateQry.Select( xx => xx.PersonId ).AsQueryable();

            var qry = new PersonService( rockContext ).Queryable()
                .Where( p => innerQry.Any( xx => xx == p.Id ) );

            Expression extractedFilterExpression = FilterExpressionExtractor.Extract<Rock.Model.Person>( qry, parameterExpression, "p" );

            return extractedFilterExpression;
        }