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

Truncate employer name after 35 characters #5455

Merged
merged 4 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions app/helpers/state_file/nj_2450_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,22 @@ def get_persons_w2s(intake, primary_or_spouse)
ssn = primary_or_spouse == :primary ? intake.primary.ssn : intake.spouse.ssn
intake.state_file_w2s.all&.select { |w2| w2.employee_ssn == ssn }
end

def get_employer_name(w2, truncate: false)
truncate ? sanitize_for_xml(w2.employer_name, 35) : w2.employer_name
end

def get_wages(w2)
w2.wages&.round
end

def get_column_a(w2)
column_a = w2.box14_ui_wf_swf&.positive? ? w2.box14_ui_wf_swf : w2.box14_ui_hc_wd
mmazanec22 marked this conversation as resolved.
Show resolved Hide resolved
column_a&.round || 0
end

def get_column_c(w2)
w2.box14_fli&.round || 0
end
end
end
19 changes: 12 additions & 7 deletions app/lib/pdf_filler/nj2450_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ module PdfFiller
class Nj2450Pdf
include PdfHelper
include StateFile::NjPdfHelper
include StateFile::Nj2450Helper
include TimeHelper

W2_PDF_KEYS = [
{
employer_name: 'Name1',
employer_name: "Name1",
employer_ein: 'Fed Emp ID',
wages: 'Wages1',
column_a: 'A1',
Expand Down Expand Up @@ -115,13 +116,17 @@ def get_xml_document
end

def w2s
@xml_document.css('Body').map do |w2|
# Breaks the pattern of getting PDF values from XML
# because we don't want to truncate the employer name in the PDF
# Uses helpers to get w2 values here and in XML to keep them in sync
db_w2s = get_persons_w2s(intake, primary_or_spouse)
@w2s ||= db_w2s.map do |w2|
{
employer_name: w2.at('EmployerName')&.text,
employer_ein: w2.at('FedEmployerId')&.text,
wages: w2.at('Wages')&.text,
column_a: w2.at('ColumnA')&.text,
column_c: w2.at('ColumnC')&.text,
employer_name: get_employer_name(w2),
employer_ein: w2.employer_ein,
wages: get_wages(w2),
column_a: get_column_a(w2),
column_c: get_column_c(w2),
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def document
xml.Body do
column_a = w2.box14_ui_wf_swf&.positive? ? w2.box14_ui_wf_swf : w2.box14_ui_hc_wd
mmazanec22 marked this conversation as resolved.
Show resolved Hide resolved

xml.EmployerName w2.employer_name
xml.EmployerName get_employer_name(w2, truncate: true)
xml.FedEmployerId w2.employer_ein
xml.Wages w2.wages&.round
xml.Wages get_wages(w2)
xml.Deductions do
xml.ColumnA column_a&.round || 0
xml.ColumnA get_column_a(w2)
xml.ColumnB 0
xml.ColumnC w2.box14_fli&.round || 0
xml.ColumnC get_column_c(w2)
end
xml.FilerIndicator filer_indicator
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
<EmployerEIN>001245767</EmployerEIN>
<EmployerNameControlTxt>WSF</EmployerNameControlTxt>
<EmployerName>
<BusinessNameLine1Txt>Wharton State Forest</BusinessNameLine1Txt>
<BusinessNameLine1Txt>Wharton State Forest mountain bike trail maintenance crew</BusinessNameLine1Txt>
</EmployerName>
<EmployerUSAddress>
<AddressLine1Txt>31 Batsto Road</AddressLine1Txt>
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pdf_filler/nj2450_pdf_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rails_helper'

primary_test_cases = [
{ employer_name: 'Primary 1', wages: 1000, box14_fli: 90, box14_ui_hc_wd: 100, employer_ein: 710415181 },
{ employer_name: "Derek Zoolander Center for Kids Who Can't Read Good", wages: 1000, box14_fli: 90, box14_ui_hc_wd: 100, employer_ein: 710415181 },
{ employer_name: 'Primary 2', wages: 1001, box14_fli: 91, box14_ui_hc_wd: 101, employer_ein: 710415182 },
{ employer_name: 'Primary 3', wages: 1002, box14_fli: 92, box14_ui_hc_wd: 102, employer_ein: 710415183 },
{ employer_name: 'Primary 4', wages: 1003, box14_fli: 93, box14_ui_hc_wd: 103, employer_ein: 710415184 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
end

context "primary" do
let!(:w2_1) { create(:state_file_w2, state_file_intake: intake, employee_ssn: primary_ssn_from_fixture, box14_ui_hc_wd: 99, box14_fli: 100, employer_ein: '123456789', wages: '999') }
let(:long_employer_name) { "Derek Zoolander Center for Kids Who Can't Read Good" }
let!(:w2_1) { create(:state_file_w2, state_file_intake: intake, employee_ssn: primary_ssn_from_fixture, box14_ui_hc_wd: 99, box14_fli: 100, employer_ein: '123456789', wages: '999', employer_name: long_employer_name) }
let!(:w2_2) { create(:state_file_w2, state_file_intake: intake, employee_ssn: primary_ssn_from_fixture, box14_ui_hc_wd: 134, box14_fli: 123, employer_ein: '923456781', wages: '888') }

it "fills body for each w2" do
Expand All @@ -24,7 +25,10 @@
body_elements.each do |body|
w2 = [w2_1, w2_2].find { |test_w2| test_w2.employer_ein == body.at('FedEmployerId').text}

expect(body.at('EmployerName').text).to eq(w2.employer_name)
expect(body.at('EmployerName').text).to eq(w2.employer_name[0...35])
if w2.employer_name == long_employer_name
expect(body.at('EmployerName').text.length).to eq(35)
Copy link
Contributor

Choose a reason for hiding this comment

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

[pebble] putting expectations inside an if feels off to me, since there's an outside chance the test is only passing because the expectation isn't being tested. I think the expectation on line 28 is probably enough on its own, but if you feel there needs to be more then you could test explicitly the two expected names outside of the .each?

end
expect(body.at('Wages').text).to eq(w2.wages.round.to_s)
expect(body.at('Deductions ColumnA').text).to eq(w2.box14_ui_hc_wd.round.to_s)
expect(body.at('Deductions ColumnC').text).to eq(w2.box14_fli.round.to_s)
Expand Down
Loading