Let’s take this case:
and say we want an option to display the same reconciliation from the previous year as well.
If you create your details into a custom collection, you can call upon these details by this code:
period.minus_1y.reconciliations.name_handle.custom.collection
where
period.minus_1y
is looking into not the current period, but the period one year back (so period.minus_1p works the same, 1 period back that is)
reconciliations
is telling Silverfin to look at the reconciliation templates
name_handle
is telling Silverfin which template exactly to take (a handle of a reconciliation template is unique for each reconciliation template)
custom.collection
is the name of the custom collection.
You can build in an info-tag that checks if the previous year exists as well, by following code:
{% comment %}create info tag with check only if there's a previous year{% endcomment %}
{% stripnewlines %}
{% if period.minus_1y.exists %}
{% ic %}
{::infotext as="hover"}
{% t "Check to display the reconciliation of previous year (will also be exported in PDF!)" %}
{:/infotext}
{% endic %}
{% input custom.show.prev_year as:boolean %}
{% endif %}
{% endstripnewlines %}
{% if custom.show.prev_year == "true" %}
{% assign show_prev = true %}
{% endif %}
We use the {% if period.minus_1y.exists %}
statement in order to display the option (boolean) to check whether or not the details of previous year have to be printed or not (if there’s no previous year, no need to display this information!).
To display the details of previous year, the whole custom collection needs to be rebuild:
{% if show_prev %}
{% comment %}re-create the fori-loop of last year as a for-loop, calling on the custom collection of last year!{% endcomment %}
{% stripnewlines %}
{% for item in period.minus_1y.reconciliations.stock_cars.custom.items %}
{% assign name_p = item.name | downcase | capitalize %}
{% capture current_total_p %}total_{{ name_p }}_p{% endcapture %}
{% assign [current_total_p] = [current_total_p]+item.value %}
{% assign items_array_p = items_array_p | append:name_p | append:";" %}
{% endfor %}
{% endstripnewlines %}
{% assign items_array_p = items_array_p | split:";" | uniq %}
<br />
{% stripnewlines %}
| Group last year
| Value last year
{% newline %}
|----70%----
|----30%----#+
{% for item in items_array_p %}
{% newline %}
{% capture current_total_p %}total_{{ item }}_p{% endcapture %}
| {{ item }} | {{ [current_total_p] | currency }}
{% endfor %}
{% endstripnewlines %}
{% endif %}
Be aware that in this case, we should name our variables (the ones we use to calculate for each group) differently, so that the details don’t get added to the same variables we use for the current year!
{% for item in period.minus_1y.reconciliations.stock_cars.custom.items %}
rebuilding the forloop ...
{% endfor %}
So you can always call on details that were made as database variables, meaning that info actually has been inputted into the database of your client file. Database variables usually have a custom
in their name.
There’s no need to take those into a result tag for instance; this cannot be done! More info here:
Here’s the whole code:
{% stripnewlines %}
| Name
| Value
{% newline %}
|----70%----
|----30%----#+
{% newline %}
{% fori item in custom.items %}
| {% input item.name %}
| {% input item.value as:currency %}
{% assign name = item.name | downcase | capitalize %}
{% capture current_total %}total_{{ name }}{% endcapture %}
{% assign [current_total] = [current_total]+item.value %}
{% assign items_array = items_array | append:name | append:";" %}
{% newline %}
{% endfori %}
{% endstripnewlines %}
{% assign items_array = items_array | split:";" | uniq %}
<br />
{% stripnewlines %}
| Group
| Value
{% newline %}
|----70%----
|----30%----#+
{% for item in items_array %}
{% newline %}
{% capture current_total %}total_{{ item }}{% endcapture %}
| {{ item }} | {{ [current_total] | currency }}
{% endfor %}
{% endstripnewlines %}
<br />
{% comment %}create info tag with check only if there's a previous year{% endcomment %}
{% stripnewlines %}
{% if period.minus_1y.exists %}
{% ic %}
{::infotext as="hover"}
{% t "Check to display the reconciliation of previous year (will also be exported in PDF!)" %}
{:/infotext}
{% endic %}
{% input custom.show.prev_year as:boolean %}
{% endif %}
{% endstripnewlines %}
{% if custom.show.prev_year == "true" %}
{% assign show_prev = true %}
{% endif %}
{% if show_prev %}
{% comment %}re-create the fori-loop of last year as a for-loop, calling on the custom collection of last year!{% endcomment %}
{% stripnewlines %}
{% for item in period.minus_1y.reconciliations.stock_cars.custom.items %}
{% assign name_p = item.name | downcase | capitalize %}
{% capture current_total_p %}total_{{ name_p }}_p{% endcapture %}
{% assign [current_total_p] = [current_total_p]+item.value %}
{% assign items_array_p = items_array_p | append:name_p | append:";" %}
{% endfor %}
{% endstripnewlines %}
{% assign items_array_p = items_array_p | split:";" | uniq %}
<br />
{% stripnewlines %}
| Group last year
| Value last year
{% newline %}
|----70%----
|----30%----#+
{% for item in items_array_p %}
{% newline %}
{% capture current_total_p %}total_{{ item }}_p{% endcapture %}
| {{ item }} | {{ [current_total_p] | currency }}
{% endfor %}
{% endstripnewlines %}
{% endif %}