Hi Neil,
I think your code is too long, you could simplify it by creating a nested fori-loop as in the example below:
{% stripnewlines %}
|Stock type
|
|Workings
|Number
|Market Value
|% of MV
|Final amount
|
|
{% newline %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%----
|----5%----:+
{% newline %}
{% fori stock in custom.stock_type %}
|{% input stock.type as:select options:"Raw Materials|Work In Progress|Finshed Goods|Cattle|Sheep|Pigs|Poultry|Horses|Forage|Crops In Store|Growing Crops / Tillages|Other" option_values:"1|2|3|4|5|6|7|8|9|10|11|12" default:1 %}
|
|{% input stock.tick as:boolean %}
{% newline %}
{% if stock.tick == true %}
{% fori detail in custom[stock.name.key] %}
|
| {% input detail.annex as:file_collection %}
| {% input detail.description %}
| {% $1+input detail.number %}
| {% $2+input detail.marketvalue as:currency_dc %}
|
{% assign total_stock = (detail.number*detail.marketvalue) %}
| {%=$3+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}
{% newline %}
{% if forloop.last %}
|^ **Total** ^
|^ ^
|^ ^
|^ **{{ $1 | currency_dc}}**^
|^ **{{ $2 | currency_dc}}**^
|^ ^
|^ **{{ $3 | currency_dc}}** ^
|^ ^
|^ ^
{% newline %}
{% assign $1 = 0 %} {% assign $2 = 0 %} {% assign $3 = 0 %}
{% endif %}
{% endfori %}
{% endif %}
{% endfori %}
{% endstripnewlines %}
To understand better how nested fori-loops work, you can have a look at the following post:
https://community.silverfin.com/t/case-how-to-create-a-fori-loop-within-a-fori-loop/802
Hope that helps,
Best,
Borja