Mark up rate Fixed and Percentage

Hi,

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.

Could you please help me with this ?

|**Total profit for Cost Plus purposes**
|
{% for detail in (1..y) %}
  {% assign expense_costs = custom.cost.centre[detail]  %}
  {% assign prev_expense_costs = period.minus_1p.accounts.include_zeros.[current_account].first.custom.cost.centre[detail] %}
  {% for item in (1..x) %}
    {% capture key2 %}{{ item }}_{{ detail }}{% endcapture %}
    {%$9+ custom.other[key2].centre %}
    {%$14+ period.minus_1p.accounts.include_zeros.[current_account].first.custom.other[key2].centre %}
  {% endfor %}
|**{{ expense_costs+$9 | currency_dc }}**
{% assign total_expense_cost = expense_costs+$9 %} 
{% assign prev_total_expense_cost = prev_expense_costs+$14 %}
{% assign total_profit = total_profit | append:total_expense_cost |append:';' %}
{% assign prev_total_profit = prev_total_profit | append:prev_total_expense_cost |append:';' %}

{% assign $9 = 0 %}
{% assign $14 = 0 %}
{% endfor %}
|**{{ $1+$4 | currency_dc }}**
|
|**{{$2 | currency_dc}}**

{% newline %}
{% assign total_profit = total_profit | split:';' %}
{% assign prev_total_profit = prev_total_profit | split:';' %}

|Mark up rate
|{% if y == 0 or y == blank %}{% input custom.costPlus.rate as:percentage default:costPlusMarkUp %}{% endif %}
{% for item in (1..y) %}
|{% input custom.costPlus.rate[item] as:percentage default:costPlusMarkUp %} 
{% endfor %}
{% 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 %}

Thank you,
Stefan

Hi @Stefan.Temelie

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.

Kind regards
Wouter

HI Wouter,

Those were indeed the requirements.

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 %}

Thank you,
Stefan

Hi Stefan,

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.

{% assign markup = custom.costPlus.rate | default:costPlusMarkUp %}

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.