-
-
Notifications
You must be signed in to change notification settings - Fork 573
Expand file tree
/
Copy pathannual_reports_controller.rb
More file actions
67 lines (52 loc) · 1.92 KB
/
annual_reports_controller.rb
File metadata and controls
67 lines (52 loc) · 1.92 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
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
def range
year_start = range_params[:year_start].to_i
year_end = range_params[:year_end].to_i
if year_end < year_start
flash[:error] = "End year must be greater than or equal to start year."
redirect_to reports_annual_reports_path and return
end
reports = Reports::AnnualSurveyReportService.new(organization: current_organization, year_start: year_start, year_end: year_end).call
respond_to do |format|
format.csv do
send_data Exports::ExportReportCSVService.new(reports:).generate_csv(range: true),
filename: "NdbnAnnuals-#{year_start}-#{year_end}.csv"
end
end
end
private
def year_param
params.require(:year)
end
def range_params
params.permit(:year_start, :year_end)
end
def validate_show_params
not_found! unless year_param.to_i.positive?
end
end