Class: TaxRate

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/tax_rate.rb

Overview

Schema Information

Table name: tax_rates

id            :integer(4)      not null, primary key
percentage    :decimal(8, 2)   default(0.0), not null
state_id      :integer(4)      not null
country_id      :integer(4)      not null
start_date    :date            not null
end_date      :date
active        :boolean(1)      default(TRUE)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) active



32
33
34
# File 'app/models/tax_rate.rb', line 32

def self.active
  where(["tax_rates.active = ?", true])
end

+ (Object) at(time = Time.zone.now)



36
37
38
39
# File 'app/models/tax_rate.rb', line 36

def self.at(time = Time.zone.now)
  where(["tax_rates.start_date <= ? AND
         (end_date > ? OR end_date IS NULL)", time.to_date.to_s(:db), time.to_date.to_s(:db)])
end

+ (Object) for_region(region_id)

region_id can be state or country depending on the setup in config/settings.yml



42
43
44
# File 'app/models/tax_rate.rb', line 42

def self.for_region(region_id)
  where(["#{ Settings.tax_per_state_id ? 'state_id' : 'country_id'} = ?", region_id ])
end

Instance Method Details

- (Object) tax_percentage



24
25
26
# File 'app/models/tax_rate.rb', line 24

def tax_percentage
  Settings.vat ? 0.0 : percentage
end

- (Object) vat_percentage



28
29
30
# File 'app/models/tax_rate.rb', line 28

def vat_percentage
  Settings.vat ? percentage : 0.0
end