Household Dynamic Mailing Labels - Avery 5160
Imports: 3

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


<!-- 

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>