Class: Show

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveRecord::Transitions, Ext::Integrations::Show, Ext::Resellable::Show, Ext::Uuid, Ticket::Foundry, Ticket::Reporting
Defined in:
app/models/show.rb

Constant Summary

Constants included from Ext::Uuid

Ext::Uuid::PREFIX

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ext::Uuid

included, #set_uuid, uuid

Methods included from Ext::Integrations::Show

#record_publish

Methods included from Ticket::Reporting

#glance

Methods included from Ticket::Foundry

#build_tickets, #create_tickets, #foundry_template

Class Method Details

.next_datetime(show) ⇒ Object



100
101
102
# File 'app/models/show.rb', line 100

def self.next_datetime(show)
  show.nil? ? future(Time.now.beginning_of_day + 20.hours) : future(show.datetime_local_to_event + 1.day)
end

Instance Method Details

#<=>(obj) ⇒ Object



205
206
207
208
209
210
211
212
213
# File 'app/models/show.rb', line 205

def <=>(obj)
  return -1 unless obj.kind_of? Show

  if self.event == obj.event
    self.datetime <=> obj.datetime
  else
    self.event <=> obj.event
  end
end

#as_json(options = {}) ⇒ Object



128
129
130
131
132
133
134
135
136
137
# File 'app/models/show.rb', line 128

def as_json(options={})
  { "id" => id,
    "uuid" => uuid,
    "chart_id" => chart.id,
    "state" => state,
    "show_time" => show_time,
    "datetime" => datetime_local_to_event,
    "destroyable" => destroyable?
  }
end

#as_widget_json(options = {}) ⇒ Object



201
202
203
# File 'app/models/show.rb', line 201

def as_widget_json(options = {})
  as_json.merge(:event => event.as_json, :venue => event.venue.as_json, :chart => chart.as_json)
end

#bulk_change_price(ids, price) ⇒ Object



153
154
155
# File 'app/models/show.rb', line 153

def bulk_change_price(ids, price)
  tickets.where(:id => ids).collect{ |ticket| ticket.id if ticket.change_price(price) }.compact
end

#bulk_delete(ids) ⇒ Object



149
150
151
# File 'app/models/show.rb', line 149

def bulk_delete(ids)
  tickets.where(:id => ids).collect{ |ticket| ticket.id if ticket.destroy }#.compact
end

#bulk_off_sale(ids) ⇒ Object



144
145
146
147
# File 'app/models/show.rb', line 144

def bulk_off_sale(ids)
  targets = (ids == :all) ? tickets : tickets.where(:id => ids)
  Ticket.take_off_sale(targets)
end

#bulk_on_sale(ids) ⇒ Object



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

def bulk_on_sale(ids)
  targets = (ids == :all) ? tickets : tickets.where(:id => ids)
  Ticket.put_on_sale(targets)
end

#compable_ticketsObject



197
198
199
# File 'app/models/show.rb', line 197

def compable_tickets
  tickets.select(&:compable?)
end

#create_and_on_sale_ticketsObject



67
68
69
70
# File 'app/models/show.rb', line 67

def create_and_on_sale_tickets
  create_tickets
  bulk_on_sale(:all)
end

#destroyable?Boolean

Returns:

  • (Boolean)


173
174
175
# File 'app/models/show.rb', line 173

def destroyable?
  (tickets_comped + tickets_sold).empty? && items.empty?
end

#destroyable_ticketsObject



193
194
195
# File 'app/models/show.rb', line 193

def destroyable_tickets
  tickets.select(&:destroyable?)
end

#dup!Object



117
118
119
120
121
122
# File 'app/models/show.rb', line 117

def dup!
  copy = Show.new(self.attributes.reject { |key, value| key == 'id' || key == 'uuid' || key == 'state' })
  copy.event = self.event
  copy.datetime = copy.datetime + 1.day
  copy
end

#event_deleted?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'app/models/show.rb', line 80

def event_deleted?
  !unscoped_event.deleted_at.nil?
end

#go!(and_publish = true) ⇒ Object

wraps build, publish (or unpublish), and save



58
59
60
61
62
63
64
65
# File 'app/models/show.rb', line 58

def go!(and_publish = true)
  return false if !valid?
  transaction do
    build!    
    and_publish ? publish! : unpublish!
    save
  end
end

#gross_potentialObject



84
85
86
# File 'app/models/show.rb', line 84

def gross_potential
  @gross_potential ||= tickets.inject(0) { |sum, ticket| sum += ticket.price.to_i }
end

#gross_salesObject



88
89
90
# File 'app/models/show.rb', line 88

def gross_sales
  @gross_sales ||= tickets_sold.inject(0) { |sum, ticket| sum += ticket.price.to_i }
end

#has_door_list?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'app/models/show.rb', line 104

def has_door_list?
  published? or unpublished?
end

#imported?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'app/models/show.rb', line 76

def imported?
  unscoped_event.imported?
end

#live?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'app/models/show.rb', line 177

def live?
  (tickets_comped + tickets_sold).any?
end

#load(attrs) ⇒ Object



112
113
114
115
# File 'app/models/show.rb', line 112

def load(attrs)
  super(attrs)
  set_attributes(attrs)
end

#off_saleable_ticketsObject



189
190
191
# File 'app/models/show.rb', line 189

def off_saleable_tickets
  tickets.select(&:off_saleable?)
end

#on_saleable_ticketsObject



185
186
187
# File 'app/models/show.rb', line 185

def on_saleable_tickets
  tickets.select(&:on_saleable?)
end

#played?Boolean

Returns:

  • (Boolean)


181
182
183
# File 'app/models/show.rb', line 181

def played?
  datetime < Time.now
end

#reseller_settleablesObject



161
162
163
164
165
166
167
168
169
170
171
# File 'app/models/show.rb', line 161

def reseller_settleables
  settleables = {}

  items.includes(:reseller_order).select(&:reseller_order).reject(&:modified?).each do |item|
    reseller = item.reseller_order.organization
    settleables[reseller] ||= []
    settleables[reseller] << item
  end

  settleables
end

#reseller_sold_countObject



215
216
217
# File 'app/models/show.rb', line 215

def reseller_sold_count
  self.ticket_offers.inject(0) { |sum, to| sum + to.sold }
end

#settleablesObject



157
158
159
# File 'app/models/show.rb', line 157

def settleables
  items.reject(&:modified?)
end

#show_timeObject



124
125
126
# File 'app/models/show.rb', line 124

def show_time
  I18n.l(datetime_local_to_event, :format => :long_with_day)
end

#tickets_compedObject



96
97
98
# File 'app/models/show.rb', line 96

def tickets_comped
  @tickets_comped ||= tickets.select { |ticket| ticket.comped? }
end

#tickets_soldObject



92
93
94
# File 'app/models/show.rb', line 92

def tickets_sold
  @tickets_sold ||= tickets.select { |ticket| ticket.sold? }
end

#time_zoneObject



108
109
110
# File 'app/models/show.rb', line 108

def time_zone
  @time_zone ||= event.time_zone
end

#unscoped_eventObject



72
73
74
# File 'app/models/show.rb', line 72

def unscoped_event
  ::Event.unscoped.find(event_id)
end