Class: HrLite::EmployeeProfile

Inherits:
ApplicationRecord show all
Includes:
Audited, EncryptedMoney
Defined in:
app/models/hr_lite/employee_profile.rb

Overview

Statutory identity + employment window. PII columns are encrypted at rest; masked readers feed the employee-facing view (full values render only in the leadership edit form). Records are never destroyed — exits are a date, payroll history is a statutory record.

Constant Summary collapse

TAX_REGIMES =
%w[new old].freeze

Constants included from Audited

Audited::REDACTED, Audited::SKIPPED_ATTRIBUTES

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#new_user_emailObject

Onboarding-form virtuals (the controller hands them to config.onboard_user; never persisted, never audited).



22
23
24
# File 'app/models/hr_lite/employee_profile.rb', line 22

def new_user_email
  @new_user_email
end

#new_user_nameObject

Onboarding-form virtuals (the controller hands them to config.onboard_user; never persisted, never audited).



22
23
24
# File 'app/models/hr_lite/employee_profile.rb', line 22

def new_user_name
  @new_user_name
end

#new_user_passwordObject

Onboarding-form virtuals (the controller hands them to config.onboard_user; never persisted, never audited).



22
23
24
# File 'app/models/hr_lite/employee_profile.rb', line 22

def new_user_password
  @new_user_password
end

Instance Method Details

#active_managerObject

The manager as shown to the employee — an exited manager reads as "no manager" until leadership reassigns (matches the org chart).



54
55
56
57
58
59
# File 'app/models/hr_lite/employee_profile.rb', line 54

def active_manager
  return nil if manager.nil?

  boss_exit = EmployeeProfile.where(user_id: manager_id).pick(:date_of_exit)
  boss_exit && boss_exit < Date.current ? nil : manager
end

#active_on?(date) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/hr_lite/employee_profile.rb', line 42

def active_on?(date)
  date_of_joining <= date && (date_of_exit.nil? || date_of_exit >= date)
end

#employment_range_in(month) ⇒ Object



46
47
48
49
50
# File 'app/models/hr_lite/employee_profile.rb', line 46

def employment_range_in(month)
  from = [ date_of_joining, month.beginning_of_month ].max
  to = [ date_of_exit || month.end_of_month, month.end_of_month ].min
  from <= to ? (from..to) : nil
end

#masked_accountObject



81
82
83
84
# File 'app/models/hr_lite/employee_profile.rb', line 81

def 
  value = 
  value.blank? ? nil : "•••• #{value.last(4)}"
end

#masked_panObject



77
78
79
# File 'app/models/hr_lite/employee_profile.rb', line 77

def masked_pan
  mask_middle(pan_number)
end

#masked_uanObject



86
87
88
# File 'app/models/hr_lite/employee_profile.rb', line 86

def masked_uan
  mask_middle(pf_uan)
end

#reporting_chainObject

[L1 user, L2 user, ...] walking manager_id upward. Cycle-safe.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/hr_lite/employee_profile.rb', line 62

def reporting_chain
  chain = []
  seen = { user_id => true }
  current = manager_id
  while current && !seen[current]
    seen[current] = true
    boss = HrLite.user_klass.find_by(id: current)
    break if boss.nil?

    chain << boss
    current = EmployeeProfile.where(user_id: boss.id).pick(:manager_id)
  end
  chain
end