-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c674e50
commit 6a80c24
Showing
39 changed files
with
549 additions
and
8 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
app/controllers/claims/support/claims/payment_responses_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class Claims::Support::Claims::PaymentResponsesController < Claims::Support::ApplicationController | ||
append_pundit_namespace :claims | ||
|
||
before_action :authorize_claims_payments_response | ||
|
||
helper_method :claims_payment_response | ||
|
||
def new | ||
render "new_not_permitted" unless policy(claims_payment_response).update? | ||
end | ||
|
||
def check | ||
render "new" unless claims_payment_response.save | ||
end | ||
|
||
def update | ||
Claims::PaymentResponse::Process.call(payment_response: claims_payment_response, current_user:) | ||
|
||
redirect_to claims_support_claims_payments_path, flash: { success: true, heading: t(".success") } | ||
end | ||
|
||
private | ||
|
||
def authorize_claims_payments_response | ||
authorize claims_payment_response | ||
end | ||
|
||
def claims_payment_response_params | ||
params.fetch(:claims_payment_response, {}).permit(:csv_file).merge(user: current_user) | ||
end | ||
|
||
def claims_payment_response | ||
@claims_payment_response ||= params[:id] ? Claims::PaymentResponse.find(params[:id]) : Claims::PaymentResponse.new(claims_payment_response_params) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Claims::RemoveUnprocessedPaymentResponsesJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform | ||
Claims::PaymentResponse.where(processed: false, created_at: ..1.day.ago).find_each(&:destroy!) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# == Schema Information | ||
# | ||
# Table name: payment_responses | ||
# | ||
# id :uuid not null, primary key | ||
# processed :boolean default(FALSE) | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# user_id :uuid not null | ||
# | ||
# Indexes | ||
# | ||
# index_payment_responses_on_user_id (user_id) | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (user_id => users.id) | ||
# | ||
class Claims::PaymentResponse < ApplicationRecord | ||
belongs_to :user | ||
|
||
has_one_attached :csv_file | ||
|
||
validates :csv_file, presence: true | ||
|
||
def row_count | ||
@row_count ||= CSV.parse(csv_file.download, headers: true).length | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
app/policies/claims/support/claims/payment_response_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Claims::Support::Claims::PaymentResponsePolicy < Claims::ApplicationPolicy | ||
def new? | ||
true | ||
end | ||
|
||
def update? | ||
Claims::Claim.payment_in_progress.any? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class Claims::PaymentResponse::Process < ApplicationService | ||
def initialize(payment_response:, current_user:) | ||
@payment_response = payment_response | ||
@current_user = current_user | ||
end | ||
|
||
def call | ||
return if Claims::Claim.payment_in_progress.none? | ||
|
||
ActiveRecord::Base.transaction do | ||
CSV.parse(payment_response.csv_file.download, headers: true).each do |row| | ||
claim = Claims::Claim.find_by(reference: row["claim_reference"]) | ||
|
||
next unless claim | ||
next unless claim.payment_in_progress? | ||
|
||
case row["claim_status"] | ||
when "paid" | ||
claim.update!(status: :paid) | ||
when "unpaid" | ||
claim.update!(status: :payment_information_requested, unpaid_reason: row["claim_unpaid_reason"]) | ||
end | ||
end | ||
|
||
Claims::ClaimActivity.create!(action: :payment_response_uploaded, user: current_user, record: payment_response) | ||
|
||
payment_response | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :payment_response, :current_user | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/views/claims/support/claims/payment_responses/check.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<%= render "claims/support/primary_navigation", current: :claims %> | ||
<% content_for(:page_title) { sanitize t(".page_title") } %> | ||
|
||
<% content_for(:before_content) do %> | ||
<%= govuk_back_link href: claims_support_claims_payments_path %> | ||
<% end %> | ||
|
||
<div class="govuk-width-container"> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= form_with model: claims_payment_response, url: claims_support_claims_payment_response_path(claims_payment_response) do |f| %> | ||
<p class="govuk-caption-l"><%= t(".page_caption") %></p> | ||
<h1 class="govuk-heading-l"><%= t(".page_title") %></h1> | ||
|
||
<p class="govuk-body"><%= t(".description", count: claims_payment_response.row_count) %></p> | ||
|
||
<%= f.govuk_submit t(".submit") %> | ||
<% end %> | ||
|
||
<p class="govuk-body"><%= govuk_link_to t(".cancel"), claims_support_claims_payments_path %></p> | ||
</div> | ||
</div> | ||
</div> |
36 changes: 36 additions & 0 deletions
36
app/views/claims/support/claims/payment_responses/new.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<%= render "claims/support/primary_navigation", current: :claims %> | ||
<% content_for(:page_title) { sanitize t(".page_title") } %> | ||
|
||
<% content_for(:before_content) do %> | ||
<%= govuk_back_link href: claims_support_claims_payments_path %> | ||
<% end %> | ||
|
||
<div class="govuk-width-container"> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= form_with model: claims_payment_response, url: check_claims_support_claims_payment_responses_path do |f| %> | ||
<%= f.govuk_error_summary %> | ||
|
||
<p class="govuk-caption-l"><%= t(".page_caption") %></p> | ||
<h1 class="govuk-heading-l"><%= t(".page_title") %></h1> | ||
|
||
<%= f.govuk_file_field :csv_file, label: { text: t(".label") }, accept: "text/csv" %> | ||
|
||
<%= govuk_details summary_text: t(".help.label") do %> | ||
<p class="govuk-body"><%= t(".help.description") %></p> | ||
<p class="govuk-body"><%= t(".help.csv_instructions") %></p> | ||
|
||
<%= govuk_list type: :bullet do %> | ||
<% t(".help.csv_headers").each do |header| %> | ||
<li><%= header %></li> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
|
||
<%= f.govuk_submit t(".submit") %> | ||
<% end %> | ||
|
||
<p class="govuk-body"><%= govuk_link_to t(".cancel"), claims_support_claims_payments_path %></p> | ||
</div> | ||
</div> | ||
</div> |
19 changes: 19 additions & 0 deletions
19
app/views/claims/support/claims/payment_responses/new_not_permitted.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<%= render "claims/support/primary_navigation", current: :claims %> | ||
<% content_for(:page_title) { sanitize t(".page_title") } %> | ||
|
||
<% content_for(:before_content) do %> | ||
<%= govuk_back_link href: claims_support_claims_payments_path %> | ||
<% end %> | ||
|
||
<div class="govuk-width-container"> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<p class="govuk-caption-l"><%= t(".page_caption") %></p> | ||
<h1 class="govuk-heading-l"><%= t(".page_title") %></h1> | ||
|
||
<p class="govuk-body"><%= t(".description") %></p> | ||
|
||
<p class="govuk-body"><%= govuk_link_to t(".cancel"), claims_support_claims_payments_path %></p> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
config/locales/en/claims/support/claims/payment_responses.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
en: | ||
claims: | ||
support: | ||
claims: | ||
payment_responses: | ||
new: | ||
page_caption: Payments | ||
page_title: Upload ESFA response | ||
label: Upload CSV file | ||
help: | ||
label: Help with the CSV file | ||
description: Use this form to upload the CSV file sent by the ESFA. | ||
csv_instructions: "The CSV file must contain the following headers in the first row:" | ||
csv_headers: | ||
- claim_reference | ||
- school_urn | ||
- school_name | ||
- school_local_authority | ||
- school_establishment_type | ||
- school_establishment_type_group | ||
- claim_amount | ||
- claim_submission_date | ||
- claim_status | ||
- claim_unpaid_reason | ||
submit: Upload CSV file | ||
cancel: Cancel | ||
new_not_permitted: | ||
page_caption: Payments | ||
page_title: You cannot upload a response from the ESFA | ||
description: You cannot upload a response from the ESFA as there are no claims waiting for a response. | ||
cancel: Cancel | ||
check: | ||
page_caption: Payments | ||
page_title: Are you sure you want to upload the ESFA response? | ||
description: | ||
one: There is %{count} claim included in this upload. | ||
other: There are %{count} claims included in this upload. | ||
submit: Upload response | ||
cancel: Cancel | ||
update: | ||
success: ESFA response uploaded |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
db/migrate/20241224133333_create_claims_payment_responses.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateClaimsPaymentResponses < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :payment_responses, id: :uuid do |t| | ||
t.references :user, null: false, foreign_key: true, type: :uuid | ||
t.boolean :processed, default: false | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, :text | ||
end | ||
end |
Oops, something went wrong.