Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  
  def show
    @page_title = "#{@company.name} - IT Reports"
    @report = Report.find_by_id_and_public(params[:id], true)
    return redirect_to(:action => "index") if @report.nil?

    combine = (params[:format].blank? || params[:format] == 'pdf')
    prepare_data_for(@report, :combine_items => combine, :sort_by => params[:sort_by])
    @report.update_attributes(:last_run => Time.now)

    case params[:format]
    when /pdf$/
      send_data spicetable_pdf("#{@company.name}: #{@report.name}", @columns, @headings, @items, :description => @report.description) { |col, item| col.display_value(item, false) }, :type => 'application/pdf'
      increment_stat "report_exported_to_pdf_from_help_desk"
    when /xls$/
      render :text => spicetable_excel("#{@company.name}: #{@report.name}", @columns, @headings, @items, :description => @report.description) { |col, item| col.display_value(item) }
      increment_stat "report_exported_to_excel_from_help_desk"
    when /csv$/
      send_data spicetable_csv("#{@company.name}: #{@report.name}", @columns, @headings, @items, :description => @report.description) { |col, item| col.display_value(item) }, :type => 'text/csv'
      increment_stat "report_exported_to_csv_from_help_desk"
    else
      increment_stat "report_viewed_from_help_desk"
      #fall through for html
    end
  end