I’m making a overview of all the investments based on the details given in the template “Depreciation and investment table”.
Now I only need to output the totals per year.
So if there are 3 investments in 2011 they need to sum of those details.
The code already sums up the first year in the details but the following details output 0. So I made a mistake but I can’t seem to find where.
I would do it like this (based on what we use as well in the standard template to create the details):
_Installaties_{% assign current_account = #230000 %}
{% addnewinputs %}
{% assign details = current_account.details | sort:'date' %}
{% endaddnewinputs %}
{% for detail in details %}
{% comment %}when date is input, we can create the book year it belongs to{% endcomment %}
{% if detail.date == blank %}
{% assign new_year = "" %}
{% else %}
{% assign new_year = company.periods[detail.date].year_end_date | date:'%Y' %}
{% endif %}
{% comment %}display the total of each book year only when the last detail is given of each book year{% endcomment %}
{% if current_year != blank and current_year != new_year %}
**Totaal {{ current_year }}** _{{ $4 | currency }}_
{% assign current_year = new_year %}
{% comment %}at the end of each book year, we will need to reset the register $4{% endcomment %}
{% assign $4 = 0 %}
{% endif %}
{% if current_year == blank %}
{% assign current_year = new_year %}
{% endif %}
{% $4+ detail.value %}
{% endfor %}
I added extra comment-tags where I think explanation is needed. Let me know if this is not what you’re looking for.
If it is, let me know as well so this topic can be marked as a solution
so in the “plain code” you can not see the 0 but in the table above (about the same coding) I always have a 0 line.
_Installaties_{% assign current_account = #230000 %}
{% addnewinputs %}
{% assign details = current_account.details | sort:'date' %}
{% endaddnewinputs %}
{% fori detail in details %}
{% if forloop.first %} {% assign $4 = 0 %}
|Jaar|vorig bj |a/b |boekjaar|Waarde|D/L|%|Vorige boekj|Boekj|Balans|BW|
|----|---------|----|--------|------|:--:|:--|--------:|-----|------|-----:+{% endif %}
{% stripnewlines %}{% comment %}when date is input, we can create the book year it belongs to{% endcomment %}
{% if detail.date == blank %}
{% assign new_year = "" %}
{% else %}
{% assign new_year = company.periods[detail.date].year_end_date | date:'%Y' %}
{% endif %}
{% comment %}display the total of each book year only when the last detail is given of each book year{% endcomment %}
{% if current_year != blank and current_year != new_year and current_year != blank %}
|{{ current_year }}
|{{ $4 | currency }}
|a
|aanschaf
|bal & aan
|{{"L/D"}}
|{{"5"}}
|afschr
|afschr nu
|tot af
|boekw{% assign current_year = new_year %}
{% comment %}at the end of each book year, we will need to reset the register $4{% endcomment %}
{% assign $4 = 0 %}
{% endif %}
{% if current_year == blank %}
{% assign current_year = new_year %}
{% endif %}
{% $4+ detail.value %}
{% endstripnewlines %} {% endfori %}
Code community:
{% for detail in details %}
{% comment %}when date is input, we can create the book year it belongs to{% endcomment %}
{% if detail.date == blank %}
{% assign new_year = "" %}
{% else %}
{% assign new_year = company.periods[detail.date].year_end_date | date:'%Y' %}
{% endif %}
{% comment %}display the total of each book year only when the last detail is given of each book year{% endcomment %}
{% if current_year != blank and current_year != new_year and current_year != blank %}
**Totaal {{ current_year }}** _{{ $4 | currency }}_
{% assign current_year = new_year %}
{% comment %}at the end of each book year, we will need to reset the register $4{% endcomment %}
{% assign $4 = 0 %}
{% endif %}
{% if current_year == blank %}
{% assign current_year = new_year %}
{% endif %}
{% $4+ detail.value %}
{% endfor %}
I found my mistake, there is more code in the text than I showed you and some of the variables you used were already being used and assigned so I started with the wrong content.