Class: HrLite::SalarySlip

Inherits:
ApplicationRecord show all
Includes:
EncryptedMoney
Defined in:
app/models/hr_lite/salary_slip.rb

Overview

One employee-month. All MONEY is snapshotted (encrypted JSON line items + encrypted totals); identity numbers (PAN/UAN/bank) render live from the profile — a typo fix must flow to old slips, and duplicating encrypted PII per month multiplies liability. Visibility and immutability delegate to the run's lifecycle.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fy_to_date(user, period_month) ⇒ Object

Indian FY (Apr 1) to-date sums of PUBLISHED slips before this period — feeds the TDS projector and the slip's YTD table.



38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/hr_lite/salary_slip.rb', line 38

def self.fy_to_date(user, period_month)
  fy_start = period_month.month >= 4 ? Date.new(period_month.year, 4, 1)
                                     : Date.new(period_month.year - 1, 4, 1)
  slips = published.where(user_id: user.id)
                   .where(period_month: fy_start...period_month)
  {
    gross: slips.sum(BigDecimal(0)) { |s| s.gross_earnings || BigDecimal(0) },
    tds: slips.sum(BigDecimal(0)) { |s| Money.d(s.deduction_amount("tds")) },
    months: slips.count
  }
end

Instance Method Details

#deduction_amount(code) ⇒ Object



50
51
52
53
# File 'app/models/hr_lite/salary_slip.rb', line 50

def deduction_amount(code)
  row = deductions_rows.find { |r| r["code"] == code }
  row ? Money.d(row["amount"]) : BigDecimal(0)
end

#deductions_rowsObject



28
# File 'app/models/hr_lite/salary_slip.rb', line 28

def deductions_rows = parse_json(deductions)

#earnings_rowsObject



27
# File 'app/models/hr_lite/salary_slip.rb', line 27

def earnings_rows = parse_json(earnings)

#effective_lop_daysObject



32
33
34
# File 'app/models/hr_lite/salary_slip.rb', line 32

def effective_lop_days
  lop_override || lop_days
end

#employer_costs_hashObject



29
# File 'app/models/hr_lite/salary_slip.rb', line 29

def employer_costs_hash = parse_json(employer_costs, fallback: {})

#pdf_cache_keyObject



55
56
57
58
# File 'app/models/hr_lite/salary_slip.rb', line 55

def pdf_cache_key
  [ "hr_lite_slip", id, updated_at.to_i, payroll_run.status,
    &.updated_at.to_i ].join("/")
end

#published?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/models/hr_lite/salary_slip.rb', line 23

def published?
  payroll_run.published?
end

#tax_details_hashObject



30
# File 'app/models/hr_lite/salary_slip.rb', line 30

def tax_details_hash = parse_json(tax_details, fallback: {})

#user_profileObject



60
61
62
# File 'app/models/hr_lite/salary_slip.rb', line 60

def 
  @user_profile ||= EmployeeProfile.find_by(user_id: user_id)
end