mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Code tidying and currency symbol internationalisation
This commit is contained in:
@@ -92,10 +92,12 @@
|
||||
= label_tag :included_tax, t(:included_tax)
|
||||
%span.icon-question-sign{'ofn-with-tip' => "The total tax included in the example monthly bill, given the settings and the turnover provided."}
|
||||
.two.columns.omega
|
||||
%input.fullwidth{ id: 'included_tax', type: "text", readonly: true, ng: { value: 'includedTax() | currency' } }
|
||||
%span= Spree::Money.currency_symbol
|
||||
%input.fullwidth{ id: 'included_tax', type: "text", readonly: true, ng: { value: 'includedTax()' } }
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= label_tag :total_incl_tax, t(:total_monthly_bill_incl_tax)
|
||||
%span.icon-question-sign{'ofn-with-tip' => "The example total monthly bill with tax included, given the settings and the turnover provided."}
|
||||
.two.columns.omega
|
||||
%input.fullwidth{ id: 'total_incl_tax', type: "text", readonly: true, ng: { value: 'total() | currency' } }
|
||||
%span= Spree::Money.currency_symbol
|
||||
%input.fullwidth{ id: 'total_incl_tax', type: "text", readonly: true, ng: { value: 'total()' } }
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
module OpenFoodNetwork
|
||||
module OpenFoodNetwork
|
||||
class BillCalculator
|
||||
attr_accessor :turnover, :fixed, :rate, :cap, :tax_rate, :min_bill_to
|
||||
|
||||
def initialize(opts={})
|
||||
@turnover = opts[:turnover] || 0
|
||||
@fixed = opts[:fixed] || Spree::Config[:account_invoices_monthly_fixed]
|
||||
@rate = opts[:rate] || Spree::Config[:account_invoices_monthly_rate]
|
||||
@cap = opts[:cap] || Spree::Config[:account_invoices_monthly_cap]
|
||||
@tax_rate = opts[:tax_rate] || Spree::Config[:account_invoices_tax_rate]
|
||||
@min_bill_to = opts[:min_bill_to] || Spree::Config[:minimum_billable_turnover]
|
||||
defaults = {
|
||||
fixed: :account_invoices_monthly_fixed
|
||||
rate: :account_invoices_monthly_rate
|
||||
cap: :account_invoices_monthly_cap
|
||||
tax_rate: :account_invoices_tax_rate
|
||||
min_bill_to: :minimum_billable_turnover
|
||||
}
|
||||
defaults.each do |key, config|
|
||||
this[key] = opts[key] || Spree::Config[config]
|
||||
end
|
||||
end
|
||||
|
||||
def bill
|
||||
bill = fixed + (turnover * rate)
|
||||
bill = cap > 0 ? [bill, cap].min : bill
|
||||
bill = [bill, cap].min if cap > 0
|
||||
bill = turnover > min_bill_to ? bill : 0
|
||||
bill * (1 + tax_rate)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user