Sha256: 2a01b9a165c46cc167d1bfa6710eb6c79bdf9881d394b44728a67aba7a37ef8d

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

class Pass < ActiveRecord::Base
  belongs_to  :pass_type
  belongs_to  :person
  belongs_to  :organization
  has_many    :tickets

  def self.for(pass_type)
    new.tap do |pass|
      pass.pass_type  = pass_type
      pass.organization     = pass_type.organization
      pass.price            = pass_type.price
      pass.sold_price       = pass.price
      pass.tickets_allowed  = pass_type.tickets_allowed
      pass.tickets_allowed  = 0
      pass.pass_code        = new_pass_code
    end
  end  

  def cart_price
    price
  end

  def realized_fee
    self.pass_type.hide_fee? ? self.price * PassType::SERVICE_FEE : 0
  end

  def self.new_pass_code(size=8)
    # Avoid confusable characters like 1/L and 0/O
    charset = %w{ 2 3 4 6 7 9 A C D E F G H J K M N P Q R T V W X Y Z}
    (0...size).map{ charset.to_a[rand(charset.size)] }.join
  end

  def apply_pass_to_cart(cart)
    transaction do
      cart.applied_pass = self
      cart.tickets.each do |ticket|
        ticket.pass = self
        ticket.cart_price = 0
        ticket.save
      end
      FeeCalculator.apply(FeeStrategy.new).to(cart)
      cart.save
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
artfully_ose-1.2.0.pre.23 app/models/pass.rb