Skip to content

Commit

Permalink
[WIP] Add ESFA response flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitemaeric committed Oct 3, 2024
1 parent 0f91cf2 commit 1a23b79
Show file tree
Hide file tree
Showing 28 changed files with 193 additions and 9 deletions.
3 changes: 2 additions & 1 deletion app/assets/stylesheets/components/_all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@import "page_header";
@import "phase_banner";
@import "primary_navigation";
@import "secondary_navigation";
@import "search_results";
@import "secondary_navigation";
@import "tag";
@import "typography";
3 changes: 3 additions & 0 deletions app/assets/stylesheets/components/_tag.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.govuk-tag {
max-width: unset;
}
4 changes: 4 additions & 0 deletions app/components/claim/status_tag_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def status_colours
draft: "grey",
submitted: "blue",
sent_to_esfa: "light-blue",
paid: "green",
request_information: "orange",
pending_esfa_check: "light-blue",
payment_not_approved: "red",
}.with_indifferent_access
end
end
14 changes: 13 additions & 1 deletion app/controllers/claims/support/claims_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Claims::Support::ClaimsController < Claims::Support::ApplicationController
before_action :set_claim, only: %i[show]
before_action :set_claim, only: %i[show information_sent_to_esfa payment_not_approved]
before_action :authorize_claim
helper_method :filter_form
before_action :set_filtered_claims, only: %i[index download_csv]
Expand All @@ -19,6 +19,18 @@ def download_csv
send_data csv_data, filename: "claims-#{Date.current}.csv", type: "text/csv", disposition: "attachment"
end

def information_sent_to_esfa
@claim.update!(status: :pending_esfa_check)

redirect_to claims_support_claim_path(@claim)
end

def payment_not_approved
@claim.update!(status: :payment_not_approved)

redirect_to claims_support_claim_path(@claim)
end

private

def set_filtered_claims
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Claims::Support::Payments::ConfirmationsController < Claims::Support::ApplicationController
before_action :authorize_payment

def create
Claims::Payment::ParseConfirmation.call(file: file_param)

redirect_to claims_support_payments_path, flash: { success: t(".success") }
end

private

def file_param
params.require(:file)
end

def authorize_payment
authorize [Claims::Payment, :confirmation]
end
end
5 changes: 5 additions & 0 deletions app/models/claims/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# status :enum
# submitted_at :datetime
# submitted_by_type :string
# unpaid_reason :string
# created_at :datetime not null
# updated_at :datetime not null
# claim_window_id :uuid
Expand Down Expand Up @@ -71,6 +72,10 @@ class Claims::Claim < ApplicationRecord
draft: "draft",
submitted: "submitted",
sent_to_esfa: "sent_to_esfa",
paid: "paid",
request_information: "request_information",
pending_esfa_check: "pending_esfa_check",
payment_not_approved: "payment_not_approved",
},
validate: true

Expand Down
8 changes: 8 additions & 0 deletions app/policies/claims/claim_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def download_csv?
user.support_user?
end

def information_sent_to_esfa?
user.support_user? && record.request_information?
end

def payment_not_approved?
user.support_user? && record.request_information?
end

private

def current_claim_window?
Expand Down
9 changes: 9 additions & 0 deletions app/policies/claims/payment/confirmation_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Claims::Payment::ConfirmationPolicy < Claims::ApplicationPolicy
def new?
true
end

def create?
Claims::Claim.where(status: %i[sent_to_esfa pending_esfa_check request_information]).any?
end
end
25 changes: 25 additions & 0 deletions app/services/claims/payment/parse_confirmation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Claims::Payment::ParseConfirmation < ApplicationService
def initialize(file:)
@file = file
end

def call
CSV.foreach(file, headers: true) do |row|
next unless row["claim_status"].in? %w[paid unpaid]

claim = Claims::Claim.find_by(reference: row["claim_reference"])

next unless claim.status.in? %w[sent_to_esfa pending_esfa_check request_information]

if row["claim_status"] == "paid"
claim.update!(status: :paid)
elsif row["claim_status"] == "unpaid"
claim.update!(status: :request_information, unpaid_reason: row["claim_unpaid_reason"])
end
end
end

private

attr_reader :file
end
11 changes: 11 additions & 0 deletions app/views/claims/support/claims/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
<span><%= render Claim::StatusTagComponent.new(claim: @claim) %></span>
</div>

<% if @claim.unpaid_reason.present? %>
<%= govuk_inset_text text: t(".unpaid_reason", reason: @claim.unpaid_reason) %>
<% end %>
<% if @claim.request_information? %>
<div class="app-page-actions">
<%= govuk_button_to t(".actions.information_sent_to_esfa"), information_sent_to_esfa_claims_support_claim_path(@claim), method: :put %>
<%= govuk_button_to t(".actions.payment_not_approved"), payment_not_approved_claims_support_claim_path(@claim), secondary: true, method: :put %>
</div>
<% end %>
<% if @claim.submitted_by_id? %>
<p class="govuk-body"><%= t(".submitted_by", name: @claim.submitted_by.full_name, date: l(@claim.submitted_on, format: :long)) %></p>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<span class="govuk-caption-l"><%= t(".caption") %></span>
<h1 class="govuk-heading-l"><%= t(".heading") %></h1>

<%= form_with url: claims_support_payments_confirmations_path do |f| %>
<%= f.govuk_file_field :file, label: { text: t(".label") }, accept: "text/csv" %>
<%= f.govuk_submit t(".submit") %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= content_for :page_title, t(".heading") %>

<span class="govuk-caption-l"><%= t(".caption") %></span>
<h1 class="govuk-heading-l"><%= t(".heading") %></h1>

<p class="govuk-body"><%= t(".description") %></p>
21 changes: 21 additions & 0 deletions app/views/claims/support/payments/confirmations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%= render "claims/support/primary_navigation", current: :claims %>
<%= content_for(:before_content) do %>
<%= govuk_back_link(href: claims_support_payments_path) %>
<% end %>

<div class="govuk-width-container" data-controller="filter">
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<% if policy([Claims::Payment, :confirmation]).create? %>
<%= render "new_confirmation" %>
<% else %>
<%= render "no_claims_sent_to_esfa" %>
<% end %>

<p class="govuk-body">
<%= govuk_link_to t(".cancel"), claims_support_payments_path %>
</p>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/claims/support/payments/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<p class="govuk-body"><strong><%= t(".results", count: @pagy.count) %></strong></p>

<div class="govuk-!-margin-bottom-2">
<% claims.each do |claim| %>
<% @claims.each do |claim| %>
<%= render Claim::CardComponent.new(claim:) %>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/claims/support/payments/instructions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<h2 class="govuk-heading-m"><%= t(".sub_heading") %></h2>

<%= govuk_button_link_to t(".send_to_esfa"), new_claims_support_payment_path %>
<%= govuk_button_link_to t(".upload_esfa_response"), "#", secondary: true %>
<%= govuk_button_link_to t(".upload_esfa_response"), new_claims_support_payments_confirmation_path, secondary: true %>

<p class="govuk-body"><%= t(".no_claims") %></p>
</div>
1 change: 1 addition & 0 deletions config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ shared:
- reviewed
- previous_revision_id
- claim_window_id
- unpaid_reason
:schools:
- id
- urn
Expand Down
1 change: 1 addition & 0 deletions config/locales/en/claims/support/claims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ en:
provider: Accredited provider
mentor_with_index: Mentor %{index}
mentor: Mentor
unpaid_reason: "This payment was not approved because: %{reason}"
submitted_by: Submitted by %{name} on %{date}.
actions:
information_sent_to_esfa: Information sent to ESFA
Expand Down
18 changes: 18 additions & 0 deletions config/locales/en/claims/support/payments/confirmations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
en:
claims:
support:
payments:
confirmations:
new:
cancel: Cancel
new_confirmation:
caption: Payments
heading: Upload response from ESFA
label: Upload a file
submit: Continue
no_claims_sent_to_esfa:
caption: Payments
heading: You cannot upload a response from the ESFA
description: You cannot upload a response from the ESFA as there are no claims pending payment.
create:
success: ESFA response uploaded
9 changes: 9 additions & 0 deletions config/routes/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,19 @@

resources :claims, only: %i[index show] do
get :download_csv, on: :collection

member do
put :information_sent_to_esfa
put :payment_not_approved
end
end

resources :payments, only: %i[index new create]

namespace :payments do
resources :confirmations, only: %i[new create]
end

resources :support_users, path: "support-users" do
get :check, on: :collection
get :remove, on: :member
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddPaidAndRequestInformationToClaimStatus < ActiveRecord::Migration[7.2]
def change
add_enum_value :claim_status, "paid"
add_enum_value :claim_status, "request_information"
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddPendingESFACheckAndPaymentNotApprovedClaimStatuses < ActiveRecord::Migration[7.2]
def change
add_enum_value :claim_status, "pending_esfa_check"
add_enum_value :claim_status, "payment_not_approved"
end
end
5 changes: 5 additions & 0 deletions db/migrate/20240919150611_add_unpaid_reason_to_claims.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUnpaidReasonToClaims < ActiveRecord::Migration[7.2]
def change
add_column :claims, :unpaid_reason, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# Custom types defined in this database.
# Note that some types may not work with other database engines. Be careful if changing database.
create_enum "claim_status", ["internal_draft", "draft", "submitted", "sent_to_esfa"]
create_enum "claim_status", ["internal_draft", "draft", "submitted", "sent_to_esfa", "paid", "request_information", "pending_esfa_check", "payment_not_approved"]
create_enum "mentor_training_type", ["refresher", "initial"]
create_enum "placement_status", ["draft", "published"]
create_enum "placement_year_group", ["year_1", "year_2", "year_3", "year_4", "year_5", "year_6"]
Expand Down Expand Up @@ -81,6 +81,7 @@
t.uuid "previous_revision_id"
t.boolean "reviewed", default: false
t.uuid "claim_window_id"
t.string "unpaid_reason"
t.index ["claim_window_id"], name: "index_claims_on_claim_window_id"
t.index ["created_by_type", "created_by_id"], name: "index_claims_on_created_by"
t.index ["previous_revision_id"], name: "index_claims_on_previous_revision_id"
Expand Down
1 change: 1 addition & 0 deletions spec/factories/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# status :enum
# submitted_at :datetime
# submitted_by_type :string
# unpaid_reason :string
# created_at :datetime not null
# updated_at :datetime not null
# claim_window_id :uuid
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/claims/payments.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# == Schema Information
#
# Table name: payment_deliveries
# Table name: payments
#
# id :uuid not null, primary key
# claim_ids :string default([]), is an Array
Expand All @@ -10,7 +10,7 @@
#
# Indexes
#
# index_payment_deliveries_on_sent_by_id (sent_by_id)
# index_payments_on_sent_by_id (sent_by_id)
#
# Foreign Keys
#
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/claims/claim_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe Claims::ClaimHelper do
describe "#claim_statuses_for_selection" do
it "returns an array of claims statuses, except draft statuses" do
expect(claim_statuses_for_selection).to contain_exactly("submitted", "sent_to_esfa")
expect(claim_statuses_for_selection).to contain_exactly("paid", "payment_not_approved", "pending_esfa_check", "request_information", "sent_to_esfa", "submitted")
end
end
end
5 changes: 5 additions & 0 deletions spec/models/claims/claim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# status :enum
# submitted_at :datetime
# submitted_by_type :string
# unpaid_reason :string
# created_at :datetime not null
# updated_at :datetime not null
# claim_window_id :uuid
Expand Down Expand Up @@ -96,6 +97,10 @@
draft: "draft",
submitted: "submitted",
sent_to_esfa: "sent_to_esfa",
paid: "paid",
request_information: "request_information",
pending_esfa_check: "pending_esfa_check",
payment_not_approved: "payment_not_approved",
)
.backed_by_column_of_type(:enum)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ def then_i_should_see_the_payment_actions
expect(page).to have_css("h2", text: "Payments")

expect(page).to have_link("Send claims to ESFA", href: new_claims_support_payment_path)
expect(page).to have_link("Upload ESFA response")
expect(page).to have_link("Upload ESFA response", href: new_claims_support_payments_confirmation_path)
end
end

0 comments on commit 1a23b79

Please sign in to comment.