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).



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

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)


44
45
46
# File 'app/models/hr_lite/employee_profile.rb', line 44

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

#employment_range_in(month) ⇒ Object



48
49
50
51
52
# File 'app/models/hr_lite/employee_profile.rb', line 48

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



83
84
85
86
# File 'app/models/hr_lite/employee_profile.rb', line 83

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

#masked_panObject



79
80
81
# File 'app/models/hr_lite/employee_profile.rb', line 79

def masked_pan
  mask_middle(pan_number)
end

#masked_uanObject



88
89
90
# File 'app/models/hr_lite/employee_profile.rb', line 88

def masked_uan
  mask_middle(pf_uan)
end

#reporting_chainObject

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



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

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