Let’s take this case again:
We might want to be able to tell when the roll-forward function has to be executed.
For instance: if you copy details between periods within the same book year, it might not be needed to have the roll forward function be executed; only when we have a new book year, we want the function to be executed.
From now on, we can do this by choosing a destination-period. Just like you would use a regular period-drop and its methods, you can do this for the rollforward function as well:
rollforward.period
Although it actually has a difference, where the rollforward.period will only have a “value” during the actual copying of the data. So this isn’t something you can’t print (although you could use a workaround for that, but that would be stretching it for now).
Let’s take the code of previously mentioned case, and implement that the roll-forward function only can be executed when copying to a period of a new book year:
{% assign fy_to = rollforward.period.fiscal_year %}
{% assign fy_from = period.fiscal_year %}
I’ll create a variable fy_from which is the fiscal year of the period I’m copying from
(so if I copy details from Q4 2017 in a normal book year, the outcome of that var is 2018).
Now, I want my destination period to be part of a new fiscal year, so I can create some logic for it: rollforward.period.fiscal_year is the fiscal year of the period I’m copying to (so the outcome of the var fy_to is 2019 when I copy details from Q4 2017 to Q4 2018 f.i.)
Now, we can use the outcome of these local variables to use around our roll-forward code:
{% if fy_to > fy_from %}
{% rollforward nil item.purchase %}
{% rollforward nil item.sold %}
{% rollforward $1+$2+$3 item.begin_value %}
{% endif %}
meaning the rollforward will only be done if we copy details to a period that has a larger fiscal year than the fiscal year of the period we copy from.
You see that the rollforward.period can be used like the regular period-drop:
- rollforward.period.year_end_date
- rollforward.period.minus_1p
- rollforward.period.minus_1y
- …
Implemented in the code of the case:
{% comment %}check whether or not a new fiscal year is the case when copying data through roll forward function{% endcomment %}
{% assign fy_to = rollforward.period.fiscal_year %}
{% assign fy_from = period.fiscal_year %}
<table class="usr-width-100">
<thead>
<tr>
<th class="usr-width-20 usr-line-bottom"><b>Description</b></th>
<th class="usr-width-20 usr-line-bottom usr-align-right"><b>Begin value</b></th>
<th class="usr-width-20 usr-line-bottom usr-align-right"><b>Purchased</b></th>
<th class="usr-width-20 usr-line-bottom usr-align-right"><b>Sold</b></th>
<th class="usr-width-20 usr-line-bottom usr-align-right"><b>End value</b></th>
</tr>
</thead>
<tbody>
{% fori item in custom.financial_investments %}
<tr>
<td>
{% input item.description placeholder:"" %}
</td>
<td class="usr-align-right">
{% $1+input item.begin_value as:currency %}
</td>
<td class="usr-align-right">
{% $2+input item.purchase as:currency %}
</td>
<td class="usr-align-right">
{% $3+input item.sold as:n_currency %}
</td>
<td class="usr-align-right">
{% =$4+ $1+$2+$3 | currency %}
</td>
{% comment %}execute roll forward when new fiscal year is the case{% endcomment %}
{% if fy_to > fy_from %}
{% rollforward nil item.purchase %}
{% rollforward nil item.sold %}
{% rollforward $1+$2+$3 item.begin_value %}
{% endif %}
{% comment %}reset each register for next loop{% endcomment %}
{% assign $1 = 0 %}{% assign $2 = 0 %}{% assign $3 = 0 %}
</tr>
{% if forloop.last %}
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="usr-line-top usr-line-bottom usr-align-right"><b>{{ $4 | currency }}</b></td>
</tr>
{% endif %}
{% endfori %}
</tbody>
</table>
This case has been updated on 03/10/2022 to include HTML tables.