Sha256: a36739ebe9514df61093be9f7a7beedb82f929c8627825baec2d54943500b088

Contents?: true

Size: 931 Bytes

Versions: 21

Compression:

Stored size: 931 Bytes

Contents

module Valuation

  #
  # Anything with a :lifetime_ticket_value column and has_many orders can use this module.
  #
  module LifetimeTicketValue
    extend ActiveSupport::Concern
    
    #
    # Includers can define a method called lifetime_orders which
    # will override this method.
    #
    # lifetime_orders should return the orders that this model wants to include in the calculation
    #  
    def lifetime_orders
      orders
    end
    
    #
    # Calculate the lifetime value of this model by summing the price of all items 
    # attached to orders attached to this person.  Save the value in lifetime_value.
    # Return the value
    #
    def calculate_lifetime_ticket_value
      self.lifetime_ticket_value = Item.where(:order_id => self.lifetime_orders).where(:product_type => "Ticket").sum(Item.total_price_sql_sum).to_i
      self.save(:validate => false)
      self.lifetime_ticket_value
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
artfully_ose-1.2.0.pre.23 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.21 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.20 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.19 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.18 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.17 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.16 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.15 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.12 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.11 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.10 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.9 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.8 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.7 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.6 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.5 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.4 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.3 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.2 app/models/valuation/lifetime_ticket_value.rb
artfully_ose-1.2.0.pre.1 app/models/valuation/lifetime_ticket_value.rb