Skip to content

Commit

Permalink
Merge pull request #6185 from ministryofjustice/CTSKF_597_AGFS_16_Sec…
Browse files Browse the repository at this point in the history
…tion_28_Fees

CTSKF-597 AGFS 16 Section 28 fees
  • Loading branch information
AlexRyanShep authored Nov 14, 2023
2 parents 7140a86 + 44956f0 commit aa3e7bb
Show file tree
Hide file tree
Showing 42 changed files with 27,822 additions and 104 deletions.
17 changes: 9 additions & 8 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1000`
# on 2023-10-27 11:16:27 UTC using RuboCop version 1.57.2.
# on 2023-11-13 11:17:57 UTC using RuboCop version 1.57.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -79,7 +79,7 @@ Lint/MissingSuper:
- 'lib/caching/memory_store.rb'
- 'lib/caching/redis_store.rb'

# Offense count: 55
# Offense count: 57
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
Metrics/AbcSize:
Exclude:
Expand All @@ -99,6 +99,7 @@ Metrics/AbcSize:
- 'app/models/claim/transfer_detail.rb'
- 'app/models/claims/search.rb'
- 'app/models/claims/state_machine.rb'
- 'app/models/fee_scheme_factory/agfs.rb'
- 'app/models/stats/collector/completion_rate_collector.rb'
- 'app/models/timed_transitions/transitioner.rb'
- 'app/presenters/claim_history_presenter.rb'
Expand Down Expand Up @@ -1224,7 +1225,7 @@ RSpec/MultipleExpectations:
- 'spec/views/case_workers/claims/show_spec.rb'
- 'spec/views/external_users/claims/show_spec.rb'

# Offense count: 1332
# Offense count: 1333
# Configuration parameters: AllowSubject, Max.
RSpec/MultipleMemoizedHelpers:
Exclude:
Expand Down Expand Up @@ -1451,11 +1452,12 @@ RSpec/NotToNot:
- 'spec/views/case_workers/claims/show_spec.rb'
- 'spec/views/external_users/claims/show_spec.rb'

# Offense count: 2
# Offense count: 3
RSpec/PendingWithoutReason:
Exclude:
- 'spec/controllers/case_workers/claims_controller_spec.rb'
- 'spec/controllers/messages_controller_spec.rb'
- 'spec/models/fee_scheme_factory/agfs_spec.rb'

# Offense count: 107
# This cop supports unsafe autocorrection (--autocorrect-all).
Expand Down Expand Up @@ -1757,7 +1759,7 @@ Rails/ReadWriteAttribute:
- 'app/models/expense.rb'
- 'app/models/injection_attempt.rb'

# Offense count: 9
# Offense count: 7
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/RedundantPresenceValidationOnBelongsTo:
Exclude:
Expand All @@ -1766,7 +1768,6 @@ Rails/RedundantPresenceValidationOnBelongsTo:
- 'app/models/external_user.rb'
- 'app/models/injection_attempt.rb'
- 'app/models/message.rb'
- 'app/models/offence.rb'
- 'app/models/user_message_status.rb'

# Offense count: 1
Expand All @@ -1777,7 +1778,7 @@ Rails/RequestReferer:
Exclude:
- 'app/controllers/feedback_controller.rb'

# Offense count: 41
# Offense count: 42
# Configuration parameters: ForbiddenMethods, AllowedMethods.
# ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all
Rails/SkipsModelValidations:
Expand Down Expand Up @@ -2204,7 +2205,7 @@ Style/RescueStandardError:
Exclude:
- 'spec/factories/claim/base_claims.rb'

# Offense count: 684
# Offense count: 685
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Expand Down
3 changes: 2 additions & 1 deletion app/interfaces/api/v1/dropdown_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class DropdownData < API::Helpers::GrapeAPIHelper
type: String,
desc: I18n.t('api.v1.dropdown_data.params.role_filter'),
values: %w[
agfs agfs_scheme_9 agfs_scheme_10 agfs_scheme_12 agfs_scheme_13 agfs_scheme_14 agfs_scheme_15
agfs agfs_scheme_9 agfs_scheme_10 agfs_scheme_12
agfs_scheme_13 agfs_scheme_14 agfs_scheme_15 agfs_scheme_16
lgfs lgfs_scheme_9 lgfs_scheme_10
]
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/claim/base_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class BaseClaim < ApplicationRecord
delegate :provider_id, :provider, to: :creator
delegate :requires_trial_dates?, :requires_retrial_dates?, to: :case_type, allow_nil: true
delegate :agfs_reform?, :agfs_scheme_12?, :agfs_scheme_13?, :agfs_scheme_14?,
:agfs_scheme_15?, to: :fee_scheme, allow_nil: true
:agfs_scheme_15?, :agfs_scheme_16?, to: :fee_scheme, allow_nil: true

has_many :case_worker_claims, foreign_key: :claim_id, dependent: :destroy
has_many :case_workers, through: :case_worker_claims
Expand Down
2 changes: 1 addition & 1 deletion app/models/fee/base_fee_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize(message = DEFAULT_MSG)
class BaseFeeType < ApplicationRecord
ROLES = %w[
lgfs lgfs_scheme_9 lgfs_scheme_10
agfs agfs_scheme_9 agfs_scheme_10 agfs_scheme_12 agfs_scheme_13 agfs_scheme_14 agfs_scheme_15
agfs agfs_scheme_9 agfs_scheme_10 agfs_scheme_12 agfs_scheme_13 agfs_scheme_14 agfs_scheme_15 agfs_scheme_16
].freeze
include ActionView::Helpers::NumberHelper
include Comparable
Expand Down
4 changes: 4 additions & 0 deletions app/models/fee_scheme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def agfs_scheme_15?
agfs? && version.eql?(15)
end

def agfs_scheme_16?
agfs? && version.eql?(16)
end

def claims
date_range = agfs_scheme_13? ? (Settings.clar_release_date..end_date) : (start_date..end_date)

Expand Down
9 changes: 7 additions & 2 deletions app/models/fee_scheme_factory/agfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def filters
{ scheme: 12, range: scheme_twelve_range },
{ scheme: 13, range: scheme_thirteen_range },
{ scheme: 14, range: scheme_fourteen_range },
{ scheme: 15, range: scheme_fifteen_range }
{ scheme: 15, range: scheme_fifteen_range },
{ scheme: 16, range: scheme_sixteen_range }
]
end

Expand All @@ -33,7 +34,11 @@ def scheme_fourteen_range
end

def scheme_fifteen_range
Settings.agfs_scheme_15_additional_prep_fee_and_kc..Time.zone.today
Settings.agfs_scheme_15_additional_prep_fee_and_kc..Settings.agfs_scheme_16_section_twenty_eight_increase - 1.day
end

def scheme_sixteen_range
Settings.agfs_scheme_16_section_twenty_eight_increase..Time.zone.today
end
end
end
7 changes: 7 additions & 0 deletions app/models/offence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def in_scheme_nine?
scope :in_scheme_fifteen, -> { joins(:fee_schemes).merge(FeeScheme.version(15)).distinct }
singleton_class.send(:alias_method, :in_scheme_15, :in_scheme_fifteen)

scope :in_scheme_sixteen, -> { joins(:fee_schemes).merge(FeeScheme.version(16)).distinct }
singleton_class.send(:alias_method, :in_scheme_16, :in_scheme_sixteen)

scope :in_lgfs_scheme_ten, -> { joins(:fee_schemes).merge(FeeScheme.lgfs).merge(FeeScheme.ten).distinct }
singleton_class.send(:alias_method, :in_lgfs_scheme_10, :in_lgfs_scheme_ten)

Expand Down Expand Up @@ -99,6 +102,10 @@ def scheme_fifteen?
fee_schemes.map(&:version).any?(15)
end

def scheme_sixteen?
fee_schemes.map(&:version).any?(16)
end

def lgfs_scheme_ten?
fee_schemes.lgfs.map(&:version).any?(FeeScheme::TEN)
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/claims/fetch_eligible_advocate_categories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(claim)
def call
return unless claim&.agfs?
return all_categories unless claim.fee_scheme
return new_monarch_categories if claim.fee_scheme.agfs_scheme_15?
return new_monarch_categories if claim.fee_scheme.version >= 15
return agfs_reform_categories if claim.agfs_reform?
default_categories
end
Expand Down
3 changes: 2 additions & 1 deletion app/services/claims/fetch_eligible_misc_fee_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def call

attr_reader :claim
delegate :case_type, :agfs?, :lgfs?, :agfs_reform?, :agfs_scheme_12?, :agfs_scheme_13?, :agfs_scheme_14?,
:agfs_scheme_15?, :hardship?,
:agfs_scheme_15?, :agfs_scheme_16?, :hardship?,
to: :claim, allow_nil: true

def eligible_fee_types
Expand All @@ -37,6 +37,7 @@ def agfs_fee_types_by_claim_type
end

def agfs_scheme_scope
return Fee::MiscFeeType.agfs_scheme_16s if agfs_scheme_16?
return Fee::MiscFeeType.agfs_scheme_15s if agfs_scheme_15?
return Fee::MiscFeeType.agfs_scheme_14s if agfs_scheme_14?
return Fee::MiscFeeType.agfs_scheme_13s if agfs_scheme_13?
Expand Down
10 changes: 10 additions & 0 deletions app/views/pages/api_release_notes.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
= govuk_link_to 'GitHub issues', '/~https://github.com/ministryofjustice/Claim-for-Crown-Court-Defence/issues'
for bugs or other problems.

%section.api-documentation
%hr.govuk-section-break.govuk-section-break--l.govuk-section-break--visible
%h2.govuk-heading-m 16th November 2023
%ul.govuk-list.govuk-list--bullet
%li
New fee scheme - AGFS 16
%br/
A new fee scheme has been created taking effect as of 16th November 2023. This fee scheme increases the payment for
Section 28 fees from £670.00 to £1000.00.

%section.api-documentation
%hr.govuk-section-break.govuk-section-break--l.govuk-section-break--visible
%h2.govuk-heading-m 15th May 2023
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ agfs_scheme_13_clair_release_date: 2022-09-30
clair_contingency_date: 2022-10-31
agfs_scheme_14_section_twenty_eight: 2023-02-01
agfs_scheme_15_additional_prep_fee_and_kc: 2023-04-17
agfs_scheme_16_section_twenty_eight_increase: 2023-11-16

# number of weeks in one state before automatic transition to archived pending delete
timed_transition_stale_weeks: 16
Expand Down
1 change: 1 addition & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
scheme_13
scheme_14
scheme_15
scheme_16
]

SEED_FILES.each do |file|
Expand Down
158 changes: 158 additions & 0 deletions db/seeds/schemas/add_agfs_fee_scheme_16.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
module Seeds
module Schemas
class AddAGFSFeeScheme16
attr_reader :pretend
alias_method :pretending?, :pretend

def initialize(pretend: false)
@pretend = pretend
end

def status
<<~STATUS
\sAGFS scheme 15 end date: #{agfs_fee_scheme_15&.end_date || 'nil'}
\sAGFS scheme 16 start date: #{agfs_fee_scheme_16&.start_date || 'nil'}
\sAGFS scheme 16 fee scheme: #{agfs_fee_scheme_16&.attributes || 'nil'}
\sAGFS scheme 16 offence count: #{scheme_16_offence_count}
\sAGFS scheme 16 total fee_type count: #{scheme_16_fee_type_count}
\s------------------------------------------------------------
Status: #{agfs_fee_scheme_16.present? && scheme_16_offence_count > 0 ? 'up' : 'down'}
STATUS
end

def up
create_agfs_scheme_sixteen
set_agfs_scheme_sixteen_offences
create_scheme_sixteen_fee_types
end

def down
unset_agfs_scheme_sixteen_offences
remove_scheme_sixteen_fee_type_roles
destroy_agfs_scheme_sixteen
end

private

def agfs_fee_scheme_15
@agfs_fee_scheme_15 ||= FeeScheme.agfs.version(15).first
end

def agfs_fee_scheme_16
@agfs_fee_scheme_16 ||= FeeScheme.agfs.version(16).first
end

def scheme_16_offence_count
Offence.joins(:fee_schemes).merge(FeeScheme.version(16)).merge(FeeScheme.agfs).distinct.count
end

def scheme_16_fee_type_count
Fee::BaseFeeType.agfs_scheme_16s.count
end

def create_agfs_scheme_sixteen
print "Finding AGFS scheme 15".yellow
agfs_fee_scheme_fifteen = FeeScheme.find_by(name: 'AGFS', version: 15, start_date: Settings.agfs_scheme_15_additional_prep_fee_and_kc.beginning_of_day)
agfs_fee_scheme_fifteen ? print("...found\n".green) : print("...not found\n".red)

print "Updating AGFS scheme 15 end date to #{Settings.agfs_scheme_16_section_twenty_eight_increase.end_of_day-1.day}".yellow
if pretending?
print "...not updated\n".green if pretending?
else
agfs_fee_scheme_fifteen.update(end_date: Settings.agfs_scheme_16_section_twenty_eight_increase.end_of_day-1.day)
print "...updated\n".green
end

print "Finding or creating scheme 16 with start date #{Settings.agfs_scheme_16_section_twenty_eight_increase.beginning_of_day}...".yellow
if pretending?
print "...not created\n".green if pretending?
else
FeeScheme.find_or_create_by(name: 'AGFS', version: 16, start_date: Settings.agfs_scheme_16_section_twenty_eight_increase.beginning_of_day)
print "...created\n".green
end
end

def destroy_agfs_scheme_sixteen
if pretending?
puts "Would delete fee scheme 16: #{agfs_fee_scheme_16&.attributes || 'does not exist'}".yellow
puts "Would update #{agfs_fee_scheme_15.attributes} end date to nil".yellow
else
puts 'Deleted fee scheme 16'.red if agfs_fee_scheme_16&.destroy
puts 'Updated fee scheme 15 end date to nil'.green if agfs_fee_scheme_15&.update(end_date: nil)
end
end

def set_agfs_scheme_sixteen_offences
puts 'Setting scheme 15 offences to include scheme 16'.yellow
puts "Scheme 16 offence count before: #{scheme_16_offence_count}".yellow
Offence.transaction do
agfs_scheme_fifteen_offences.each do |offence|
if pretending?
puts "[WOULD-ADD] Fee Scheme 16 to #{offence.unique_code}".yellow
else
next if offence.fee_schemes.include? agfs_fee_scheme_16

offence.fee_schemes << agfs_fee_scheme_16
print '.'.green
end
end
end
print "\n"
puts "Scheme 16 offence count after: #{scheme_16_offence_count}".yellow
end

def unset_agfs_scheme_sixteen_offences
Offence.transaction do
Offence.joins(:fee_schemes).merge(FeeScheme.version(16)).merge(FeeScheme.agfs).distinct.each do |offence|
if pretending?
puts "[WOULD-REMOVE] Fee Scheme 16 from #{offence.unique_code}".yellow
else
offence.fee_schemes.delete(agfs_fee_scheme_16)
print '.'.green
end
end
end
print "\n"
puts "Scheme 16 offence count after: #{scheme_16_offence_count}".yellow
end

def agfs_scheme_fifteen_offences
Offence.unscoped.
joins(:fee_schemes).
merge(FeeScheme.version(15)).
merge(FeeScheme.agfs).
order(:id).
distinct
end

def create_scheme_sixteen_fee_types
puts "Scheme 16 fee type count before: #{scheme_16_fee_type_count}".yellow
require Rails.root.join('db', 'seeds', 'fee_types', 'csv_seeder')
Seeds::FeeTypes::CsvSeeder.new(dry_mode: pretending?, stdout: false).call
puts "Scheme 16 fee type count after: #{scheme_16_fee_type_count}".yellow
end

def remove_scheme_sixteen_fee_type_roles
fee_types_with_scheme_16_role = Fee::BaseFeeType.agfs_scheme_16s

if pretending?
puts "Would remove agfs_scheme_16 role from #{fee_types_with_scheme_16_role.count} fee_types".yellow
else
ActiveRecord::Base.transaction do
fee_types_with_scheme_16_role.each do |ft|
if ft.roles == ['agfs_scheme_16']
puts "Deleting fee type #{ft.description}".red
ft.delete
else
puts "Removing agfs_scheme_16 role from #{ft.description}".green
ft.roles.delete('agfs_scheme_16')
ft.save!
end
end
end
puts "Fee types with scheme 16 role after: #{fee_types_with_scheme_16_role.count}".green
end
end
end
end
end
4 changes: 4 additions & 0 deletions db/seeds/scheme_16.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require Rails.root.join('db','seeds', 'schemas', 'add_agfs_fee_scheme_16')

adder = Seeds::Schemas::AddAGFSFeeScheme16.new(pretend: false)
adder.up
Loading

0 comments on commit aa3e7bb

Please sign in to comment.