Skip to content

Commit

Permalink
Remove limit on number of payments
Browse files Browse the repository at this point in the history
Now the payroll run software has been updated we no longer need to limit
the number of payments in a payroll run.
  • Loading branch information
rjlynch committed Nov 1, 2024
1 parent 782fc9a commit 6ed3edd
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 100 deletions.
13 changes: 0 additions & 13 deletions app/controllers/admin/payroll_runs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,6 @@ def index
def new
@claims = Claim.payrollable.order(submitted_at: :asc)

# Due to limitations with the current payroll software we need a temporary
# cap on the number of claims that can enter payroll, especially expecting
# a high volume of approved claims in the first few months.
#
# Ideally, we should limit topups as well, as some may be related to claims
# paid in a previous payroll run, but we wouldn't have any topups at the beginning.
#
# TODO: Remove this capping once the payroll software is upgraded.
if @claims.size > PayrollRun::MAX_MONTHLY_PAYMENTS
flash[:notice] = "The number of payments entering this payrun will be capped to #{PayrollRun::MAX_MONTHLY_PAYMENTS}"
@claims = @claims.limit(PayrollRun::MAX_MONTHLY_PAYMENTS)
end

@topups = Topup.payrollable
@total_award_amount = @claims.sum(&:award_amount) + @topups.sum(&:award_amount)
end
Expand Down
12 changes: 0 additions & 12 deletions app/models/payroll_run.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
class PayrollRun < ApplicationRecord
MAX_BATCH_SIZE = 1000
MAX_MONTHLY_PAYMENTS = 3000

has_many :payments, dependent: :destroy
has_many :claims, through: :payments
has_many :payment_confirmations, dependent: :destroy
Expand All @@ -13,7 +10,6 @@ class PayrollRun < ApplicationRecord
belongs_to :confirmation_report_uploaded_by, class_name: "DfeSignIn::User", optional: true

validate :ensure_no_payroll_run_this_month, on: :create
validate :ensure_within_max_monthly_payments, on: :create

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

Expand All @@ -35,10 +31,6 @@ def total_claim_amount_for_policy(policy, filter: :all)
line_items(policy, filter: filter).sum(&:award_amount)
end

def total_batches
(payments.count / MAX_BATCH_SIZE.to_f).ceil
end

def total_confirmed_payments
payments.where.not(confirmation: nil).count
end
Expand Down Expand Up @@ -100,8 +92,4 @@ def line_items(policy, filter: :all)
def ensure_no_payroll_run_this_month
errors.add(:base, "There has already been a payroll run for #{Date.today.strftime("%B")}") if PayrollRun.this_month.any?
end

def ensure_within_max_monthly_payments
errors.add(:base, "This payroll run exceeds #{MAX_MONTHLY_PAYMENTS} payments") if payments.size > MAX_MONTHLY_PAYMENTS
end
end
19 changes: 0 additions & 19 deletions spec/features/admin/admin_payroll_runs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,6 @@
end
end

scenario "Limiting the maximum number of claims entering payroll" do
click_on "Payroll"

expected_claims = create_list(:claim, 3, :approved)
stubbed_max_payments = stub_const("PayrollRun::MAX_MONTHLY_PAYMENTS", 2)

month_name = Date.today.strftime("%B")
click_on "Run #{month_name} payroll"

expect(page).to have_content("The number of payments entering this payrun will be capped to #{stubbed_max_payments}")

click_on "Confirm and submit"

expect(page).to have_content("Approved claims 2")

payroll_run = PayrollRun.order(:created_at).last
expect(payroll_run.claims).to match_array(expected_claims.first(stubbed_max_payments))
end

scenario "Any claims approved in the meantime are not included" do
click_on "Payroll"

Expand Down
42 changes: 0 additions & 42 deletions spec/models/payroll_run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,6 @@
end
end

context "validating the number of payments entering payroll" do
let(:stubbed_max_payments) { 10 }
let(:payroll_run) { build(:payroll_run, :with_payments, count: payments_count) }

before do
stub_const("PayrollRun::MAX_MONTHLY_PAYMENTS", stubbed_max_payments)
end

context "when exceeding the number of maximum allowed payments" do
let(:payments_count) { stubbed_max_payments + 1 }

it "returns a validation error", :aggregate_failures do
expect(payroll_run.valid?).to eq(false)
expect(payroll_run.errors[:base]).to eq(["This payroll run exceeds #{stubbed_max_payments} payments"])
expect { payroll_run.save! }.to raise_error(ActiveRecord::RecordInvalid)
end
end

context "when not exceeding the number of maximum allowed payments" do
let(:payments_count) { stubbed_max_payments }

it "creates the payroll run", :aggregate_failures do
expect(payroll_run.valid?).to eq(true)
expect(payroll_run.errors[:base]).to be_empty
expect { payroll_run.save! }.to change { payroll_run.persisted? }.to(true)
end
end
end

describe "#total_award_amount" do
it "returns the sum of the award amounts of its claims" do
payment_1 = build(:payment, claims: [build(:claim, :approved, eligibility_attributes: {student_loan_repayment_amount: 1500})])
Expand Down Expand Up @@ -159,19 +130,6 @@
end
end

describe "#total_batches" do
subject(:total) { payroll_run.total_batches }

let(:payroll_run) { create(:payroll_run, claims_counts: {Policies::StudentLoans => 5}) }
let(:batch_size) { 2 }

before do
stub_const("#{described_class}::MAX_BATCH_SIZE", batch_size)
end

it { is_expected.to eq(3) }
end

describe "#total_confirmed_payments" do
subject(:total) { payroll_run.total_confirmed_payments }

Expand Down
14 changes: 0 additions & 14 deletions spec/requests/admin/admin_payroll_runs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@
expect(response).to have_http_status(:ok)
expect(response.body).to include("£100")
end

it "limits the number of claims entering payroll when exceeding the maximum allowed" do
stubbed_max_payments = stub_const("PayrollRun::MAX_MONTHLY_PAYMENTS", 2)

create(:claim, :approved, eligibility_attributes: {student_loan_repayment_amount: 100}, submitted_at: 3.days.ago)
create(:claim, :approved, eligibility_attributes: {student_loan_repayment_amount: 50}, submitted_at: 1.days.ago)
create(:claim, :approved, eligibility_attributes: {student_loan_repayment_amount: 10}, submitted_at: 2.days.ago)

get new_admin_payroll_run_path

expect(response).to have_http_status(:ok)
expect(response.body).to include("The number of payments entering this payrun will be capped to #{stubbed_max_payments}")
expect(response.body).to include("£110")
end
end

describe "admin_payroll_runs#create" do
Expand Down

0 comments on commit 6ed3edd

Please sign in to comment.