Giving Sources Widget

The Giving Sources widget displays a pie chart showing the sources of giving to one or more funds. Segments within the pie chart indicate what amount of the giving comes from mobile, one-time gifts, recurring gifts, and other. Typically “other” will equate to all gifts not made online, but if your church includes online giving from other sources, those gifts may also be included in the “other” segment.

Online Bundles

The widget identifies online giving by the type bundle it is in. By default, online giving is placed in a bundle of type Online. This is true for online giving transactions done through TouchPoint and also for imported online giving such as Pushpay or Txt2Give. If your church moves these contribution entries to bundles of a different type, the script as is will no longer recognize these contributions as Online. You will need to modify the script to account for the other bundle type(s) that contains online contributions.

The widget utilizes an HTML file, SQL script and Python script as shown below. Since the tasks list is the same for all users, Caching should be set to all users.

Customizing the Giving Sources Widget

For most churches, all the necessary customization can be done by modifying the settings in the opening lines of the Python script. On line 2, enter the desired fund (or comma-separated list of funds) within the single quotes. On line 3, enter the fund name or the designation for the list of funds you entered in line 2. By default, the past 30 days of giving will be analyzed. To change this, modify the number of days on line 4.

If you want the pie chart to show year-to-date giving rather than the past certain number of days, comment out line 11 and remove the comment designator from the beginning of line 12. The finished result for the two lines should look as shown below:

11
12
# Base.MinDate = MaxDate.AddDays(-Days).ToString("d")
Base.MinDate = DateTime(MaxDate.Year, 1, 1).ToString("d") # YTD

With the above change, you may also wish to change the chart label by modifying line 17 of the HTML file. Currently the label is Giving past {{days}} days. You can change it to Giving YTD.

If you need to include other bundle types in the Online group, add them (comma-separated) to the list of bundle types on lines 46 and 52. For example, SearchParameters.BundleTypes = ‘Online,SecureGive’. Separate the bundle types with only a comma; no space after the comma.

HTML Code

Below is the HTML code for the Giving Sources widget. As supplied by TouchPoint, the file name is WidgetGivingSourcesHTML.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<div class="box">
    <div class="box-title hidden-xs">
        <h5>{{WidgetName}}</h5>
    </div>
    <a class="visible-xs-block" id="giving-fc-collapse" data-toggle="collapse" href="#{{WidgetId}}-section" aria-expanded="true" aria-controls="{{WidgetId}}-section">
        <div class="box-title">
            <h5>
                <i class="fa fa-chevron-circle-right"></i>&nbsp;&nbsp;{{WidgetName}}
            </h5>
        </div>
    </a>
    <div class="collapse in" id="{{WidgetId}}-section">
        <div class="box-content center">
            <h4 class="text-center">{{fund}}</h4>
            <div class="chart">
            </div>
            <p class="text-center" style="margin-top:10px;">Giving past {{days}} days</p>
        </div>
    </div>
</div>
<script type="text/javascript">
    var {{WidgetId}} = function() {
        var data = {{{results}}};
        var totalOnline = 0;
        data = Object.values(data).map(function(item) {
            // add up online giving to find the "Other" amount
            if (item.name != 'All') totalOnline += item.results[0].Total;
            return [item.name, item.results[0].Total]
        }).filter(function(item) {
            return item[1] > 0
        });
        // convert All row to Other
        for(var i = 0; i < data.length; i++) {
            if (data[i][0] == 'All') {
                data[i][0] = 'Other';
                data[i][1] -= totalOnline;
                break;
            }
        }
        data = [['Item', 'Dollars']].concat(data);
        data = google.visualization.arrayToDataTable(data);
        var formatter = new google.visualization.NumberFormat({
            prefix: '$',
            fractionDigits: 0
        });
        formatter.format(data, 1);
        var options = {
            pieSliceText: 'percentage',
            legend: {
                position: 'bottom'
            },
            chartArea: {
                left: 0,
                top: 20,
                bottom: 20,
                width: '100%',
                height: '100%'
            }
        };

        var chart = new google.visualization.PieChart(document.querySelector('#{{WidgetId}}-section .chart'));
        chart.draw(data, options);
    }
    // load and register the chart
    google.charts.load("current", {packages:["corechart"]});
    google.charts.setOnLoadCallback({{WidgetId}});
    WidgetCharts.{{WidgetId}} = {{WidgetId}};
</script>

SQL Script

Below is the SQL script for the Giving Sources widget. As supplied by TouchPoint, the file name is WidgetGivingSourcesSQL.

1
2
3
4
select isnull(sum(ContributionAmount),0) as Total, count(*) as Contributions
from ContributionTag ct
join Contribution c on ct.ContributionId = c.ContributionId
where TagName = @Tag

Python Script

Below is the Python script for the Giving Sources widget. As supplied by TouchPoint, the file name is WidgetGivingSourcesPython.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from System import DateTime
FundIds = '1'
FundName = 'General Fund'
Days = 30

# Initialize global data
MaxDate = DateTime.Today
GivingTypesData = model.DynamicData()
Priority = 0
Base = model.DynamicData()
Base.MinDate = MaxDate.AddDays(-Days).ToString("d")
# Base.MinDate = DateTime(MaxDate.Year, 1, 1).ToString("d") # YTD
Base.NonTaxDed = -1  # both tax and non tax
Base.MaxDate = MaxDate.ToString("d")
Base.FundIds = FundIds

def NextPriority():
    global Priority
    Priority += 1
    return Priority

def GetResults(tagName):
    results = q.QuerySql(Data.SQLContent, {'Tag': tagName})
    return results

def CreateTag(fundSet, typeCategory, searchParameters):
    TagName = 'Gt{}-{}'.format(fundSet, typeCategory)
    NamePriority = '{}-{}'.format(TagName, Priority)
    dd = model.DynamicData()
    dd.params = searchParameters
    dd.name = typeCategory
    dd.link = '/ContributionsJsonSearch/{}/{}'.format('GivingTypesData', NamePriority)
    tag = model.CreateContributionTag(TagName, searchParameters)
    dd.results = GetResults(TagName)
    GivingTypesData.AddValue(TagName, dd)

def CreateTags(fundSet):
    RowType = 'Mobile'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.Source = 1  # Mobile
    CreateTag(fundSet, RowType, SearchParameters)
    RowType = 'One Time'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.BundleTypes = 'Online'
    SearchParameters.TransactionDesc = '<>Recurring Giving'
    SearchParameters.Source = 0  # Not Mobile
    CreateTag(fundSet, RowType, SearchParameters)
    RowType = 'Recurring'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.BundleTypes = 'Online'
    SearchParameters.Priority = NextPriority()
    SearchParameters.Source = 0  # Not Mobile
    SearchParameters.TransactionDesc = 'Recurring Giving'
    CreateTag(fundSet, RowType, SearchParameters)
    RowType = 'All'  # row used to determine the non online gifts later
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    CreateTag(fundSet, RowType, SearchParameters)

Priority = 100
CreateTags('MainFund')
Data.days = Days
Data.fund = FundName
Data.results = model.FormatJson(GivingTypesData)
print
model.RenderTemplate(Data.HTMLContent)


Latest Update 05/14/2020

Added this article.

© 2020 TouchPoint Software, LLC.  All rights reserved.