Skip to content

Commit

Permalink
Added methods for finding couny for ledger, tax zone for county and t…
Browse files Browse the repository at this point in the history
…ax rate for tax zone
  • Loading branch information
Nikola Trandafilovic committed Nov 22, 2011
1 parent ea93bf9 commit 255b5d3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
14 changes: 14 additions & 0 deletions app/models/county.rb
Expand Up @@ -4,4 +4,18 @@ class County < ActiveRecord::Base
accepts_nested_attributes_for :county_tax_zones, :allow_destroy => false
accepts_nested_attributes_for :county_ledgers, :allow_destroy => false
validates_presence_of :name, :allow_nil => false

def tax_zone_at_date date
if !self.county_tax_zones.blank?
tz = self.county_tax_zones.where('"from" <= ? ', date).where('is_visible is true').order('"from" asc').first
if tz != nil
return tz.tax_zone
else
return nil
end
else
[]
end
end

end
7 changes: 6 additions & 1 deletion app/models/ledger.rb
Expand Up @@ -48,7 +48,12 @@ def last_name

def county_at_date date
if !self.county_ledgers.blank?
self.county_ledgers.where('"from" <= ? ', date).first.county
c = self.county_ledgers.where('"from" <= ? ', date).order('"from" asc').first
if c != nil
return c.county
else
return nil
end
else
[]
end
Expand Down
14 changes: 14 additions & 0 deletions app/models/tax_zone.rb
Expand Up @@ -3,4 +3,18 @@ class TaxZone < ActiveRecord::Base
has_many :county_tax_zones
accepts_nested_attributes_for :county_tax_zones, :allow_destroy => false
accepts_nested_attributes_for :tax_zone_taxes, :allow_destroy => false

def tax_zone_rate_at_date date
tr = nil
if !self.tax_zone_taxes.blank?
tr = self.tax_zone_taxes.where('"from" <= ? ', date).where('is_visible is true').order('"from" asc').first
end

if tr != nil
return tr.tax_rate.to_f
else
return nil
end
end

end

0 comments on commit 255b5d3

Please sign in to comment.