Hey,
I would like to have a account model that is composed of 4 columns.
The first one, a title is indicated.
The second one: the value of the previous year
The third: the variation in % of column 2 and 4
The fourth: the value of the year
Is there a specific piece of the code that you’re struggling with? Can you maybe share what you have so far?
Or are you more looking for some general advice on how to get started with this?
These cases might be interesting, depending on your exact use case:
I haven’t started yet and am looking for advice on how to make my account model. I want to use the “Facutres à recevoir (444000)” template as a starting point, except that I want 4 columns as explained in my previous message.
I couldn’t find the necessary information in the other topics
since the code of the template you mentioned is available, I’ll also use it to start this example.
I will be using HTML for the table formatting however, since that’s what we recommend going forward.
Not sure how you want the account template to work exactly, so I’ll be assuming you want some automation. Let’s work with an account selector, so you can select a relevant account then print the values automatically?
I’m just giving you a very basic table with 4 columns (actually 5 with the account selector) and a total line. Hope this can be a foundation for you to build further on. If there’s any specific feature you’re wanting to add but struggle with, feel free to reach out again.
{% comment %}Set the range of accounts users can select from{% endcomment %}
{% assign account_range = "4" %}
{% comment %}Table start{% endcomment %}
<table class="usr-width-100">
{% comment %}Template header: 4 columns{% endcomment %}
<thead>
<tr>
<th class="usr-align-center usr-line-bottom"><b>{% t "Title" %}</b></th>
{% comment %}Column for account selector{% endcomment %}
<th class="usr-align-center usr-line-bottom usr-width-6"></th>
<th class="usr-align-right usr-width-15 usr-line-bottom"><b>{% t "Previous year value" %}</b></th>
<th class="usr-align-right usr-width-15 usr-line-bottom"><b>{% t "Variation in %" %}</b></th>
<th class="usr-align-right usr-width-15 usr-line-bottom"><b>{% t "Current year value" %}</b></th>
</tr>
</thead>
{% comment %}Body: fori loop - custom attached to the current account{% endcomment %}
<tbody>
{% fori detail in current_account.custom.details %}
{% comment %}Start a new row every loop{% endcomment %}
<tr>
<td>{% input detail.custom.title placeholder:"Title" %}</td>
<td>{% input detail.custom.description_range as:account_collection range:account_range %}</td>
{% comment %}CY and PY values from the chosen account{% endcomment %}
{% assign account_chosen_cy = period.accounts | range:detail.custom.description_range %}
{% assign account_chosen_py = period.minus_1y.accounts | range:detail.custom.description_range %}
{% comment %}Gather totals{% endcomment %}
{% assign total_value_cy = total_value_cy+account_chosen_cy %}
{% assign total_value_py = total_value_py+account_chosen_py %}
{% comment %}Calculate variation{% endcomment %}
{% comment %}Build failsafe as not to divide by zero{% endcomment %}
{% if account_chosen_cy != 0 %}
{% assign account_variation = (account_chosen_cy-account_chosen_py)/account_chosen_cy %}
{% else %}
{% assign account_variation = 0 %}
{% endif %}
<td class="usr-align-right">{{ account_chosen_py | currency }}</td>
<td class="usr-align-right">{{ account_variation | percentage }}</td>
<td class="usr-align-right">{{ account_chosen_cy | currency }}</td>
</tr>
{% endfori %}
{% if current_account.custom.details.size > 1 %}
{% comment %}Total line - only shown if there's more than 1 detail available{% endcomment %}
<tr>
<td class="usr-line-top"></td>
<td class="usr-line-top"></td>
<td class="usr-line-top usr-align-right"><b>{{ total_value_py | currency }}</b></td>
<td class="usr-line-top"></td>
<td class="usr-line-top usr-align-right"><b>{{ total_value_cy | currency }}</b></td>
</tr>
{% endif %}
</tbody>
</table>
Note that this code will only work on an account since it’s been written for an account template specifically, because we’re using the current_account.custom drop. If you want to test in a text template first, you can remove “current_account”, so the collection would just be “custom.details”. Just don’t forget to switch it back to current_account afterwards
I don’t know HTML at all so I’m a bit lost in the code.
This is almost the result I want to have. The template is used to justify an account. I don’t need an account selector, the values should be manual fields. Copying from one year to another will automatically fill in the previous year value column. In the titles, I want to have the period. I would also like to have a total on column 2 and 4.
I know HTML tables in templates is still pretty new, but it’s a lot easier to style your table and to read and organize your code. I strongly recommend you check out the documentation we’ve posted on it so far.
For the column titles, you can print what you need from the period drop.
One that’s often used is the period.year_end_date, you then apply the date filter do get the format you want.
Since you don’t want an account selector, the code is actually even less complicated, like you said you just need two input fields for current and previous year.
For the rollforward, what’s important is to have to code within your for(i) loop, as it needs to be executed for each iteration. For the title we don’t need to specify anything since it’s the standard 1-1 copy.
Applying everything you just mentioned, we have the following:
My bad , if you want the values to reconcile against the account, then the naming needs to follow a certain rule.
So for the values you want to reconcile, in the current year column, the name should be “detail.custom.value”, instead of “detail.custom.cy_value”.
(it’s also documented here).