Hey @Pieter1,
If you’re completely new in STL, this might be a little be too much in the beginning, but I’ll try to explain you how this function is tackled in our standard code
{% comment %} vanaf 1/1/2017 update percentage vr VU 17% -> 40% indien tankkaart. Wordt meegeteld met link naar 'belastingberekening' -update 22/4/2017{% endcomment %}
{% assign jaar = period.year_end_date | date:'%Y' %}
{% if jaar >= '2017' %}
{% assign accounts_f_40_new = true %}
{% assign accounts_f_perc = 0.40 %}
{% endif %}
So here we look at the year for the last period of the book year; if that is 2017
we’ll need to use a new percentage.
That’s what this does :
{% if jaar >= '2017' %}
{% assign accounts_f_40_new = true %}
{% assign accounts_f_perc = 0.40 %}
{% endif %}
further more, we’ll have this code :
{% comment %}
onderstaande is enkel voor gebroken boekjaar op te vangen van 2016-2017, waarbij deel 2016 aan 17% is, en 2017 aan 40% is -
boekjaren die 3 kalenderjaren beslaan, wordt niet ondersteund
voor beide jaren wordt gerekend met de teller = 365 dagen
{% endcomment %}
{% if jaar == '2017' %}
{% if period.calendar_years.size == 2 %}
{% assign broken_by_2017 = true %}
{% endif %}
{% endif %}
Basically, what we do here, is check if it’s indeed book year 2017 BUT also to check if it’s a broken book year.
We can know this by following code :
{% if period.calendar_years.size == 2 %}
{% assign broken_by_2017 = true %}
{% endif %}
So this variable period.calendar_years.size
gives us how many calendar years there are in one current book year. If it’s 2, we have ourselves a broken book year.
Finally, we have the big code that generates the calculations with the right percentage, and a split up between 2016 and 2017 in case of a broken book year :
{% if accounts_f_40_new %}
{% ifi accounts_f_40 != empty or custom.f_40 != empty or check == true %}
{{ title_header }}
| **{% t "Met tankkaart" %}** {% input custom.accounts.f_40 as:account_collection range:6,7 range:range_tankkaart %}{% assign $1 = 0 %}
| {% ic %}*{% t "koppel hier de rekeningen die betrekking hebben op autokosten met tankkaart" %}*{% endic %}
{{ accounts_header }}{% for account in accounts_f_40 %}
|| {{ account.number }} {{ account.name }} | {%=$1+ ABS(account.value) %}{% endfor %}{% fori extra in custom.f_40 %}
|| {% input extra.description %} | {%=$1+input extra.value as:currency placeholder:'0'%}{% endfori %}{% if broken_by_2017 %}
||{% ic %}*{% t "Er wordt gerekend met aantal dagen kalenderjaar / door aantal dagen begin boekjaar tot einddatum periode" %}*{% endic %}{% for year in period.calendar_years %}{% stripnewlines %}
{% assign start_date = year.start_date %}
{% assign end_date = year.end_date %}
{% assign by = year.end_date | date:'%Y' %}
{% assign amount_of_days = end_date+1-start_date %}
{% assign $3 = 0 %}
{% endstripnewlines %}
|| {% t "Deel" %} {{ year.start_date | date:'%Y' }}| {% assign deel_bj = $1*amount_of_days/total_days_in_book_year %}*{% $3+input custom[year].tankkaart.deel_bj as:currency placeholder_default:deel_bj %}* | {% if by == '2017' %}{{ accounts_f_perc*100 | integer }}% | {% assign autokosten_vaa_new_aj = $3*accounts_f_perc | round %}{% if autokosten_vaa_new_aj <= 0 %}*{%=$0+ 0 | currency %}*{% else %}*{%=$0+ autokosten_vaa_new_aj | currency %}*{% endif %}{% else %} 17% | {% assign autokosten_vaa_old_aj = $3*0.17 | round %}{% if autokosten_vaa_old_aj <= 0 %}*{%=$0+ 0 | currency %}*{% else %}*{%=$0+ autokosten_vaa_old_aj | currency %}*{% endif %}{% endif %}{% endfor %}{% endif %}{% unless broken_by_2017 %}
|| | *{{ $1 | currency }}* | {{ accounts_f_perc*100 | integer }}% | {% assign autokosten_vaa_new_aj = $1*accounts_f_perc | round %}*{%=$0+ autokosten_vaa_new_aj | currency %}*{% endunless %}
{% nic %}
{:/group}
{::group}
{% endnic %}
{% endifi %}
{% endif %}
{% endifi %}
Can this be a start for you to tackle this code? I don’t want to dig in deeper with you, because it might be too much the first time around.
Can you try with your code?
PS every quarter we give 3 technical workshops (for free!) for people that want to start with STL; no need to have experience in coding because we start from scratch.
More info here