Created
November 20, 2014 19:11
-
-
Save goldnuggets24/69fb7330658412085ba8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EmployeeDemographic < ActiveRecord::Base | |
#Start Activity Tracking | |
include PublicActivity::Model | |
include ::ActivityMethods | |
tracked except: :update, owner: -> (controller, model) { controller && controller.current_user } | |
tracked except: :update, account_id: -> (controller, model) { controller && controller.current_user.account_id } | |
tracked except: :update, user_id: -> (controller, model) { controller && model.user_id } | |
tracked except: :update, activity_type: -> (controller, model) { controller && "private" } | |
monitor_attr_changed :eeo_job_category, :employee_number, :ethnicity, :flsa_code, :hire_date, :performance_review_due, :termination_date, :veteran_status, :ssn | |
#End Activity Tracking | |
belongs_to :user | |
belongs_to :flsa_code_id, :class_name => "LookupTable", :foreign_key => "flsa_code" | |
belongs_to :ethnicity_id, :class_name => "LookupTable", :foreign_key => "ethnicity" | |
belongs_to :eeo_job_category_id, :class_name => "LookupTable", :foreign_key => "eeo_job_category" | |
belongs_to :veteran_status_id, :class_name => "LookupTable", :foreign_key => "veteran_status" | |
belongs_to :termination_reason_id, :class_name => "LookupTable", :foreign_key => "degree_type" | |
attr_accessor :modal, :comment, :rehire_date_formatted, :termination_validation, :rehire_validation | |
has_many :comments, dependent: :destroy | |
accepts_nested_attributes_for :comments | |
validates :termination_date_formatted, :presence => true, if: :firing_terminate? | |
validates :rehire_date_formatted, :termination_reason, :presence => true, if: :rehiring? | |
validates_associated :comments | |
acts_as_commentable | |
track_who_does_it | |
def firing_terminate? | |
termination_validation == "yes" | |
end | |
def rehiring? | |
rehire_validation == "yes" | |
end | |
def hire_date_formatted | |
self.hire_date | |
end | |
def hire_date_formatted=(hire_date_format) | |
if hire_date_format.present? | |
self.hire_date = Date.strptime(hire_date_format, "%m-%d-%Y") | |
else | |
self.hire_date = nil | |
end | |
end | |
def performance_review_due_formatted | |
self.performance_review_due | |
end | |
def performance_review_due_formatted=(performance_review_due_format) | |
if performance_review_due_format.present? | |
self.performance_review_due = Date.strptime(performance_review_due_format, "%m-%d-%Y") | |
else | |
self.performance_review_due = nil | |
end | |
end | |
def termination_date_formatted | |
self.termination_date | |
end | |
def termination_date_formatted=(termination_date_format) | |
if termination_date_format.present? | |
self.termination_date = Date.strptime(termination_date_format, "%m-%d-%Y") | |
else | |
self.termination_date = nil | |
end | |
end | |
def rehire_date_formatted | |
self.rehire_date | |
end | |
def rehire_date_formatted=(rehire_date_format) | |
if rehire_date_format.present? | |
self.rehire_date = Date.strptime(rehire_date_format, "%m-%d-%Y") | |
else | |
self.rehire_date = nil | |
end | |
end | |
def run_conditional(termination_date_formatted) | |
(:firing_terminate? == termination_date_formatted) || super | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment