-
Notifications
You must be signed in to change notification settings - Fork 14
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
WIP: Add "Beginning Cash Balance" to total contributions #234
Open
tdooner
wants to merge
1
commit into
master
Choose a base branch
from
wip-test-out-beginning-cash
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+34
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,8 @@ def fetch | |
WHERE "Filer_ID" = "FPPC"::varchar | ||
AND "Form_Type" = 'F460' | ||
AND "Line_Item" = '5' | ||
AND ("Start_Date" IS NULL OR "Rpt_Date" >= "Start_Date") | ||
AND ("End_Date" IS NULL OR "Rpt_Date" <= "End_Date") | ||
AND ("Start_Date" IS NULL OR "From_Date" >= "Start_Date") | ||
AND ("End_Date" IS NULL OR "Thru_Date" <= "End_Date") | ||
GROUP BY "Filer_ID" | ||
ORDER BY "Filer_ID" | ||
SQL | ||
|
@@ -46,10 +46,42 @@ def fetch | |
contributions_by_filer_id[filer_id] += result['Total'].to_f | ||
end | ||
|
||
# For candidates where we specify a "Start Date", we include their initial | ||
# "Beginning Cash Balance" as a contribution so that our calculation of | ||
# their remaining balance matches up with their actual reported balance. | ||
starting_balances_by_filer_id.each do |filer_id, result| | ||
# Skip records with no Summary sheet for now, to prevent conflicting | ||
# `total_contributions` calculation with contribution_list_calculator. | ||
next unless contributions_by_filer_id.include?(filer_id) | ||
|
||
contributions_by_filer_id[filer_id] += result['Starting_Balance'].to_f | ||
end | ||
|
||
contributions_by_filer_id.each do |filer_id, total_contributions| | ||
candidate = @candidates_by_filer_id[filer_id] | ||
candidate.save_calculation(:total_contributions, total_contributions) | ||
end | ||
end | ||
|
||
def starting_balances_by_filer_id | ||
ActiveRecord::Base.connection.execute(<<-SQL).index_by { |r| r['Filer_ID'] } | ||
WITH first_filing_after_start_dates AS ( | ||
-- Get the first report after the Start Date for each filer | ||
SELECT "Filer_ID", MIN("Thru_Date") as "Thru_Date" | ||
FROM "Summary", candidates | ||
WHERE "Filer_ID" = "FPPC"::varchar | ||
AND "Start_Date" IS NOT NULL | ||
AND "Thru_Date" >= "Start_Date" | ||
GROUP BY "Filer_ID" | ||
) | ||
SELECT "Summary"."Filer_ID", "Summary"."Thru_Date", "Amount_A" as "Starting_Balance" | ||
FROM "Summary" | ||
INNER JOIN first_filing_after_start_dates | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love the use of two different syntax forms for inner join ;) |
||
ON first_filing_after_start_dates."Filer_ID" = "Summary"."Filer_ID" | ||
AND first_filing_after_start_dates."Thru_Date" = "Summary"."Thru_Date" | ||
WHERE "Form_Type" = 'F460' | ||
AND "Line_Item" = '12'; | ||
SQL | ||
end | ||
end | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is just a bug fix. While it should not happen, it seems like there could be a problem where the reporting period spans the Start or End date. This would imply that the date recorded as the start/end of the campaign was not accurate, I think. I recall these dates are set fairly arbitrarily.