forked from codeforamerica/vita-min
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadditional_dependents_pdf.rb
37 lines (32 loc) · 1.4 KB
/
additional_dependents_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
module PdfFiller
class AdditionalDependentsPdf
include PdfHelper
attr_accessor :start_node
def source_pdf_name
"tax_documents/additional_dependents"
end
def initialize(submission, start_node: 4)
# For some PDF fields, use values from the database b/c the XML values are truncated or missing.
@xml_document = SubmissionBuilder::Ty2021::Documents::Irs1040.new(submission).document
@start_node = start_node
end
def hash_for_pdf
answers = {}
dependent_nodes = @xml_document.search("DependentDetail")
answers.merge!(dependents_info(dependent_nodes[start_node..])) if dependent_nodes.length > start_node
answers
end
private
def dependents_info(dependent_nodes)
answers = {}
dependent_nodes.each_with_index do |dependent, index|
answers["DependentNameRow#{index + 1}"] = [dependent.at("DependentFirstNm").text, dependent.at("DependentLastNm").text].join(" ")
answers["TINRow#{index + 1}"] = dependent.at("DependentSSN").text
answers["RelationshipRow#{index + 1}"] = dependent.at("DependentRelationshipCd").text
answers["CTCRow#{index + 1}"] = xml_value_to_bool(dependent.at("EligibleForChildTaxCreditInd"), "CheckboxType") ? "Yes" : nil
answers["ODCRow#{index + 1}"] = xml_value_to_bool(dependent.at("EligibleForODCInd"), "CheckboxType") ? "Yes" : nil
end
answers
end
end
end