Sha256: 9ab8420c28171d1860f9a1041ceca990a80a3263a65be4d4dbf40eb1ef46e35d
Contents?: true
Size: 1.37 KB
Versions: 13
Compression:
Stored size: 1.37 KB
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? } after_save :set_employee_id belongs_to :crew_type validates :name, :address, :qualification, :employment, :wage, :guarantor_name, :guarantor_phone, presence: true validates :employment, inclusion: EMPLOYMENT_TYPES has_many :site_crews has_many :sites, through: :site_crews has_many :crew_id_cards has_many :crew_contracts 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 def set_employee_id company = Ecom::Core::Company.first date = employment_date.to_s[0..3] company_name = company ? company.name : '' employee_id = "#{company_name}/#{employment}/#{date}/#{id}" update_column(:employee_id, employee_id) end end end end
Version data entries
13 entries across 13 versions & 1 rubygems