Class: Adm::FinancialsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/adm/financials_controller.rb

Instance Method Summary collapse

Instance Method Details

#collectionObject



15
16
17
# File 'app/controllers/adm/financials_controller.rb', line 15

def collection
  @projects = projects.page(params[:page])
end

#indexObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/adm/financials_controller.rb', line 19

def index
  respond_to do |format|
    format.html {collection}
    format.csv do
      csv_string = CSV.generate do |csv|
        # header row
        csv << ["name", "moip", "goal", "reached", "moip_tax", "catarse_fee", "repass_value","expires_at", "backer_report", "state"]
        # data rows
        projects.each do |project|
          catarse_fee = ::Configuration[:catarse_fee].to_f * project.pledged
          csv << [project.name,
                  project.user.,
                  project.display_goal,
                  project.display_pledged,
                  view_context.number_to_currency(project.total_payment_service_fee, precision: 2),
                  view_context.number_to_currency(catarse_fee, precision: 2),
                  view_context.number_to_currency(project.pledged*0.87, precision: 2),
                  project.display_expires_at,
                  adm_reports_backer_reports_url(project_id: project.id, format: :csv),
                  project.state
          ]
        end
      end
      send_data csv_string,
                type: 'text/csv; charset=iso-8859-1; header=present',
                disposition: "attachment; filename=financials.csv"
    end
  end
end

#projectsObject



11
12
13
# File 'app/controllers/adm/financials_controller.rb', line 11

def projects
  @search = apply_scopes(Project).includes(:user).order("CASE state WHEN 'successful' THEN 1 WHEN 'waiting_funds' THEN 2 ELSE 3 END, (projects.expires_at)::date DESc")
end