Class: HrLite::SalarySlip
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- HrLite::SalarySlip
- 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
-
.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.
Instance Method Summary collapse
- #deduction_amount(code) ⇒ Object
- #deductions_rows ⇒ Object
- #earnings_rows ⇒ Object
- #effective_lop_days ⇒ Object
- #employer_costs_hash ⇒ Object
- #pdf_cache_key ⇒ Object
- #published? ⇒ Boolean
- #tax_details_hash ⇒ Object
- #user_profile ⇒ Object
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_rows ⇒ Object
28 |
# File 'app/models/hr_lite/salary_slip.rb', line 28 def deductions_rows = parse_json(deductions) |
#earnings_rows ⇒ Object
27 |
# File 'app/models/hr_lite/salary_slip.rb', line 27 def earnings_rows = parse_json(earnings) |
#effective_lop_days ⇒ Object
32 33 34 |
# File 'app/models/hr_lite/salary_slip.rb', line 32 def effective_lop_days lop_override || lop_days end |
#employer_costs_hash ⇒ Object
29 |
# File 'app/models/hr_lite/salary_slip.rb', line 29 def employer_costs_hash = parse_json(employer_costs, fallback: {}) |
#pdf_cache_key ⇒ Object
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, user_profile&.updated_at.to_i ].join("/") end |
#published? ⇒ Boolean
23 24 25 |
# File 'app/models/hr_lite/salary_slip.rb', line 23 def published? payroll_run.published? end |
#tax_details_hash ⇒ Object
30 |
# File 'app/models/hr_lite/salary_slip.rb', line 30 def tax_details_hash = parse_json(tax_details, fallback: {}) |
#user_profile ⇒ Object
60 61 62 |
# File 'app/models/hr_lite/salary_slip.rb', line 60 def user_profile @user_profile ||= EmployeeProfile.find_by(user_id: user_id) end |