New account model

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

Can anyone help me?

Thank you,

Kind regards

Hi @THANAS

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? :slightly_smiling_face:

These cases might be interesting, depending on your exact use case:

Kind regards,
Romy

Hey @Romy_Vermeeren ,

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

Thank you,

Kind regards

Hi @THANAS,

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 :wink:

Kind regards,
Romy

hey @Romy_Vermeeren ,

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.

Thank you very much for your help,

Sincerely

Hi @THANAS

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:

{% 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>
      <th class="usr-align-right usr-width-15 usr-line-bottom"><b>{{ period.minus_1y.year_end_date | date:"%d/%m/%Y" }}</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>{{ period.year_end_date | date:"%d/%m/%Y"  }}</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 class="usr-align-right">{% input detail.custom.py_value as:currency placeholder:0 %}</td>
      
      {% comment %}Calculate variation{% endcomment %}
      {% comment %}Build failsafe as not to divide by zero{% endcomment %}
      {% if detail.custom.cy_value != 0 %}
        {% assign account_variation = (detail.custom.cy_value-detail.custom.py_value)/detail.custom.cy_value %}
      {% else %}
        {% assign account_variation = 0 %}
      {% endif %}

      <td class="usr-align-right">{{ account_variation | percentage }}</td>
      <td class="usr-align-right">{% input detail.custom.cy_value as:currency placeholder:0 %}</td>
      
      {% comment %}Calcualte totals{% endcomment %}
      {% assign total_value_py = total_value_py+detail.custom.py_value %}
      {% assign total_value_cy = total_value_cy+detail.custom.cy_value %}
      
      {% comment %}Rollforward{% endcomment %}
      {% rollforward nil detail.custom.cy_value %}
      {% rollforward detail.custom.cy_value detail.custom.py_value %}
      
    </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 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>

I think this should be a good basis to add anything else you might need.

Kind regards,
Romy

Hi @Romy_Vermeeren ,

Thank you for the documentation!

and many thanks for your help.

Hi @Romy_Vermeeren ,

Why can’t I get a justified account?

Thank,

kind regards

Hi @THANAS

My bad :face_with_hand_over_mouth:, 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).

Kind regards,
Romy

@Romy_Vermeeren ,
No worries :slight_smile: Can you send me the code? I tried but it doesn’t work so I have to do something wrong…

@THANAS the custom is mentioned a couple of times, so I did a “replace all” to make sure I changed it to the new custom everywhere.
This code works:

{% 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>
      <th class="usr-align-right usr-width-15 usr-line-bottom"><b>{{ period.minus_1y.year_end_date | date:"%d/%m/%Y" }}</b></th>
      <th class="usr-align-right usr-width-15 usr-line-bottom"><b>{% t "Variation" %}</b></th>
      <th class="usr-align-right usr-width-15 usr-line-bottom"><b>{{ period.year_end_date | date:"%d/%m/%Y"  }}</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 class="usr-align-right">{% input detail.custom.py_value as:currency placeholder:0 %}</td>
      
      {% comment %}Calculate variation{% endcomment %}
      {% comment %}Build failsafe as not to divide by zero{% endcomment %}
      {% if detail.custom.value != 0 %}
        {% assign account_variation = (detail.custom.value-detail.custom.py_value)/detail.custom.value %}
      {% else %}
        {% assign account_variation = 0 %}
      {% endif %}

      <td class="usr-align-right">{{ account_variation | percentage }}</td>
      <td class="usr-align-right">{% input detail.custom.value as:currency placeholder:0 %}</td>
      
      {% comment %}Calcualte totals{% endcomment %}
      {% assign total_value_py = total_value_py+detail.custom.py_value %}
      {% assign total_value_cy = total_value_cy+detail.custom.value %}
      
      {% comment %}Rollforward{% endcomment %}
      {% rollforward nil detail.custom.value %}
      {% rollforward detail.custom.value detail.custom.py_value %}
      
    </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 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>