Household Dynamic Mailing Labels - Avery 5160
Imports: 44

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 on 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.

Preview

Report Preview


  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
<!-- 

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.

-->
<html>
  <head>
    <title>Avery Labels</title>
    <style>
      @page { margin: 0.5in 0in 0in 0.0825in; size: US-Letter; }
      ul { margin: 0 0 0 0.1in; padding: 0; }
      ul.labels li {
        margin: 0 0.14in 0 0;
        padding: 0;
        float: left;
        width: 2.625in;
        height: 1in;
        display: block;
        font-family: "Lato", Arial, Helvetica, sans-serif;
        font-size: 11pt;
      }
      ul.labels li div.address {
        margin-left: 0.125in;
        margin-top: 0.1in;
      }
    </style>
  </head>
  <body>
    <ul class="labels">
      
      <!-- 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 labels -->
        <li>
          <div class="address">
            {{ nameString }}<br />
            {{ household.primary_address.postal_address }}
          </div>
        </li>
      
      {% endfor %}

    </ul>
  </body>
</html>