Class: Ticket

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
ActionView::Helpers::TextHelper
Includes:
ActiveRecord::Transitions, Ext::Integrations::Ticket, Ext::Resellable::Ticket, Pricing, SaleTransitions, Transfers
Defined in:
app/models/ticket.rb

Defined Under Namespace

Modules: Foundry, Pricing, Reporting, Reports, SaleTransitions, Transfers Classes: Glance, Template

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SaleTransitions

#put_on_sale, #take_off_sale

Methods included from Transfers

#comp_to, #exchange_to, #return!, #sell_to

Methods included from Pricing

#cart_price, #change_price, #exchange_prices_from, #remove_from_cart, #reset_price!, #set_cart_price

Methods included from Ext::Integrations::Ticket

#record_comp, #record_exchange, #record_sale

Methods included from Ext::Resellable::Ticket

#reseller

Class Method Details

.available(params = {}, limit = 4) ⇒ Object

Unfortunately named. This will return available tickets, not a count of available tickets as is the idiom elsewhere in the app



74
75
76
77
78
79
# File 'app/models/ticket.rb', line 74

def self.available(params = {}, limit = 4)
  conditions = params.dup
  conditions[:state] ||= :on_sale
  conditions[:cart_id] = nil
  where(conditions).limit(limit)
end

.build_one(show, section, price, quantity, on_sale = false) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
# File 'app/models/ticket.rb', line 163

def self.build_one(show, section, price, quantity, on_sale = false)
  t = Ticket.new({
    :venue => show.event.venue.name,
    :price => price,
    :section => section,
  })
  t.show = show
  t.organization = show.organization
  t.state = 'on_sale' if on_sale
  t
end

.create_many(show, section, quantity, on_sale = false) ⇒ Object

Bulk creation of tickets should use this method to ensure all tickets are created the same Reminder that this returns a ActiveRecord::Import::Result, not an array of tickets



153
154
155
156
157
158
159
160
161
# File 'app/models/ticket.rb', line 153

def self.create_many(show, section, quantity, on_sale = false)
  new_tickets = []
  quantity.times do
    new_tickets << build_one(show, section, section.price, quantity, on_sale)
  end
  
  result = Ticket.import(new_tickets)
  result
end

.feeObject



99
100
101
# File 'app/models/ticket.rb', line 99

def self.fee
  0
end

.sold_after(datetime) ⇒ Object



25
26
27
# File 'app/models/ticket.rb', line 25

def self.sold_after(datetime)
  sold.where("sold_at > ?", datetime)
end

.sold_before(datetime) ⇒ Object



29
30
31
# File 'app/models/ticket.rb', line 29

def self.sold_before(datetime)
  sold.where("sold_at < ?", datetime)
end

.to_sentence(tickets) ⇒ Object



64
65
66
67
68
# File 'app/models/ticket.rb', line 64

def self.to_sentence(tickets)
  shows_string = tickets.map(&:show).uniq.length > 1 ? ", multiple shows" : " on " + I18n.localize(tickets.first.show.datetime_local_to_event, :format => :day_time_at)
  events_string = tickets.map(&:show).map(&:event).uniq.length > 1 ? "multiple events" : tickets.first.show.event.name + shows_string
  pluralize(tickets.length, "ticket") + " to " + events_string
end

.unsoldObject



60
61
62
# File 'app/models/ticket.rb', line 60

def self.unsold
  where(:state => [:off_sale, :on_sale])
end

Instance Method Details

#as_json(options = {}) ⇒ Object



56
57
58
# File 'app/models/ticket.rb', line 56

def as_json(options = {})
  super(options).merge!({:section => section})
end

#committed?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'app/models/ticket.rb', line 119

def committed?
  sold? or comped?
end

#compable?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'app/models/ticket.rb', line 135

def compable?
  on_sale? or off_sale?
end

#datetimeObject



52
53
54
# File 'app/models/ticket.rb', line 52

def datetime
  show.datetime_local_to_event
end

#destroyObject



143
144
145
# File 'app/models/ticket.rb', line 143

def destroy
  super if destroyable?
end

#destroyable?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'app/models/ticket.rb', line 131

def destroyable?
  !sold? and !comped? and items.empty?
end

#exchangeable?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'app/models/ticket.rb', line 111

def exchangeable?
  !expired? and sold?
end

#expired?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'app/models/ticket.rb', line 103

def expired?
  datetime < DateTime.now
end

#off_saleable?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'app/models/ticket.rb', line 127

def off_saleable?
  on_sale?
end

#on_saleable?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'app/models/ticket.rb', line 123

def on_saleable?
  !(sold? or comped?)
end

#refundable?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'app/models/ticket.rb', line 107

def refundable?
  sold?
end

#repriceable?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'app/models/ticket.rb', line 147

def repriceable?
  not committed?
end

#resellable?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'app/models/ticket.rb', line 139

def resellable?
  on_sale?
end

#returnable?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'app/models/ticket.rb', line 115

def returnable?
  !expired?
end

#settled_itemObject



85
86
87
# File 'app/models/ticket.rb', line 85

def settled_item
  @settled_item ||= items.select(&:settled?).first
end

#settlement_idObject



81
82
83
# File 'app/models/ticket.rb', line 81

def settlement_id
  settled_item.settlement_id unless settled_item.nil?
end

#sold_itemObject



89
90
91
92
93
# File 'app/models/ticket.rb', line 89

def sold_item
  items.select(&:purchased?).first ||
  items.select(&:settled?).first ||
  items.select(&:comped?).first
end

#special_instructionsObject



95
96
97
# File 'app/models/ticket.rb', line 95

def special_instructions
  sold_item.nil? ? nil : sold_item.order.special_instructions
end