Class: EducationForm::Create10203SpoolSubmissionsReport
- Inherits:
-
Object
- Object
- EducationForm::Create10203SpoolSubmissionsReport
- Includes:
- Sidekiq::Job
- Defined in:
- app/sidekiq/education_form/create10203_spool_submissions_report.rb
Instance Method Summary collapse
- #create_csv_array ⇒ Object
- #denied(state) ⇒ Object
- #denied?(state) ⇒ Boolean
- #format_name(full_name) ⇒ Object
- #header_row(data) ⇒ Object
- #perform ⇒ Object
- #poa?(poa) ⇒ Boolean
- #processed_at_range ⇒ Object
- #processed_submissions ⇒ Object
- #row(ebc) ⇒ Object
Instance Method Details
#create_csv_array ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/sidekiq/education_form/create10203_spool_submissions_report.rb', line 32 def create_csv_array data = { csv_array: [] } header_row(data) submissions = processed_submissions denial_count = 0 submissions.find_each do |education_benefits_claim| automated_decision_state = education_benefits_claim.education_stem_automated_decision&.automated_decision_state denial_count += 1 if denied?(automated_decision_state) data[:csv_array] << row(education_benefits_claim) end # Totals row data[:csv_array] << ['Total Submissions and Denials', '', '', '', submissions.count, denial_count, ''] data end |
#denied(state) ⇒ Object
18 19 20 |
# File 'app/sidekiq/education_form/create10203_spool_submissions_report.rb', line 18 def denied(state) denied?(state) ? 'Y' : 'N' end |
#denied?(state) ⇒ Boolean
22 23 24 |
# File 'app/sidekiq/education_form/create10203_spool_submissions_report.rb', line 22 def denied?(state) state == 'denied' end |
#format_name(full_name) ⇒ Object
8 9 10 11 12 |
# File 'app/sidekiq/education_form/create10203_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 |
#header_row(data) ⇒ Object
53 54 55 56 57 58 |
# File 'app/sidekiq/education_form/create10203_spool_submissions_report.rb', line 53 def header_row(data) data[:csv_array] << ['Submitted VA.gov Applications - Report YYYY-MM-DD', 'Claimant Name', 'Veteran Name', 'Confirmation #', 'Time Submitted', 'Denied (Y/N)', 'POA (Y/N)', 'RPO'] data end |
#perform ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/sidekiq/education_form/create10203_spool_submissions_report.rb', line 82 def perform @time = Time.zone.now folder = 'tmp/spool10203_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 false unless FeatureFlipper.send_edu_report_email? Spool10203SubmissionsReportMailer.build(filename).deliver_now end |
#poa?(poa) ⇒ Boolean
26 27 28 29 30 |
# File 'app/sidekiq/education_form/create10203_spool_submissions_report.rb', line 26 def poa?(poa) return '' if poa.nil? poa ? 'Y' : 'N' end |
#processed_at_range ⇒ Object
14 15 16 |
# File 'app/sidekiq/education_form/create10203_spool_submissions_report.rb', line 14 def processed_at_range (@time - 24.hours)..@time end |
#processed_submissions ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'app/sidekiq/education_form/create10203_spool_submissions_report.rb', line 60 def processed_submissions EducationBenefitsClaim.includes(:saved_claim, :education_stem_automated_decision).where( processed_at: processed_at_range, saved_claims: { form_id: '22-10203' } ) end |
#row(ebc) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/sidekiq/education_form/create10203_spool_submissions_report.rb', line 69 def row(ebc) parsed_form = ebc.parsed_form ['', format_name(parsed_form['relativeFullName']), format_name(parsed_form['veteranFullName']), ebc.confirmation_number, ebc.processed_at.to_s, denied(ebc.education_stem_automated_decision&.automated_decision_state), poa?(ebc.education_stem_automated_decision&.poa), ebc.regional_processing_office] end |