Class: Swap

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

Overview

Schema Information

Table name: swaps

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

Instance Method Summary collapse

Instance Method Details

#approveObject



68
69
70
71
72
73
# File 'app/models/swap.rb', line 68

def approve
  #self.approved_by = manager.id
  #self.approved_date = Time.zone.now
  self.status = 'approved'
  save
end

#approved?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/models/swap.rb', line 44

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

#cancelObject



75
76
77
78
79
80
# File 'app/models/swap.rb', line 75

def cancel
  #self.approved_by = manager.id
  #self.approved_date = Time.zone.now
  self.status = 'cancelled'
  save
end

#due_dateObject



64
65
66
# File 'app/models/swap.rb', line 64

def due_date
  self.shift.due_date
end

#get_shiftObject



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

def get_shift
     @swap = Swap.find_by_id(self.alert_type_id)
     if !@swap.nil? 
      @swap.shift
     end 
end

#notifyObject



28
29
30
31
32
33
34
35
# File 'app/models/swap.rb', line 28

def notify
  if alert 
    employees = shift.schedule.user.organization.get_employees
    employees.each do |candidate|
      candidate.notify_alert(self)
    end
  end
end

#pending?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/swap.rb', line 40

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

#shift_detailObject



36
37
38
39
# File 'app/models/swap.rb', line 36

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

#shift_hoursObject



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

def shift_hours
  self.shift.hours.strftime('%H')
end

#user_nameObject



48
49
50
# File 'app/models/swap.rb', line 48

def user_name
  self.shift.schedule.user.name
end