Class: HrLite::Admin::SalarySlipsController
- Inherits:
-
SuperadminController
- Object
- HrLite::ApplicationController
- BaseController
- LeadershipController
- SuperadminController
- HrLite::Admin::SalarySlipsController
- Defined in:
- app/controllers/hr_lite/admin/salary_slips_controller.rb
Instance Method Summary collapse
- #show ⇒ Object
-
#update ⇒ Object
Review-stage overrides (LOP days / monthly TDS) — the slip rebuilds immediately with the overrides applied.
Instance Method Details
#show ⇒ Object
4 5 6 7 |
# File 'app/controllers/hr_lite/admin/salary_slips_controller.rb', line 4 def show @slip = SalarySlip.includes(:payroll_run).find(params[:id]) @profile = @slip.user_profile end |
#update ⇒ Object
Review-stage overrides (LOP days / monthly TDS) — the slip rebuilds immediately with the overrides applied.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/hr_lite/admin/salary_slips_controller.rb', line 11 def update slip = SalarySlip.includes(:payroll_run).find(params[:id]) run = slip.payroll_run unless run.review? return redirect_to admin_salary_slip_path(slip), alert: "Overrides are only editable while the run is in review." end lop_override = params.dig(:salary_slip, :lop_override).presence tds_override = params.dig(:salary_slip, :tds_override).presence profile = EmployeeProfile.find_by(user_id: slip.user_id) structure = SalaryStructure.effective_for(slip.user, run.period_month) if structure.nil? return redirect_to admin_salary_slip_path(slip), alert: "No salary structure is effective for #{run.label} — add one first." end lop = lop_override && BigDecimal(lop_override) tds = tds_override && BigDecimal(tds_override) # Unbounded overrides are a money bug, not a typo: a negative LOP pays # for days never worked, one above the month zeroes the person out. if lop && !lop.between?(0, slip.days_in_month) return redirect_to admin_salary_slip_path(slip), alert: "LOP days must be between 0 and #{slip.days_in_month}." end if tds&.negative? return redirect_to admin_salary_slip_path(slip), alert: "TDS cannot be negative." end attributes = SlipBuilder.call( run: run, user: slip.user, structure: structure, profile: profile, lop_override: lop, tds_override: tds ) slip.update!(attributes) AuditLog.create!( actor: hr_current_user, action: "override", subject_type: slip.class.name, subject_id: slip.id, audited_changes: { "period" => run.label, "employee" => HrLite.display_name(slip.user), "lop_override" => lop_override || "cleared", "tds_override" => tds_override ? "[changed]" : "cleared" } ) redirect_to admin_salary_slip_path(slip), notice: "Slip recomputed with overrides." rescue ArgumentError redirect_to admin_salary_slip_path(params[:id]), alert: "Overrides must be numbers." end |