Stop information being carried forward to next section

Hi, I have the below coding for a stock rec I am working on. I am hoping to have the stock sheet in sections, e.g. Raw Materials, Cattle, Pigs (we deal with agricultural clients). I like the layout I have set up but am not sure how to make each section independent? I assume it is something I have not done with the fori’s. I tried to add a break but lost everything below it.

Thanks in advance.

I hope I have shared the coding in a reasonable state.

Cheers

`{% stripnewlines %}
|Stock type
|
|Workings
|Number
|Market Value
|% of MV
|Final amount
|
|

{% newline %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%----
|----5%----:+
{% newline %}
|{% input custom.choice.template.1 as:select options:“Raw Materials|Work In Progress|Finshed Goods|Cattle” option_values:“1|2|3|4” default:1 %}
|
|{% input custom.tick.workings1 as:boolean %}
|
|
|
|
|
|
{% endstripnewlines %}

{% if custom.choice.template.1 == 1 and custom.tick.workings1 %}

{% assign $0 = 0 %}{% assign $1 = 0 %}{% assign $2 = 0 %}
{% assign stock_types = “Raw Materials” %}

{% stripnewlines %}
{% fori detail in current_account.details %}
{% if forloop.first %}
| {% t “Stock type” %}
|
| {% t “Stock description” %}
| {% t “Number” %}
| {% t “Market Value” %}
|
| {% t “Final amount” %}
| {% t “Notes” %}
|
{% newline %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%—:
|----5%----+
{% endif %}
{% newline %}
| {% input detail.custom.type as:select options:stock_types %} {% if custom.check.comments == true %}
{% input custom.comments placeholder:“Comments” as:text size:mini %}
{% endif %}
| {% input detail.custom.annex as:file_collection %}
| {% input detail.custom.description %}
| {% $0+input detail.custom.number %}
| {% $1+input detail.custom.marketvalue as:currency_dc %}
|
{% assign total_stock = (detail.custom.number*detail.custom.marketvalue) %}
| {%=$2+ total_stock | currency_dc %}
| {% ic %}{% input detail.custom.extra_comment placeholder:“Comment” %}{% endic %}{% nic %}{{ detail.custom.extra_comment | multiline_table }}{% endnic %}
|
{% if forloop.last %}
{% endif %}
{% endfori %}
{% endstripnewlines %}

{% endif %}

{% stripnewlines %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%—:
|----5%----+
{% newline %}
|^ Total ^
|^ ^
|^ ^
|^ {{ $0 | currency_dc}}^
|^ {{ $1 | currency_dc}}^
|^ ^
|^ {{ $2 | currency_dc}} ^
|^ ^
|^ ^
{% endstripnewlines %}

{% stripnewlines %}
|Stock type
|
|Workings
|Number
|Market Value
|% of MV
|Final amount
|
|
{% newline %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%----
|----5%----:+
{% newline %}
|{% input custom.choice.template.2 as:select options:“Raw Materials|Work In Progress|Finshed Goods|Cattle” option_values:“1|2|3|4” default:1 %}
|
|{% input custom.tick.workings2 as:boolean %}
|
|
|
|
|
|
{% endstripnewlines %}

{% if custom.choice.template.2 == 2 and custom.tick.workings2 %}

{% assign $4 = 0 %}{% assign $5 = 0 %}{% assign $6 = 0 %}
{% assign stock_types2 = “Work In Progress” %}

{% stripnewlines %}
{% fori detail in current_account.details %}
{% if forloop.first %}
| {% t “Stock type” %}
|
| {% t “Stock description” %}
| {% t “Number” %}
| {% t “Market Value” %}
|
| {% t “Final amount” %}
| {% t “Notes” %}
|
{% newline %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%—:
|----5%----+
{% endif %}
{% newline %}
| {% input detail.custom.type2 as:select options:stock_types2 %} {% if custom.check.comments2 == true %}
{% input custom.comments2 placeholder:“Comments” as:text size:mini %}
{% endif %}
| {% input detail.custom.annex as:file_collection %}
| {% input detail.custom.description2 %}
| {% $4+input detail.custom.number2 %}
| {% $5+input detail.custom.marketvalue2 as:currency_dc %}
|
{% assign total_stock2 = (detail.custom.number2*detail.custom.marketvalue2) %}
| {%=$6+ total_stock2 | currency_dc %}
| {% ic %}{% input detail.custom.extra_comment2 placeholder:“Comment” %}{% endic %}{% nic %}{{ detail.custom.extra_comment2 | multiline_table }}{% endnic %}
|
{% if forloop.last %}
{% endif %}
{% endfori %}
{% endstripnewlines %}

{% endif %}

{% stripnewlines %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%—:
|----5%----+
{% newline %}
|^ Total ^
|^ ^
|^ ^
|^ {{ $4 | currency_dc}}^
|^ {{ $5 | currency_dc}}^
|^ ^
|^ {{ $6 | currency_dc}} ^
|^ ^
|^ ^
{% endstripnewlines %}

{% stripnewlines %}
{% newline %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%----
|----5%----:+
{% newline %}
|{% input custom.choice.template.3 as:select options:“Raw Materials|Work In Progress|Finshed Goods|Cattle” option_values:“1|2|3|4” default:1 %}
|
|{% input custom.tick.workings3 as:boolean %}
|
|
|
|
|
|
{% endstripnewlines %}

{% if custom.choice.template.3 == 3 and custom.tick.workings3 %}

{% assign $7 = 0 %}{% assign $8 = 0 %}{% assign $9 = 0 %}
{% assign stock_types3 = “Finished Goods” %}

{% stripnewlines %}
{% fori detail in current_account.details %}
{% if forloop.first %}
| {% t “Stock type” %}
|
| {% t “Stock description” %}
| {% t “Number” %}
| {% t “Market Value” %}
|
| {% t “Final amount” %}
| {% t “Notes” %}
|
{% newline %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%—:
|----5%----+
{% endif %}
{% newline %}
| {% input detail.custom.type3 as:select options:stock_types3 %} {% if custom.check.comments3 == true %}
{% input custom.comments3 placeholder:“Comments” as:text size:mini %}
{% endif %}
| {% input detail.custom.annex as:file_collection %}
| {% input detail.custom.description3 %}
| {% $4+input detail.custom.number3 %}
| {% $5+input detail.custom.marketvalue3 as:currency_dc %}
|
{% assign total_stock3 = (detail.custom.number3*detail.custom.marketvalue3) %}
| {%=$6+ total_stock3 | currency_dc %}
| {% ic %}{% input detail.custom.extra_comment3 placeholder:“Comment” %}{% endic %}{% nic %}{{ detail.custom.extra_comment3 | multiline_table }}{% endnic %}
|
{% if forloop.last %}
{% endif %}
{% endfori %}
{% endstripnewlines %}

{% endif %}

{% stripnewlines %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%—:
|----5%----+
{% newline %}
|^ Total ^
|^ ^
|^ ^
|^ {{ $7 | currency_dc}}^
|^ {{ $8 | currency_dc}}^
|^ ^
|^ {{ $9 | currency_dc}} ^
|^ ^
|^ ^
{% endstripnewlines %}

{% stripnewlines %}
{% newline %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%----
|----5%----:+
{% newline %}
|{% input custom.choice.template.4 as:select options:“Raw Materials|Work In Progress|Finshed Goods|Cattle” option_values:“1|2|3|4” default:1 %}
|
|{% input custom.tick.workings4 as:boolean %}
|
|
|
|
|
|
{% endstripnewlines %}

{% if custom.choice.template.4 == 4 and custom.tick.workings4 %}

{% assign $10 = 0 %}{% assign $11 = 0 %}{% assign $12 = 0 %}
{% assign stock_types4 = “Bulls|Cows|Barreners|Heifers incalf|Heifers over 25 months|Heifers 19 to 24 months|Heifers 13 to 18 months|Heifers 7 to 12 months|Heifers 0 to 6 months|Beef Male cattle over 24 months|Beef Female cattle over 24 months|Beef Male cattle 19 to 24 months|Beef Female cattle 19 to 24 months|Beef Male cattle 13 to 18 months|Beef Female cattle 13 to 18 months|Beef Male cattle 7 to 12 months|Beef Female cattle 7 to 12 months|Beef Male cattle 0 to 6 months|Beef Female cattle 0 to 6 months” %}

{% stripnewlines %}
{% fori detail in current_account.details %}
{% if forloop.first %}
| {% t “Stock type” %}
|
| {% t “Stock description” %}
| {% t “Number” %}
| {% t “Market Value” %}
| {% t “60% of MV” %}
| {% t “Final amount” %}
| {% t “Notes” %}
|
{% newline %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%—:
|----5%----+
{% endif %}
{% newline %}
| {% input detail.custom.type4 as:select options:stock_types %} {% if custom.check.comments4 == true %}
{% input custom.comments4 placeholder:“Comments” as:text size:mini %}
{% endif %}
| {% input detail.custom.annex as:file_collection %}
| {% input detail.custom.description4 %}
| {% $10+input detail.custom.number4 %}
| {% $11+input detail.custom.marketvalue4 as:currency_dc %}
| 60%
{% assign total_stock4 = (detail.custom.number4*detail.custom.marketvalue4)*0.6 %}
| {%=$12+ total_stock4 | currency_dc %}
| {% ic %}{% input detail.custom.extra_comment4 placeholder:“Comment” %}{% endic %}{% nic %}{{ detail.custom.extra_comment4 | multiline_table }}{% endnic %}
|
{% if forloop.last %}
{% endif %}
{% endfori %}
{% endstripnewlines %}

{% endif %}

{% stripnewlines %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%—:
|----5%----+
{% newline %}
|^ Total ^
|^ ^
|^ ^
|^ {{ $10 | currency_dc}}^
|^ {{ $11 | currency_dc}}^
|^ ^
|^ {{ $12 | currency_dc}}^
|^ ^
|^ ^
{% endstripnewlines %}

{% stripnewlines %}
{% newline %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%----
|----5%----:+
{% newline %}
|{% input custom.choice.template.5 as:select options:“Raw Materials|Work In Progress|Finshed Goods|Cattle” option_values:“1|2|3|4” default:1 %}
|
|{% input custom.tick.workings5 as:boolean %}
|
|
|
|
|
|
{% endstripnewlines %}

{% if custom.choice.template.5 == 5 and custom.tick.workings5 %}

{% assign $13 = 0 %}{% assign $14 = 0 %}{% assign $15 = 0 %}
{% assign stock_types5 = “Rams|Ewes|Barren ewes|Young ewes|Sheraling/tups|Gimmer|Hogget|Ram lambs|Store lambs|Lambs” %}

{% stripnewlines %}
{% fori detail in current_account.details %}
{% if forloop.first %}
| {% t “Stock type” %}
|
| {% t “Stock description” %}
| {% t “Number” %}
| {% t “Market Value” %}
| {% t “60% of MV” %}
| {% t “Final amount” %}
| {% t “Notes” %}
|
{% newline %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%—:
|----5%----+
{% endif %}
{% newline %}
| {% input detail.custom.type5 as:select options:stock_types %} {% if custom.check.comments5 == true %}
{% input custom.comments5 placeholder:“Comments” as:text size:mini %}
{% endif %}
| {% input detail.custom.annex as:file_collection %}
| {% input detail.custom.description5 %}
| {% $13+input detail.custom.number5 %}
| {% $14+input detail.custom.marketvalue5 as:currency_dc %}
| 75%
{% assign total_stock5 = (detail.custom.number5*detail.custom.marketvalue5)*0.75 %}
| {%=$15+ total_stock5 | currency_dc %}
| {% ic %}{% input detail.custom.extra_comment5 placeholder:“Comment” %}{% endic %}{% nic %}{{ detail.custom.extra_comment5 | multiline_table }}{% endnic %}
|
{% if forloop.last %}
{% endif %}
{% endfori %}
{% endstripnewlines %}

{% endif %}

{% stripnewlines %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%—:
|----5%----+
{% newline %}
|^ Total ^
|^ ^
|^ ^
|^ {{ $13 | currency_dc}}^
|^ {{ $14 | currency_dc}}^
|^ ^
|^ {{ $15 | currency_dc}}^
|^ ^
|^ ^
{% endstripnewlines %}

{% stripnewlines %}
{% newline %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%----
|----5%----:+
{% newline %}
|{% input custom.choice.template.6 as:select options:“Raw Materials|Work In Progress|Finshed Goods|Cattle|Sheep|Pigs” option_values:“1|2|3|4|5|6” default:1 %}
|
|{% input custom.tick.workings6 as:boolean %}
|
|
|
|
|
|
{% endstripnewlines %}

{% if custom.choice.template.6 == 6 and custom.tick.workings6 %}

{% assign $16 = 0 %}{% assign $17 = 0 %}{% assign $18 = 0 %}
{% assign stock_types6 = “Boars|Sows|Barren sows|Gilts|Store pigs|Porkers|Piglets” %}

{% stripnewlines %}
{% fori detail in current_account.details %}
{% if forloop.first %}
| {% t “Stock type” %}
|
| {% t “Stock description” %}
| {% t “Number” %}
| {% t “Market Value” %}
| {% t “60% of MV” %}
| {% t “Final amount” %}
| {% t “Notes” %}
|
{% newline %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%—:
|----5%----+
{% endif %}
{% newline %}
| {% input detail.custom.type6 as:select options:stock_types %} {% if custom.check.comments6 == true %}
{% input custom.comments6 placeholder:“Comments” as:text size:mini %}
{% endif %}
| {% input detail.custom.annex as:file_collection %}
| {% input detail.custom.description6 %}
| {% $13+input detail.custom.number6 %}
| {% $14+input detail.custom.marketvalue6 as:currency_dc %}
| 75%
{% assign total_stock6 = (detail.custom.number6*detail.custom.marketvalue6)*0.75 %}
| {%=$15+ total_stock6 | currency_dc %}
| {% ic %}{% input detail.custom.extra_comment6 placeholder:“Comment” %}{% endic %}{% nic %}{{ detail.custom.extra_comment6 | multiline_table }}{% endnic %}
|
{% if forloop.last %}
{% endif %}
{% endfori %}
{% endstripnewlines %}

{% endif %}

{% stripnewlines %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%—:
|----5%----+
{% newline %}
|^ Total ^
|^ ^
|^ ^
|^ {{ $16 | currency_dc}}^
|^ {{ $17 | currency_dc}}^
|^ ^
|^ {{ $18 | currency_dc}}^
|^ ^
|^ ^
{% endstripnewlines %}

{% stripnewlines %}

{% newline %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%----
|----5%----:+
{% newline %}
|
|
|
|
|
|
|
|
{% newline %}
|^Grand Total^
|^^
|^^
|^^
|^^
|^^
|^{{ $2+$6 | currency_dc}}{% unexplained $2+$6-current_account.value as:indicator %}^
|^^
|^^
{% endstripnewlines %}`

Hi Neil,

That code seems to be broken, could you please share the link to the code in your environment? (next time you can just copy paste the link on your query)

Thanks,
Borja

Hi Borja,

Please see link below, I have added several more sections now.

https://live.getsilverfin.com/f/1671/account_detail_templates/36771/edit

Any issues let me know, thanks.

Neil

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

Hi Borja, thanks for this. I like the layout.

Is there a way I can get something like the below to work.

{% if stock.type == ‘1’ %}{% input detail.type as:select options:“Raw Materials” %}{% endif %}

This is on line 40 of the above coding so the first line on the second fori. I’d like to be able to have different options of drop downs depending on what the answer is to the first drop down on line 29.

Hope that makes sense, if you need anymore information let me know.

Cheers

Hi Neil,

You can try capturing the option values depending on the stock type selected and then just create an input that retrieves the option values assigned. Like this:

{% if stock.type == 1 %}
 {% capture option_values %}Raw Materials|Sheep{% endcapture %}
{% elsif stock.type == 2 %}
 {% capture option_values %}Poultry|Horses{% endcapture %}
{% endif %}

{% input detail.type as:select options:option_values %}

Let me know if that makes sense.

Best,
Borja

Hi Borja,

Managed to get to work with the following and also got a cost vs % of MV so we can have either as it depend son the situation.

Would you be able to point me in the right direction of getting a total row at the bottom or preferably the top (but not sure the coding works that way). I have tried with the very bottom second but that doesn’t seem to pull through.

Thank you

Hopefully sorted the coding in the box this time :slight_smile:

Cheers Neil

{% stripnewlines %}
|Stock type
|
|Workings
|Number
|Market Value
|% of MV
|Final amount
|Comments
|

{% 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" %}**_
|
|{% input stock.tick as:boolean %}


{% newline %}




{% if stock.type == 1 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Raw Materials" %}
| {% 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 %}
{% endif %}



{% if stock.type == 2 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Work In Progress" %}
| {% input detail.annex as:file_collection %}
| {% input detail.description  %}
| {% $4+input detail.number %}
| {% $5+input detail.marketvalue as:currency_dc %}
| 
{% assign total_stock = (detail.number*detail.marketvalue) %}
| {%=$6+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ ^
|^ **{{ $4 | currency_dc}}**^
|^ **{{ $5 | currency_dc}}**^
|^ ^
|^ **{{ $6 | currency_dc}}** ^
|^ ^
|^ ^

{% newline %}

{% assign $4 = 0 %} {% assign $5 = 0 %} {% assign $6 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 3 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Finished Goods" %}
| {% input detail.annex as:file_collection %}
| {% input detail.description  %}
| {% $7+input detail.number %}
| {% $8+input detail.marketvalue as:currency_dc %}
| 
{% assign total_stock = (detail.number*detail.marketvalue) %}
| {%=$9+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ ^
|^ **{{ $7 | currency_dc}}**^
|^ **{{ $8 | currency_dc}}**^
|^ ^
|^ **{{ $9 | currency_dc}}** ^
|^ ^
|^ ^

{% newline %}

{% assign $7 = 0 %} {% assign $8 = 0 %} {% assign $9 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 4 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Bulls|Cows|Barreners|Heifers incalf|Heifers over 25 months|Heifers 19 to 24 months|Heifers 13 to 18 months|Heifers 7 to 12 months|Heifers 0 to 6 months|Beef Male cattle over 24 months|Beef Female cattle over 24 months|Beef Male cattle 19 to 24 months|Beef Female cattle 19 to 24 months|Beef Male cattle 13 to 18 months|Beef Female cattle 13 to 18 months|Beef Male cattle 7 to 12 months|Beef Female cattle 7 to 12 months|Beef Male cattle 0 to 6 months|Beef Female cattle 0 to 6 months" %}
| {% input detail.annex as:file_collection %}
| {% input detail.description  %}
| {% $10+input detail.number %}
| {% $11+input detail.marketvalue as:currency_dc %}
| {% input detail.mvpercentage as:select options:"60%|Cost" default:"60%" %} 
{% if detail.mvpercentage == "60%" %}{% assign percentage = 0.6 %}{% elsif detail.mvpercentage == "Cost" %}{% assign percentage = 1.0 %}{% endif %}
{% assign total_stock = (detail.number*detail.marketvalue)*percentage %}
| {%=$12+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ ^
|^ **{{ $10 | currency_dc}}**^
|^ **{{ $11 | currency_dc}}**^
|^ ^
|^ **{{ $12 | currency_dc}}** ^
|^ ^
|^ ^

{% newline %}

{% assign $10 = 0 %} {% assign $11 = 0 %} {% assign $12 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 5 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Rams|Ewes|Barren ewes|Young ewes|Sheraling/tups|Gimmer|Hogget|Ram lambs|Store lambs|Lambs" %}
| {% input detail.annex as:file_collection %}
| {% input detail.description  %}
| {% $13+input detail.number %}
| {% $14+input detail.marketvalue as:currency_dc %}
| {% input detail.mvpercentage as:select options:"75%|Cost" default:"75%" %} 
{% if detail.mvpercentage == "75%" %}{% assign percentage = 0.75 %}{% elsif detail.mvpercentage == "Cost" %}{% assign percentage = 1.0 %}{% endif %}
{% assign total_stock = (detail.number*detail.marketvalue)*percentage %}
| {%=$15+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ ^
|^ **{{ $13 | currency_dc}}**^
|^ **{{ $14 | currency_dc}}**^
|^ ^
|^ **{{ $15 | currency_dc}}** ^
|^ ^
|^ ^

{% newline %}

{% assign $13 = 0 %} {% assign $14 = 0 %} {% assign $15 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 6 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Boars|Sows|Barren sows|Gilts|Store pigs|Porkers|Piglets" %}
| {% input detail.annex as:file_collection %}
| {% input detail.description  %}
| {% $16+input detail.number %}
| {% $17+input detail.marketvalue as:currency_dc %}
|  {% input detail.mvpercentage as:select options:"75%|Cost" default:"75%" %} 
{% if detail.mvpercentage == "75%" %}{% assign percentage = 0.75 %}{% elsif detail.mvpercentage == "Cost" %}{% assign percentage = 1.0 %}{% endif %}
{% assign total_stock = (detail.number*detail.marketvalue)*percentage %}
| {%=$18+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ ^
|^ **{{ $16 | currency_dc}}**^
|^ **{{ $17 | currency_dc}}**^
|^ ^
|^ **{{ $18 | currency_dc}}** ^
|^ ^
|^ ^

{% newline %}

{% assign $16 = 0 %} {% assign $17 = 0 %} {% assign $18 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 7 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Cockerals|Laying hens|Turkeys|Geese|Ducks|Pheasants|Partridge" %}
| {% input detail.annex as:file_collection %}
| {% input detail.description  %}
| {% $19+input detail.number %}
| {% $20+input detail.marketvalue as:currency_dc %}
| {% input detail.mvpercentage as:select options:"75%|Cost" default:"75%" %} 
{% if detail.mvpercentage == "75%" %}{% assign percentage = 0.75 %}{% elsif detail.mvpercentage == "Cost" %}{% assign percentage = 1.0 %}{% endif %}
{% assign total_stock = (detail.number*detail.marketvalue)*percentage %}
| {%=$21+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ ^
|^ **{{ $19 | currency_dc}}**^
|^ **{{ $20 | currency_dc}}**^
|^ ^
|^ **{{ $21 | currency_dc}}** ^
|^ ^
|^ ^

{% newline %}

{% assign $19 = 0 %} {% assign $20 = 0 %} {% assign $21 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 8 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Stallions|Breeding mares|Brood mares|Geldings|Fillies|Foals" %}
| {% input detail.annex as:file_collection %}
| {% input detail.description  %}
| {% $22+input detail.number %}
| {% $23+input detail.marketvalue as:currency_dc %}
| {% input detail.mvpercentage as:select options:"75%|Cost" default:"75%" %} 
{% if detail.mvpercentage == "75%" %}{% assign percentage = 0.75 %}{% elsif detail.mvpercentage == "Cost" %}{% assign percentage = 1.0 %}{% endif %}
{% assign total_stock = (detail.number*detail.marketvalue)*percentage %}
| {%=$24+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ ^
|^ **{{ $22 | currency_dc}}**^
|^ **{{ $23 | currency_dc}}**^
|^ ^
|^ **{{ $24 | currency_dc}}** ^
|^ ^
|^ ^

{% newline %}

{% assign $22 = 0 %} {% assign $23 = 0 %} {% assign $24 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 9 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Grass silage|Maize silage|Haylage|Straw|Whole crop silage|Hay" %}
| {% input detail.annex as:file_collection %}
| {% input detail.description  %}
| {% $25+input detail.number %}
| {% $26+input detail.marketvalue as:currency_dc %}
| {% input detail.mvpercentage as:select options:"75%|Cost" default:"75%" %} 
{% if detail.mvpercentage == "75%" %}{% assign percentage = 0.75 %}{% elsif detail.mvpercentage == "Cost" %}{% assign percentage = 1.0 %}{% endif %}
{% assign total_stock = (detail.number*detail.marketvalue)*percentage %}
| {%=$27+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ ^
|^ **{{ $25 | currency_dc}}**^
|^ **{{ $26 | currency_dc}}**^
|^ ^
|^ **{{ $27 | currency_dc}}** ^
|^ ^
|^ ^

{% newline %}

{% assign $25 = 0 %} {% assign $26 = 0 %} {% assign $27 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 10 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Organic milling wheat|Milling wheat|Feed wheat|Organice malting barley|Malting barley|Feed barley|Organic oats|Oats|Oil seed rape|Linseed|Peas|Beans|Potatoes|Sugar beet" %}
| {% input detail.annex as:file_collection %}
| {% input detail.description  %}
| {% $28+input detail.number %}
| {% $29+input detail.marketvalue as:currency_dc %}
| {% input detail.mvpercentage as:select options:"75%|Cost" default:"75%" %} 
{% if detail.mvpercentage == "75%" %}{% assign percentage = 0.75 %}{% elsif detail.mvpercentage == "Cost" %}{% assign percentage = 1.0 %}{% endif %}
{% assign total_stock = (detail.number*detail.marketvalue)*percentage %}
| {%=$30+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ ^
|^ **{{ $28 | currency_dc}}**^
|^ **{{ $29 | currency_dc}}**^
|^ ^
|^ **{{ $30 | currency_dc}}** ^
|^ ^
|^ ^

{% newline %}

{% assign $28 = 0 %} {% assign $29 = 0 %} {% assign $30 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 11 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Winter organic wheat|Winter wheat|Winter organic barley|Winter barley|Winter organic oats|Winter oats|Winter oil seed rape|Winter beans|Winter new grass leys|Winter second grass leys|Spring organic barley|Spring barley|Spring organic oats|Spring oats|Spring oil seed rape|Spring beans|Spring peas|Spring maize|Spring potatoes|Crops on other land - wheat|Crops on other land - Barley|Crops on other land - Maize" %}
| {% input detail.annex as:file_collection %}
| {% input detail.description  %}
| {% $31+input detail.number %}
| {% $32+input detail.marketvalue as:currency_dc %}
| 
{% assign total_stock = (detail.number*detail.marketvalue) %}
| {%=$33+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ ^
|^ **{{ $31 | currency_dc}}**^
|^ **{{ $32 | currency_dc}}**^
|^ ^
|^ **{{ $33 | currency_dc}}** ^
|^ ^
|^ ^

{% newline %}

{% assign $31 = 0 %} {% assign $32 = 0 %} {% assign $33 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 12 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Concentrates|Feed|Other feed|Minerals|Fertiliser - nitrogen|Fertiliser - NPK|Fertiliser - other|Sprays|Sprays - other|Lime|Derv|Gas oil|Petrol|Oil|Veterinary supplies|Dairy chemicals|Semen|Embryos|Fencing materials|Twine & net wrap" %}
| {% input detail.annex as:file_collection %}
| {% input detail.description  %}
| {% $34+input detail.number %}
| {% $35+input detail.marketvalue as:currency_dc %}
| 
{% assign total_stock = (detail.number*detail.marketvalue) %}
| {%=$36+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ ^
|^ **{{ $34 | currency_dc}}**^
|^ **{{ $35 | currency_dc}}**^
|^ ^
|^ **{{ $36 | currency_dc}}** ^
|^ ^
|^ ^

{% newline %}

{% assign $34 = 0 %} {% assign $35 = 0 %} {% assign $36 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}

{% endfori %}

{% endstripnewlines %}

<!------------------------------------------------- END -------------------------------------------->

{% stripnewlines %}
{% newline %}
|----20%----
|-----2%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%----
|----5%----:+
{% newline %}
|
|
|
|
|
|
|
|
{% newline %}
|^**Grand Total**^
|^^
|^^
|^^
|^^
|^^
|^**{{ $3+$6+$9+$12+$15+$18+$21+$24+$27+$30+$33+$36 | currency_dc}}**{% unexplained $3+$6+$9+$12+$15+$18+$21+$24+$27+$30+$33+$36-current_account.value as:indicator %}^
|^^
|^^


{% endstripnewlines %}'''

Hi Neil,

Yes, the code looks now great inside the box :grinning:

The reason why your grand total calculation is not working is because you are assigning a zero value to your registers ($3,$6,$9…) at the end of each loop so when you try to retrieve the sum of the values at the bottom, the result is nil. This makes sense if you are using the same registers again for the subsequent loops but in your case you are using different ones so you can just delete these lines:

{% assign $1 = 0 %} {% assign $2 = 0 %} {% assign $3 = 0 %}

...

{% assign $4 = 0 %} {% assign $5 = 0 %} {% assign $6 = 0 %}

[etc.]

However, if you want to use the same registers (reseting then their values to zero) you could add the following line of code before you assign the registers to zero:

{% assign grand_total = grand_total+$3 %}

{% assign $1 = 0 %} {% assign $2 = 0 %} {% assign $3 = 0 %}

...

{% assign grand_total = grand_total+$6 %}

{% assign $4 = 0 %} {% assign $5 = 0 %} {% assign $6 = 0 %}

[etc.]

Then you print the value of the variable ‘grand_total’ at the bottom of the template:

{{ grand_total | currency_dc}} {% unreconciled grand_total-current_account.value as:indicator %}

By the way, you should use unreconciled rather than unexplained since the latter has now been deprecated.

On the other hand, it would be possible to put the total on top but you need to make the calculations before showing them. Let me know exactly where you would like to show it and I can think of a solution.

Best,
Borja

Thanks Borja, that has worked perfectly.

I have added a bit more coding onto our stock template. I would like it to work so that the stock.depreciation as:boolean bit works independently of each row. At the moment if I have 4 rows under the same heading and tick the box it puts a tick in all the boxes. Is this doable?

Let me know if you would like more information.

Cheers

_**{% t "Verification of stock" %}:**_  

|{% input custom.verification.selection as:select options:"Verified by us|Independent verification|Client|Other" %}  | {::infotext as="hover"}Please provide an attachement of any stock paperwork.{:/infotext}{% input custom.verification.annex as:file_collection %} 

{% if custom.verification.selection == "Other" %}
{% input custom.verification.other as:text size:mini placeholder:"Detail other" %}
{% endif %}

{% endifi %}

{% stripnewlines %}
|Stock type
|Workings
|Number
|Market Value
|% of MV
|Final amount
|Comments
|{::infotext as="hover"}Tick the box to confirm this stock item is to be considered when looking at how much depreciation is held within stock.{:/infotext}
|Depreciation

{% newline %}

|----20%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%----
|:----3%----:
|----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" %}**_
|{% input stock.tick as:boolean %}


{% newline %}




{% if stock.type == 1 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Raw Materials" %}
| {% 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 %}
| {% input stock.depreciation as:boolean %}
{% assign stock_depreciation = (detail.number*detail.marketvalue)*0.15 %}
| {% if stock.depreciation == true %} {%=$37+ stock_depreciation | currency_dc %} {% endif %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ **{{ $1 | currency_dc}}**^
|^ **{{ $2 | currency_dc}}**^
|^ ^
|^ **{{ $3 | currency_dc}}** ^
|^ ^
|^ ^
|^ **{{ $37 | currency_dc}}** ^

{% newline %}
{% assign grand_total = grand_total+$3 %}
{% assign depreciation_total = depreciation_total+$37 %}
{% assign $1 = 0 %} {% assign $2 = 0 %} {% assign $3 = 0 %} {% assign $37 = 0 %}


{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 2 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Work In Progress" %}
| {% input detail.description  %}
| {% $4+input detail.number %}
| {% $5+input detail.marketvalue as:currency_dc %}
| 
{% assign total_stock = (detail.number*detail.marketvalue) %}
| {%=$6+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}
| {% input stock.depreciation as:boolean %}
{% assign stock_depreciation = (detail.number*detail.marketvalue)*0.15 %}
| {% if stock.depreciation == true %} {%=$37+ stock_depreciation | currency_dc %} {% endif %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ **{{ $4 | currency_dc}}**^
|^ **{{ $5 | currency_dc}}**^
|^ ^
|^ **{{ $6 | currency_dc}}** ^
|^ ^
|^ ^
|^ **{{ $37 | currency_dc}}** ^

{% newline %}
{% assign grand_total = grand_total+$6 %}
{% assign depreciation_total = depreciation_total+$37 %}
{% assign $4 = 0 %} {% assign $5 = 0 %} {% assign $6 = 0 %}{% assign $37 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 3 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Finished Goods" %}
| {% input detail.description  %}
| {% $7+input detail.number %}
| {% $8+input detail.marketvalue as:currency_dc %}
| 
{% assign total_stock = (detail.number*detail.marketvalue) %}
| {%=$9+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}
| {% input stock.depreciation as:boolean %}
{% assign stock_depreciation = (detail.number*detail.marketvalue)*0.15 %}
| {% if stock.depreciation == true %} {%=$37+ stock_depreciation | currency_dc %} {% endif %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ **{{ $7 | currency_dc}}**^
|^ **{{ $8 | currency_dc}}**^
|^ ^
|^ **{{ $9 | currency_dc}}** ^
|^ ^
|^ ^
|^ **{{ $37 | currency_dc}}** ^

{% newline %}
{% assign grand_total = grand_total+$9 %}
{% assign depreciation_total = depreciation_total+$37 %}
{% assign $7 = 0 %} {% assign $8 = 0 %} {% assign $9 = 0 %}{% assign $37 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 4 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Bulls|Cows|Barreners|Heifers incalf|Heifers over 25 months|Heifers 19 to 24 months|Heifers 13 to 18 months|Heifers 7 to 12 months|Heifers 0 to 6 months|Beef Male cattle over 24 months|Beef Female cattle over 24 months|Beef Male cattle 19 to 24 months|Beef Female cattle 19 to 24 months|Beef Male cattle 13 to 18 months|Beef Female cattle 13 to 18 months|Beef Male cattle 7 to 12 months|Beef Female cattle 7 to 12 months|Beef Male cattle 0 to 6 months|Beef Female cattle 0 to 6 months" %}
| {% input detail.description  %}
| {% $10+input detail.number %}
| {% $11+input detail.marketvalue as:currency_dc %}
| {% input detail.mvpercentage as:select options:"60%|Cost" default:"60%" %} 
{% if detail.mvpercentage == "60%" %}{% assign percentage = 0.6 %}{% elsif detail.mvpercentage == "Cost" %}{% assign percentage = 1.0 %}{% endif %}
{% assign total_stock = (detail.number*detail.marketvalue)*percentage %}
| {%=$12+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}
| {% input stock.depreciation as:boolean %}
{% assign stock_depreciation = (detail.number*detail.marketvalue)*0.15 %}
| {% if stock.depreciation == true %} {%=$37+ stock_depreciation | currency_dc %} {% endif %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ **{{ $10 | currency_dc}}**^
|^ **{{ $11 | currency_dc}}**^
|^ ^
|^ **{{ $12 | currency_dc}}** ^
|^ ^
|^ ^
|^ **{{ $37 | currency_dc}}** ^

{% newline %}
{% assign grand_total = grand_total+$12 %}
{% assign depreciation_total = depreciation_total+$37 %}
{% assign $10 = 0 %} {% assign $11 = 0 %} {% assign $12 = 0 %}{% assign $37 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 5 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Rams|Ewes|Barren ewes|Young ewes|Sheraling/tups|Gimmer|Hogget|Ram lambs|Store lambs|Lambs" %}
| {% input detail.description  %}
| {% $13+input detail.number %}
| {% $14+input detail.marketvalue as:currency_dc %}
| {% input detail.mvpercentage as:select options:"75%|Cost" default:"75%" %} 
{% if detail.mvpercentage == "75%" %}{% assign percentage = 0.75 %}{% elsif detail.mvpercentage == "Cost" %}{% assign percentage = 1.0 %}{% endif %}
{% assign total_stock = (detail.number*detail.marketvalue)*percentage %}
| {%=$15+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}
| {% input stock.depreciation as:boolean %}
{% assign stock_depreciation = (detail.number*detail.marketvalue)*0.15 %}
| {% if stock.depreciation == true %} {%=$37+ stock_depreciation | currency_dc %} {% endif %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ **{{ $13 | currency_dc}}**^
|^ **{{ $14 | currency_dc}}**^
|^ ^
|^ **{{ $15 | currency_dc}}** ^
|^ ^
|^ ^
|^ **{{ $37 | currency_dc}}** ^

{% newline %}
{% assign grand_total = grand_total+$15 %}
{% assign depreciation_total = depreciation_total+$37 %}
{% assign $13 = 0 %} {% assign $14 = 0 %} {% assign $15 = 0 %}{% assign $37 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 6 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Boars|Sows|Barren sows|Gilts|Store pigs|Porkers|Piglets" %}
| {% input detail.description  %}
| {% $16+input detail.number %}
| {% $17+input detail.marketvalue as:currency_dc %}
|  {% input detail.mvpercentage as:select options:"75%|Cost" default:"75%" %} 
{% if detail.mvpercentage == "75%" %}{% assign percentage = 0.75 %}{% elsif detail.mvpercentage == "Cost" %}{% assign percentage = 1.0 %}{% endif %}
{% assign total_stock = (detail.number*detail.marketvalue)*percentage %}
| {%=$18+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}
| {% input stock.depreciation as:boolean %}
{% assign stock_depreciation = (detail.number*detail.marketvalue)*0.15 %}
| {% if stock.depreciation == true %} {%=$37+ stock_depreciation | currency_dc %} {% endif %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ **{{ $16 | currency_dc}}**^
|^ **{{ $17 | currency_dc}}**^
|^ ^
|^ **{{ $18 | currency_dc}}** ^
|^ ^
|^ ^
|^ **{{ $37 | currency_dc}}** ^

{% newline %}
{% assign grand_total = grand_total+$18 %}
{% assign depreciation_total = depreciation_total+$37 %}
{% assign $16 = 0 %} {% assign $17 = 0 %} {% assign $18 = 0 %}{% assign $37 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 7 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Cockerals|Laying hens|Turkeys|Geese|Ducks|Pheasants|Partridge" %}
| {% input detail.description  %}
| {% $19+input detail.number %}
| {% $20+input detail.marketvalue as:currency_dc %}
| {% input detail.mvpercentage as:select options:"75%|Cost" default:"75%" %} 
{% if detail.mvpercentage == "75%" %}{% assign percentage = 0.75 %}{% elsif detail.mvpercentage == "Cost" %}{% assign percentage = 1.0 %}{% endif %}
{% assign total_stock = (detail.number*detail.marketvalue)*percentage %}
| {%=$21+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}
| {% input stock.depreciation as:boolean %}
{% assign stock_depreciation = (detail.number*detail.marketvalue)*0.15 %}
| {% if stock.depreciation == true %} {%=$37+ stock_depreciation | currency_dc %} {% endif %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ **{{ $19 | currency_dc}}**^
|^ **{{ $20 | currency_dc}}**^
|^ ^
|^ **{{ $21 | currency_dc}}** ^
|^ ^
|^ ^
|^ **{{ $37 | currency_dc}}** ^

{% newline %}
{% assign grand_total = grand_total+$21 %}
{% assign depreciation_total = depreciation_total+$37 %}
{% assign $19 = 0 %} {% assign $20 = 0 %} {% assign $21 = 0 %}{% assign $37 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 8 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Stallions|Breeding mares|Brood mares|Geldings|Fillies|Foals" %}
| {% input detail.description  %}
| {% $22+input detail.number %}
| {% $23+input detail.marketvalue as:currency_dc %}
| {% input detail.mvpercentage as:select options:"75%|Cost" default:"75%" %} 
{% if detail.mvpercentage == "75%" %}{% assign percentage = 0.75 %}{% elsif detail.mvpercentage == "Cost" %}{% assign percentage = 1.0 %}{% endif %}
{% assign total_stock = (detail.number*detail.marketvalue)*percentage %}
| {%=$24+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}
| {% input stock.depreciation as:boolean %}
{% assign stock_depreciation = (detail.number*detail.marketvalue)*0.15 %}
| {% if stock.depreciation == true %} {%=$37+ stock_depreciation | currency_dc %} {% endif %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ **{{ $22 | currency_dc}}**^
|^ **{{ $23 | currency_dc}}**^
|^ ^
|^ **{{ $24 | currency_dc}}** ^
|^ ^
|^ ^
|^ **{{ $37 | currency_dc}}** ^

{% newline %}
{% assign grand_total = grand_total+$24 %}
{% assign depreciation_total = depreciation_total+$37 %}
{% assign $22 = 0 %} {% assign $23 = 0 %} {% assign $24 = 0 %}{% assign $37 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 9 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Grass silage|Maize silage|Haylage|Straw|Whole crop silage|Hay" %}
| {% input detail.description  %}
| {% $25+input detail.number %}
| {% $26+input detail.marketvalue as:currency_dc %}
| {% input detail.mvpercentage as:select options:"75%|Cost" default:"75%" %} 
{% if detail.mvpercentage == "75%" %}{% assign percentage = 0.75 %}{% elsif detail.mvpercentage == "Cost" %}{% assign percentage = 1.0 %}{% endif %}
{% assign total_stock = (detail.number*detail.marketvalue)*percentage %}
| {%=$27+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}
| {% input stock.depreciation as:boolean %}
{% assign stock_depreciation = (detail.number*detail.marketvalue)*0.15 %}
| {% if stock.depreciation == true %} {%=$37+ stock_depreciation | currency_dc %} {% endif %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ **{{ $25 | currency_dc}}**^
|^ **{{ $26 | currency_dc}}**^
|^ ^
|^ **{{ $27 | currency_dc}}** ^
|^ ^
|^ ^
|^ **{{ $37 | currency_dc}}** ^

{% newline %}
{% assign grand_total = grand_total+$27 %}
{% assign depreciation_total = depreciation_total+$37 %}
{% assign $25 = 0 %} {% assign $26 = 0 %} {% assign $27 = 0 %}{% assign $37 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 10 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Organic milling wheat|Milling wheat|Feed wheat|Organice malting barley|Malting barley|Feed barley|Organic oats|Oats|Oil seed rape|Linseed|Peas|Beans|Potatoes|Sugar beet" %}
| {% input detail.description  %}
| {% $28+input detail.number %}
| {% $29+input detail.marketvalue as:currency_dc %}
| {% input detail.mvpercentage as:select options:"75%|Cost" default:"75%" %} 
{% if detail.mvpercentage == "75%" %}{% assign percentage = 0.75 %}{% elsif detail.mvpercentage == "Cost" %}{% assign percentage = 1.0 %}{% endif %}
{% assign total_stock = (detail.number*detail.marketvalue)*percentage %}
| {%=$30+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}
| {% input stock.depreciation as:boolean %}
{% assign stock_depreciation = (detail.number*detail.marketvalue)*0.15 %}
| {% if stock.depreciation == true %} {%=$37+ stock_depreciation | currency_dc %} {% endif %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ **{{ $28 | currency_dc}}**^
|^ **{{ $29 | currency_dc}}**^
|^ ^
|^ **{{ $30 | currency_dc}}** ^
|^ ^
|^ ^
|^ **{{ $37 | currency_dc}}** ^

{% newline %}
{% assign grand_total = grand_total+$30 %}
{% assign depreciation_total = depreciation_total+$37 %}
{% assign $28 = 0 %} {% assign $29 = 0 %} {% assign $30 = 0 %}{% assign $37 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 11 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Winter organic wheat|Winter wheat|Winter organic barley|Winter barley|Winter organic oats|Winter oats|Winter oil seed rape|Winter beans|Winter new grass leys|Winter second grass leys|Spring organic barley|Spring barley|Spring organic oats|Spring oats|Spring oil seed rape|Spring beans|Spring peas|Spring maize|Spring potatoes|Crops on other land - wheat|Crops on other land - Barley|Crops on other land - Maize" %}
| {% input detail.description  %}
| {% $31+input detail.number %}
| {% $32+input detail.marketvalue as:currency_dc %}
| 
{% assign total_stock = (detail.number*detail.marketvalue) %}
| {%=$33+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}
| {% input stock.depreciation as:boolean %}
{% assign stock_depreciation = (detail.number*detail.marketvalue)*0.15 %}
| {% if stock.depreciation == true %} {%=$37+ stock_depreciation | currency_dc %} {% endif %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ **{{ $31 | currency_dc}}**^
|^ **{{ $32 | currency_dc}}**^
|^ ^
|^ **{{ $33 | currency_dc}}** ^
|^ ^
|^ ^
|^ **{{ $37 | currency_dc}}** ^

{% newline %}
{% assign grand_total = grand_total+$33 %}
{% assign depreciation_total = depreciation_total+$37 %}
{% assign $31 = 0 %} {% assign $32 = 0 %} {% assign $33 = 0 %}{% assign $37 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}



{% if stock.type == 12 %}
{% if stock.tick == true %}

{% fori detail in custom[stock.name.key] %}

| {% input detail.type as:select options:"Concentrates|Feed|Other feed|Minerals|Fertiliser - nitrogen|Fertiliser - NPK|Fertiliser - other|Sprays|Sprays - other|Lime|Derv|Gas oil|Petrol|Oil|Veterinary supplies|Dairy chemicals|Semen|Embryos|Fencing materials|Twine & net wrap" %}
| {% input detail.description  %}
| {% $34+input detail.number %}
| {% $35+input detail.marketvalue as:currency_dc %}
| 
{% assign total_stock = (detail.number*detail.marketvalue) %}
| {%=$36+ total_stock | currency_dc %}
| {% ic %}{% input detail.extra_comment placeholder:"Comment" %}{% endic %}{% nic %}{{ detail.extra_comment | multiline_table }}{% endnic %}
| {% input stock.depreciation as:boolean %}
{% assign stock_depreciation = (detail.number*detail.marketvalue)*0.15 %}
| {% if stock.depreciation == true %} {%=$37+ stock_depreciation | currency_dc %} {% endif %}

{% newline %}

{% if forloop.last %}

|^ **Total** ^
|^ ^
|^ **{{ $34 | currency_dc}}**^
|^ **{{ $35 | currency_dc}}**^
|^ ^
|^ **{{ $36 | currency_dc}}** ^
|^ ^
|^ ^
|^ **{{ $37 | currency_dc}}** ^

{% newline %}
{% assign grand_total = grand_total+$36 %}
{% assign depreciation_total = depreciation_total+$37 %}
{% assign $34 = 0 %} {% assign $35 = 0 %} {% assign $36 = 0 %}{% assign $37 = 0 %}

{% endif %}
{% endfori %}
{% endif %}
{% endif %}

{% endfori %}

{% endstripnewlines %}

<!------------------------------------------------- END -------------------------------------------->

{% stripnewlines %}
{% newline %}
|----20%----
|-----20%----
|----10%----:
|----10%----:
|----10%----:
|----10%----:
|----10%----
|:----3%----:
|----5%----+
{% newline %}
|
|
|
|
|
|
|
|
|
{% newline %}
|^**Grand Total**^
|^^
|^^
|^^
|^^
|^**{{ grand_total | currency_dc}}**{% unreconciled grand_total-current_account.value as:indicator %}^
|^^
|^^
|^**{{ depreciation_total | currency_dc}}**^

{% endstripnewlines %}'''

Hi Neil,

For the variable to be independent you should rename it to detail.depreciation. This is because your boolean is part of the below loop and always needs to start with the same word:

{% fori detail in custom[stock.name.key] %}

Let me know if that works for you.

Best,
Borja

That’s worked perfectly, thank you for all your help, we should be sorted on the stock schedule now :slight_smile:

Great, let me know if you get stuck with anything else :wink: