ActiveAdmin.register_page "JamClassReports", as: "JamClass Cohort Report" do
  menu :parent => 'JamClass'

  content :title => "JamClass Report" do
    para do
      link_to "Campaign Spend", admin_campaignspend_path
    end
    para do
      table_for JamClassReport.analyse do

        column "Campaign" do |r|
          if r.campaign.nil?
            "N/A"
          else
            r.campaign
          end
        end
        column "Cohort" do |r|
          if r.cohort.nil?
            "Total"
          else
            "#{Date::ABBR_MONTHNAMES[r.cohort.month]} #{r.cohort.year}"
          end
        end
        column "Spend" do |r|
          if r.spend.nil?
            "N/A"
          else
            r.spend
          end
        end
        column "Registrations", :registrations
        column "TD Customers", :td_customers
        column "JamClass Revenues", :jamclass_rev
        column "TD4", :td4
        column "TD2", :td2
        column "TD1", :td1
        column "Spend/TD" do |r|
          if r.spend_td.nil?
            "N/A"
          else
            r.spend_td
          end
        end
        column "% 0 BC" do |r|
          (r.purchases0 * 100).round
        end
        column "% 1 BC" do |r|
          (r.purchases1 * 100).round
        end
        column "% 2 BC" do |r|
          (r.purchases2 * 100).round
        end
        column "% 3 BC" do |r|
          (r.purchases3 * 100).round
        end
        column "% 4+ BC" do |r|
          (r.purchases_rest * 100).round
        end
      end
    end

  end
end


