From cf0fcca64b3aeae25beceb6b06178c1a0c8277ef Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Fri, 6 Dec 2024 16:21:25 +0000 Subject: [PATCH] Add fe approved failing pv task report Adds the model to handle generating the reporting code for further education claims that have been approved but with a failing provider verification. --- ...aims_with_failing_provider_verification.rb | 91 ++++++++ ...with_failing_provider_verification_spec.rb | 207 ++++++++++++++++++ 2 files changed, 298 insertions(+) create mode 100644 app/models/admin/reports/fe_approved_claims_with_failing_provider_verification.rb create mode 100644 spec/models/admin/reports/fe_approved_claims_with_failing_provider_verification_spec.rb diff --git a/app/models/admin/reports/fe_approved_claims_with_failing_provider_verification.rb b/app/models/admin/reports/fe_approved_claims_with_failing_provider_verification.rb new file mode 100644 index 0000000000..0e6c515abf --- /dev/null +++ b/app/models/admin/reports/fe_approved_claims_with_failing_provider_verification.rb @@ -0,0 +1,91 @@ +module Admin + module Reports + class FeApprovedClaimsWithFailingProviderVerification + HEADERS = [ + "Claim reference", + "Full name", + "Claim amount", + "Claim status", + "Decision date", + "Decision agent", + "Contract of employment", + "Teaching responsibilities", + "First 5 years of teaching", + "One full term", + "Timetabled teaching hours", + "Age range taught", + "Subject", + "Course", + "2.5 hours weekly teaching", + "Performance", + "Disciplinary" + ] + + def as_csv + [HEADERS, *scope.map(&ClaimPresenter.method(:new)).map(&:to_a)] + end + + private + + def scope + Claim + .by_policy(Policies::FurtherEducationPayments) + .approved + .joins(:tasks) + .merge(Task.where(name: "provider_verification", passed: false)) + .includes(:eligibility, decisions: :created_by) + end + + class ClaimPresenter + include Admin::ClaimsHelper + include ActionView::Helpers::NumberHelper + + def initialize(claim) + @claim = claim + end + + def to_a + [ + claim.reference, + claim.full_name, + number_to_currency(claim.award_amount, precision: 0), + status(claim), + approval_date, + approval.created_by.full_name, + present_assertion("contract_type"), + present_assertion("teaching_responsibilities"), + present_assertion("further_education_teaching_start_year"), + present_assertion("taught_at_least_one_term"), + present_assertion("teaching_hours_per_week"), + present_assertion("half_teaching_hours"), + present_assertion("subjects_taught"), + "??", # FIXME RL: not sure what courses should be + present_assertion("teaching_hours_per_week_next_term"), + present_assertion("subject_to_formal_performance_action"), + present_assertion("subject_to_disciplinary_action") + ] + end + + private + + attr_reader :claim + + def approval_date + I18n.l(approval.created_at.to_date, format: :day_month_year) + end + + def approval + @approval ||= claim.decisions.reject(&:undone).last + end + + def present_assertion(name) + case claim.eligibility.verification_assertion(name) + when true then "Yes" + when false then "No" + else "N/A" # fixed and variable contracts have different assertions + end + end + end + end + end +end diff --git a/spec/models/admin/reports/fe_approved_claims_with_failing_provider_verification_spec.rb b/spec/models/admin/reports/fe_approved_claims_with_failing_provider_verification_spec.rb new file mode 100644 index 0000000000..39521ea4c7 --- /dev/null +++ b/spec/models/admin/reports/fe_approved_claims_with_failing_provider_verification_spec.rb @@ -0,0 +1,207 @@ +require "rails_helper" + +RSpec.describe Admin::Reports::FeApprovedClaimsWithFailingProviderVerification do + around do |example| + travel_to Date.new(2024, 11, 1) do + example.run + end + end + + describe "as_csv" do + it "returns a csv of approved fe claims with failing provider verification" do + fe_claim_with_passing_provider_check = create( + :claim, + :approved, + policy: Policies::FurtherEducationPayments + ) + + create( + :task, + :passed, + name: "provider_verification", + claim: fe_claim_with_passing_provider_check + ) + + fe_fixed_claim_with_failing_provider_check = create( + :claim, + :approved, + policy: Policies::FurtherEducationPayments, + first_name: "Elizabeth", + surname: "Hoover", + qa_required: true, + eligibility_attributes: { + award_amount: 2_000, + contract_type: "permanent", + verification: { + assertions: [ + { + name: "contract_type", + outcome: true + }, + { + name: "teaching_responsibilities", + outcome: true + }, + { + name: "further_education_teaching_start_year", + outcome: true + }, + { + name: "teaching_hours_per_week", + outcome: true + }, + { + name: "half_teaching_hours", + outcome: false + }, + { + name: "subjects_taught", + outcome: false + }, + { + name: "subject_to_formal_performance_action", + outcome: true + }, + { + name: "subject_to_disciplinary_action", + outcome: true + } + ] + } + } + ) + + create( + :task, + :failed, + name: "provider_verification", + claim: fe_fixed_claim_with_failing_provider_check + ) + + fe_variable_claim_with_failing_provider_check = create( + :claim, + :approved, + policy: Policies::FurtherEducationPayments, + first_name: "Edna", + surname: "Krabappel", + eligibility_attributes: { + award_amount: 3_000, + contract_type: "variable_hours", + verification: { + assertions: [ + { + name: "contract_type", + outcome: true + }, + { + name: "teaching_responsibilities", + outcome: true + }, + { + name: "further_education_teaching_start_year", + outcome: true + }, + { + name: "taught_at_least_one_term", + outcome: true + }, + { + name: "teaching_hours_per_week", + outcome: true + }, + { + name: "half_teaching_hours", + outcome: true + }, + { + name: "subjects_taught", + outcome: true + }, + { + name: "teaching_hours_per_week_next_term", + outcome: true + }, + { + name: "subject_to_formal_performance_action", + outcome: true + }, + { + name: "subject_to_disciplinary_action", + outcome: false + } + ] + } + } + ) + + create( + :task, + :failed, + name: "provider_verification", + claim: fe_variable_claim_with_failing_provider_check + ) + + csv = described_class.new.as_csv + + expect(csv).to match_array([ + [ + "Claim reference", + "Full name", + "Claim amount", + "Claim status", + "Decision date", + "Decision agent", + "Contract of employment", + "Teaching responsibilities", + "First 5 years of teaching", + "One full term", + "Timetabled teaching hours", + "Age range taught", + "Subject", + "Course", + "2.5 hours weekly teaching", + "Performance", + "Disciplinary" + ], + [ + fe_fixed_claim_with_failing_provider_check.reference, + "Elizabeth Hoover", + "£2,000", + "Approved awaiting QA", + "01/11/2024", + "Aaron Admin", + "Yes", # contract of employment + "Yes", # teaching responsibilities + "Yes", # first 5 years of teaching + "N/A", # one full term - not a question for fixed term contracts + "Yes", # timetabled teaching hours + "No", # age range taught + "No", # subject + "??", # course + "N/A", # 2.5 hours weekly teaching + "Yes", # performance + "Yes" # disciplinary + ], + [ + fe_variable_claim_with_failing_provider_check.reference, + "Edna Krabappel", + "£3,000", + "Approved awaiting payroll", + "01/11/2024", + "Aaron Admin", + "Yes", # contract of employment + "Yes", # teaching responsibilities + "Yes", # first 5 years of teaching + "Yes", # one full term + "Yes", # timetabled teaching hours + "Yes", # age range taught + "Yes", # subject + "??", # course + "Yes", # 2.5 hours weekly teaching + "Yes", # performance + "No" # disciplinary + ] + ]) + end + end +end