Skip to content

Commit

Permalink
Add fe approved failing pv task report
Browse files Browse the repository at this point in the history
Adds the model to handle generating the reporting code for further
education claims that have been approved but with a failing provider
verification.
  • Loading branch information
rjlynch committed Dec 6, 2024
1 parent 48d1ba5 commit dc8caee
Show file tree
Hide file tree
Showing 3 changed files with 308 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions app/models/policies/further_education_payments/eligibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def eligible_itt_subject
nil
end

def verification_assertion(name)
assertion_hash[name]
end

private

def provider_and_claimant_names_match?
Expand All @@ -116,6 +120,12 @@ def provider_first_name
def provider_last_name
verification.dig("verifier", "last_name")
end

def assertion_hash
@assertion_hash ||= verification.fetch("assertions").map do |assertion|
[assertion["name"], assertion["outcome"]]
end.to_h
end
end
end
end
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dc8caee

Please sign in to comment.