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 SETTLED slips before this period — feeds the TDS projector and the slip's YTD table.



42
43
44
45
46
47
48
49
50
51
# File 'app/models/hr_lite/salary_slip.rb', line 42

def self.fy_to_date(user, period_month)
  fy_start = FinancialYear.start_for(period_month)
  slips = settled.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



53
54
55
56
# File 'app/models/hr_lite/salary_slip.rb', line 53

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

#deductions_rowsObject



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

def deductions_rows = parse_json(deductions)

#earnings_rowsObject



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

def earnings_rows = parse_json(earnings)

#effective_lop_daysObject



36
37
38
# File 'app/models/hr_lite/salary_slip.rb', line 36

def effective_lop_days
  lop_override || lop_days
end

#employer_costs_hashObject



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

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

#pdf_cache_keyObject



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

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)


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

def published?
  payroll_run.published?
end

#tax_details_hashObject



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

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

#user_profileObject



63
64
65
# File 'app/models/hr_lite/salary_slip.rb', line 63

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