Provide editable range to the end-of-year report

This commit is contained in:
Eric Schultz 2018-10-23 10:43:05 -05:00 committed by Eric Schultz
parent 0ca77c5c72
commit efbe2a0a80
2 changed files with 22 additions and 10 deletions

View file

@ -22,10 +22,13 @@ module Nonprofits
name_description = params[:year] name_description = params[:year]
elsif (params[:start]) elsif (params[:start])
name_description = "from-#{params[:start]}" name_description = "from-#{params[:start]}"
if (params[:end])
name_description += "-to-#{params[:end]}"
end
end end
filename = "end-of-year-report-#{name_description}.csv" filename = "aggregate-report-#{name_description}.csv"
data = QuerySupporters.year_aggregate_report(params[:nonprofit_id], {:year => params[:year], :start => params[:start]}) data = QuerySupporters.year_aggregate_report(params[:nonprofit_id], {:year => params[:year], :start => params[:start], :end => params[:end]})
send_data(Format::Csv.from_array(data), filename: filename) send_data(Format::Csv.from_array(data), filename: filename)
end end
end end

View file

@ -630,16 +630,13 @@ UNION DISTINCT
end end
end end
if (time_range_params[:start]) if (time_range_params[:start])
wip = time_range_params[:start].is_a?(DateTime) ? time_range_params[:start] : nil start = parse_convert_datetime(time_range_params[:start])
if (wip.nil? && time_range_params[:start].is_a?(Date)) if (time_range_params[:end])
wip = time_range_params[:start].to_datetime end_datetime = parse_convert_datetime(time_range_params[:end])
end
if(wip.nil? && time_range_params[:start].is_a?(String))
wip = DateTime.parse(time_range_params[:start])
end end
unless wip.nil? unless start.nil?
return wip, wip + 1.year return start, end_datetime ? end_datetime : start + 1.year
end end
end end
raise ArgumentError.new("no valid time range provided") raise ArgumentError.new("no valid time range provided")
@ -672,5 +669,17 @@ UNION DISTINCT
supporters = Supporter.where('supporters.nonprofit_id = ?', npo_id).includes(:recurring_donations) supporters = Supporter.where('supporters.nonprofit_id = ?', npo_id).includes(:recurring_donations)
supporters.select{|s| s.recurring_donations.select{|rd| rd.active }.length > 1} supporters.select{|s| s.recurring_donations.select{|rd| rd.active }.length > 1}
end end
def self.parse_convert_datetime(date)
if (date.is_a?(DateTime))
return date
end
if (date.is_a?(Date))
return date.to_datetime
end
if(date.is_a?(String))
return DateTime.parse(date)
end
end
end end