-
-
Notifications
You must be signed in to change notification settings - Fork 572
Expand file tree
/
Copy pathreports.rb
More file actions
62 lines (58 loc) · 2.26 KB
/
reports.rb
File metadata and controls
62 lines (58 loc) · 2.26 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
module Reports
class << self
# @param year [Integer]
# @param organization [Organization]
# @return [Array<Reports::Report>]
def all_reports(year:, organization:)
[
Reports::DiaperReportService.new(year: year, organization: organization).report,
Reports::WarehouseReportService.new(year: year, organization: organization).report,
Reports::AdultIncontinenceReportService.new(year: year, organization: organization).report,
Reports::PeriodSupplyReportService.new(year: year, organization: organization).report,
Reports::OtherProductsReportService.new(year: year, organization: organization).report,
Reports::PartnerInfoReportService.new(year: year, organization: organization).report,
Reports::ChildrenServedReportService.new(year: year, organization: organization).report,
Reports::SummaryReportService.new(year: year, organization: organization).report,
]
end
# @param year [Integer]
# @param organization [Organization]
# @param recalculate [Boolean]
# @return [AnnualReport]
def retrieve_report(year:, organization:, recalculate: false)
report_attributes = { organization: organization, year: year }
report = AnnualReport.find_or_create_by(report_attributes)
if report.all_reports.blank? || recalculate
calculated_reports = all_reports(**report_attributes)
report.update!(all_reports: calculated_reports)
end
report
end
# @param organization [Organization]
# @return [Array<Reports::Report>]
def reports_across_the_year(organization:)
foundation_year = organization.earliest_reporting_year
last_completed_year = 1.year.ago.year
years = (foundation_year..last_completed_year).to_a
reports_across_the_year = []
years.each do |year|
report = retrieve_report(year: year, organization: organization)
unless report.all_reports.blank?
reports_across_the_year << report.all_reports.unshift(year_hash(year))
end
end
reports_across_the_year
end
private
# @param year [Integer]
# @return [Hash]
def year_hash(year)
{
"name" => "Report Year",
"entries" => {
"Year" => year.to_s
}
}
end
end
end