Class: HrLite::Admin::LeaveBalancesController

Inherits:
BaseController show all
Defined in:
app/controllers/hr_lite/admin/leave_balances_controller.rb

Instance Method Summary collapse

Instance Method Details

#adjustObject

Manual credit/debit — also the comp-off credit mechanism.



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
# File 'app/controllers/hr_lite/admin/leave_balances_controller.rb', line 11

def adjust
  user = HrLite.user_klass.find(params[:user_id])
  type = LeaveType.find(params[:leave_type_id])
  # Unsanitised, a missing param wrote the adjustment into leave year 0,
  # where no screen can ever show it.
  year = sanitized_year
  delta = BigDecimal(params[:delta].to_s)
  note = params[:note].to_s.strip

  if note.blank?
    return redirect_to admin_leave_balances_path(year: year), alert: "A note is required."
  end

  balance = LeaveBalance.adjust!(user, type, year, delta: delta, note: "#{delta.to_f}#{note}")

  AuditLog.record!(
    action: "adjust", subject: balance, actor: hr_current_user,
    changes: { "user" => HrLite.display_name(user), "type" => type.code,
               "delta" => delta.to_f, "note" => note }
  )
  redirect_to admin_leave_balances_path(year: year),
              notice: "Balance adjusted for #{HrLite.display_name(user)}."
rescue ArgumentError
  # Keep the admin on the year they were looking at.
  redirect_to admin_leave_balances_path(year: sanitized_year),
              alert: "Enter a valid adjustment number."
end

#indexObject



4
5
6
7
8
# File 'app/controllers/hr_lite/admin/leave_balances_controller.rb', line 4

def index
  @year = sanitized_year
  @types = LeaveType.active.where(paid: true).where.not(annual_quota: nil)
  @employees = HrLite.employees
end