-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathaz322_pdf.rb
51 lines (46 loc) · 2.36 KB
/
az322_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
module PdfFiller
class Az322Pdf
include PdfHelper
def source_pdf_name
"az322-TY2024"
end
def initialize(submission)
@submission = submission
# Most PDF fields are grabbed right off the XML
builder = StateFile::StateInformationService.submission_builder_class(:az)
@xml_document = builder.new(submission).document
end
def hash_for_pdf
answers = {
"TP_Name" => [@xml_document.at('Primary TaxpayerName FirstName')&.text, @xml_document.at('Primary TaxpayerName MiddleInitial')&.text, @xml_document.at('Primary TaxpayerName LastName')&.text, @xml_document.at('Primary TaxpayerName NameSuffix')&.text].join(' '),
"TP_SSN" => @xml_document.at('Primary TaxpayerSSN')&.text,
"Spouse_Name" => [@xml_document.at('Secondary TaxpayerName FirstName')&.text, @xml_document.at('Secondary TaxpayerName MiddleInitial')&.text, @xml_document.at('Secondary TaxpayerName LastName')&.text, @xml_document.at('Secondary TaxpayerName NameSuffix')&.text].join(' '),
"Spouse_SSN" => @xml_document.at('Secondary TaxpayerSSN')&.text,
"4" => @xml_document.at('Form322 TotalContributionsContSheet')&.text,
"5" => @xml_document.at('Form322 TotalContributions')&.text,
"9" => '0',
"10" => '0',
"11" => @xml_document.at('Form322 SubTotalAmt')&.text,
"12" => @xml_document.at('Form322 SingleHOH')&.text,
"13" => @xml_document.at('Form322 CurrentYrCr')&.text,
"20" => @xml_document.at('Form322 CurrentYrCr')&.text,
"22" => @xml_document.at('Form322 TotalAvailCr')&.text,
"4h" => @xml_document.at('Form322 TotalContributionsContSheet')&.text,
}
@submission.data_source.az322_contributions.each_with_index do |contribution, index|
if index < 3 # First three contributions on the first page with labels 1-3
prefix = (index + 1).to_s
else
letter = ('a'..'g').to_a[index - 3] # Remaining contributions on page 3 use labels #4a-4g
prefix = "4#{letter}"
end
answers["#{prefix}a"] = contribution.date_of_contribution.strftime("%m%d")
answers["#{prefix}b"] = contribution.ctds_code
answers["#{prefix}c"] = contribution.school_name
answers["#{prefix}d"] = contribution.district_name
answers["#{prefix}e"] = contribution.amount.round
end
answers
end
end
end