From 3045c1b605ef7c7097348fba6c65a113d247e548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Roberto=20Silva?= Date: Thu, 12 Apr 2012 23:32:34 -0300 Subject: [PATCH] implement all confirmed backers report --- app/admin/dashboards.rb | 1 + app/controllers/reports_controller.rb | 10 +++++++++- config/routes.rb | 1 + lib/reports/users/backers.rb | 24 ++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/admin/dashboards.rb b/app/admin/dashboards.rb index 92d12d1424..9e75226c10 100644 --- a/app/admin/dashboards.rb +++ b/app/admin/dashboards.rb @@ -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 diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index d982b5a068..3868059d28 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -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 \ No newline at end of file + + 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 diff --git a/config/routes.rb b/config/routes.rb index c31f5749e2..dfe4b013cc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/lib/reports/users/backers.rb b/lib/reports/users/backers.rb index e69d0f2fe3..fdde48d088 100644 --- a/lib/reports/users/backers.rb +++ b/lib/reports/users/backers.rb @@ -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)