/// <summary> /// Shows the detail. /// </summary> private void ShowDetail() { pnlNoGiving.Visible = false; pnlGiving.Visible = false; pnlInactiveGiver.Visible = false; var contributionType = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION.AsGuid()); if (contributionType == null) { return; } Person.LoadAttributes(); var rockContext = new RockContext(); var financialTransactionService = new FinancialTransactionService(rockContext); var givingId = Person.GivingId; var threeYearsAgo = RockDateTime.Now.AddMonths(-35).StartOfMonth(); List <MonthlyAccountGivingHistory> threeYearsOfMonthlyAccountGiving = financialTransactionService.GetGivingAutomationMonthlyAccountGivingHistory(givingId, threeYearsAgo); if (threeYearsOfMonthlyAccountGiving.Any()) { var inactiveGiverCutOffDate = RockDateTime.Now.AddDays(-GetAttributeValue(AttributeKey.InactiveGiverCutoff).AsInteger()).Date; pnlGiving.Visible = true; var hasGiftsAfterCutoff = threeYearsOfMonthlyAccountGiving .Any(h => h.Amount > 0 && ( h.Year >= inactiveGiverCutOffDate.Year || (h.Year == inactiveGiverCutOffDate.Year && h.Month >= inactiveGiverCutOffDate.Month) )); if (!hasGiftsAfterCutoff) { var lastGaveObject = threeYearsOfMonthlyAccountGiving.FirstOrDefault(h => h.Amount > 0); var lastGaveDate = lastGaveObject != null ? ( DateTime? )new DateTime(lastGaveObject.Year, lastGaveObject.Month, 1) : null; pnlInactiveGiver.Visible = true; pnlGivingStats.AddCssClass("inactive-giving"); lLastGiver.Text = lastGaveDate.HasValue ? lastGaveDate.Value.ToString("MMM yyyy") : string.Empty; } } else { pnlNoGiving.Visible = true; return; } var contributionByMonths = new Dictionary <DateTime, decimal>(); for (var i = 35; i >= 0; i--) { var currentMonthlyDate = RockDateTime.Now.StartOfMonth().AddMonths(-i); var month = currentMonthlyDate.Month; var year = currentMonthlyDate.Year; var total = threeYearsOfMonthlyAccountGiving.Where(h => h.Year == year && h.Month == month).Sum(h => h.Amount); contributionByMonths[currentMonthlyDate] = total; } MaxGiftAmount = contributionByMonths.Max(a => a.Value); // Giving By Month Chart rptGivingByMonth.DataSource = contributionByMonths.OrderBy(a => a.Key); rptGivingByMonth.DataBind(); // Community View ShowCommunityView(); ShowGivingStatsForLast12Months(); ShowGivingCharacteristicsKPI(rockContext); ShowMessageIfStale(); BindYearlySummary(); var eraFirstGave = Person.GetAttributeValue("core_EraFirstGave").AsDateTime(); bdgFirstGift.Text = $"First Gift: {eraFirstGave.ToElapsedString()}"; bdgFirstGift.ToolTip = eraFirstGave.ToShortDateString(); var eraLastGive = Person.GetAttributeValue("core_EraLastGave").AsDateTime(); bdgLastGift.Text = $"Last Gift: {eraLastGive.ToElapsedString()}"; bdgLastGift.ToolTip = eraLastGive.ToShortDateString(); ShowGivingAlerts(); }