Sha256: d31df4b179d9d25a93684096cef04010c81d51651e5d12f659780e9192ad6065

Contents?: true

Size: 1003 Bytes

Versions: 4

Compression:

Stored size: 1003 Bytes

Contents

module Ecom
  module Core
    class Crew < ApplicationRecord
      mount_base64_uploader :photo, PhotoUploader
      PERMANENT = 'Permanent'.freeze
      SUPERVISOR = 'Supervisor'.freeze
      TEMPORARY = 'Temporary'.freeze
      EMPLOYMENT_TYPES = [PERMANENT, SUPERVISOR, TEMPORARY].freeze

      before_save :set_employment_date,
                  if: proc { |c| c.employment_date.nil? }

      belongs_to :crew_type

      validates :name, :address, :qualification, :employment, :wage, :wage_in_words, presence: true
      validates :employment, inclusion: EMPLOYMENT_TYPES

      has_many :project_crews
      has_many :projects, through: :project_crews

      scope :by_active, ->(active) { where(active: active) }
      scope :by_qualification, ->(qualification) { where(qualification: qualification) }
      scope :by_sub_contracted, ->(sub_contracted) { where(sub_contracted: sub_contracted) }

      def set_employment_date
        self.employment_date = Date.today
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ecom_core-1.2.31 app/models/ecom/core/crew.rb
ecom_core-1.2.30 app/models/ecom/core/crew.rb
ecom_core-1.2.29 app/models/ecom/core/crew.rb
ecom_core-1.2.28 app/models/ecom/core/crew.rb