Class: Cancellation

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/cancellation.rb

Overview

Schema Information

Table name: cancellations

id            :integer          not null, primary key
shift_id      :integer
reason        :string(255)
status        :string(255)      default("pending")
created_at    :datetime
updated_at    :datetime
approved_date :datetime
approved_by   :integer

Instance Method Summary collapse

Instance Method Details

#approve(manager, cancellation, excused) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/cancellation.rb', line 34

def approve(manager, cancellation, excused)
  self.approved_by = manager.id
  self.approved_date = Time.zone.now
  self.notes = cancellation[:notes] if !cancellation[:notes].blank?
  self.unexcused_note = cancellation[:unexcused_note] if !cancellation[:unexcused_note].blank?
  if excused == true
    self.status = 'approved excused'
  else
    self.status = 'approved unexcused'
  end
  save
end

#approved?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/cancellation.rb', line 26

def approved?
  self.status == 'approved'
end

#cancelObject



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

def cancel
  self.status = 'cancelled'
  save
end

#deny(cancellation) ⇒ Object



47
48
49
50
51
# File 'app/models/cancellation.rb', line 47

def deny(cancellation)
  self.status = 'denied'
  self.notes = cancellation[:notes] if !cancellation[:notes].blank?
  save
end

#discuss(cancellation) ⇒ Object



53
54
55
56
57
# File 'app/models/cancellation.rb', line 53

def discuss(cancellation)
  self.status = 'discuss'
  self.notes = cancellation[:notes] if !cancellation[:notes].blank?
  save
end

#pending?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/models/cancellation.rb', line 22

def pending?
  self.status == 'pending'
end

#shift_detailObject



30
31
32
# File 'app/models/cancellation.rb', line 30

def shift_detail
  "AS #{shift.job_name} from #{shift.start_time.strftime('%H:%M')} to #{shift.end_time.strftime('%H:%M')} on #{shift.formatted_due_date}"
end