Class: SavedClaim::EducationBenefits::VA1990

Inherits:
SavedClaim::EducationBenefits show all
Defined in:
app/models/saved_claim/education_benefits/va_1990.rb

Constant Summary collapse

BENEFIT_TITLE_FOR_1990 =
{
  'chapter30' => 'Montgomery GI Bill (MGIB or Chapter 30) Education Assistance Program',
  'chapter33' => 'Post-9/11 GI Bill (Chapter 33)',
  'chapter1606' => 'Montgomery GI Bill Selected Reserve (MGIB-SR or Chapter 1606) Educational Assistance Program',
  'chapter32' => 'Post-Vietnam Era Veterans’ Educational Assistance Program (VEAP or chapter 32)'
}.freeze
BENEFIT_RELINQUISHED_TITLE_FOR_1990 =
{
  'unknown' => 'I’m only eligible for the Post-9/11 GI Bill',
  'chapter30' => 'Montgomery GI Bill (MGIB-AD, Chapter 30)',
  'chapter1606' => 'Montgomery GI Bill Selected Reserve (MGIB-SR, Chapter 1606)',
  'chapter1607' => 'Reserve Educational Assistance Program (REAP, Chapter 1607)'
}.freeze

Instance Method Summary collapse

Methods inherited from SavedClaim::EducationBenefits

#add_education_benefits_claim, form_class, #in_progress_form_id, #regional_office_address

Methods inherited from SavedClaim

add_form_and_validation, #after_create_metrics, #after_destroy_metrics, #attachment_keys, #business_line, #confirmation_number, #email, #form_is_string, #form_matches_schema, #form_must_be_string, #insert_notification, #open_struct_form, #parsed_form, #process_attachments!, #submitted_at, #to_pdf, #update_form, #va_notification?, #validate_form, #validate_schema

Methods inherited from ApplicationRecord

descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?

Instance Method Details

#after_submit(_user) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'app/models/saved_claim/education_benefits/va_1990.rb', line 22

def after_submit(_user)
  return unless Flipper.enabled?(:form1990_confirmation_email)

  parsed_form_data ||= JSON.parse(form)
  email = parsed_form_data['email']
  return if email.blank?

  send_confirmation_email(parsed_form_data, email)
end

#benefits_claimed(parsed_form_data) ⇒ Object (private)



56
57
58
59
60
61
# File 'app/models/saved_claim/education_benefits/va_1990.rb', line 56

def benefits_claimed(parsed_form_data)
  %w[chapter30 chapter33 chapter1606 chapter32]
    .map { |benefit| parsed_form_data[benefit] ? BENEFIT_TITLE_FOR_1990[benefit] : nil }
    .compact
    .join("\n\n^")
end

#send_confirmation_email(parsed_form_data, email) ⇒ Object (private)



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/saved_claim/education_benefits/va_1990.rb', line 34

def send_confirmation_email(parsed_form_data, email)
  benefit_relinquished = if parsed_form_data['benefitsRelinquished'].present?
                           "__Benefits Relinquished:__\n^" \
                             "#{BENEFIT_RELINQUISHED_TITLE_FOR_1990[parsed_form_data['benefitsRelinquished']]}"
                         else
                           ''
                         end

  VANotify::EmailJob.perform_async(
    email,
    Settings.vanotify.services.va_gov.template_id.form1990_confirmation_email,
    {
      'first_name' => parsed_form.dig('veteranFullName', 'first')&.upcase.presence,
      'benefits' => benefits_claimed(parsed_form_data),
      'benefit_relinquished' => benefit_relinquished,
      'date_submitted' => Time.zone.today.strftime('%B %d, %Y'),
      'confirmation_number' => education_benefits_claim.confirmation_number,
      'regional_office_address' => regional_office_address
    }
  )
end