Class: Schedule

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

Overview

Schema Information

Table name: schedules

id         :integer          not null, primary key
publish    :boolean
user_id    :integer
job_id     :integer
created_at :datetime
updated_at :datetime
start_date :date
end_date   :date

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.publishObject



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

def self.publish
  where(:publish => true)
end

.publish!(schedule_ids, org_id) ⇒ Object



41
42
43
44
45
46
47
# File 'app/models/schedule.rb', line 41

def self.publish! schedule_ids, org_id
  schedules = where(:id => schedule_ids)
  schedules.each do |schedule|
    schedule.notify_employee(org_id)
  end
  return schedules.update_all(:publish => true)
end

.schedule_resend(schedules) ⇒ Object



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

def self.schedule_resend(schedules)
  where(:id => schedules).each do |schedule|
    schedule.notify_employee
  end
end

Instance Method Details

#calculate_total_hoursObject



63
64
65
66
67
68
69
70
71
72
# File 'app/models/schedule.rb', line 63

def calculate_total_hours
  sum = 0.0
  prop = self.user.member.find_by_organization_id(self.organization_id).in_train ? 'training_hours' : 'hours'
  shifts.each do |shift|
      shift[prop] = "2000-01-01 00:00:00 UTC" if shift[prop].nil?
      sum = sum + shift[prop].hour
      sum = sum + ( shift[prop].min + 0.00 ) / 60
  end
  self.update_attributes(:total_hours => sum)
end

#check_timeoff_conflict(start_time, end_time, due_date) ⇒ Object



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

def check_timeoff_conflict start_time, end_time, due_date
  self.shifts.where(:due_date => due_date).each do |shift|
    if (start_time.strftime("%H:%M") >= shift.start_time.strftime("%H:%M") and start_time.strftime("%H:%M") < shift.end_time.strftime("%H:%M")) or (end_time.strftime("%H:%M") >= shift.start_time.strftime("%H:%M") and end_time.strftime("%H:%M") < shift.end_time.strftime("%H:%M"))
      return true
    end 
  end
  return false
end

#get_sumObject



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

def get_sum
  total_hours.try(:round, 1)
end

#notify_employee(org_id) ⇒ Object



49
50
51
# File 'app/models/schedule.rb', line 49

def notify_employee org_id
  Notifier.delay.schedule_published(self, org_id)
end

#published?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/schedule.rb', line 33

def published?
  self.publish == true
end