Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create views for claim activity #1347

Merged
merged 11 commits into from
Feb 3, 2025
2 changes: 1 addition & 1 deletion app/assets/stylesheets/components/_timeline.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

.app-timeline__description {
@include govuk-font($size: 19);
margin-top: govuk-spacing(4);
margin-top: govuk-spacing(2);
}

/* ==========================================================================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@
class Claims::Support::Claims::ClaimActivitiesController < Claims::Support::ApplicationController
def index
@pagy, @claim_activities = pagy(Claims::ClaimActivity.order(created_at: :desc))
claim_activities = Claims::ClaimActivity.order(created_at: :desc)
authorize [:claims, claim_activities]

authorize [:claims, @claim_activities]
@pagy, @claim_activities = pagy(claim_activities)
@claim_activities = @claim_activities.decorate
end

def show
@claim_activity = Claims::ClaimActivity.find(params[:id])
authorize [:claims, claim_activity]

if @claim_activity.sampling_uploaded?
@pagy, @provider_samplings = pagy(@claim_activity.record.provider_samplings.order_by_provider_name)
if claim_activity.sampling_uploaded?
@pagy, @provider_samplings = pagy(claim_activity.record.provider_samplings.order_by_provider_name)
end

authorize [:claims, @claim_activity]
@claim_activity = claim_activity.decorate
end

def resend_payer_email
authorize [:claims, claim_activity]
case claim_activity.action
when "payment_request_delivered"
Claims::Payment::ResendEmail.call(payment: claim_activity.record)
when "clawback_request_delivered"
Claims::Clawback::ResendEmail.call(clawback: claim_activity.record)
else
raise "Unknown action: #{claim_activity.action}"
end

redirect_to claims_support_claims_claim_activity_path(claim_activity), flash: { success: true, heading: t(".success") }
end

def resend_provider_email
authorize [:claims, claim_activity]
Claims::Sampling::ResendEmails.call(provider_sampling:)

redirect_to claims_support_claims_claim_activity_path(claim_activity), flash: { success: true, heading: t(".success", provider_name: provider_sampling.provider_name) }
end

private

def claim_activity
@claim_activity ||= Claims::ClaimActivity.find(params[:id])
end

def provider_sampling
@provider_sampling ||= claim_activity.record.provider_samplings.find(params[:provider_sampling_id])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,32 @@ def show; end
def confirm_information_sent; end

def information_sent
@claim.payment_information_sent!
@claim.transaction do
@claim.payment_information_sent!
Claims::ClaimActivity.create!(action: "information_sent_to_payer", user: current_user, record: @claim)
end

redirect_to claims_support_claims_payments_claim_path(@claim), flash: { success: true, heading: t(".success") }
end

def confirm_paid; end

def paid
@claim.paid!
@claim.transaction do
@claim.paid!
Claims::ClaimActivity.create!(action: "paid_by_payer", user: current_user, record: @claim)
end

redirect_to claims_support_claims_payments_claim_path(@claim), flash: { success: true, heading: t(".success") }
end

def confirm_reject; end

def reject
@claim.payment_not_approved!
@claim.transaction do
@claim.payment_not_approved!
Claims::ClaimActivity.create!(action: "rejected_by_payer", user: current_user, record: @claim)
end

redirect_to claims_support_claims_payments_claim_path(@claim), flash: { success: true, heading: t(".success") }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def update
@claim.status = :paid
@claim.save!

Claims::ClaimActivity.create!(action: :sampling_approved_manually, user: current_user, record: @claim)
Claims::ClaimActivity.create!(action: :provider_approved_audit, user: current_user, record: @claim)

redirect_to claims_support_claims_samplings_path, flash: {
heading: t(".success_heading"),
Expand Down
44 changes: 44 additions & 0 deletions app/decorators/claims/claim_activity_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Claims::ClaimActivityDecorator < Draper::Decorator
delegate_all

def title
case action
when "payment_request_delivered"
I18n.t("#{translation_path}.payment_request_delivered", count: record.claims.count)
when "payment_response_uploaded"
I18n.t("#{translation_path}.payment_response_uploaded")
when "sampling_uploaded"
I18n.t("#{translation_path}.sampling_uploaded", count: record.claims.count)
when "sampling_response_uploaded"
I18n.t("#{translation_path}.sampling_response_uploaded", count: record.claims.count)
when "clawback_request_delivered"
I18n.t("#{translation_path}.clawback_request_delivered", count: record.claims.count)
when "clawback_response_uploaded"
I18n.t("#{translation_path}.clawback_response_uploaded", count: record.claims.count)
when "provider_approved_audit"
I18n.t("#{translation_path}.provider_approved_audit", provider_name: record.provider_name, claim_reference: record.reference)
when "rejected_by_provider"
I18n.t("#{translation_path}.rejected_by_provider", provider_name: record.provider_name, claim_reference: record.reference)
when "rejected_by_school"
I18n.t("#{translation_path}.rejected_by_school", school_name: record.school_name, claim_reference: record.reference)
when "approved_by_school"
I18n.t("#{translation_path}.approved_by_school", school_name: record.school_name, claim_reference: record.reference)
when "clawback_requested"
I18n.t("#{translation_path}.clawback_requested", claim_reference: record.reference)
when "rejected_by_payer"
I18n.t("#{translation_path}.rejected_by_payer", claim_reference: record.reference)
when "paid_by_payer"
I18n.t("#{translation_path}.paid_by_payer", claim_reference: record.reference)
when "information_sent_to_payer"
I18n.t("#{translation_path}.information_sent_to_payer", claim_reference: record.reference)
else
raise "Unknown action: #{action}"
end
end

private

def translation_path
"activerecord.attributes.claims/claim_activity/action"
end
end
8 changes: 8 additions & 0 deletions app/mailers/claims/esfa_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ def claims_require_clawback(clawback)
body: t(".body", url_for_csv: claims_clawback_claims_url(token:), support_email:, service_name:)
end

def resend_claims_require_clawback(clawback)
@clawback = clawback

notify_email to: esfa_email_addresses,
subject: t(".subject"),
body: t(".body", url_for_csv: claims_clawback_claims_url(token:), support_email:, service_name:)
end

private

def esfa_email_addresses
Expand Down
13 changes: 13 additions & 0 deletions app/mailers/claims/payment_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ def payment_created_notification(payment)
)
end

def resend_payment_created_notification(payment)
@payment = payment

notify_email to: esfa_email_addresses,
from: support_email,
subject: t(".subject"),
body: t(
".body",
download_page_url: claims_payments_claims_url(token:),
support_email:,
)
end

private

def esfa_email_addresses
Expand Down
17 changes: 14 additions & 3 deletions app/models/claims/claim_activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,25 @@ class Claims::ClaimActivity < ApplicationRecord
sampling_response_uploaded: "sampling_response_uploaded",
clawback_request_delivered: "clawback_request_delivered",
clawback_response_uploaded: "clawback_response_uploaded",
sampling_approved_manually: "sampling_approved_manually",
provider_approved_audit: "provider_approved_audit",
rejected_by_provider: "rejected_by_provider",
rejected_by_school: "rejected_by_school",
approved_by_school: "approved_by_school",
clawback_requested: "clawback_requested",
rejected_by_payer: "rejected_by_payer",
paid_by_payer: "paid_by_payer",
information_sent_to_payer: "information_sent_to_payer",
}, validate: true

delegate :full_name, to: :user, prefix: true, allow_nil: true

PAYMENT_OR_CLAWBACK_ACTION = %w[payment_request_delivered clawback_request_delivered payment_response_uploaded clawback_response_uploaded].freeze
SAMPLING_ACTION = %w[sampling_uploaded sampling_response_uploaded].freeze
PAYMENT_AND_CLAWBACK_ACTIONS = %w[payment_request_delivered clawback_request_delivered clawback_response_uploaded].freeze
SAMPLING_ACTIONS = %w[sampling_uploaded sampling_response_uploaded].freeze
MANUAL_ACTIONS = %w[provider_approved_audit rejected_by_provider rejected_by_school clawback_requested rejected_by_payer paid_by_payer information_sent_to_payer].freeze

def claims_by_provider
return {} unless record.respond_to?(:claims)

record.claims.group_by(&:provider)
end
end
1 change: 1 addition & 0 deletions app/models/claims/sampling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
#
class Claims::Sampling < ApplicationRecord
has_many :provider_samplings
has_many :claims, through: :provider_samplings
end
7 changes: 7 additions & 0 deletions app/policies/claims/support/claims/claim_activity_policy.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
class Claims::Support::Claims::ClaimActivityPolicy < Claims::ApplicationPolicy
def resend_payer_email?
true
end

def resend_provider_email?
true
end
end
13 changes: 13 additions & 0 deletions app/services/claims/clawback/resend_email.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Claims::Clawback::ResendEmail < ApplicationService
def initialize(clawback:)
@clawback = clawback
end

def call
Claims::ESFAMailer.resend_claims_require_clawback(clawback).deliver_later
end

private

attr_reader :clawback
end
13 changes: 13 additions & 0 deletions app/services/claims/payment/resend_email.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Claims::Payment::ResendEmail < ApplicationService
def initialize(payment:)
@payment = payment
end

def call
Claims::PaymentMailer.resend_payment_created_notification(payment).deliver_later
end

private

attr_reader :payment
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%# locals: (claim_activity:) -%>

<div class="govuk-button-group">
<%= govuk_button_link_to t(".download_csv"), claim_activity.record.csv_file, secondary: true %>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<%# locals: (claim_activity:) -%>

<h2 class="govuk-heading-m"><%= t(".providers") %></h2>

<h3 class="govuk-heading-s"><%= claim_activity.record.provider_name %></h3>

<%= govuk_table do |table| %>
<% table.with_head do |head| %>
<% head.with_row do |row| %>
<% row.with_cell text: t(".claim_reference") %>
<% row.with_cell text: t(".number_of_mentors") %>
<% row.with_cell text: t(".claim_amount") %>
<% end %>
<% end %>

<% table.with_body do |body| %>
<% body.with_row do |row| %>
<% row.with_cell text: govuk_link_to(claim_activity.record.reference, claims_support_claim_path(claim_activity.record)) %>
<% row.with_cell text: claim_activity.record.mentors.count %>
<% row.with_cell text: humanized_money_with_symbol(claim_activity.record.amount) %>
<% end %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%# locals: (claim_activity:) -%>

<div class="govuk-button-group">
<%= govuk_button_link_to t(".download_csv"), claim_activity.record.csv_file, secondary: true %>
<% unless claim_activity.action == "clawback_response_uploaded" %>
<%= govuk_button_link_to t(".resend_email_to_payer"), resend_payer_email_claims_support_claims_claim_activity_path(claim_activity), secondary: true %>
<% end %>
</div>

<h2 class="govuk-heading-m"><%= t(".providers") %></h2>

<% claim_activity.claims_by_provider.each do |provider, provider_claims| %>
<h3 class="govuk-heading-s"><%= provider.name %></h3>

<%= govuk_table do |table| %>
<% table.with_head do |head| %>
<% head.with_row do |row| %>
<% row.with_cell text: t(".claim_reference") %>
<% row.with_cell text: t(".number_of_mentors") %>
<% row.with_cell text: t(".claim_amount") %>
<% end %>
<% end %>

<% table.with_body do |body| %>
<% provider_claims.each do |claim| %>
<% body.with_row do |row| %>
<% row.with_cell text: govuk_link_to(claim.reference, claims_support_claim_path(claim)) %>
<% row.with_cell text: claim.mentors.count %>
<% row.with_cell text: humanized_money_with_symbol(claim.amount) %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%# locals: (claim_activity:) -%>

<h2 class="govuk-heading-m"><%= t(".providers") %></h2>

<% claim_activity.record.provider_samplings.each do |provider_sampling| %>
<h3 class="govuk-heading-s"><%= provider_sampling.provider.name %></h3>

<div class="govuk-button-group">
<%= govuk_button_link_to t(".download_csv"), provider_sampling.csv_file, secondary: true %>
<% unless claim_activity.action == "sampling_response_uploaded" %>
<%= govuk_button_link_to t(".resend_email_to_provider"), resend_provider_email_claims_support_claims_claim_activity_path(claim_activity, provider_sampling_id: provider_sampling.id), secondary: true %>
<% end %>
</div>

<%= govuk_table do |table| %>
<% table.with_head do |head| %>
<% head.with_row do |row| %>
<% row.with_cell text: t(".claim_reference") %>
<% row.with_cell text: t(".number_of_mentors") %>
<% row.with_cell text: t(".claim_amount") %>
<% end %>
<% end %>

<% table.with_body do |body| %>
<% provider_sampling.claims.each do |claim| %>
<% body.with_row do |row| %>
<% row.with_cell text: govuk_link_to(claim.reference, claims_support_claim_path(claim)) %>
<% row.with_cell text: claim.mentors.count %>
<% row.with_cell text: humanized_money_with_symbol(claim.amount) %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
Loading