Class: HrLite::ResignationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/hr_lite/resignations_controller.rb

Overview

Employee self-service resignation: submit, see status, withdraw while pending. Always scoped to hr_current_user.

Instance Method Summary collapse

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
# File 'app/controllers/hr_lite/resignations_controller.rb', line 15

def create
  @resignation = Resignation.new(resignation_params.merge(user_id: hr_current_user.id))
  if @resignation.save
    redirect_to resignation_path, notice: "Resignation submitted — leadership has been notified."
  else
    @new_resignation = @resignation
    render :show, status: :unprocessable_entity
  end
end

#showObject



5
6
7
8
9
10
11
12
13
# File 'app/controllers/hr_lite/resignations_controller.rb', line 5

def show
  @resignation = own.recent_first.first
  # No form once one is pending OR already accepted: an agreed exit date is
  # not something to re-file, and accepting a second one would overwrite
  # the date payroll and attendance already clip to.
  unless @resignation&.pending? || @resignation&.accepted?
    @new_resignation = Resignation.new(proposed_last_day: Date.current + 30)
  end
end

#withdrawObject



25
26
27
28
29
30
31
32
33
# File 'app/controllers/hr_lite/resignations_controller.rb', line 25

def withdraw
  resignation = own.pending.first
  if resignation
    resignation.withdraw!(actor: hr_current_user)
    redirect_to resignation_path, notice: "Resignation withdrawn."
  else
    redirect_to resignation_path, alert: "Nothing pending to withdraw."
  end
end