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]
elsif (params[:start])
name_description = "from-#{params[:start]}"
if (params[:end])
name_description += "-to-#{params[:end]}"
end
end
filename = "end-of-year-report-#{name_description}.csv"
data = QuerySupporters.year_aggregate_report(params[:nonprofit_id], {:year => params[:year], :start => params[:start]})
filename = "aggregate-report-#{name_description}.csv"
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)
end
end

View file

@ -630,16 +630,13 @@ UNION DISTINCT
end
end
if (time_range_params[:start])
wip = time_range_params[:start].is_a?(DateTime) ? time_range_params[:start] : nil
if (wip.nil? && time_range_params[:start].is_a?(Date))
wip = time_range_params[:start].to_datetime
end
if(wip.nil? && time_range_params[:start].is_a?(String))
wip = DateTime.parse(time_range_params[:start])
start = parse_convert_datetime(time_range_params[:start])
if (time_range_params[:end])
end_datetime = parse_convert_datetime(time_range_params[:end])
end
unless wip.nil?
return wip, wip + 1.year
unless start.nil?
return start, end_datetime ? end_datetime : start + 1.year
end
end
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.select{|s| s.recurring_donations.select{|rd| rd.active }.length > 1}
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