Skip to content

Instantly share code, notes, and snippets.

@gnufied
Created October 15, 2010 22:22
Show Gist options
  • Save gnufied/629074 to your computer and use it in GitHub Desktop.
Save gnufied/629074 to your computer and use it in GitHub Desktop.
user_addons = profile.charges.where(:parent_id => nil)
total_charge = 0
user_addons.each do |user_addon|
addon_history = user_addon.children.where(["timestamp > ", Time.beginning_of_the_month]).order(:version).asc
unless addon_history.blank?
duration_in_use = 0
last_active_timestamp = Time.beginning_of_the_month
addon_history.each do |record|
if(record.active?)
duration_in_use += record.updated_at - last_active_timestamp
last_active_timestamp = record.updated_at
else
last_active_timestamp = record.updated_at
end
end
elsif(user_addon.active?)
timediff = (Time.now - Time.beginning_of_the_month).days
total_charge += (user_addon.addon.charge*timediff)/user_addon.addon.duration
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment