Skip to content

Instantly share code, notes, and snippets.

@valachi
Created June 18, 2013 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valachi/5804277 to your computer and use it in GitHub Desktop.
Save valachi/5804277 to your computer and use it in GitHub Desktop.
def forfeited_amount
sum = 0
all_grants.each do |grant|
sum += grant.forfeitures.between(from_date, to_date).sum(:amount)
end
sum
end
def second_forfeited_amount
all_grants.joins(:forfeitures)
.where("option_grant_actions.created_at > ? AND option_grant_actions.created_at < ?", from_date.beginning_of_day, to_date.end_of_day)
.select("option_grants.*, option_grant_actions.created_at AS forfeiture_created_at,"\
"option_grant_actions.amount AS forfeited_amount")
.map{ |it| it.forfeited_amount.to_i }.sum
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment