-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnj2450_pdf.rb
144 lines (127 loc) · 4.39 KB
/
nj2450_pdf.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
module PdfFiller
class Nj2450Pdf
include PdfHelper
include StateFile::NjPdfHelper
include StateFile::Nj2450Helper
include TimeHelper
W2_PDF_KEYS = [
{
employer_name: "Name1",
employer_ein: 'Fed Emp ID',
wages: 'Wages1',
column_a: 'A1',
column_c: 'C1',
},
{
employer_name: 'Name2',
employer_ein: 'Fed Emp ID2',
wages: 'Wages12',
column_a: 'A2',
column_c: 'C2',
},
{
employer_name: 'Name3',
employer_ein: 'Fed Emp ID3',
wages: 'Text-9RgwFiPMah', # Modified because it was also named Wages12
column_a: 'A3',
column_c: 'C3',
},
{
employer_name: 'Name4',
employer_ein: 'Fed Emp ID4',
wages: 'Wages14',
column_a: 'A4',
column_c: 'C4',
},
{
employer_name: 'Name5',
employer_ein: 'Fed Emp ID5',
wages: 'Wages15',
column_a: 'A5',
column_c: 'C5',
}
].freeze
def source_pdf_name
"nj2450-TY2024"
end
def initialize(submission, kwargs)
@submission = submission
@kwargs = kwargs
builder = StateFile::StateInformationService.submission_builder_class(:nj)
@parent_xml_doc = builder.new(submission).document
@xml_document = get_xml_document
end
def hash_for_pdf
answers = {
# Header - get from nj 1040 submission
'Names as shown on Form NJ1040': get_name(@parent_xml_doc),
'Social Security Number': intake.primary.ssn,
'Claimant Name': get_name(@parent_xml_doc, include_spouse: false, spouse_only: primary_or_spouse == :spouse),
'Claimant SSN': ssn,
Address: get_address(@parent_xml_doc),
City: @parent_xml_doc.at("ReturnHeaderState Filer USAddress CityNm")&.text,
State: @parent_xml_doc.at("ReturnHeaderState Filer USAddress StateAbbreviationCd")&.text,
'ZIP Code': @parent_xml_doc.at("ReturnHeaderState Filer USAddress ZIPCd")&.text,
# Sum of remaining W2s
'If additional space is required enclose a rider and enter the total on this line': total_rider_column_a,
'3If additional space is required enclose a rider and enter the total on this line': total_rider_column_c,
# Totals
'Total Deducted Add lines 1A through 1F Enter here': @xml_document.at('ColumnATotal')&.text,
'3Total Deducted Add lines 1A through 1F Enter here': @xml_document.at('ColumnCTotal')&.text,
'14620Subtract line 3 column A from line 2 column A Enter on line 58 of the NJ1040': @xml_document.at('ColumnAExcess')&.text,
'2752Subtract line 3 column C from line 2 column C Enter on line 60 of the NJ1040': @xml_document.at('ColumnCExcess')&.text,
Date: default_date_format(Time.now)
}
W2_PDF_KEYS.each.with_index do |pdf_w2, i|
w2 = w2s[i]
next unless w2
w2_hash = {}
pdf_w2.each_key do |key|
pdf_w2_field_name = pdf_w2[key]
w2_hash[pdf_w2_field_name] = w2[key]
end
answers.merge!(w2_hash)
end
answers
end
private
def intake
@submission.data_source
end
def ssn
primary_or_spouse == :primary ? intake.primary.ssn : intake.spouse&.ssn
end
def primary_or_spouse
@kwargs[:primary_or_spouse]
end
def get_xml_document
nj_2450s = @parent_xml_doc.css('FormNJ2450')
filer_indicator = primary_or_spouse == :primary ? 'T' : 'S'
docs = nj_2450s.select { |nj_2450| nj_2450.at('FilerIndicator')&.text == filer_indicator }
docs[0]
end
def w2s
# 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: 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
def total_rider_column_a
return if w2s.length < 6
w2s[5..].reduce(0) { |sum, w2| sum + w2[:column_a].to_d }.round
end
def total_rider_column_c
return if w2s.length < 6
w2s[5..].reduce(0) { |sum, w2| sum + w2[:column_c].to_d }.round
end
end
end