Class: Crm::Reports::KpiCallController

Inherits:
CrmController
  • Object
show all
Includes:
Controllers::ReportCommandFlashable
Defined in:
app/controllers/crm/reports/kpi_call_controller.rb

Instance Method Summary collapse

Instance Method Details

#refresh_dataObject



27
28
29
30
# File 'app/controllers/crm/reports/kpi_call_controller.rb', line 27

def refresh_data
  job_id = RefreshKpiCallDataWorker.perform_async
  redirect_to job_path(job_id)
end

#showObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/crm/reports/kpi_call_controller.rb', line 6

def show
  authorize! :read, CallLog
  command_attrs = kpi_call_command_params
  unless helpers.user_has_role?(%w[admin sales_director sales_manager accounting_manager])
    command_attrs[:employee_ids] = [current_user.id.to_s] if command_attrs.present?
  end
  @report_command = ::Report::KpiCall::KpiCallCommand.new(command_attrs)
  @results = @report_command.execute

  return render partial: 'mini_view', layout: false if request.headers['Turbo-Frame'].present?

  flash_report_command_errors
  respond_to do |format|
    format.html do
      render partial: 'mini_view', layout: false if request.xhr?
    end
    format.turbo_stream
    format.csv { send_data @report_command.to_csv, filename: "kpi-call-#{Date.current}.csv" }
  end
end