-
-
Notifications
You must be signed in to change notification settings - Fork 572
Expand file tree
/
Copy pathannual_reports_controller.rb
More file actions
53 lines (42 loc) · 1.55 KB
/
annual_reports_controller.rb
File metadata and controls
53 lines (42 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
48
49
50
51
52
53
class Reports::AnnualReportsController < ApplicationController
before_action :validate_show_params, only: [:show, :recalculate]
def index
# 2813_update_annual_report -- changed to earliest_reporting_year
# so that we can do system tests and staging
foundation_year = current_organization.earliest_reporting_year
@actual_year = Time.current.year
@years = (foundation_year...@actual_year).to_a
@month_remaining_to_report = 12 - Time.current.month
respond_to do |format|
format.html
format.csv do
yearly_reports = Reports.reports_across_the_year(organization: current_organization)
send_data Exports::ExportYearlyReportCSVService.new(yearly_reports:).generate_csv,
filename: "NdbnYearlyReports-#{Time.zone.today}.csv"
end
end
end
def show
@year = year_param
@report = Reports.retrieve_report(organization: current_organization, year: @year)
respond_to do |format|
format.html
format.csv do
send_data Exports::ExportReportCSVService.new(reports: @report.all_reports).generate_csv,
filename: "NdbnAnnuals-#{@year}-#{Time.zone.today}.csv"
end
end
end
def recalculate
year = year_param
Reports.retrieve_report(organization: current_organization, year: year, recalculate: true)
redirect_to reports_annual_report_path(year), notice: "Recalculated annual report!"
end
private
def year_param
params.require(:year)
end
def validate_show_params
not_found! unless year_param.to_i.positive?
end
end