/// <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> /// Binds the yearly summary. /// </summary> private void BindYearlySummary() { var givingId = Person.GivingId; using (var rockContext = new RockContext()) { DateTime?startDate; if (!IsYearlySummaryExpanded) { // Only show this current year and last year startDate = RockDateTime.Now.StartOfYear().AddYears(-1); } else { startDate = null; } var monthlyAccountGivingHistoryList = new FinancialTransactionService(rockContext).GetGivingAutomationMonthlyAccountGivingHistory(givingId, startDate); var financialAccounts = new FinancialAccountService(rockContext).Queryable() .AsNoTracking() .ToDictionary(k => k.Id, v => v.Name); var summaryList = monthlyAccountGivingHistoryList .GroupBy(a => new { a.Year, a.AccountId }) .Select(t => new SummaryRecord { Year = t.Key.Year, AccountId = t.Key.AccountId, TotalAmount = t.Sum(d => d.Amount) }) .OrderByDescending(a => a.Year) .ToList(); var contributionSummaries = new List <ContributionSummary>(); foreach (var item in summaryList.GroupBy(a => a.Year)) { var contributionSummary = new ContributionSummary(); contributionSummary.Year = item.Key; contributionSummary.SummaryRecords = new List <SummaryRecord>(); foreach (var a in item) { a.AccountName = financialAccounts.ContainsKey(a.AccountId) ? financialAccounts[a.AccountId] : string.Empty; contributionSummary.SummaryRecords.Add(a); } contributionSummary.TotalAmount = item.Sum(a => a.TotalAmount); contributionSummaries.Add(contributionSummary); } rptYearSummary.DataSource = contributionSummaries; rptYearSummary.DataBind(); // Show the correct button to expand or collapse lbShowLessYearlySummary.Visible = IsYearlySummaryExpanded; lbShowMoreYearlySummary.Visible = !IsYearlySummaryExpanded; } }
/// <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")); }
/// <summary> /// Handles the Click event of the control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnPrint_Click(object sender, EventArgs e) { var keys = new List <int>(); var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(RockPage); var rockContext = new RockContext(); var formattedTemplate = GetAttributeValue("FormattedTemplate"); if (gPayments.SelectedKeys.Count > 0) { keys = gPayments.SelectedKeys.Cast <int>().ToList(); } else { gPayments.AllowPaging = false; BindPaymentsGrid(); gPayments.AllowPaging = true; foreach (DataKey k in gPayments.DataKeys) { keys.Add(( int )k.Value); } } int instanceId = PageParameter("RegistrationInstanceId").AsInteger(); mergeFields.Add("RegistrationInstance", new RegistrationInstanceService(rockContext).Get(instanceId)); var transactions = new FinancialTransactionService(rockContext) .Queryable() .Where(t => keys.Contains(t.Id)) .OrderBy(t => t.TransactionDateTime) .ToList(); mergeFields.Add("Transactions", transactions); var currencyTypes = transactions .GroupBy(t => t.FinancialPaymentDetail.CurrencyAndCreditCardType) .Select(g => new { Title = g.Key, Amount = g.Sum(t => t.TotalAmount) }) .ToList(); mergeFields.Add("CurrencyTypes", currencyTypes); mergeFields.Add("Total", transactions.Sum(t => t.TotalAmount)); ltFormattedOutput.Text = formattedTemplate.ResolveMergeFields(mergeFields); pnlDetails.Visible = false; pnlPrint.Visible = true; }
/// <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); }