foodsoft/app/models/concerns/price_calculation.rb

41 lines
872 B
Ruby
Raw Permalink Normal View History

module PriceCalculation
extend ActiveSupport::Concern
# Gross price = net price + deposit + tax.
# @return [Number] Gross price.
def gross_price
2023-09-28 22:42:52 +02:00
add_percent(price, tax) + deposit
end
def gross_price_without_deposit
add_percent(price, tax)
end
2023-09-28 22:42:52 +02:00
def net_deposit_price
remove_percent(deposit, tax)
end
# @return [Number] Price for the foodcoop-member.
def fc_price
add_percent(gross_price, FoodsoftConfig[:price_markup].to_i)
end
def fc_price_without_deposit
add_percent(gross_price_without_deposit, FoodsoftConfig[:price_markup].to_i)
end
def fc_deposit_price
2023-09-28 22:42:52 +02:00
add_percent(deposit, FoodsoftConfig[:price_markup].to_i)
end
private
2023-09-28 22:42:52 +02:00
def remove_percent(value, percent)
(value / ((percent * 0.01) + 1)).round(2)
end
def add_percent(value, percent)
(value * ((percent * 0.01) + 1)).round(2)
end
end