ActiveAdmin.register JamRuby::AffiliateQuarterlyPayment, :as => 'Affiliate Quarterly Payments' do

  menu :label => 'Quarterly Reports', :parent => 'Affiliates'

  config.sort_order = 'year desc, quarter desc, due_amount_in_cents desc'
  config.batch_actions = false
  config.clear_action_items!
  config.filters = true
  config.per_page = 50
  config.paginate = true

  filter :affiliate_partner
  filter :year
  filter :quarter
  filter :closed
  filter :paid
  filter :jamtracks_sold
  filter :subscriptions_count
  filter :due_amount_in_cents

  form :partial => 'form'

  scope("Sorted By Due Amount",  default: true) { |scope| scope.order('year desc, quarter desc, due_amount_in_cents desc') }
  scope("Sorted By Jamtracks Sold",  default: false) { |scope| scope.order('year desc, quarter desc, jamtracks_sold desc') }
  scope("Sorted By Subs",  default: false) { |scope| scope.order('year desc, quarter desc, subscriptions_count desc') }
  scope("Sorted By Newest First") { |scope| scope.order('year desc, quarter desc, id desc') }
  scope("Any") { |scope| scope.order('year desc, quarter desc, due_amount_in_cents desc') }


  index do

    # default_actions # use this for all view/edit/delete links

    column 'Year' do |oo| oo.year end
    column 'Quarter' do |oo| oo.quarter end
    column 'Partner Id' do |oo| oo.affiliate_partner.id end
    column 'Partner' do |oo| link_to(oo.affiliate_partner.display_name, oo.affiliate_partner.admin_url, {:title => oo.affiliate_partner.display_name}) end
    column "Tot ($)" do |oo| sprintf("$%.2f", oo.due_amount_in_cents.to_f / 100.to_f) end
    column "Sub ($)" do |oo| sprintf("$%.2f", oo.subscription_due_amount_in_cents.to_f / 100.to_f) end
    column "Jam ($)" do |oo| sprintf("$%.2f", oo.jamtrack_due_amount_in_cents.to_f / 100.to_f) end
    column 'JamTracks' do |oo| oo.jamtracks_sold end
    column 'Subscriptions' do |oo| oo.subscriptions_count end
    column 'Paid' do |oo| oo.paid end
    column 'Closed' do |oo| oo.paid end

  end

  controller do

  end
end
