Permalink
Browse files

Added methods for finding couny for ledger, tax zone for county and t…

…ax rate for tax zone
  • Loading branch information...
Nikola Trandafilovic
Nikola Trandafilovic committed Nov 22, 2011
1 parent ea93bf9 commit 255b5d3b0db2dc01c430bf507ce8f7424083aeb3
Showing with 34 additions and 1 deletion.
  1. +14 −0 app/models/county.rb
  2. +6 −1 app/models/ledger.rb
  3. +14 −0 app/models/tax_zone.rb
View
@@ -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
View
@@ -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
View
@@ -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.