GivingTypesData Python Script

To install this script, copy all of the code below. Create a new Python document in Special Content using the name GivingTypes. Then paste the code into editor and save.

  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
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#Roles=Finance

from System import DateTime

# Initialize global data
MaxDate = DateTime.Today
NameOfChurch = model.Setting("NameOfChurch")
GivingTypesData = model.DynamicData() 
GivingTypesData.Created = DateTime.Now
ValidationReportList = []
Priority = 0

Base = model.DynamicData()
Base.MinDate = MaxDate.AddDays(-365).ToString("d")
Base.MaxDate = MaxDate
if NameOfChurch == "Mount Pisgah UMC":
    pass # negative amounts are OK
else:
    Base.FromAmount = 0 # no negative amounts

def CreateDateRangeTags():
    SearchParameters = model.DynamicData()
    SearchParameters.NonTaxDed = -1 # both tax and non tax
    SearchParameters.MaxDate = MaxDate.ToString("d")

    SearchParameters.MinDate = DateTime(MaxDate.Year, 1, 1).ToString("d")
    model.CreateContributionTag('GtrYtd', SearchParameters)

    SearchParameters.MinDate = MaxDate.AddDays(-30).ToString("d")
    model.CreateContributionTag('Gtr30', SearchParameters)

    SearchParameters.MinDate = MaxDate.AddDays(-365).ToString("d")
    model.CreateContributionTag('Gtr365', SearchParameters)

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

def CreateTag(fundSet, typeCategory, searchParameters):
    TagName = 'Gt{}-{}'.format(fundSet, typeCategory)
    NamePriority = '{}-{}'.format(TagName, Priority)
    dd = model.DynamicData()
    dd.parms = searchParameters
    dd.link = '/ContributionsJsonSearch/{}/{}'.format('GivingTypesData', NamePriority)
    GivingTypesData.AddValue(NamePriority, dd)
    ValidationReportList.append('<h4><a href="{}" target="validate">{}</a></h4>'.format(dd.link, NamePriority))
    ValidationReportList.append('<pre>{}</pre>'.format(model.CreateContributionTag(TagName, searchParameters)))

def CreateTags(fundSet):
    RowType = 'Mobile' 
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.Source = 1
    CreateTag(fundSet, RowType, SearchParameters)

    RowType = 'MissionTrip'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.ContributionDesc = '%MissionTrip: org%'
    CreateTag(fundSet, RowType, SearchParameters)

    # church specific
    RowType = 'MissionTrip'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.AddToTag = 1
    SearchParameters.BundleTypes = ['Mission Trip Transaction']
    CreateTag(fundSet, RowType, SearchParameters)

    RowType = 'Online'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.Source = 1
    SearchParameters.TransactionDesc = 'Online Giving'
    CreateTag(fundSet, RowType, SearchParameters)

    RowType = 'Online'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.AddToTag = 1
    SearchParameters.Priority = NextPriority()
    SearchParameters.Source = 0
    SearchParameters.BundleTypes = ['Online']
    SearchParameters.TransactionDesc = '<>Recurring Giving'
    CreateTag(fundSet, RowType, SearchParameters)

    # church specific
    RowType = 'Online'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.AddToTag = 1
    SearchParameters.Priority = NextPriority()
    SearchParameters.BundleTypes = ['Manual Credit Cards','Payroll Deductions']
    CreateTag(fundSet, RowType, SearchParameters)

    RowType = 'Recurring'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.TransactionDesc = ['Recurring Giving']
    CreateTag(fundSet, RowType, SearchParameters)

    RowType = 'SundayMainWorship'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.BundleTypes = ['Generic Envelopes','Loose Checks and Cash','Preprinted Envelopes']
    CreateTag(fundSet, RowType, SearchParameters)

    # church specific
    RowType = 'SundayMainWorship'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.AddToTag = 1
    SearchParameters.Priority = NextPriority()
    SearchParameters.BundleTypes = ['Sunday Main Worship']
    CreateTag(fundSet, RowType, SearchParameters)

    # church specific
    RowType = 'MailedChecksAndCash'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.BundleTypes = ['Mailed Checks & Cash']
    CreateTag(fundSet, RowType, SearchParameters)

    # church specific
    RowType = 'BankDrafts'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.BundleTypes = ['Bank Draft','Bank Drafts']
    CreateTag(fundSet, RowType, SearchParameters)

    # church specific
    RowType = 'SecureGive'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.BundleTypes = ['SecureGive']
    CreateTag(fundSet, RowType, SearchParameters)

    # church specific
    RowType = 'Stock'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.BundleTypes = ['Stock']
    CreateTag(fundSet, RowType, SearchParameters)

    # church specific
    RowType = 'Students'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.BundleTypes = ['Students']
    CreateTag(fundSet, RowType, SearchParameters)

    # church specific
    RowType = 'Hispanic'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.BundleTypes = ['Hispanic']
    CreateTag(fundSet, RowType, SearchParameters)

    RowType = 'NonTaxDeductible'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.NonTaxDed = 1
    CreateTag(fundSet, RowType, SearchParameters)

    RowType = 'Unknown'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = NextPriority()
    SearchParameters.NonTaxDed = -1
    SearchParameters.ContributionTags = "<>Gt{}-%".format(fundSet)
    CreateTag(fundSet, RowType, SearchParameters)

    RowType = 'Total'
    SearchParameters = model.DynamicData(Base)
    SearchParameters.Priority = Priority / 100 * 100 + 99 # 199, 299, 399, etc.
    SearchParameters.NonTaxDed = -1 # either tax or non-tax
    CreateTag(fundSet, RowType, SearchParameters)

def CreateFundSetColumns():
    global Priority
    nc = NameOfChurch
    if NameOfChurch == 'Mount Pisgah UMC':
        Priority = 100
        allFunds = model.CustomStatementsFundIdList('Mount Pisgah Church') # all funds for church
        Base.FundIds = allFunds
        CreateTags('AllFunds')

        Priority=200
        Base.FundIds = '180' # Main Giving Fund
        CreateTags('MainFund')

        # Fund Others, all funds except the main giving fund
        Priority=300
        Base.FundIds = allFunds.replace('180,', '') #remove fund 180
        CreateTags('Other')
    else:
        Priority = 100 # fundSet1
        # All funds included in first fundSet
        CreateTags('AllFunds')

        # Fund 1 (General Tithe), this highlights the main giving fund in a fundSet
        Priority=200 # fundSet2
        Base.FundIds = '1'
        CreateTags('MainFund')

        # Fund Others, all funds except the main giving fund in a fundSet
        Priority=300 # fundSet3
        Base.FundIds = '<>1'
        CreateTags('Other')

model.DeleteContributionTags('Gt%')

CreateDateRangeTags()
CreateFundSetColumns()

json = model.FormatJson(GivingTypesData)
model.WriteContentText('GivingTypesData', json) 

html = '\n'.join(ValidationReportList)
print html


# the following is only used in development 
#runfrom=C:/dev/bvcmsdocs/source/CustomProgramming/Python/Scripts/Giving/Types/Files/Content/GivingTypesData.py