Prints a household as a single row in HTML output, per the requirements for submitting a membership roster to Universal Church Directories (and maybe others).
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<!--
This report is based on "Household Dynamic Mailing Labels - Table (Run as HTML)"
by Devin Wipperman (https://pcochef.com/recipes/7ZKBM8y). It prints household members on a single row in the
HTML output, per the requirements for submitting a membership roster to
Universal Church Directories (and maybe others).
Using the original's core logic, only the names of people on the list passed into
the report are included. If both members of a married couple are included in the list,
the "first name" field generates as "John & Jane" or "John Smith & Jane Doe" depending
on whether they share a last name. Two unmarried adults (of the same household) are included
similarly. Children of the household are listed as a single field, comma-separated.
UCDirectories allows home, cell-1 (presumably primary member) and cell-2 (second adult) for phone
numbers; emails are similarly email-1 (primary member) and email-2 (second adult). All additional
data in the household are discarded, as UCDirectories doesn't recognize them for their roster.
The report generates as a table when run as an HTML report, suitable for copy-and-pasting
into a spreadsheet.
-->
<html lang="en">
<head>
<meta charset="utf-8">
<link href="https://unpkg.com/bootstrap@4.3.1/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://unpkg.com/bootstrap-table@1.15.5/dist/bootstrap-table.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<style>
#toolbar { margin: 0; }
tr.household > td {
padding: 0.25em; }
tr:nth-child(even) { background-color: #edf2f7; }
thead {
border-bottom: 1px solid #bec9d3; }
th { padding: .5em; }
.avatar {
width: 50px;
height: 50px;
border-radius: 25px 25px 25px 25px;
-moz-border-radius: 25px 25px 25px 25px;
-webkit-border-radius: 25px 25px 25px 25px;
}
.container {
width: 100%;
padding-top: 15px;
}
</style>
</head>
<body>
<div class="container">
<h2>
{{ list.name }}
<br>
<small>
{{ organization.name }}
</small>
</h2>
<div class="clearfix"></div>
<table id="table" style="width: 100%"<thead>
<tr>
<th style="text-align: left">LastName</th>
<th style="text-align: left">First(adult)</th>
<th style="text-align: left">Children</th>
<th style="text-align: left">Street 1</th>
<th style="text-align: left">Street 2</th>
<th style="text-align: left">City</th>
<th style="text-align: left">State</th>
<th style="text-align: left">Zip</th>
<th style="text-align: left">Home Phone</th>
<th style="text-align: left">Cell-Phone1</th>
<th style="text-align: left">Cell-Phone2</th>
<th style="text-align: left">Email1</th>
<th style="text-align: left">Email2</th>
</tr>
</thead>
<tbody>
<!-- Add IDs of all people on list to array -->
{% assign inclusionArray = '' | split: '$' %}
{% for person in people %}
{% assign addArray = person.id | split: '$' %}
{% assign inclusionArray = inclusionArray | concat: addArray %}
{% endfor %}
{% for household in households %}
{% assign lastNameArray = '' | split: '$' %}
{% assign marriedAdults = 0 %}
{% assign includedAdults = 0 %}
{% assign sameLast = false %}
{% assign homePhone = '' %}
{% assign cellPrimary = '' %}
{% assign cellSecondary = '' %}
{% assign emailPrimary = '' %}
{% assign emailSecondary = '' %}
<!-- Count number of married adults, and total adults on the list in this household -->
{% for person in household.adults %}
<!-- Convert Person ID from number to string -->
{% assign personID = person.id | downcase %}
{% if inclusionArray contains personID %}
{% assign includedAdults = includedAdults | plus: 1 %}
{% if person.marital_status == 'Married' %}
{% assign marriedAdults = marriedAdults | plus: 1 %}
{% endif %}
<!-- Add last names to array -->
{% if person.marital_status == 'Married' %}
{% assign addArray = person.last_name | split: '$' %}
{% assign lastNameArray = lastNameArray | concat: addArray %}
{% endif %}
{% endif %}
{% endfor %}
<!-- Filter for unique last names -->
{% assign lastNameArray = lastNameArray | uniq %}
<!-- Generate addressee string using included people -->
{% assign nameArray = '' | split: '$' %}
{% assign nameString = '' | split: '$' %}
<!-- Children Only -->
{% if includedAdults == 0 %}
{% assign nameString = household.name %}
<!-- Married couple, same name -->
{% elsif lastNameArray.size == 1 and marriedAdults > 1 %}
{% for person in household.adults %}
{% assign personID = person.id | downcase %}
{% if inclusionArray contains personID and household.primary_contact.id == person.id %}
{% capture addArray %}{{person.first_name}}{% endcapture%}
{% assign addArray = addArray | split: '$' %}
{% assign nameArray = nameArray | concat: addArray %}
{% endif %}
{% endfor %}
{% for person in household.adults %}
{% assign personID = person.id | downcase %}
{% if inclusionArray contains personID and household.primary_contact.id != person.id %}
{% capture addArray %}{{person.first_name}}{% endcapture%}
{% assign addArray = addArray | split: '$' %}
{% assign nameArray = nameArray | concat: addArray %}
{% endif %}
{% endfor %}
{% assign nameString = nameArray | join: ' & ' %}
<!-- Married couple, different names -->
{% elsif lastNameArray.size > 1 and marriedAdults > 1 %}
{% for person in household.adults %}
{% assign personID = person.id | downcase %}
{% if inclusionArray contains personID and household.primary_contact.id == person.id %}
{% capture addArray %}{{person.name}}{% endcapture%}
{% assign addArray = addArray | split: '$' %}
{% assign nameArray = nameArray | concat: addArray %}
{% endif %}
{% endfor %}
{% for person in household.adults %}
{% assign personID = person.id | downcase %}
{% if inclusionArray contains personID and household.primary_contact.id != person.id %}
{% capture addArray %}{{person.name}}{% endcapture%}
{% assign addArray = addArray | split: '$' %}
<!-- assign addArray = person.name_prefix | append: person.name | split: '$' %} -->
{% assign nameArray = nameArray | concat: addArray %}
{% endif %}
{% endfor %}
{% assign nameString = nameArray | join: ' & ' %}
<!-- Single or unmarried adults -->
{% elsif marriedAdults <= 2 %}
{% for person in household.adults %}
{% assign personID = person.id | downcase %}
{% if inclusionArray contains personID and household.primary_contact.id == person.id %}
{% capture addArray %}{{person.first_name}}{% endcapture%}
{% assign addArray = addArray | split: '$' %}
{% assign nameArray = nameArray | concat: addArray %}
{% endif %}
{% endfor %}
{% for person in household.adults %}
{% assign personID = person.id | downcase %}
{% if inclusionArray contains personID and household.primary_contact.id != person.id %}
{% capture addArray %}{{person.first_name}}{% endcapture %}
{% assign addArray = addArray | split: '$' %}
{% assign nameArray = nameArray | concat: addArray %}
{% endif %}
{% endfor %}
{% assign nameString = nameArray | join: ' & ' %}
<!-- All other cases -->
{% else %}
{% assign nameString = household.name %}
{% endif %}
<!-- Generate list of children, separated by commas -->
{% assign childrenArray = '' | split: '$' %}
{% assign childrenString = '' | split: '$' %}
{% for child in household.active_children %}
{% assign addArray = child.first_name | split: '$' %}
{% assign childrenArray = childrenArray | concat: addArray %}
{% endfor %}
{% assign childrenString = childrenArray | join: ", " %}
<!-- Grab email and cell phone numbers -->
{% for person in household.adults %}
{% assign personID = person.id | downcase %}
<!-- Processing phone numbers for 'Mobile', add to either cellPrimary or cellSecondary -->
{% if inclusionArray contains personID and household.primary_contact.id == person.id %}
{% for phonenum in person.phone_numbers %}
{% if phonenum.location == "Mobile" %}
{% assign cellPrimary = phonenum.number | split: '$' %}
{% endif %}
<!-- Home phone should be true for whole family -->
{% if phonenum.location == "Home" %}
{% assign homePhone = phonenum.number | split: '$' %}
{%endif%}
{% endfor %}
<!-- Grab email for Primary contact -->
{% assign emailPrimary = person.primary_email | split: '$' %}
{% elsif inclusionArray contains personID and household.primary_contact.id != person.id %}
{% for phonenum in person.phone_numbers %}
{% if phonenum.location == "Mobile" %}
{% assign cellSecondary = phonenum.number | split: '$' %}
{% endif %}
{% endfor %}
{% assign emailSecondary = person.primary_email | split: '$' %}
{% endif %}
{% endfor %}
<!-- Pull "household" string out of household name -->
{% assign householdNameArray = household.name | split: " "%}
<!-- Generate Table -->
<tr class="household">
<td>{{ householdNameArray[0] }}</td>
<td>{{ nameString }}</td>
<td>{{ childrenString }}</td>
<td>{{ household.primary_address.street_line_1 }}</td>
<td>{{ household.primary_address.street_line_2 }}</td>
<td>{{ household.primary_address.city }}</td>
<td>{{ household.primary_address.state }}</td>
<td>{{ household.primary_address.zip }}</td>
<td>{{ homePhone }}</td>
<td>{{ cellPrimary] }}</td>
<td>{{ cellSecondary }}</td>
<td>{{ emailPrimary }}</td>
<td>{{ emailSecondary }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
</html>