Skip to content

Commit

Permalink
Begin refactoring PDF Stamper
Browse files Browse the repository at this point in the history
  • Loading branch information
Thrillberg committed Apr 8, 2024
1 parent 8939f6a commit c85c819
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ def handle_attachments(file_path)
end
end

def desired_stamps
coords = if data['preparer_type'] == 'veteran'
[[50, 690]]
elsif data['third_party_type'] == 'power-of-attorney'
[[50, 445]]
elsif data['preparer_type'] == 'third-party-veteran' ||
data['preparer_type'] == 'third-party-non-veteran' ||
data['preparer_type'] == 'non-veteran'
[[50, 570]]
end
[{ coords:, text: data['statement_of_truth_signature'], page: 4 }]
end

def submission_date_config
{
should_stamp_date?: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def words_to_remove
person_address + organization_address
end

def desired_stamps
[{ coords: [50, 240], text: data['statement_of_truth_signature'], page: 2 }]
end

def submission_date_config
{
should_stamp_date?: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def third_party_info
end
end

def desired_stamps
[{ coords: [50, 415], text: data['statement_of_truth_signature'], page: 1 }]
end

def submission_date_config
{
should_stamp_date?: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def zip_code_is_us_based
@data.dig('preparer_address', 'country') == 'USA'
end

def desired_stamps
[{ coords: [50, 465], text: data['statement_of_truth_signature'], page: 2 }]
end

def submission_date_config
{
should_stamp_date?: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def words_to_remove
statement + witness_phone + witness_email
end

def desired_stamps
[{ coords: [50, 160], text: data['statement_of_truth_signature'], page: 2 }]
end

def submission_date_config
{
should_stamp_date?: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ def zip_code_is_us_based
@data.dig('veteran', 'address', 'country') == 'USA'
end

def desired_stamps
[
{
coords: [50, 560],
text: data['statement_of_truth_signature'],
page: 1
}
]
end

def submission_date_config
{
should_stamp_date?: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def zip_code_is_us_based
@data.dig('preparer_address', 'country') == 'USA'
end

def desired_stamps
[{ coords: [50, 190], text: data['statement_of_truth_signature'], page: 1 }]
end

def submission_date_config
{
should_stamp_date?: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ def zip_code_is_us_based
@data.dig('veteran', 'address', 'country') == 'USA'
end

def desired_stamps
desired_stamps = []
unless data['previous_sah_application']['has_previous_sah_application']
desired_stamps.append({ coords: [73, 390], text: 'X',
page: 0 })
end
unless data['previous_hi_application']['has_previous_hi_application']
desired_stamps.append({ coords: [73, 355], text: 'X',
page: 0 })
end
unless data['living_situation']['is_in_care_facility']
desired_stamps.append({ coords: [73, 320], text: 'X',
page: 0 })
end
desired_stamps
end

def submission_date_config
{ should_stamp_date?: false }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def zip_code_is_us_based
true
end

def desired_stamps
[{ coords: [26, 82.5], text: data['statement_of_truth_signature'], page: 0 }]
end

def submission_date_config
{ should_stamp_date?: false }
end
Expand Down
159 changes: 42 additions & 117 deletions modules/simple_forms_api/app/services/simple_forms_api/pdf_stamper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@ class PdfStamper
SUBMISSION_DATE_TITLE = 'Application Submitted:'

def self.stamp_pdf(stamped_template_path, form, current_loa)
stamp_signature(stamped_template_path, form)

stamp_auth_text(stamped_template_path, current_loa)

stamp_submission_date(stamped_template_path, form.submission_date_config)
end

def self.stamp_signature(stamped_template_path, form)
form_number = form.data['form_number']
if FORM_REQUIRES_STAMP.include? form_number
stamp_method = "stamp#{form_number.gsub('-', '')}".downcase
send(stamp_method, stamped_template_path, form)
form.desired_stamps.each do |desired_stamp|
stamp(desired_stamp, stamped_template_path)
end
end
end

def self.stamp_auth_text(stamped_template_path, current_loa)
current_time = "#{Time.current.in_time_zone('America/Chicago').strftime('%H:%M:%S')} "
auth_text = case current_loa
when 3
Expand All @@ -24,118 +35,13 @@ def self.stamp_pdf(stamped_template_path, form, current_loa)
else
'Signee not signed in.'
end
stamp_text = SUBMISSION_TEXT + current_time
desired_stamps = [[10, 10, stamp_text]]
verify(stamped_template_path) { stamp(desired_stamps, stamped_template_path, auth_text, text_only: false) }

stamp_submission_date(stamped_template_path, form.submission_date_config)
end

def self.stamp107959f1(stamped_template_path, form)
desired_stamps = [[26, 82.5, form.data['statement_of_truth_signature']]]
append_to_stamp = false
verify(stamped_template_path) { stamp(desired_stamps, stamped_template_path, append_to_stamp) }
end

def self.stamp264555(stamped_template_path, form)
desired_stamps = []
desired_stamps.append([73, 390, 'X']) unless form.data['previous_sah_application']['has_previous_sah_application']
desired_stamps.append([73, 355, 'X']) unless form.data['previous_hi_application']['has_previous_hi_application']
desired_stamps.append([73, 320, 'X']) unless form.data['living_situation']['is_in_care_facility']
append_to_stamp = false
stamp(desired_stamps, stamped_template_path, append_to_stamp)
end

def self.stamp214142(stamped_template_path, form)
desired_stamps = [[50, 560]]
signature_text = form.data['statement_of_truth_signature']
page_configuration = [
{ type: :new_page },
{ type: :text, position: desired_stamps[0] },
{ type: :new_page }
]

verified_multistamp(stamped_template_path, signature_text, page_configuration)
end

def self.stamp2110210(stamped_template_path, form)
desired_stamps = [[50, 160]]
signature_text = form.data['statement_of_truth_signature']
page_configuration = [
{ type: :new_page },
{ type: :new_page },
{ type: :text, position: desired_stamps[0] }
]

verified_multistamp(stamped_template_path, signature_text, page_configuration)
end

def self.stamp210845(stamped_template_path, form)
desired_stamps = [[50, 240]]
signature_text = form.data['statement_of_truth_signature']
page_configuration = [
{ type: :new_page },
{ type: :new_page },
{ type: :text, position: desired_stamps[0] }
]

verified_multistamp(stamped_template_path, signature_text, page_configuration)
end

def self.stamp21p0847(stamped_template_path, form)
desired_stamps = [[50, 190]]
signature_text = form.data['statement_of_truth_signature']
page_configuration = [
{ type: :new_page },
{ type: :text, position: desired_stamps[0] }
]

verified_multistamp(stamped_template_path, signature_text, page_configuration)
end

def self.stamp210972(stamped_template_path, form)
desired_stamps = [[50, 465]]
signature_text = form.data['statement_of_truth_signature']
page_configuration = [
{ type: :new_page },
{ type: :new_page },
{ type: :text, position: desired_stamps[0] }
]

verified_multistamp(stamped_template_path, signature_text, page_configuration)
end

def self.stamp210966(stamped_template_path, form)
desired_stamps = [[50, 415]]
signature_text = form.data['statement_of_truth_signature']
page_configuration = [
{ type: :new_page },
{ type: :text, position: desired_stamps[0] }
]

verified_multistamp(stamped_template_path, signature_text, page_configuration)
end

def self.stamp2010207(stamped_template_path, form)
desired_stamps = if form.data['preparer_type'] == 'veteran'
[[50, 690]]
elsif form.data['third_party_type'] == 'power-of-attorney'
[[50, 445]]
elsif form.data['preparer_type'] == 'third-party-veteran' ||
form.data['preparer_type'] == 'third-party-non-veteran' ||
form.data['preparer_type'] == 'non-veteran'
[[50, 570]]
end
signature_text = form.data['statement_of_truth_signature']
page_configuration = [
{ type: :new_page },
{ type: :new_page },
{ type: :new_page },
{ type: :new_page },
{ type: :text, position: desired_stamps[0] }
]

verified_multistamp(stamped_template_path, signature_text, page_configuration)
coords = [10, 10]
text = SUBMISSION_TEXT + current_time
page = 0
desired_stamp = { coords:, text:, page: }
verify(stamped_template_path) do
stamp(desired_stamp, stamped_template_path, append_to_stamp: auth_text, text_only: false)
end
end

def self.stamp4010007_uuid(uuid)
Expand Down Expand Up @@ -170,13 +76,21 @@ def self.multistamp(stamped_template_path, signature_text, page_configuration, f
Common::FileHelpers.delete_file_if_exists(stamp_path) if defined?(stamp_path)
end

def self.stamp(desired_stamps, stamped_template_path, append_to_stamp, text_only: true)
def self.stamp(desired_stamp, stamped_template_path, append_to_stamp: false, text_only: true)
current_file_path = stamped_template_path
desired_stamps.each do |x, y, text|
coords = desired_stamp[:coords]
text = desired_stamp[:text]
page = desired_stamp[:page]
x = coords[0]
y = coords[1]
if page.positive?
page_configuration = get_page_configuration(page, coords)
verified_multistamp(stamped_template_path, text, page_configuration)
else
datestamp_instance = CentralMail::DatestampPdf.new(current_file_path, append_to_stamp:)
current_file_path = datestamp_instance.run(text:, x:, y:, text_only:, size: 9)
File.rename(current_file_path, stamped_template_path)
end
File.rename(current_file_path, stamped_template_path)
end

def self.perform_multistamp(stamped_template_path, stamp_path)
Expand Down Expand Up @@ -233,5 +147,16 @@ def self.default_page_configuration
{ type: :new_page }
]
end

def self.get_page_configuration(page, position)
config = [
{ type: :new_page },
{ type: :new_page },
{ type: :new_page },
{ type: :new_page }
]
config[page] = { type: :text, position: }
config
end
end
end
Loading

0 comments on commit c85c819

Please sign in to comment.