Skip to content

Commit

Permalink
NJ 118 - Lines 45, 49, 50, 54: Calculating Total Tax Due
Browse files Browse the repository at this point in the history
  • Loading branch information
aloverso committed Nov 22, 2024
1 parent cc02b7a commit b95e2a7
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 2 deletions.
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 @@ -42,7 +42,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 @@ -302,10 +306,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.positive? ? difference : 0
end

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

def calculate_line_54
sum = calculate_line_50 + calculate_line_51
sum.positive? ? sum : 0
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 @@ -340,6 +340,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 @@ -355,6 +404,23 @@ def hash_for_pdf
]))
end

# line 50
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 @@ -165,8 +165,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 @@ -1032,12 +1032,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 (tax)' 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 @@ -1055,6 +1086,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: 112 additions & 1 deletion spec/lib/pdf_filler/nj1040_pdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,87 @@
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,615.10 (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 "6"
expect(pdf_fields["Text102"]).to eq "1"
expect(pdf_fields["Text108"]).to eq "5"
# 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

p pdf_fields

# 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,615.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 "6"
expect(pdf_fields["Text127"]).to eq "1"
expect(pdf_fields["Text128"]).to eq "5"
# 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 @@ -1416,7 +1497,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 @@ -1431,6 +1512,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: 200
)
}

it "writes $7815 (line 50 $7,615 + line 51 $200)" 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 "5"
# 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
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,50 @@
end
end

describe 'line 45 - balance of tax' do
let(:intake) { create(:state_file_nj_intake) }
it 'sets line 45 to calculated value' do
stub_value = 20_000
allow_any_instance_of(Efile::Nj::Nj1040Calculator).to receive(:calculate_line_45).and_return stub_value
expect(xml.at("BalanceOfTaxA").text).to eq(stub_value.to_s)
end
end

describe 'line 49 - total credits' do
let(:intake) { create(:state_file_nj_intake) }
it 'sets line 49 to calculated value' do
stub_value = 0
allow_any_instance_of(Efile::Nj::Nj1040Calculator).to receive(:calculate_line_49).and_return stub_value
expect(xml.at("TotalCredits").text).to eq(stub_value.to_s)
end
end

describe 'line 50 - balance of tax after credits' do
let(:intake) { create(:state_file_nj_intake) }
it 'sets line 50 to calculated value' do
stub_value = 10_000
allow_any_instance_of(Efile::Nj::Nj1040Calculator).to receive(:calculate_line_50).and_return stub_value
expect(xml.at("BalanceOfTaxAfterCredit").text).to eq(stub_value.to_s)
end
end

describe "use tax - line 51" do
let(:intake) { create(:state_file_nj_intake, sales_use_tax: 123) }
it "fills SalesAndUseTax with sales_use_tax" do
expect(xml.at("SalesAndUseTax").text).to eq(123.to_s)
end
end

describe 'line 54 - total tax due' do
let(:intake) { create(:state_file_nj_intake) }
it 'sets line 54 to calculated value' do
stub_value = 10_000
allow_any_instance_of(Efile::Nj::Nj1040Calculator).to receive(:calculate_line_54).and_return stub_value
expect(xml.at("TotalTaxAndPenalty").text).to eq(stub_value.to_s)
end
end


describe "property tax credit - line 56" do
context 'when no property tax paid' do
let(:intake) {
Expand Down

0 comments on commit b95e2a7

Please sign in to comment.