Class: Comp

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
app/models/comp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(show, tickets_or_ids, memberships, recipient, benefactor, notes = nil) ⇒ Comp

tickets can be an array of tickets_ids or an array of tickets



12
13
14
15
16
17
18
19
20
# File 'app/models/comp.rb', line 12

def initialize(show, tickets_or_ids, memberships, recipient, benefactor, notes=nil)
  @show = show
  @tickets = []
  @memberships = memberships
  load_tickets(tickets_or_ids)
  @recipient = Person.find(recipient) unless recipient.blank?
  @benefactor = benefactor
  @notes      = notes
end

Instance Attribute Details

#benefactorObject

Returns the value of attribute benefactor.



8
9
10
# File 'app/models/comp.rb', line 8

def benefactor
  @benefactor
end

#comped_countObject

Returns the value of attribute comped_count.



9
10
11
# File 'app/models/comp.rb', line 9

def comped_count
  @comped_count
end

#detailsObject

Returns the value of attribute details.



9
10
11
# File 'app/models/comp.rb', line 9

def details
  @details
end

#membershipsObject

Returns the value of attribute memberships.



8
9
10
# File 'app/models/comp.rb', line 8

def memberships
  @memberships
end

#notesObject

Returns the value of attribute notes.



8
9
10
# File 'app/models/comp.rb', line 8

def notes
  @notes
end

#orderObject

Returns the value of attribute order.



8
9
10
# File 'app/models/comp.rb', line 8

def order
  @order
end

#recipientObject

Returns the value of attribute recipient.



8
9
10
# File 'app/models/comp.rb', line 8

def recipient
  @recipient
end

#showObject

Returns the value of attribute show.



8
9
10
# File 'app/models/comp.rb', line 8

def show
  @show
end

#ticketsObject

Returns the value of attribute tickets.



8
9
10
# File 'app/models/comp.rb', line 8

def tickets
  @tickets
end

#uncomped_countObject

Returns the value of attribute uncomped_count.



9
10
11
# File 'app/models/comp.rb', line 9

def uncomped_count
  @uncomped_count
end

Instance Method Details

#has_recipient?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/comp.rb', line 38

def has_recipient?
  !recipient.blank?
end

#persisted?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/comp.rb', line 42

def persisted?
  false
end

#submitObject



46
47
48
49
50
51
52
# File 'app/models/comp.rb', line 46

def submit
  ActiveRecord::Base.transaction do
    create_order(@tickets, @memberships, @recipient, @benefactor, @notes)
    self.comped_count    = tickets.size
    self.uncomped_count  = 0
  end
end

#valid_recipient_and_benefactorObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/comp.rb', line 22

def valid_recipient_and_benefactor
  if @recipient.nil?
    errors.add(:base, "Please select a person to comp to or create a new person record")
    return
  end

  if @benefactor.nil?
    errors.add(:base, "Please select a benefactor")
    return
  end

  unless @benefactor.current_organization.eql? @recipient.organization
    errors.add(:base, "Recipient and benefactor are from different organizations")
  end
end