Class: HrLite::Admin::LeaveBalancesController
- Inherits:
-
BaseController
- Object
- HrLite::ApplicationController
- BaseController
- HrLite::Admin::LeaveBalancesController
- Defined in:
- app/controllers/hr_lite/admin/leave_balances_controller.rb
Instance Method Summary collapse
-
#adjust ⇒ Object
Manual credit/debit — also the comp-off credit mechanism.
- #index ⇒ Object
Instance Method Details
#adjust ⇒ Object
Manual credit/debit — also the comp-off credit mechanism.
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 |
# File 'app/controllers/hr_lite/admin/leave_balances_controller.rb', line 12 def adjust user = HrLite.user_klass.find(params[:user_id]) type = LeaveType.find(params[:leave_type_id]) year = params[:year].to_i 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.for(user, type, year) balance.adjustment += delta balance.adjustment_note = [ balance.adjustment_note.presence, "#{delta.to_f} — #{note}" ].compact.join("; ") balance.save! AuditLog.create!( actor: hr_current_user, action: "adjust", subject_type: balance.class.name, subject_id: balance.id, audited_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 redirect_to admin_leave_balances_path, alert: "Enter a valid adjustment number." end |
#index ⇒ Object
4 5 6 7 8 9 |
# File 'app/controllers/hr_lite/admin/leave_balances_controller.rb', line 4 def index year = params[:year].to_i @year = year.between?(2000, 2100) ? year : LeaveYear.current_key @types = LeaveType.active.where(paid: true).where.not(annual_quota: nil) @employees = HrLite.employees end |