CASE: create overview of accounts with the account collection (hashtag)

In this case, we will demonstrate how you, as an user, are able to select a certain range of accounts and display them with certain values from the accounts-drop (the accounts-drop stores information like debet_value, opening_value, name, number, value, … ).

We want to create a hashtag that lets us select certain accounts from a range of accounts. It’s the attribute account_collection that let’s us do this:

{% input custom.range.accounts as:account_collection %}

which will create a hashtag:
45

However, you’ll not be able to choose certain accounts just yet:
06

We’ll need to define in our statement which range of accounts need to be selectable, which can be done by adding the filter range :

{% input custom.range.accounts as:account_collection range:"61" %} 

Now, all 61-accounts that have a value, will be selectable:
00

You can even add a default to it, if you want a certain range of accounts already been selected:

{% input custom.range.accounts as:account_collection range:"61" default:"610,611,612" accounts_var:costs %}

Now, the default is already selected, but you can still change it:
19

The purpose of it, is to loop over all these selected accounts and show information of these in a nice table. So, we are going to create a so-called accounts_var, which will take all those selected accounts and add them to a certain collection. That collection, named something you can choose with the accounts_var attribute, will have all information of the accounts-drop!

{% input custom.range.accounts_x as:account_collection range:"61" default:"610,611,612" accounts_var:costs %} 

The collection (or accounts variable - short for accounts_var) is called costs. In that collection we can loop over all it has stored of accounts.

Let’s build the table first:

{% stripnewlines %}
| Account
| Value
{% newline %}
|----80%----
|----20%----:+
{% endstripnewlines %}

which will give this lay-out:

Now, we need to add our forloop in it. Each loop ( = account ) should be a newline in our table:

{% stripnewlines %}
| Account
| Value
{% newline %}
|----80%----
|----20%----:+
  {% for acc in costs %}
    {% newline %}
      | {{ acc.link }}
      | {{ acc.value | currency }}
  {% endfor %}
{% endstripnewlines %} 

which will present this:

However, my table header is fixed and will even be printed even if there are no accounts in my collection. So, we’ll add some logic to our code and will say that the table header only may be executed in the first loop with the {% if forloop.first %} … {% endif %} statement. And that can only be done if there’s a first loop. In other words, if there’s at least one account!

We’ll put the table header inside the forloop and put the if forloop.first logic around it:

{% stripnewlines %}
{% for acc in costs %}
{% if forloop.first %}
| Account
| Value
{% newline %}
|----80%----
|----20%----:+
{% endif %}  
    {% newline %}
      | {{ acc.link }}
      | {{ acc.value | currency }}
{% endfor %}
{% endstripnewlines %}

It won’t change anything unless you deselect all accounts through the hashtag and the table header will be gone. If you select at least one account, it will show.

This is purely done to make sure in an export an empty table is not shown.

A final tweaking of our code: let’s add the total of those accounts in a nice top border table.
Like the forloop.first statement, we could add quite the opposite to display a last line in our table (if there’s at least one account) with the {% if forloop.last %} … {% endif %} statement. This statement means the code will only be executed in the last loop:

{% stripnewlines %}
{% for acc in costs %}
{% if forloop.first %}
| Account
| Value
{% newline %}
|----80%----
|----20%----:+
{% endif %}  
    {% newline %}
      | {{ acc.link }}
      | {{ acc.value | currency }}
    {% if forloop.last %}
      {% newline %}
        |
        |_^ {{ costs.value | currency }}  ^_|
    {% endif %}  
{% endfor %}
{% endstripnewlines %} 

To display the value of our collection costs, you can add the method .value to it, so it’ll print the end-value:

{{ costs.value | currency }} 

You can do that with any custom collection that’s “filled” with the accounts-drop.

Here’s the complete code of the case:

{% input custom.range.accounts as:account_collection range:"61" default:"610,611,612" accounts_var:costs %}

{% stripnewlines %}
{% for acc in costs %}
{% if forloop.first %}
{% newline %}
| Account
| Value
{% newline %}
|----80%----
|----20%----:+
{% endif %}
  {% newline %}
    | {{ acc.link }}
    | {{ acc.value | currency }}
  {% if forloop.last %}
    {% newline %}
    |
    |_^ {{ costs.value | currency }}  ^_|
  {% endif %}  
{% endfor %}
{% endstripnewlines %}

Preview: