Skip to content

Instantly share code, notes, and snippets.

@fxposter
Created July 22, 2011 07:50
Show Gist options
  • Save fxposter/1099044 to your computer and use it in GitHub Desktop.
Save fxposter/1099044 to your computer and use it in GitHub Desktop.
claims = customer.claims.where(:deal_id => business.deal_ids)
last_ticket_creation_date = customer.tickets.where(:id.ne => id).order(:created_at.desc).first.try(:created_at)
claims = claims.where(:created_at.gt => tickets.last.created_at) if last_ticket_creation_date
deal_ids = claims.map(&:deal_id).uniq
deals_scope = business.deals.open_up.where(:id.in => deal_ids)
loyality_points = [deals_scope.open_up.max(:price), deals_scope.special.max(:loyalty_bonus), flyer ? flyer.value : 0].max
customer_relation = customer.customer_relations.where(:business => business).first
customer_relation.increment!(:gift_points, loyality_points) if customer_relation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment