Sha256: 66220eaebaaccc2696a8ed7a38c8c28cfd159c8edcee4c58f7f5a76af2a6b847

Contents?: true

Size: 834 Bytes

Versions: 18

Compression:

Stored size: 834 Bytes

Contents

module Ecom
  module Core
    class CrewOvertime < ApplicationRecord
      belongs_to :overtime_type
      belongs_to :overtime_sheet_entry
      belongs_to :revision_to, class_name: 'Ecom::Core::CrewOvertime', optional: true
      belongs_to :created_by, class_name: 'Ecom::Core::User'

      has_one :revision, class_name: 'Ecom::Core::CrewOvertime', foreign_key: :revision_to_id

      validates :hours, :raw_hours, presence: true

      scope :by_overtime, lambda { |id|
        joins(:overtime_sheet_entry).where(ecom_core_overtime_sheet_entries: { overtime_sheet_id: id })
      }
      scope :revised, ->(revised) { where(revised: revised) }

      before_save :calculate_hours

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ecom_core-1.2.26 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.25 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.24 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.23 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.22 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.21 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.20 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.19 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.18 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.17 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.16 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.15 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.14 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.13 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.12 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.11 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.10 app/models/ecom/core/crew_overtime.rb
ecom_core-1.2.9 app/models/ecom/core/crew_overtime.rb