Class: HrLite::Admin::ExpensesController

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

Overview

The other side of the claim: decide it, then say when it was paid.

Instance Method Summary collapse

Instance Method Details

#approveObject



14
15
16
17
18
# File 'app/controllers/hr_lite/admin/expenses_controller.rb', line 14

def approve
  expense = decidable.find(params[:id])
  expense.approve!(actor: hr_current_user, note: params[:decision_note].presence)
  redirect_to admin_expenses_path, notice: "Claim approved."
end

#indexObject



8
9
10
11
12
# File 'app/controllers/hr_lite/admin/expenses_controller.rb', line 8

def index
  @status = params[:status].presence_in(Expense::STATUSES) || "submitted"
  scope = Expense.where(status: @status).includes(:user, :category).recent_first
  @expenses = paginate(hr_scope(scope, "expense.approve"))
end

#reimburseObject



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

def reimburse
  expense = decidable.find(params[:id])
  month = parse_month_param(params[:period_month])
  expense.reimburse!(actor: hr_current_user, period_month: month)
  redirect_to admin_expenses_path, notice: "Marked reimbursed with #{month.strftime('%B %Y')}."
rescue ActiveRecord::RecordInvalid
  redirect_to admin_expenses_path, alert: "Only an approved claim can be reimbursed."
end

#rejectObject



20
21
22
23
24
25
26
27
# File 'app/controllers/hr_lite/admin/expenses_controller.rb', line 20

def reject
  expense = decidable.find(params[:id])
  note = params[:decision_note].to_s.strip
  return redirect_to admin_expenses_path, alert: "A note is required to reject." if note.blank?

  expense.reject!(actor: hr_current_user, note: note)
  redirect_to admin_expenses_path, notice: "Claim rejected."
end