Skip to content

Commit

Permalink
NJ 118 - Lines 45, 49, 50, 54: Calculating Total Tax Due (#5023)
Browse files Browse the repository at this point in the history
Co-authored-by: Hugo Melo <hmelo@codeforamerica.org>
  • Loading branch information
aloverso and squanto committed Nov 27, 2024
1 parent cc7cb53 commit 9aa9f70
Show file tree
Hide file tree
Showing 7 changed files with 299 additions and 3 deletions.
8 changes: 8 additions & 0 deletions app/lib/efile/line_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,16 @@ NJ1040_LINE_42:
label: '42 New Jersey Taxable Income (Subtract line 41 from line 39)'
NJ1040_LINE_43:
label: '43 Tax on amount on line 42 (Tax Table page 54)'
NJ1040_LINE_45:
label: '45 Balance of Tax (Subtract line 44 from line 43)'
NJ1040_LINE_49:
label: '49 Total Credits (Add lines 46 through 48)'
NJ1040_LINE_50:
label: '50 Balance of Tax After Credits (Subtract line 49 from line 45) If zero or less, make no entry'
NJ1040_LINE_51:
label: '51 Use Tax Due on Internet, Mail-Order, or Other Out-of-State Purchases (See instructions) If no Use Tax, enter 0.00'
NJ1040_LINE_54:
label: '54 Total Tax Due (Add lines 50 through 53c)'
NJ1040_LINE_56:
label: '56 Property Tax Credit (See instructions page 25)'
NJ1040_LINE_57:
Expand Down
22 changes: 22 additions & 0 deletions app/lib/efile/nj/nj1040_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ def calculate
set_line(:NJ1040_LINE_41, :calculate_line_41)
set_line(:NJ1040_LINE_42, :calculate_line_42)
set_line(:NJ1040_LINE_43, :calculate_line_43)
set_line(:NJ1040_LINE_45, :calculate_line_45)
set_line(:NJ1040_LINE_49, :calculate_line_49)
set_line(:NJ1040_LINE_50, :calculate_line_50)
set_line(:NJ1040_LINE_51, :calculate_line_51)
set_line(:NJ1040_LINE_54, :calculate_line_54)
set_line(:NJ1040_LINE_56, :calculate_line_56)
set_line(:NJ1040_LINE_57, :calculate_line_57)
set_line(:NJ1040_LINE_58, :calculate_line_58)
Expand Down Expand Up @@ -332,10 +336,28 @@ def calculate_line_43
should_use_property_tax_deduction ? calculate_tax_liability_with_deduction.round : calculate_tax_liability_without_deduction.round
end

def calculate_line_45
calculate_line_43
end

def calculate_line_49
0
end

def calculate_line_50
difference = calculate_line_45 - calculate_line_49
[difference, 0].max
end

def calculate_line_51
(@intake.sales_use_tax || 0).round
end

def calculate_line_54
sum = calculate_line_50 + calculate_line_51
[sum, 0].max
end

def calculate_line_56
if should_use_property_tax_deduction || is_ineligible_or_unsupported_for_property_tax_credit
nil
Expand Down
66 changes: 66 additions & 0 deletions app/lib/pdf_filler/nj1040_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,55 @@ def hash_for_pdf
]))
end

# line 45
if @xml_document.at("BalanceOfTaxA").present?
tax_balance = @xml_document.at("BalanceOfTaxA").text.to_i
answers.merge!(insert_digits_into_fields(tax_balance, [
"Text110",
"Text109",
"Text108",
"Text102",
"Text99",
"undefined_126",
"undefined_125",
"45",
"4036y54ethdf!!!##\$$",
"Enter Code4332243ewR@434",
]))
end

# line 49
if @xml_document.at("TotalCredits").present?
credits = @xml_document.at("TotalCredits").text.to_i
answers.merge!(insert_digits_into_fields(credits, [
"Text125",
"Text124",
"Text123",
"Text122",
"Text121",
"undefined_132",
"undefined_131",
"48",
]))
end

# line 50
if @xml_document.at("BalanceOfTaxAfterCredit").present?
balance_after_credits = @xml_document.at("BalanceOfTaxAfterCredit").text.to_i
answers.merge!(insert_digits_into_fields(balance_after_credits, [
"Text130",
"Text129",
"Text128",
"Text127",
"Text126",
"undefined_134",
"undefined_133",
"49",
'4036y54ethdf\(*H', # this has to be single-quotes not double-quotes or everything will break
"Enter Code4332243ew6576z66z##",
]))
end

# line 51
if @xml_document.at("SalesAndUseTax").present?
tax = @xml_document.at("SalesAndUseTax").text.to_i
Expand All @@ -389,6 +438,23 @@ def hash_for_pdf
]))
end

# line 54
if @xml_document.at("TotalTaxAndPenalty").present?
total_tax_and_penalty = @xml_document.at("TotalTaxAndPenalty").text.to_i
answers.merge!(insert_digits_into_fields(total_tax_and_penalty, [
"Text152",
"Text151",
"Text150",
"Text149",
"Text148",
"undefined_142",
"undefined_141",
"53",
"4036y54ethdf%%^87",
"Enter Code4332243ew^^%$#",
]))
end

# line 56
if @xml_document.at("PropertyTaxCredit").present?
tax = @xml_document.at("PropertyTaxCredit").text.to_i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,14 @@ def document

xml.Tax calculated_fields.fetch(:NJ1040_LINE_43)

xml.BalanceOfTaxA calculated_fields.fetch(:NJ1040_LINE_45)
xml.TotalCredits calculated_fields.fetch(:NJ1040_LINE_49)
xml.BalanceOfTaxAfterCredit calculated_fields.fetch(:NJ1040_LINE_50)

xml.SalesAndUseTax calculated_fields.fetch(:NJ1040_LINE_51)

xml.TotalTaxAndPenalty calculated_fields.fetch(:NJ1040_LINE_54)

if calculated_fields.fetch(:NJ1040_LINE_57)
xml.EstimatedPaymentTotal calculated_fields.fetch(:NJ1040_LINE_57)
end
Expand Down
50 changes: 49 additions & 1 deletion spec/lib/efile/nj/nj1040_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1078,12 +1078,43 @@ def over_65_birth_year
end

describe 'line 42 - new jersey taxable income' do
let(:intake) { create(:state_file_nj_intake, :primary_over_65, :primary_blind) }
let(:intake) { create(:state_file_nj_intake) }
it 'sets line 42 to line 39 (taxable income)' do
expect(instance.lines[:NJ1040_LINE_42].value).to eq(instance.lines[:NJ1040_LINE_39].value)
end
end

describe 'line 45 - balance of tax' do
let(:intake) { create(:state_file_nj_intake) }
it 'sets line 45 to equal line 43' do
expect(instance.lines[:NJ1040_LINE_45].value).to eq(instance.lines[:NJ1040_LINE_43].value)
end
end

describe 'line 49 - total credits' do
let(:intake) { create(:state_file_nj_intake) }
it 'sets line 49 to equal 0 always' do
expect(instance.lines[:NJ1040_LINE_49].value).to eq(0)
end
end

describe 'line 50 - balance of tax after credits' do
let(:intake) { create(:state_file_nj_intake) }
it 'sets line 50 to equal line 45 minus line 49' do
allow(instance).to receive(:calculate_line_45).and_return 20_000
allow(instance).to receive(:calculate_line_49).and_return 8_000
instance.calculate
expect(instance.lines[:NJ1040_LINE_50].value).to eq(12_000)
end

it 'sets line 50 to 0 if the difference is negative' do
allow(instance).to receive(:calculate_line_45).and_return 20_000
allow(instance).to receive(:calculate_line_49).and_return 30_000
instance.calculate
expect(instance.lines[:NJ1040_LINE_50].value).to eq(0)
end
end

describe 'line 51 - sales and use tax' do

context 'when sales_use_tax exists (already calculated automated or manual)' do
Expand All @@ -1101,6 +1132,23 @@ def over_65_birth_year
end
end

describe 'line 54 - total tax due' do
let(:intake) { create(:state_file_nj_intake) }
it 'sets line 54 to equal line 50 plus line 51' do
allow(instance).to receive(:calculate_line_50).and_return 20_000
allow(instance).to receive(:calculate_line_51).and_return 8_000
instance.calculate
expect(instance.lines[:NJ1040_LINE_54].value).to eq(28_000)
end

it 'sets line 54 to 0 if the sum is negative' do
allow(instance).to receive(:calculate_line_50).and_return -20_000
allow(instance).to receive(:calculate_line_51).and_return 10_000
instance.calculate
expect(instance.lines[:NJ1040_LINE_54].value).to eq(0)
end
end

describe 'line 57 - estimated tax payments' do

context 'when estimated_tax_payments exists' do
Expand Down
113 changes: 111 additions & 2 deletions spec/lib/pdf_filler/nj1040_pdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

it 'uses field names that exist in the pdf' do
missing_fields = pdf.hash_for_pdf.keys.map(&:to_s) - pdf_fields.keys
expect(missing_fields).to eq([])
expect(missing_fields).to eq(["4036y54ethdf\\(*H"]) # expected from NJ1040 Line 50 due to HTML-escaping issues
end

context "with county code" do
Expand Down Expand Up @@ -1481,6 +1481,85 @@
end
end

describe "line 45 - balance of tax" do
let(:submission) {
create :efile_submission, tax_return: nil, data_source: create(
:state_file_nj_intake,
:df_data_many_w2s,
:married_filing_jointly,
household_rent_own: 'own',
property_tax_paid: 15_000,
)
}

it "writes rounded tax amount $7,519.00 (same as line 43)" do
# millions
expect(pdf_fields["Enter Code4332243ewR@434"]).to eq ""
expect(pdf_fields["4036y54ethdf!!!##\$$"]).to eq ""
# thousands
expect(pdf_fields["45"]).to eq ""
expect(pdf_fields["undefined_125"]).to eq ""
expect(pdf_fields["undefined_126"]).to eq "7"
# hundreds
expect(pdf_fields["Text99"]).to eq "5"
expect(pdf_fields["Text102"]).to eq "1"
expect(pdf_fields["Text108"]).to eq "9"
# decimals
expect(pdf_fields["Text109"]).to eq "0"
expect(pdf_fields["Text110"]).to eq "0"
end
end

describe "line 49 - total credits" do
let(:submission) {
create :efile_submission, tax_return: nil, data_source: create(:state_file_nj_intake,)
}

it "writes total credits $0" do

# thousands
expect(pdf_fields["48"]).to eq ""
expect(pdf_fields["undefined_131"]).to eq ""
expect(pdf_fields["undefined_132"]).to eq ""
# hundreds
expect(pdf_fields["Text121"]).to eq ""
expect(pdf_fields["Text122"]).to eq ""
expect(pdf_fields["Text123"]).to eq "0"
# decimals
expect(pdf_fields["Text124"]).to eq "0"
expect(pdf_fields["Text125"]).to eq "0"
end
end

describe "line 50 - balance of tax after credit" do
let(:submission) {
create :efile_submission, tax_return: nil, data_source: create(
:state_file_nj_intake,
:df_data_many_w2s,
:married_filing_jointly,
household_rent_own: 'own',
property_tax_paid: 15_000,
)
}

it "writes rounded tax amount $7,519.10 (same as line 45)" do
# millions
expect(pdf_fields["Enter Code4332243ew6576z66z##"]).to eq ""
expect(pdf_fields["4036y54ethdf(*H"]).to eq ""
# thousands
expect(pdf_fields["49"]).to eq ""
expect(pdf_fields["undefined_133"]).to eq ""
expect(pdf_fields["undefined_134"]).to eq "7"
# hundreds
expect(pdf_fields["Text126"]).to eq "5"
expect(pdf_fields["Text127"]).to eq "1"
expect(pdf_fields["Text128"]).to eq "9"
# decimals
expect(pdf_fields["Text129"]).to eq "0"
expect(pdf_fields["Text130"]).to eq "0"
end
end

describe "line 51 - use tax" do
let(:submission) {
create :efile_submission, tax_return: nil, data_source: create(
Expand All @@ -1489,7 +1568,7 @@
)
}

it "writes $123.00 property tax credit" do
it "writes $123.00 use tax" do
# thousands
expect(pdf_fields["50"]).to eq ""
expect(pdf_fields["50_2"]).to eq ""
Expand All @@ -1504,6 +1583,36 @@
end
end

describe "line 54 - total tax and penalty" do
let(:submission) {
create :efile_submission, tax_return: nil, data_source: create(
:state_file_nj_intake,
:df_data_many_w2s,
:married_filing_jointly,
household_rent_own: 'own',
property_tax_paid: 15_000,
sales_use_tax: 300
)
}

it "writes $7819 (line 50 $7,519 + line 51 $300)" do
# millions
expect(pdf_fields["Enter Code4332243ew^^%$#"]).to eq ""
expect(pdf_fields["4036y54ethdf%%^87"]).to eq ""
# thousands
expect(pdf_fields["53"]).to eq ""
expect(pdf_fields["undefined_141"]).to eq ""
expect(pdf_fields["undefined_142"]).to eq "7"
# hundreds
expect(pdf_fields["Text148"]).to eq "8"
expect(pdf_fields["Text149"]).to eq "1"
expect(pdf_fields["Text150"]).to eq "9"
# decimals
expect(pdf_fields["Text151"]).to eq "0"
expect(pdf_fields["Text152"]).to eq "0"
end
end

describe "line 56 - property tax credit" do
context 'when taxpayer income is above property tax minimum' do
let(:submission) {
Expand Down
Loading

0 comments on commit 9aa9f70

Please sign in to comment.