Class: HrLite::ExpensesController

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

Overview

An employee's own claims. Scoped to the signed-in person the same way every other self-service screen is: a foreign id 404s through the relation rather than 403ing.

Instance Method Summary collapse

Instance Method Details

#cancelObject



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

def cancel
  expense = own.find(params[:id])
  if expense.draft? || expense.
    expense.update!(status: "cancelled")
    expense.approval_route.cancel_all!
    redirect_to expenses_path, notice: "Claim withdrawn."
  else
    redirect_to expenses_path, alert: "Only a claim still waiting can be withdrawn."
  end
end

#createObject



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

def create
  @expense = Expense.new(expense_params.merge(user_id: hr_current_user.id))
  if @expense.save
    @expense.submit!(actor: hr_current_user)
    redirect_to expenses_path, notice: "Claim submitted."
  else
    @categories = ExpenseCategory.active.alphabetical
    render :new, status: :unprocessable_entity
  end
end

#indexObject



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

def index
  @expenses = paginate(own.includes(:category).recent_first)
  @categories = ExpenseCategory.active.alphabetical
end

#newObject



13
14
15
16
# File 'app/controllers/hr_lite/expenses_controller.rb', line 13

def new
  @expense = Expense.new(spent_on: Date.current)
  @categories = ExpenseCategory.active.alphabetical
end