<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -7,10 +7,10 @@ class Appearance &lt; ActiveRecord::Base
   attr_accessor :saw_at
   
   before_save :set_timefields
-  after_save { |record| record.device.update_attribute(:appearance_id, record.id) }
+  after_save :record_billing
   
   named_scope :current, { :conditions =&gt; ['last_seen_at &gt; ?', 5.minutes.ago] }
-  named_scope :today, { :conditions =&gt; ['day_number=?', Time.now.day_number] }
+  named_scope :today, lambda { { :conditions =&gt; ['day_number=?', Time.now.day_number] } }
   named_scope :recent, :order =&gt; 'id DESC'
 
   def self.store(saw, ip, mac, name=nil)
@@ -50,6 +50,14 @@ class Appearance &lt; ActiveRecord::Base
       end
     end
   end
+  
+  def record_billing
+    self.device.update_attribute(:appearance_id, self.id)
+    # determine if appearance is billable (match an active membership?)
+    # membership generates the bill
+    m = self.device.person.memberships.find(:all, :conditions =&gt; ['start_date &lt;= ? AND (end_date IS NULL OR end_date &gt; ?)', saw_at, saw_at]).first
+    m.bill_appearance(self)
+  end
 
   def image
     device.image</diff>
      <filename>app/models/appearance.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>0e2655d200d60392d68d3b104a91bcd9f66d9087</id>
    </parent>
  </parents>
  <author>
    <name>David Troy</name>
    <email>davetroy@teflon.local</email>
  </author>
  <url>http://github.com/davetroy/honeycomb/commit/1905cf9064efafd8840b5b0eacb1a874345e276e</url>
  <id>1905cf9064efafd8840b5b0eacb1a874345e276e</id>
  <committed-date>2009-10-20T15:31:34-07:00</committed-date>
  <authored-date>2009-10-20T15:31:34-07:00</authored-date>
  <message>appearance updates</message>
  <tree>5517790d22b00b44b72fd74a6e80da83b4b399b8</tree>
  <committer>
    <name>David Troy</name>
    <email>davetroy@teflon.local</email>
  </committer>
</commit>
