Skip to content

Commit

Permalink
Add 1099r pdf, xml and tax calculations (#4707)
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Rotondo <[email protected]>
Co-authored-by: Martha Pidcock <[email protected]>
  • Loading branch information
3 people authored Sep 12, 2024
1 parent 9270a7e commit 48faf32
Show file tree
Hide file tree
Showing 19 changed files with 243 additions and 121 deletions.
38 changes: 28 additions & 10 deletions app/lib/efile/az/az140_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def calculate
set_line(:AZ140_LINE_14, :calculate_line_14)
set_line(:AZ140_LINE_19, :calculate_line_19)
set_line(:AZ140_LINE_28, @direct_file_data, :interest_reported_amount)
set_line(:AZ140_LINE_29A, :calculate_line_29A)
set_line(:AZ140_LINE_29B, :calculate_line_29B)
set_line(:AZ140_LINE_30, @direct_file_data, :fed_taxable_ssb)
set_line(:AZ140_LINE_31, :calculate_line_31)
set_line(:AZ140_LINE_32, :calculate_line_32)
Expand Down Expand Up @@ -94,6 +96,23 @@ def calculate_line_19
line_or_zero(:AZ140_LINE_14)
end

def calculate_line_29A
# total subtraction amount for pensions up to the maximum of $2,500 each for primary and spouse
pension_amount = 0
if @intake.primary_received_pension_yes?
pension_amount += [@intake.primary_received_pension_amount.round, 2_500].min
end
if filing_status_mfj? && @intake.spouse_received_pension_yes?
pension_amount += [@intake.spouse_received_pension_amount.round, 2_500].min
end
pension_amount
end

def calculate_line_29B
# total subtraction amount for uniformed services
@intake.received_military_retirement_payment_yes? ? @intake.received_military_retirement_payment_amount.round : 0
end

def calculate_line_31
@intake.tribal_member_yes? ? @intake.tribal_wages : 0
end
Expand All @@ -103,7 +122,8 @@ def calculate_line_32
end

def calculate_line_35
subtractions = 0
# Subtotal after additions and subtractions
subtractions = line_or_zero(:AZ140_LINE_29A) + line_or_zero(:AZ140_LINE_29B)
(30..32).each do |line_num|
subtractions += line_or_zero("AZ140_LINE_#{line_num}")
end
Expand Down Expand Up @@ -213,7 +233,7 @@ def calculate_line_50
wrksht_2_line_5 = 120
end

#wrksheet 2
# worksheet 2
wrksht_2_line_3 = @dependent_count + wrksht_2_line_2
wrksht_2_line_4 = wrksht_2_line_3 * 40
[wrksht_2_line_4, wrksht_2_line_5].min
Expand All @@ -224,17 +244,15 @@ def calculate_line_52
[line_52_value, 0].max
end

# TODO: test combination of multiple forms (w2, 1099G, 1099R) in the spec for this calculator
def calculate_line_53
# zzz
total_state_taxes_withheld = @direct_file_data.total_state_tax_withheld
state_file_1099gs = @intake.state_file1099_gs
state_file_1099gs.each do |state_file_1099g|
total_state_taxes_withheld += state_file_1099g.state_income_tax_withheld
end
total_state_taxes_withheld
# AZ income tax withheld
# sum of tax withheld from all income documents: W-2, 1099-R, 1099-G, 1099-INT
@direct_file_data.total_w2_state_tax_withheld +
@intake.state_file1099_gs.sum(&:state_income_tax_withheld) +
@direct_file_data.total_1099r_state_tax_withheld
end


def calculate_line_56
if @intake.disqualified_from_excise_credit_df? || @intake.disqualified_from_excise_credit_fyst?
0
Expand Down
6 changes: 5 additions & 1 deletion app/lib/efile/line_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ AZ140_LINE_12:
AZ140_LINE_14:
label: '14 Modified federal adjusted gross income. Subtract line 13 from line 12.'
AZ140_LINE_19:
label: '19 Subtotal: Add lines 14 through 18 and enter the total .'
label: '19 Subtotal: Add lines 14 through 18 and enter the total.'
AZ140_LINE_28:
label: '28 Interest on US obligations such as Savings Bonds and Treasury Bills included in the AZ Column'
AZ140_LINE_29A:
label: '29A total subtraction amount for pensions up to the maximum of $2,500 each for primary and spouse.'
AZ140_LINE_29B:
label: "29B Total subtraction amount for benefits, annuities, and pensions for retired/retainer pay of uniformed services"
AZ140_LINE_30:
label: '30 U.S. Social Security or Railroad Retirement Act benefits included as income on your federal return (taxable amount)'
AZ140_LINE_31:
Expand Down
12 changes: 5 additions & 7 deletions app/lib/efile/ny/it201.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,14 @@ def calculate_line_69a
end

def calculate_line_72
total_state_taxes_withheld = @direct_file_data.total_state_tax_withheld
state_file_1099gs = @intake.state_file1099_gs
state_file_1099gs.each do |state_file_1099g|
total_state_taxes_withheld += state_file_1099g.state_income_tax_withheld
end
total_state_taxes_withheld
# NY income tax withheld
# sum of tax withheld from all income documents
@direct_file_data.total_w2_state_tax_withheld +
@intake.state_file1099_gs.sum(&:state_income_tax_withheld)
end

def calculate_line_73
@direct_file_data.total_local_tax_withheld
@direct_file_data.total_w2_local_tax_withheld
end

def calculate_line_76
Expand Down
4 changes: 3 additions & 1 deletion app/lib/pdf_filler/az140_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ def hash_for_pdf
end

answers.merge!({
"19" => @xml_document.at('AzAdjSubtotal')&.text,
"12" => @xml_document.at('FedAdjGrossIncome')&.text,
"14" => @xml_document.at('ModFedAdjGrossInc')&.text,
"19" => @xml_document.at('AzAdjSubtotal')&.text,
"28" => @xml_document.at("Subtractions IntUSObligations")&.text,
"29a" => @xml_document.at('ExecFedStateLocGovPen')&.text,
"29b" => @xml_document.at('SubExclBenAnnPen')&.text,
"30" => @xml_document.at('USSSRailRoadBnft')&.text,
"31" => @xml_document.at('WageAmIndian')&.text,
"32" => @xml_document.at('CompNtnlGrdArmdFrcs')&.text,
Expand Down
2 changes: 2 additions & 0 deletions app/lib/submission_builder/ty2022/states/az/az_return_xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def documents_wrapper
xml.AzAdjSubtotal calculated_fields.fetch(:AZ140_LINE_19)
xml.Subtractions do
add_non_zero_value(xml, :IntUSObligations, :AZ140_LINE_28)
xml.ExecFedStateLocGovPen calculated_fields.fetch(:AZ140_LINE_29A)
xml.SubExclBenAnnPen calculated_fields.fetch(:AZ140_LINE_29B)
xml.USSSRailRoadBnft calculated_fields.fetch(:AZ140_LINE_30)
xml.WageAmIndian calculated_fields.fetch(:AZ140_LINE_31)
xml.CompNtnlGrdArmdFrcs calculated_fields.fetch(:AZ140_LINE_32)
Expand Down
13 changes: 9 additions & 4 deletions app/models/df_1099r_accessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ class Df1099rAccessor < DfXmlAccessor
SELECTORS = {
PayerNameControlTxt: "PayerNameControlTxt",
PayerName: "PayerName BusinessNameLine1Txt",
AddressLine1Txt: "PayerUSAddress AddressLine1Txt",
CityNm: "PayerUSAddress CityNm",
StateAbbreviationCd: "PayerUSAddress StateAbbreviationCd",
ZIPCd: "PayerUSAddress ZIPCd",
PayerAddressLine1Txt: "PayerUSAddress AddressLine1Txt",
PayerAddressLine2Txt: "PayerUSAddress AddressLine2Txt",
PayerCityNm: "PayerUSAddress CityNm",
PayerStateAbbreviationCd: "PayerUSAddress StateAbbreviationCd",
PayerZIPCd: "PayerUSAddress ZIPCd",
PayerEIN: "PayerEIN",
PhoneNum: "PhoneNum",
GrossDistributionAmt: "GrossDistributionAmt",
TaxableAmt: "TaxableAmt",
FederalIncomeTaxWithheldAmt: "FederalIncomeTaxWithheldAmt",
F1099RDistributionCd: "F1099RDistributionCd",
StandardOrNonStandardCd: "StandardOrNonStandardCd",
StateTaxWithheldAmt: "F1099RStateLocalTaxGrp F1099RStateTaxGrp StateTaxWithheldAmt",
StateAbbreviationCd: "F1099RStateLocalTaxGrp F1099RStateTaxGrp StateAbbreviationCd",
PayerStateIdNumber: "F1099RStateLocalTaxGrp F1099RStateTaxGrp PayerStateIdNumber",
StateDistributionAmt: "F1099RStateLocalTaxGrp F1099RStateTaxGrp StateDistributionAmt",
}

def self.selectors
Expand Down
124 changes: 59 additions & 65 deletions app/models/direct_file_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,22 +260,16 @@ def fed_total_adjustments=(value)
write_df_xml_value(__method__, value)
end

def total_state_tax_withheld
total = 0
parsed_xml.css('IRSW2').map do |w2|
amt = w2.at('StateIncomeTaxAmt')&.text.to_i
total += amt
end
total
def total_1099r_state_tax_withheld
form1099rs.sum(&:StateTaxWithheldAmt)
end

def total_local_tax_withheld
total = 0
parsed_xml.css('IRSW2').map do |w2|
amt = w2.at('LocalIncomeTaxAmt')&.text.to_i
total += amt
end
total
def total_w2_state_tax_withheld
w2s.sum(&:StateIncomeTaxAmt)
end

def total_w2_local_tax_withheld
w2s.sum(&:LocalIncomeTaxAmt)
end

def fed_ctc_claimed
Expand Down Expand Up @@ -758,57 +752,57 @@ def attributes
class Df1099R < Df1099rAccessor; end

def attributes
[
:tax_return_year,
:filing_status,
:primary_ssn,
:primary_occupation,
:spouse_ssn,
:spouse_occupation,
:mailing_city,
:mailing_street,
:mailing_apartment,
:mailing_zip,
:cell_phone_number,
:tax_payer_email,
:total_state_tax_withheld,
:fed_tax_amt,
:fed_agi,
:fed_wages,
:fed_wages_salaries_tips,
:fed_taxable_income,
:fed_total_adjustments,
:fed_taxable_ssb,
:fed_ssb,
:fed_eic,
:fed_refund_amt,
:fed_ctc,
:fed_qualify_child,
:fed_puerto_rico_income_exclusion_amount,
:total_exempt_primary_spouse,
:fed_irs_1040_nr,
:fed_unemployment,
:fed_housing_deduction_amount,
:fed_gross_income_exclusion_amount,
:fed_total_income_exclusion_amount,
:fed_foreign_tax_credit_amount,
:fed_credit_for_child_and_dependent_care_amount,
:fed_education_credit_amount,
:fed_retirement_savings_contribution_credit_amount,
:fed_energy_efficiency_home_improvement_credit_amount,
:fed_credit_for_elderly_or_disabled_amount,
:fed_clean_vehicle_personal_use_credit_amount,
:fed_total_reporting_year_tax_increase_or_decrease_amount,
:fed_previous_owned_clean_vehicle_credit_amount,
:fed_calculated_difference_amount,
:fed_nontaxable_combat_pay_amount,
:fed_total_earned_income_amount,
:fed_residential_clean_energy_credit_amount,
:fed_mortgage_interest_credit_amount,
:fed_adoption_credit_amount,
:fed_dc_homebuyer_credit_amount,
:fed_adjustments_claimed,
:fed_taxable_pensions
%i[
tax_return_year
filing_status
primary_ssn
primary_occupation
spouse_ssn
spouse_occupation
mailing_city
mailing_street
mailing_apartment
mailing_zip
cell_phone_number
tax_payer_email
total_w2_state_tax_withheld
fed_tax_amt
fed_agi
fed_wages
fed_wages_salaries_tips
fed_taxable_income
fed_total_adjustments
fed_taxable_ssb
fed_ssb
fed_eic
fed_refund_amt
fed_ctc
fed_qualify_child
fed_puerto_rico_income_exclusion_amount
total_exempt_primary_spouse
fed_irs_1040_nr
fed_unemployment
fed_housing_deduction_amount
fed_gross_income_exclusion_amount
fed_total_income_exclusion_amount
fed_foreign_tax_credit_amount
fed_credit_for_child_and_dependent_care_amount
fed_education_credit_amount
fed_retirement_savings_contribution_credit_amount
fed_energy_efficiency_home_improvement_credit_amount
fed_credit_for_elderly_or_disabled_amount
fed_clean_vehicle_personal_use_credit_amount
fed_total_reporting_year_tax_increase_or_decrease_amount
fed_previous_owned_clean_vehicle_credit_amount
fed_calculated_difference_amount
fed_nontaxable_combat_pay_amount
fed_total_earned_income_amount
fed_residential_clean_energy_credit_amount
fed_mortgage_interest_credit_amount
fed_adoption_credit_amount
fed_dc_homebuyer_credit_amount
fed_adjustments_claimed
fed_taxable_pensions
].each_with_object({}) do |field, hsh|
hsh[field] = send(field)
end
Expand Down
12 changes: 8 additions & 4 deletions app/views/state_file/questions/federal_info/_df_1099r.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
<table>
<%= f.state_file_nested_xml_field :PayerNameControlTxt %>
<%= f.state_file_nested_xml_field :PayerName %>
<%= f.state_file_nested_xml_field :AddressLine1Txt %>
<%= f.state_file_nested_xml_field :CityNm %>
<%= f.state_file_nested_xml_field :StateAbbreviationCd %>
<%= f.state_file_nested_xml_field :ZIPCd %>
<%= f.state_file_nested_xml_field :PayerAddressLine1Txt %>
<%= f.state_file_nested_xml_field :PayerCityNm %>
<%= f.state_file_nested_xml_field :PayerStateAbbreviationCd %>
<%= f.state_file_nested_xml_field :PayerZIPCd %>
<%= f.state_file_nested_xml_field :PayerEIN %>
<%= f.state_file_nested_xml_field :PhoneNum %>
<%= f.state_file_nested_xml_field :GrossDistributionAmt %>
<%= f.state_file_nested_xml_field :TaxableAmt %>
<%= f.state_file_nested_xml_field :FederalIncomeTaxWithheldAmt %>
<%= f.state_file_nested_xml_field :F1099RDistributionCd %>
<%= f.state_file_nested_xml_field :StateTaxWithheldAmt %>
<%= f.state_file_nested_xml_field :StateAbbreviationCd %>
<%= f.state_file_nested_xml_field :PayerStateIdNumber %>
<%= f.state_file_nested_xml_field :StateDistributionAmt %>
</table>

<%= f.hidden_field :_destroy %>
Expand Down
5 changes: 0 additions & 5 deletions app/views/state_file/questions/federal_info/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@
</div>
</div>

<div style="background: #eaacea; padding: 15px; margin-bottom: 15px;">
<h3>TODO ZONE: where do these things go?</h3>
<%= f.state_file_qa_input_field :total_state_tax_withheld, "Total state tax withheld" %>
</div>

<%= f.continue %>
<% end %>
<% end %>
24 changes: 16 additions & 8 deletions spec/features/state_file/editing_df_xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,20 @@

fill_in "PayerName", with: "Rose Apothecary"
fill_in "PayerNameControlTxt", with: "ROSEAPC"
fill_in "AddressLine1Txt", with: "123 Schit Street"
fill_in "CityNm", with: "Schitts Creek"
fill_in "StateAbbreviationCd", with: "AZ"
fill_in "ZIPCd", with: "43212"
fill_in "PayerAddressLine1Txt", with: "123 Schit Street"
fill_in "PayerCityNm", with: "Schitts Creek"
fill_in "PayerStateAbbreviationCd", with: "AZ"
fill_in "PayerZIPCd", with: "43212"
fill_in "PayerEIN", with: "000000003"
fill_in "PhoneNum", with: "3025551223"
fill_in "GrossDistributionAmt", with: 3000
fill_in "TaxableAmt", with: 200
fill_in "FederalIncomeTaxWithheldAmt", with: 150
fill_in "F1099RDistributionCd", with: "8"
fill_in "StateTaxWithheldAmt", with: 20
fill_in "StateAbbreviationCd", with: "NC"
fill_in "PayerStateIdNumber", with: "987654321"
fill_in "StateDistributionAmt", with: 200

click_on "Continue"

Expand All @@ -103,15 +107,19 @@
expect(StateFileAzIntake.last.direct_file_data.fed_taxable_pensions).to eq 200
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].PayerName).to eq "Rose Apothecary"
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].PayerNameControlTxt).to eq "ROSEAPC"
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].AddressLine1Txt).to eq "123 Schit Street"
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].CityNm).to eq "Schitts Creek"
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].StateAbbreviationCd).to eq "AZ"
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].ZIPCd).to eq "43212"
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].PayerAddressLine1Txt).to eq "123 Schit Street"
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].PayerCityNm).to eq "Schitts Creek"
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].PayerStateAbbreviationCd).to eq "AZ"
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].PayerZIPCd).to eq "43212"
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].PayerEIN).to eq "000000003"
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].PhoneNum).to eq "3025551223"
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].GrossDistributionAmt).to eq 3000
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].TaxableAmt).to eq 200
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].FederalIncomeTaxWithheldAmt).to eq 150
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].F1099RDistributionCd).to eq "8"
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].StateTaxWithheldAmt).to eq 20
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].StateAbbreviationCd).to eq "NC"
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].PayerStateIdNumber).to eq "987654321"
expect(StateFileAzIntake.last.direct_file_data.form1099rs[0].StateDistributionAmt).to eq 200
end
end
Loading

0 comments on commit 48faf32

Please sign in to comment.