I want Markup Rate to have two options. Either a percent either a fixed amount.
Based on my choice the calculation would be different for any of the options.
If I understood correctly, you have the following requirements for the markup:
1/ It can be either a fixed amount in a currency or a relative amount in a percentage.
2/ The mark up can be any amount or any percent.
3/ You can’t know beforehand if the user wants to add a fixed or relative mark up.
4/ You can’t combine both types of mark up.
5/ The calculation should change depending on which kind of mark up is entered.
If I got these requirements right, I think this code can help you further:
|Mark up rate
{% assign fixed_markup_rate = custom.costPlus.fixed %}
{% assign relative_markup_rate = custom.costPlus.rate %}
{% if y == 0 or y == blank %}{% unless relative_markup_rate != blank and fixed_markup_rate == blank %}{% input custom.costPlus.fixed as:currency default:costPlusMarkUp %}{% endunless %}{% endif %}
{% if y == 0 or y == blank %}{% unless fixed_markup_rate != blank and relative_markup_rate == blank %}{% input custom.costPlus.rate as:percentage default:costPlusMarkUp %}{% endunless %}{% endif %}
{% if fixed_markup_rate != blank and relative_markup_rate != blank %}
{% ic %}{::warningtext}
You can't combine a fixed and relative markup rate
{:/warningtext}{% endic %}
{% elsif fixed_markup_rate != blank and relative_markup_rate == blank %}
Fixed markup calculation
{% elsif relative_markup_rate != blank and fixed_markup_rate == blank %}
Relative markup calculation
{% else %}
Please complete the markup rate
{% endif %}
Feel free to let me know if your requirements differ from what I understood here.
The calculation under “Cost plus mark up” doesn’t change depending on which kind of mark up I chose.
And i am not sure how i can make that work either.
|Mark up rate
{% assign fixed_markup_rate = custom.costPlus.fixed %}
{% assign relative_markup_rate = custom.costPlus.rate %}
{% if y == 0 or y == blank %}{% unless relative_markup_rate != blank and fixed_markup_rate == blank %}{% input custom.costPlus.fixed as:currency default:costPlusMarkUp %}{% endunless %}{% endif %}
{% if y == 0 or y == blank %}{% unless fixed_markup_rate != blank and relative_markup_rate == blank %}{% input custom.costPlus.rate as:percentage default:costPlusMarkUp %}{% endunless %}{% endif %}
{% if fixed_markup_rate != blank and relative_markup_rate != blank %}
{% ic %}{::warningtext}
You can't combine a fixed and relative markup rate
{:/warningtext}{% endic %}
{% elsif fixed_markup_rate != blank and relative_markup_rate == blank %}
{% elsif relative_markup_rate != blank and fixed_markup_rate == blank %}
{% else %}
Please complete the markup rate
{% endif %}
{% newline %}
|Cost Plus mark up
|
{% for item in (1..y) %}
{% assign markup = custom.costPlus.rate[item] | default:costPlusMarkUp %}
|{%=$10+ markup | times:total_profit[forloop.index0] | currency_dc %}
{% endfor %}
{% if y == 0 or y == blank %}
{% assign markup = custom.costPlus.rate | default:costPlusMarkUp %}
{%$10+ markup*($1+$4) | currency_dc %}
{% endif %}
|{{ $10 | currency_dc }}
|
|{% if z > 0 %}{{ $12 | currency_dc }}{% else %}{% assign prev_mark_up = period.minus_1p.accounts.include_zeros.[current_account].first.custom.costPlus.rate | default:costPlusMarkUp %}{{ $2*prev_mark_up | currency_dc }}{% endif %}
{% newline %}
Taking a look at your new code extract, it seems that you have implemented the logic suggested for Wouter in your "Mark up rate" section, to use either fixed_markup_rate or relative_markup_rate (when y== 0)
Now, you should adapt the Cost Plus mark up section as well, since there you are using custom.costPlus.rate in every case.
But you would need to use either custom.costPlus.rate or custom.costPlus.fixed, depending on what was defined in the previous section. You can try something like:
{% if y == 0 or y == blank %}
{% if fixed_markup_rate != blank %}
{% assign markup = custom.costPlus.fixed | default:costPlusMarkUp %}
{%$10+ markup | currency_dc %}
{% elsif relative_markup_rate != blank %}
{% assign markup = custom.costPlus.rate | default:costPlusMarkUp %}
{%$10+ markup*($1+$4) | currency_dc %}
{% else %}
{% comment %}Consider what needs to happen if both are blank or both have values{% endcomment %}
{% endif %}
{% endif %}
All this modifications, both in the “Mark up rate” and " Cost Plus mark up" sections are taking into account in your y == 0 condition. So I guess you will have to consider if you want to replicate it inside your {% for item in (1..y) %} as well.