Class: HrLite::Admin::PayrollRunsController

Inherits:
SuperadminController show all
Defined in:
app/controllers/hr_lite/admin/payroll_runs_controller.rb

Instance Method Summary collapse

Instance Method Details

#computeObject



38
39
40
# File 'app/controllers/hr_lite/admin/payroll_runs_controller.rb', line 38

def compute
  transition { |run| run.compute!(actor: hr_current_user) && "Computed — review the slips." }
end

#createObject



12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/hr_lite/admin/payroll_runs_controller.rb', line 12

def create
  month = parse_month_param(params.dig(:payroll_run, :period_month))
  @run = PayrollRun.new(period_month: month, created_by_id: hr_current_user.id,
                        notes: params.dig(:payroll_run, :notes))
  if @run.save
    redirect_to admin_payroll_run_path(@run), notice: "Run created — compute when ready."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



28
29
30
31
32
33
34
35
36
# File 'app/controllers/hr_lite/admin/payroll_runs_controller.rb', line 28

def destroy
  run = PayrollRun.find(params[:id])
  if run.destroy
    redirect_to admin_payroll_runs_path, notice: "Draft run deleted.", status: :see_other
  else
    redirect_to admin_payroll_run_path(run), alert: run.errors.full_messages.to_sentence,
                status: :see_other
  end
end

#finalizeObject



42
43
44
# File 'app/controllers/hr_lite/admin/payroll_runs_controller.rb', line 42

def finalize
  transition { |run| run.finalize!(actor: hr_current_user) && "Run finalized." }
end

#indexObject



4
5
6
# File 'app/controllers/hr_lite/admin/payroll_runs_controller.rb', line 4

def index
  @runs = paginate(PayrollRun.recent_first)
end

#newObject



8
9
10
# File 'app/controllers/hr_lite/admin/payroll_runs_controller.rb', line 8

def new
  @run = PayrollRun.new(period_month: Date.current.prev_month.beginning_of_month)
end

#publishObject



50
51
52
# File 'app/controllers/hr_lite/admin/payroll_runs_controller.rb', line 50

def publish
  transition { |run| run.publish!(actor: hr_current_user) && "Published — employees notified." }
end

#registerObject

Payout register: the full money sheet including bank details — deliberately leadership-only PII.



56
57
58
59
60
# File 'app/controllers/hr_lite/admin/payroll_runs_controller.rb', line 56

def register
  run = PayrollRun.find(params[:id])
  send_data register_csv(run), filename: "payroll-register-#{run.period_month.strftime('%Y-%m')}.csv",
                               type: "text/csv"
end

#showObject



23
24
25
26
# File 'app/controllers/hr_lite/admin/payroll_runs_controller.rb', line 23

def show
  @run = PayrollRun.find(params[:id])
  @slips = @run.salary_slips.includes(:user).sort_by { |slip| HrLite.display_name(slip.user) }
end

#unlockObject



46
47
48
# File 'app/controllers/hr_lite/admin/payroll_runs_controller.rb', line 46

def unlock
  transition { |run| run.unlock!(actor: hr_current_user) && "Back in review." }
end