Class: HrLite::Admin::ReportsController

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

Overview

The numbers somebody asks for at the end of a month, and the CSV they ask for straight afterwards.

Every report is scoped by the SAME permission that guards the screens its data comes from — a report is not a side door into rows somebody cannot otherwise reach.

Constant Summary collapse

REPORTS =
{
  "headcount" => "Headcount by department",
  "joiners_and_leavers" => "Joiners and leavers",
  "leave_balances" => "Leave balances",
  "attendance" => "Attendance summary",
  "expenses" => "Expense claims"
}.freeze

Instance Method Summary collapse

Instance Method Details

#indexObject



25
26
27
28
29
30
# File 'app/controllers/hr_lite/admin/reports_controller.rb', line 25

def index
  # Only the reports this person could actually open — a list of links
  # that turn you away is worse than a shorter list.
  @reports = REPORTS.select { |name, _| permitted?(name) }
  @month = parse_month_param(params[:month])
end

#showObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/hr_lite/admin/reports_controller.rb', line 32

def show
  @month = parse_month_param(params[:month])
  @name = params[:id]
  return hr_access_denied unless REPORTS.key?(@name)
  return hr_access_denied unless permitted?(@name)

  @rows = rows_for(@name)
  respond_to do |format|
    format.html
    format.csv do
      AuditLog.record!(action: "report.exported", subject: hr_current_user,
                       actor: hr_current_user,
                       changes: { "report" => @name, "rows" => @rows.size,
                                  "month" => @month.strftime("%Y-%m") })
      send_data to_csv(@rows), filename: "#{@name}-#{@month.strftime('%Y-%m')}.csv",
                               type: "text/csv"
    end
  end
end