Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process Form 497 Page 2 (Late Expenditures) #31

Merged
merged 5 commits into from
Sep 21, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion calculators/candidate_expenditures_by_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,21 @@ def expenditures_by_candidate_by_type
ORDER BY "Expn_Code", "Filer_ID", "Report_Num" DESC
SQL

results.each do |result|
# 497 does not contain "Expn_Code" making this calculator pretty useless
# for those contributions.
# To make the numbers line up closer, we'll bucket those all under "Not
# Stated".
late_expenditures = ActiveRecord::Base.connection.execute(<<-SQL)
SELECT DISTINCT ON ("Filer_ID")
"Filer_ID", '' AS "Expn_Code", SUM("Amount") AS "Total"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should '' be 'Not stated'? Or maybe null so it's easier to handle on the frontend?

FROM "efile_COAK_2016_497"
WHERE "Filer_ID" IN ('#{@candidates_by_filer_id.keys.join "','"}')
AND "Form_Type" = 'F497P2'
GROUP BY "Filer_ID", "Report_Num"
ORDER BY "Filer_ID", "Report_Num" DESC
SQL

(results.to_a + late_expenditures.to_a).each do |result|
hash[result['Filer_ID']] ||= {}
hash[result['Filer_ID']][result['Expn_Code']] = result['Total']
end
Expand Down