Skip to content

Commit

Permalink
implement all confirmed backers report
Browse files Browse the repository at this point in the history
  • Loading branch information
devton committed Apr 13, 2012
1 parent 6e92d8c commit 3045c1b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/admin/dashboards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
section "Relatorios" do
ul do
li link_to 'Usuários que mais apoiaram', most_backed_report_path
li link_to 'Todos os apoios confirmados', all_confirmed_backers_report_path
end
end

Expand Down
10 changes: 9 additions & 1 deletion app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ def users_most_backed
:type => 'text/csv; charset=utf-8; header=present',
:disposition => "attachment; filename=user_most_backed_#{params[:project_id]}.csv"
end
end

def all_confirmed_backers
return unless require_admin
@csv = Reports::Users::Backers.all_confirmed_backers
send_data @csv,
:type => 'text/csv; charset=utf-8; header=present',
:disposition => "attachment; filename=all_confirmed_backers.csv"
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
match "/reports/financial/:project_id/backers" => "reports#financial_by_project", :as => :backers_financial_report
match "/reports/location/:project_id/backers" => "reports#location_by_project", :as => :backers_location_report
match "/reports/users_most_backed" => "reports#users_most_backed", :as => :most_backed_report
match "/reports/all_confirmed_backers" => "reports#all_confirmed_backers", :as => :all_confirmed_backers_report

match '/sitemap' => "static#sitemap", :as => :sitemap
# Static Pages
Expand Down
24 changes: 24 additions & 0 deletions lib/reports/users/backers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@ module Reports
module Users
class Backers
class << self
def all_confirmed_backers
@backers = Backer.confirmed.includes(:project, :reward)

@csv = CSV.generate(:col_sep => ',') do |csv_string|
csv_string << [
'Valor',
'Recompensa Selecionada Valor',
'Recompensa Selecionada Desc.',
'Confirmado em',
'Projeto'
]

@backers.each do |backer|
csv_string << [
backer.value,
(backer.reward.minimum_value if backer.reward),
(backer.reward.description if backer.reward),
I18n.l(backer.confirmed_at.to_date),
backer.project.name
]
end
end
end

def most_backed(limit=50)
@users = User.most_backeds.limit(limit)

Expand Down

0 comments on commit 3045c1b

Please sign in to comment.