Creating and calling arrays based on actual accounting results

Hi there

I’m trying to get the system to create an array, based on the available directors, but am struggling to get it to work.

Stage one is simply to add the director’s loan accounts to the array, and then call them into a table.

Because of the design of our account numbers (XXX_XX_X or XXX_X_X, where the final X refers to the director), in order to separate the accounts by director, I cannot use the normal account selection methods.

{% assign loopno = 1 | integer %}

{% capture dir_no %}dir{{ loopno }}{% endcapture %}

{% assign dir_acc = period.accounts | range:'727_1_1.' %}

{% for acc in dir_acc %}{% assign custom.[dir_no].bfwd = custom.[dir_no].bfwd + acc.value %}{% endfor %}
{% for acc in dir_acc %}{% assign custom.other.bfwd = custom.other.bfwd + acc.value %}{% endfor %}

{% assign loopno = 2 | integer %}

{% capture dir_no %}dir{{ loopno }}{% endcapture %}

{% assign dir_acc = period.accounts | range:'727_1_2.' %}

{% for acc in dir_acc %}{% assign custom.[dir_no].bfwd = custom.[dir_no].bfwd + acc.value %}{% endfor %}
{% for acc in dir_acc %}{% assign custom.other2.bfwd = custom.other2.bfwd + acc.value %}{% endfor %}

{% for loopnew in (1..2) %}
  {% capture dir_no %}dir{{ loopnew }}{% endcapture %}
  Director {{ loopnew }}
  {{ custom.[dir_no].bfwd  }}
  {{ custom.other.bfwd }} - dir 1
  {{ custom.other2.bfwd }} - dir 2


{% endfor %}


**SECOND TRY**

{% for item in (1..5) %}
{% capture some %}dir{{ item }}{% endcapture %}

{% assign custom.[some].bf = period.accounts | range:'727_1_1.'' %}
{% assign custom.[some].cap = period.accounts | range:'727_1_2.'' %}
{% assign custom.[some].draw = period.accounts | range:'727_1_21.'' %}

{% endfor %}

{% stripnewlines %}
|director
{% for item in (1..5) %}
{% capture some %}dir{{ item }}{% endcapture %}
|{{ some }}
{% endfor %}
{% newline %}

|Brought forwards
{% for item in (1..5) %}
{% capture some %}dir{{ item }}{% endcapture %}
  {% assign $1 = 0 %}
  {% for acc in custom.[some].bf %}{% assign $1 = $1 + acc.value %}{% endfor %}
|{{ $1 }}
{% endfor %}
{% newline %}
{% endstripnewlines %}

Attempting this results in
image

However the b/fwd acount 727_1_1.000 (director 1) actually contains £-3.45, and account 727_1_2.000 (director 1) actually contains around £-15,000.

Please help me understand why the array in either attempt does not work?

Hi Thomas,

The issue here is that you are trying to assign a variable with the following syntax: custom.namespace.key, this is only valid when creating input fields. For variables you are not allowed to use a dot, you can use the underscore symbol for example.
Another thing you could do is to capture the ranges in the loop so they change for each director. Try something like this:

{% for item in (1..5) %}

{% capture bf_range %}727_1_{{ item }}.{% endcapture %}
{% capture bf_value %}dir_{{ item }}{% endcapture %}

{% assign [bf_value] = period.accounts | range:bf_range %}

{% endfor %}

...

|Brought forwards
{% for item in (1..5) %}
{% capture bf_value %}dir_{{ item }}{% endcapture %}

|{{ [bf_value] }}
{% endfor %}
{% newline %}

Hope that clarifies your query.

Best,
Borja