Class: Ecom::Core::CrewOvertime

Inherits:
ApplicationRecord show all
Defined in:
app/models/ecom/core/crew_overtime.rb

Instance Method Summary collapse

Instance Method Details

#calculate_hoursObject



33
34
35
36
# File 'app/models/ecom/core/crew_overtime.rb', line 33

def calculate_hours
  rate = OvertimeType.find(overtime_type_id).rate
  self.hours = raw_hours * rate
end

#validate_overtime_by_typeObject



21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/ecom/core/crew_overtime.rb', line 21

def validate_overtime_by_type
  return unless overtime_type

  start = Time.zone.parse(overtime_type.from)
  finish = Time.zone.parse(overtime_type.to)
  diff = ((finish - start) / 3600).round

  return unless raw_hours > diff

  errors.add(:crew_overtime, 'The selected overtime type does not allow the specified amount of hours.')
end