This report dynamically generates mailing labels based on the results from a list. Only the names of people on the list will be included on the mailing label. If both members of a married couple are included on the list, they will print as either "John & Jane Smith" or "John Smith & Jane Doe," based on whether they share the same last name. If two unmarried adults (who are members of the same household) are included, they will show as "John Smith, Jane Doe." In all cases, the primary contact will be listed first, and all names will include a prefix (if set). If only children in a household are included, the household name will be printed instead. This version generates as a table when run as an HTML report, which you can copy and paste into a spreadsheet.
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
<!--
This report dynamically generates mailing labels based on the results from a list.
Only the names of people on the list will be included on the mailing label. If
both members of a married couple are included on the list, they will print as
either "John & Jane Smith" or "John Smith & Jane Doe," based on whether they share
the same last name. If two unmarried adults (who are members of the same
household) are included, they will show as "John Smith, Jane Doe." In all cases,
the primary contact will be listed first, and all names will include a prefix (if
set). If only children in a household are included, the household name will be
printed instead.
This version generates as a table when run as an HTML report, which you can copy
and paste 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">Addressee</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">Location</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 %}
<!-- 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.name_prefix}} {{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.name_prefix}} {{person.first_name}}{% endcapture%}
{% assign addArray = addArray | split: '$' %}
{% assign nameArray = nameArray | concat: addArray %}
{% endif %}
{% endfor %}
{% assign nameString = nameArray | join: ' & ' | append: ' ' | append: household.primary_contact.last_name %}
<!-- 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_prefix}} {{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_prefix}} {{person.name}}{% endcapture%}
{% 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.name_prefix}} {{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_prefix}} {{person.name}}{% endcapture%}
{% assign addArray = person.name_prefix | append: person.name | split: '$' %}
{% assign nameArray = nameArray | concat: addArray %}
{% endif %}
{% endfor %}
{% assign nameString = nameArray | join: ', ' %}
<!-- All other cases -->
{% else %}
{% assign nameString = household.name %}
{% endif %}
<!-- Generate Table -->
<tr class="household">
<td>{{ nameString }}</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>{{ household.primary_address.location }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
</html>