Skip to content

Commit

Permalink
Merge branch 'master' into LUPEYALPHA-1103-fix-contract-type-back-button
Browse files Browse the repository at this point in the history
  • Loading branch information
vacabor authored Sep 30, 2024
2 parents 0d13d05 + d684b63 commit 547ba1c
Show file tree
Hide file tree
Showing 23 changed files with 233 additions and 110 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ GEM
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
govuk-components (5.4.0)
govuk-components (5.6.1)
html-attributes-utils (~> 1.0.0, >= 1.0.0)
pagy (>= 6, < 9)
view_component (>= 3.9, < 3.13)
pagy (>= 6, < 10)
view_component (>= 3.9, < 3.15)
govuk_design_system_formbuilder (5.4.0)
actionview (>= 6.1)
activemodel (>= 6.1)
Expand Down Expand Up @@ -325,7 +325,7 @@ GEM
webfinger (~> 1.2)
os (1.1.4)
ostruct (0.6.0)
pagy (8.6.3)
pagy (9.0.9)
parallel (1.25.1)
parallel_tests (4.7.1)
parallel
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/admin/payroll_runs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,16 @@ def show
@payroll_run = PayrollRun.where(id: params[:id]).includes({claims: [:eligibility]}, {payments: [{claims: [:eligibility]}]}).first
@pagy, @payments = pagy(@payroll_run.payments.ordered.includes(claims: [:eligibility]).includes(:topups))
end

def destroy
if PayrollRun.allow_destroy?
PayrollRun.find(params[:id]).destroy!
redirect_to admin_payroll_runs_path, notice: "Payroll run deleted"
else
redirect_to(
admin_payroll_runs_path, alert: "Payroll run deletion is not allowed"
)
end
end
end
end
30 changes: 0 additions & 30 deletions app/helpers/admin/claims_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,6 @@ def claim_route(claim)
claim.logged_in_with_tid? ? I18n.t("admin.claim_route_with_tid") : I18n.t("admin.claim_route_not_tid")
end

def matching_attributes(first_claim, second_claim)
first_attributes = matching_attributes_for_claim(first_claim)
second_attributes = matching_attributes_for_claim(second_claim)

first_eligibility_attributes = matching_attributes_for_eligibility(first_claim.eligibility)
second_eligibility_attributes = matching_attributes_for_eligibility(second_claim.eligibility)

matching_attributes = first_attributes & second_attributes
claim_matches = matching_attributes.to_h.compact.keys.map(&:humanize).sort

matching_eligibility_attributes = first_eligibility_attributes & second_eligibility_attributes
eligibility_matches = matching_eligibility_attributes.to_h.compact.keys.map(&:humanize).sort

claim_matches + eligibility_matches
end

def identity_confirmation_task_claim_verifier_match_status_tag(claim)
task = claim.tasks.detect { |t| t.name == "identity_confirmation" }

Expand Down Expand Up @@ -235,20 +219,6 @@ def no_claims(status)

private

def matching_attributes_for_claim(claim)
claim.attributes
.slice(*Claim::MatchingAttributeFinder::CLAIM_ATTRIBUTE_GROUPS_TO_MATCH.flatten)
.reject { |_, v| v.blank? }
.to_a
end

def matching_attributes_for_eligibility(eligibility)
eligibility.attributes
.slice(*eligibility.policy.eligibility_matching_attributes.flatten)
.reject { |_, v| v.blank? }
.to_a
end

def days_between(first_date, second_date)
(second_date - first_date).to_i
end
Expand Down
15 changes: 14 additions & 1 deletion app/models/claim/matching_attribute_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class MatchingAttributeFinder
CLAIM_ATTRIBUTE_GROUPS_TO_MATCH = [
["email_address"],
["national_insurance_number"],
["bank_account_number", "bank_sort_code", "building_society_roll_number"]
["bank_account_number", "bank_sort_code", "building_society_roll_number"],
["first_name", "surname", "date_of_birth"]
].freeze

def initialize(source_claim)
Expand Down Expand Up @@ -52,6 +53,18 @@ def matching_claims
claims_to_compare.merge(match_queries)
end

def matching_attributes(other_claim)
matching_claim_attributes = CLAIM_ATTRIBUTE_GROUPS_TO_MATCH.select do |attributes|
values_for_attributes(@source_claim, attributes) == values_for_attributes(other_claim, attributes)
end

matching_eligibility_attributes = eligibility_attributes_groups_to_match.select do |attributes|
values_for_attributes(@source_claim.eligibility, attributes) == values_for_attributes(other_claim.eligibility, attributes)
end

(matching_claim_attributes + matching_eligibility_attributes).flatten
end

private

def policies_to_find_matches
Expand Down
3 changes: 2 additions & 1 deletion app/models/journeys/early_years_payment/practitioner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module Practitioner
POLICIES = [Policies::EarlyYearsPayments]
FORMS = {
"claims" => {
"find-reference" => FindReferenceForm
"find-reference" => FindReferenceForm,
"enter-home-address" => AddressForm
}
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class SlugSequence
how-we-use-your-information
personal-details
enter-home-address
email-address
].freeze

def self.start_page_url
Expand Down
6 changes: 6 additions & 0 deletions app/models/payroll_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class PayrollRun < ApplicationRecord

scope :this_month, -> { where(created_at: DateTime.now.all_month) }

def self.allow_destroy?
ENV["ENVIRONMENT_NAME"].start_with?("review") ||
ENV["ENVIRONMENT_NAME"] == "test" ||
Rails.env.development?
end

def total_award_amount
payments.sum(:award_amount)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<th scope="row" class="govuk-table__header"><%= link_to matching_claim.reference, [:admin, matching_claim], class: "govuk-link" %>
<td class="govuk-table__cell">
<ul class="govuk-list">
<% matching_attributes(claim, matching_claim).each do |attribute| %>
<% Claim::MatchingAttributeFinder.new(claim).matching_attributes(matching_claim).map(&:humanize).sort.each do |attribute| %>
<li><%= attribute %></li>
<% end %>
</ul>
Expand Down
11 changes: 11 additions & 0 deletions app/views/admin/payroll_runs/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,15 @@

<%== render partial: 'pagination', locals: { pagy: @pagy } %>
</div>

<% if PayrollRun.allow_destroy? %>
<div class="govuk-grid-column-two-thirds">
<%= button_to(
"Delete payroll run",
admin_payroll_run_path(@payroll_run),
method: :delete,
class: "govuk-button govuk-button--warning",
) %>
</div>
<% end %>
</div>
26 changes: 26 additions & 0 deletions app/views/claims/_address_fields.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<%= f.govuk_text_field :address_line_1,
autocomplete: "address-line1",
label: {
text: "#{t('forms.address.answers.address_line_1')}<span class=\"govuk-visually-hidden\">#{ t('forms.address.answers.address_line_1_visually_hidden')}</span>".html_safe
} %>

<%= f.govuk_text_field :address_line_2,
autocomplete: "address-line2",
label: {
text: "#{t('forms.address.answers.address_line_2')}<span class=\"govuk-visually-hidden\">#{ t('forms.address.answers.address_line_2_visually_hidden')}</span>".html_safe
} %>

<%= f.govuk_text_field :address_line_3,
width: "two-thirds",
autocomplete: "address-level2",
label: { text: t("forms.address.answers.address_line_3") } %>

<%= f.govuk_text_field :address_line_4,
width: "two-thirds",
autocomplete: "off",
label: { text: t("forms.address.answers.address_line_4") } %>

<%= f.govuk_text_field :postcode,
width: 10,
autocomplete: "postal-code",
label: { text: t("forms.address.answers.postcode") } %>
27 changes: 1 addition & 26 deletions app/views/claims/address.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,7 @@
text: t("questions.personal_details"),
size: "xl"
} do %>
<%= f.govuk_text_field :address_line_1,
autocomplete: "address-line1",
label: {
text: "#{t('forms.address.answers.address_line_1')}<span class=\"govuk-visually-hidden\">#{ t('forms.address.answers.address_line_1_visually_hidden')}</span>".html_safe
} %>

<%= f.govuk_text_field :address_line_2,
autocomplete: "address-line2",
label: {
text: "#{t('forms.address.answers.address_line_2')}<span class=\"govuk-visually-hidden\">#{ t('forms.address.answers.address_line_2_visually_hidden')}</span>".html_safe
} %>

<%= f.govuk_text_field :address_line_3,
width: "two-thirds",
autocomplete: "address-level2",
label: { text: t("forms.address.answers.address_line_3") } %>

<%= f.govuk_text_field :address_line_4,
width: "two-thirds",
autocomplete: "off",
label: { text: t("forms.address.answers.address_line_4") } %>

<%= f.govuk_text_field :postcode,
width: 10,
autocomplete: "postal-code",
label: { text: t("forms.address.answers.postcode") } %>
<%= render "address_fields", f: f %>
<% end %>

<%= f.govuk_submit "Continue" %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p class="govuk-body">email address page goes here</p>
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
<p class="govuk-body">enter home address page goes here</p>
<% content_for(:page_title, page_title(t("forms.address.questions.your_address"), journey: current_journey_routing_name, show_error: @form.errors.any?)) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_for @form, url: claim_path(current_journey_routing_name), builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_error_summary %>

<%= f.govuk_fieldset legend: {
text: t("forms.address.questions.your_address"),
tag: "h1",
size: "l"
} do %>
<%= render "address_fields", f: f %>
<% end %>

<%= f.govuk_submit "Continue" %>
<% end %>
</div>
</div>
2 changes: 1 addition & 1 deletion config/initializers/pagy.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "pagy/extras/overflow"
require "pagy/extras/pagy"

Pagy::DEFAULT[:items] = 50
Pagy::DEFAULT[:limit] = 50
Pagy::DEFAULT[:overflow] = :last_page
Pagy::DEFAULT[:size] = [1, 1, 1, 1]
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ en:
policy_short_name: Further Education Targeted Retention Incentive
eligibility_criteria_link:
text: targeted retention incentive payments for early career further education teachers
url: "https://www.gov.uk/guidance/levelling-up-premium-payments-for-fe-teachers"
url: "https://www.gov.uk/guidance/targeted-retention-incentive-payments-for-fe-teachers"
fe_provider_list_url: "https://assets.publishing.service.gov.uk/media/66d70f9c701781e1b341dba7/List_of_eligible_FE_providers_and_payment_values_for_targeted_retention_incentives.xlsx"
admin:
decision:
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def matches?(request)
resources :student_loans_data_uploads, only: [:new, :create]
resources :tps_data_uploads, only: [:new, :create]

resources :payroll_runs, only: [:index, :new, :create, :show] do
resources :payroll_runs, only: [:index, :new, :create, :show, :destroy] do
resources :payment_confirmation_report_uploads, only: [:new, :create]
resource :download, only: [:new, :create, :show], controller: "payroll_run_downloads"
resources :payments, only: [:destroy] do
Expand Down
30 changes: 30 additions & 0 deletions spec/features/admin/admin_claim_with_matching_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,34 @@

expect(page).to have_content("Claim has been approved successfully")
end

scenario "partial matching details" do
claim = create(
:claim,
:submitted,
policy: Policies::StudentLoans,
bank_sort_code: "123456"
)

# Matching claim
create(
:claim,
:submitted,
bank_sort_code: "123456",
eligibility_attributes: {
teacher_reference_number: claim.eligibility.teacher_reference_number
}
)

visit admin_claim_tasks_path(claim)

click_on "Multiple claims"

within "#claims-with-matches" do
expect(page).to have_content "Teacher reference number"
# Bank sort code on it's own isn't enough to trigger a match,
# so shouldn't be displayed
expect(page).not_to have_content "Bank sort code"
end
end
end
6 changes: 3 additions & 3 deletions spec/features/admin/admin_payroll_runs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@
scenario "Payments can be browsed using pagination" do
payroll_run = create(:payroll_run, claims_counts: {Policies::StudentLoans => 7})

stub_const("Pagy::DEFAULT", Pagy::DEFAULT.merge(items: 5))
stub_const("Pagy::DEFAULT", Pagy::DEFAULT.merge(limit: 5))

first_page_payments = payroll_run.payments.ordered[0..Pagy::DEFAULT[:items] - 1]
second_page_payments = payroll_run.payments.ordered[Pagy::DEFAULT[:items]..]
first_page_payments = payroll_run.payments.ordered[0..Pagy::DEFAULT[:limit] - 1]
second_page_payments = payroll_run.payments.ordered[Pagy::DEFAULT[:limit]..]

click_on "Payroll"
click_on "View #{I18n.l(payroll_run.created_at.to_date, format: :month_year)} payroll run"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,14 @@
fill_in "Year", with: "1988"
fill_in "National Insurance number", with: "PX321499A"
click_on "Continue"

expect(page.title).to have_text("What is your address?")
expect(page).to have_content("What is your address?")
fill_in "House number or name", with: "57"
fill_in "Building and street", with: "Walthamstow Drive"
fill_in "Town or city", with: "Derby"
fill_in "County", with: "City of Derby"
fill_in "Postcode", with: "DE22 4BS"
click_on "Continue"
end
end
35 changes: 0 additions & 35 deletions spec/helpers/admin/claims_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,41 +172,6 @@
end
end

describe "#matching_attributes" do
let(:first_claim) {
build(
:claim,
national_insurance_number: "QQ891011C",
email_address: "[email protected]",
bank_account_number: "34682151",
bank_sort_code: "972654",
building_society_roll_number: "123456789/ABCD",
eligibility_attributes: {teacher_reference_number: "0902344"}
)
}
let(:second_claim) {
build(
:claim,
:submitted,
national_insurance_number: first_claim.national_insurance_number,
bank_account_number: first_claim.bank_account_number,
bank_sort_code: first_claim.bank_sort_code,
building_society_roll_number: first_claim.building_society_roll_number,
eligibility_attributes: {teacher_reference_number: first_claim.eligibility.teacher_reference_number}
)
}
subject { helper.matching_attributes(first_claim, second_claim) }

it "returns the humanised names of the matching attributes" do
expect(subject).to eq(["Bank account number", "Bank sort code", "Building society roll number", "National insurance number", "Teacher reference number"])
end

it "does not consider a blank building society roll number to be a match" do
[first_claim, second_claim].each { |claim| claim.building_society_roll_number = "" }
expect(subject).to eq(["Bank account number", "Bank sort code", "National insurance number", "Teacher reference number"])
end
end

describe "#identity_confirmation_task_claim_verifier_match_status_tag" do
subject(:identity_confirmation_task_claim_verifier_match_status_tag) { helper.identity_confirmation_task_claim_verifier_match_status_tag(claim) }

Expand Down
Loading

0 comments on commit 547ba1c

Please sign in to comment.