Sha256: d4cfc1d14141e6da5bb4843e37e34833ed83854654d5747bbd2ba7f494901977

Contents?: true

Size: 716 Bytes

Versions: 15

Compression:

Stored size: 716 Bytes

Contents

module Ecom
  module Core
    class CrewTime < ApplicationRecord
      belongs_to :crew
      belongs_to :overtime_type, optional: true

      validates :date, :hours, :converted_hours, presence: true
      validates_each :date do |record, attr, value|
        if record.crew && value && (value < record.crew.employment_date)
          record.errors.add(attr, 'should be after employment date')
        end
      end

      before_save :calculate_converted_hours

      def calculate_converted_hours
        if overtime
          rate = OvertimeType.find(overtime_type_id).rate
          self.converted_hours = hours * rate
        else
          self.converted_hours = hours
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ecom_core-1.1.7 app/models/ecom/core/crew_time.rb
ecom_core-1.1.6 app/models/ecom/core/crew_time.rb
ecom_core-1.1.5 app/models/ecom/core/crew_time.rb
ecom_core-1.1.4 app/models/ecom/core/crew_time.rb
ecom_core-1.1.3 app/models/ecom/core/crew_time.rb
ecom_core-1.1.2 app/models/ecom/core/crew_time.rb
ecom_core-1.1.1 app/models/ecom/core/crew_time.rb
ecom_core-1.1.0 app/models/ecom/core/crew_time.rb
ecom_core-1.0.25 app/models/ecom/core/crew_time.rb
ecom_core-1.0.24 app/models/ecom/core/crew_time.rb
ecom_core-1.0.23 app/models/ecom/core/crew_time.rb
ecom_core-1.0.22 app/models/ecom/core/crew_time.rb
ecom_core-1.0.21 app/models/ecom/core/crew_time.rb
ecom_core-1.0.20 app/models/ecom/core/crew_time.rb
ecom_core-1.0.19 app/models/ecom/core/crew_time.rb