Class: EducationForm::CreateSpoolSubmissionsReport

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/sidekiq/education_form/create_spool_submissions_report.rb

Instance Method Summary collapse

Instance Method Details

#create_csv_arrayObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/sidekiq/education_form/create_spool_submissions_report.rb', line 18

def create_csv_array
  data = {
    csv_array: [],
    stem_exists: false
  }
  data[:csv_array] << ['Claimant Name', 'Veteran Name', 'Confirmation #', 'Time Submitted', 'RPO']

  EducationBenefitsClaim.where(
    processed_at: processed_at_range
  ).find_each do |education_benefits_claim|
    parsed_form = education_benefits_claim.parsed_form
    data[:csv_array] << [
      format_name(parsed_form['relativeFullName']),
      format_name(parsed_form['veteranFullName']),
      education_benefits_claim.confirmation_number,
      education_benefits_claim.processed_at.to_s,
      education_benefits_claim.regional_processing_office
    ]
  end
  data
end

#format_name(full_name) ⇒ Object



8
9
10
11
12
# File 'app/sidekiq/education_form/create_spool_submissions_report.rb', line 8

def format_name(full_name)
  return if full_name.blank?

  [full_name['first'], full_name['last']].compact.join(' ')
end

#performObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/sidekiq/education_form/create_spool_submissions_report.rb', line 40

def perform
  @time = Time.zone.now
  folder = 'tmp/spool_reports'
  FileUtils.mkdir_p(folder)
  filename = "#{folder}/#{@time.to_date}.csv"
  csv_array_data = create_csv_array
  csv_array = csv_array_data[:csv_array]
  CSV.open(filename, 'wb') do |csv|
    csv_array.each do |row|
      csv << row
    end
  end

  return unless FeatureFlipper.send_edu_report_email?

  SpoolSubmissionsReportMailer.build(filename).deliver_now
end

#processed_at_rangeObject



14
15
16
# File 'app/sidekiq/education_form/create_spool_submissions_report.rb', line 14

def processed_at_range
  (@time - 24.hours)..@time
end