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

Fyst 663 implement form 502 su xml pdf part 1 #4942

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
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
12 changes: 11 additions & 1 deletion app/lib/efile/line_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ MD502_LINE_D_COUNT_TOTAL:
label: 'D Total Exemption Count: add lines A, B and C counts'
MD502_LINE_D_AMOUNT_TOTAL:
label: 'D Total Exemption Dollar Amount: add lines A, B and C amounts'
MD502_LINE_13:
label: Subtractions from attached form 502SU
MD502_LINE_16:
label: 'TBD'
MD502_DEDUCTION_METHOD:
Expand All @@ -574,6 +576,14 @@ MD502CR_PART_B_LINE_4:
label: "4 Multiply line 2 by line 3. Enter here and on Part AA, line 2"
MD502CR_PART_M_LINE_1:
label: "1 Enter the credit claimed here and on Part AA, line 13 (See Instructions)"
MD502_SU_LINE_AB:
label: "AB Income from U.S. Government obligations"
MD502_SU_LINE_U:
label: "TBD"
MD502_SU_LINE_V:
label: "TBD"
MD502_SU_LINE_1:
label: "1 Add lines a. through yc. and enter this amount on line 13 of Form 502 with the appropriate code letters"
NCD400_LINE_9:
label: '9 Deductions From Federal Adjusted Gross Income (From Form D-400 Schedule S, Part B, Line 41)'
NCD400_LINE_10B:
Expand Down Expand Up @@ -626,7 +636,7 @@ NJ1040_LINE_15:
label: '15 Wages, salaries, tips, and other employee compensation (State wages from Box 16 of enclosed W-2(s))'
NJ1040_LINE_16A:
label: 'Taxable interest income (Enclose federal Schedule B if over $1,500) (See instructions)'
NJ1040_LINE_16B:
NJ1040_LINE_16B:
label: 'Tax-exempt interest income (Enclose schedule) (See instructions) Do not include on line 16a'
NJ1040_LINE_27:
label: '27 Total Income (Add lines 15, 16a, and 20a)'
Expand Down
16 changes: 15 additions & 1 deletion app/lib/efile/md/md502_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def initialize(year:, intake:, include_source: false)
lines: @lines,
intake: @intake
)

@md502_su = Efile::Md::Md502SuCalculator.new(
value_access_tracker: @value_access_tracker,
lines: @lines,
intake: @intake
)
end

def calculate
Expand Down Expand Up @@ -44,6 +50,10 @@ def calculate
set_line(:MD502_LINE_15, :calculate_line_15) # STUBBED: PLEASE REPLACE, don't forget line_data.yml
set_line(:MD502_LINE_16, :calculate_line_16) # STUBBED: PLEASE REPLACE, don't forget line_data.yml

# MD502SU Subtractions
@md502_su.calculate
set_line(:MD502_LINE_13, :calculate_line_13)

# Deductions
set_line(:MD502_DEDUCTION_METHOD, :calculate_deduction_method)
set_line(:MD502_LINE_17, :calculate_line_17)
Expand Down Expand Up @@ -256,7 +266,7 @@ def calculate_line_b_amount
end

def calculate_line_c_count
# dependent exemption count
# dependent exemption count
@lines[:MD502B_LINE_3].value
end

Expand Down Expand Up @@ -377,6 +387,10 @@ def calculate_line_20
end
end

def calculate_line_13
@lines[:MD502_SU_LINE_1].value
end

def filing_status_dependent?
@filing_status == :dependent
end
Expand Down
35 changes: 35 additions & 0 deletions app/lib/efile/md/md502_su_calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Efile
module Md
class Md502SuCalculator < ::Efile::TaxCalculator
attr_reader :lines, :value_access_tracker

def initialize(value_access_tracker:, lines:, intake:)
@value_access_tracker = value_access_tracker
@lines = lines
intake = intake
@direct_file_json_data = intake.direct_file_json_data
end

def calculate
set_line(:MD502_SU_LINE_AB, :calculate_line_ab)
set_line(:MD502_SU_LINE_U, :calculate_line_u) # STUBBED: PLEASE REPLACE, don't forget line_data.yml
set_line(:MD502_SU_LINE_V, :calculate_line_v) # STUBBED: PLEASE REPLACE, don't forget line_data.yml
set_line(:MD502_SU_LINE_1, :calculate_line_1)
end

private

def calculate_line_ab
@direct_file_json_data.interest_reports.sum(&:interest_on_government_bonds).round
end

def calculate_line_u; end

def calculate_line_v; end

def calculate_line_1
line_or_zero(:MD502_SU_LINE_AB) + line_or_zero(:MD502_SU_LINE_U) + line_or_zero(:MD502_SU_LINE_V)
end
end
end
end
21 changes: 21 additions & 0 deletions app/lib/pdf_filler/md502_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def hash_for_pdf
'D. Enter Dollar Amount Total Exemptions (Add A, B and C.) ': @xml_document.at('Exemptions Total Amount')&.text,
'Enter 9': @xml_document.at('Form502 Subtractions ChildAndDependentCareExpenses')&.text,
'Enter 11': @xml_document.at('Form502 Subtractions SocialSecurityRailRoadBenefits')&.text,
'Text Field 9': generate_codes_for_502_su.at(0),
'Text Field 10': generate_codes_for_502_su.at(1),
'Text Field 11': generate_codes_for_502_su.at(2),
'Text Field 12': generate_codes_for_502_su.at(3),
'Enter 13': @xml_document.at('Form502 Subtractions Other')&.text,
'Text Box 96': @xml_document.at('ReturnHeaderState Filer Primary USPhone')&.text,
'Check Box 34': deduction_method_is_standard? ? "Yes" : "Off",
'Enter 17': deduction_method_is_standard? ? @xml_document.at('Form502 Deduction Amount')&.text : nil,
Expand Down Expand Up @@ -85,5 +90,21 @@ def filing_status(method)
def checkbox_value(value)
value.present? ? 'Yes' : 'Off'
end

def generate_codes_for_502_su
calculated_fields_code_letters = {MD502_SU_LINE_AB: "ab", MD502_SU_LINE_U: "u", MD502_SU_LINE_V: "v"}
Copy link
Member

Choose a reason for hiding this comment

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

[specs of dust] I think this would be slightly better with newlines for each pair (esp because the list may grow in the future), but incredibly minor.

Suggested change
calculated_fields_code_letters = {MD502_SU_LINE_AB: "ab", MD502_SU_LINE_U: "u", MD502_SU_LINE_V: "v"}
calculated_fields_code_letters = {
MD502_SU_LINE_AB: "ab",
MD502_SU_LINE_U: "u",
MD502_SU_LINE_V: "v"
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

happy to do that :)

applicable_codes = []

if calculated_fields.fetch(:MD502_SU_LINE_1).positive?
calculated_fields_code_letters.each do |calculated_field, code_letter|
applicable_codes << code_letter if calculated_fields.fetch(calculated_field).to_i.positive?
end
end
applicable_codes
end

def calculated_fields
@calculated_fields ||= @submission.data_source.tax_calculator.calculate
end
end
end
35 changes: 35 additions & 0 deletions app/lib/pdf_filler/md502_su_pdf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module PdfFiller
class Md502SuPdf
include PdfHelper

def source_pdf_name
"md502SU-TY2023"
end

def initialize(submission)
@submission = submission
builder = StateFile::StateInformationService.submission_builder_class(:md)
end

def hash_for_pdf
{
'Your First Name' => @submission.data_source.primary.first_name,
'Text1' => @submission.data_source.primary.middle_initial,
'Your Last Name' => @submission.data_source.primary.last_name,
'Your Social Security Number' => @submission.data_source.primary.ssn,
'Spouses First Name' => @submission.data_source.spouse.first_name,
'Text2' => @submission.data_source.spouse.middle_initial,
'Spouses Last Name' => @submission.data_source.spouse.last_name,
'Spouses Social Security Number' => @submission.data_source.spouse.ssn,
'ab Income from US Government obligations See Instruction 13 ab' => calculated_fields.fetch(:MD502_SU_LINE_AB),
'appropriate code letters TOTAL 1' => calculated_fields.fetch(:MD502_SU_LINE_1),
}
end

private

def calculated_fields
@calculated_fields ||= @submission.data_source.tax_calculator.calculate
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def document
xml.Subtractions do
xml.ChildAndDependentCareExpenses @direct_file_data.total_qualifying_dependent_care_expenses
xml.SocialSecurityRailRoadBenefits @direct_file_data.fed_taxable_ssb
xml.Other calculated_fields.fetch(:MD502_LINE_13)
end
xml.Deduction do
xml.Method calculated_fields.fetch(:MD502_DEDUCTION_METHOD)
Expand Down Expand Up @@ -159,4 +160,4 @@ def add_element_if_present(xml, tag, line_id)
value = calculated_fields.fetch(line_id)
xml.send(tag, value) if value.present?
end
end
end
33 changes: 33 additions & 0 deletions app/lib/submission_builder/ty2024/states/md/documents/md502_su.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module SubmissionBuilder
module Ty2024
module States
module Md
module Documents
class Md502Su < SubmissionBuilder::Document
include SubmissionBuilder::FormattingMethods

def document
build_xml_doc("Form502SU", documentId: "Form502SU") do |xml|
xml.Subtractions do |subtractions|
subtractions.Total calculated_fields.fetch(:MD502_SU_LINE_1)
Copy link
Contributor

Choose a reason for hiding this comment

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

[pebble] is there supposed to be an = here or is Total a method name receiving a parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is intentional! the build_xml_doc method generates the xml for the state return. therefore the value for Total will be assigned from this method.

end
end
end

private

def intake
@submission.data_source
end

def calculated_fields
@md502_su_fields ||= intake.tax_calculator.calculate
end
end
end
end
end
end
end
6 changes: 6 additions & 0 deletions app/lib/submission_builder/ty2024/states/md/md_return_xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def schema_file
def supported_documents
calculated_fields = @submission.data_source.tax_calculator.calculate
has_income_from_taxable_pensions_iras_annuities = calculated_fields.fetch(:MD502_LINE_1D)&.to_i.positive?
has_md_su_subtractions = calculated_fields.fetch(:MD502_SU_LINE_1).positive?

supported_docs = [
{
Expand All @@ -57,6 +58,11 @@ def supported_documents
xml: SubmissionBuilder::Ty2024::States::Md::Documents::Md502Cr,
pdf: PdfFiller::Md502CrPdf,
include: true,
},
{
xml: SubmissionBuilder::Ty2024::States::Md::Documents::Md502Su,
pdf: PdfFiller::Md502SuPdf,
include: has_md_su_subtractions,
}
]

Expand Down
11 changes: 11 additions & 0 deletions spec/lib/efile/md/md502_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,17 @@
end
end

describe "#calculate_line_13" do
before do
allow_any_instance_of(Efile::Md::Md502SuCalculator).to receive(:calculate_line_1).and_return 100
end

it 'the sums the amount from line A-C' do
instance.calculate
expect(instance.lines[:MD502_LINE_13].value).to eq 100
end
end

describe "#calculate_line_17" do
context "when method is standard" do
[
Expand Down
39 changes: 39 additions & 0 deletions spec/lib/efile/md/md502_su_calculator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'rails_helper'

describe Efile::Md::Md502SuCalculator do
let(:intake) { create(:state_file_md_intake) }
let(:main_calculator) do
Efile::Md::Md502Calculator.new(
year: MultiTenantService.statefile.current_tax_year,
intake: intake
)
end
let(:instance) { main_calculator.instance_variable_get(:@md502_su) }

describe 'line ab' do
before do
instance.calculate
end

context 'without interest reports' do
it 'does not set line ab' do
expect(instance.lines[:MD502_SU_LINE_AB].value).to eq(0)
end
end

context 'with interest report' do
let(:intake) { create(:state_file_md_intake, :df_data_1099_int) }
it 'sets line ab' do
expect(instance.lines[:MD502_SU_LINE_AB].value).to eq(2)
end
end
end

describe 'line 1' do
it 'totals lines a through yc' do
allow(instance).to receive(:calculate_line_ab).and_return 100
instance.calculate
expect(instance.lines[:MD502_SU_LINE_1].value).to eq(100)
end
end
end
26 changes: 26 additions & 0 deletions spec/lib/pdf_filler/md502_pdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,31 @@
expect(pdf_fields["Enter 20"]).to be_empty
end
end

context "with 502SU Subtractions" do
before do
allow_any_instance_of(Efile::Md::Md502SuCalculator).to receive(:calculate_line_1).and_return 100
allow_any_instance_of(Efile::Md::Md502SuCalculator).to receive(:calculate_line_ab).and_return 100
end

it "fills out subtractions fields correctly" do
expect(pdf_fields["Text Field 9"]).to eq "ab"
expect(pdf_fields["Text Field 10"]).to eq ""
expect(pdf_fields["Text Field 11"]).to eq ""
expect(pdf_fields["Text Field 12"]).to eq ""
expect(pdf_fields["Enter 13"].to_i).to eq 100
end
end

context "without 502SU Subtractions" do
it "fills out subtractions fields correctly" do
expect(pdf_fields["Text Field 9"]).to eq ""
expect(pdf_fields["Text Field 10"]).to eq ""
expect(pdf_fields["Text Field 11"]).to eq ""
expect(pdf_fields["Text Field 12"]).to eq ""
expect(pdf_fields["Enter 13"].to_i).to eq 0
end
end

end
end
Loading
Loading