Skip to content

Commit

Permalink
Merge pull request #6714 from alphagov/uprate-minimum-wage-calculator…
Browse files Browse the repository at this point in the history
…s-for-2024-2025

Uprate minimum wage calculator for 2024/2025
  • Loading branch information
cynthia-anya committed Mar 28, 2024
2 parents 97738da + a0f099b commit 44109cf
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 156 deletions.
2 changes: 1 addition & 1 deletion app/flows/am_i_getting_minimum_wage_flow/start.erb
Expand Up @@ -13,7 +13,7 @@
- you’re getting paid the National Living Wage
- your employer owes you past payments from the previous year because of underpayment

^You must be at least 23 years old to get the National Living Wage.^
^You must be at least <%= this_year_living_wage_min_age("minimum_wage") %> years old to get the National Living Wage.^

Check [National Minimum Wage and National Living Wage rates](/national-minimum-wage-rates) before <%= last_year_end_text("minimum_wage") %>.
<% end %>
2 changes: 1 addition & 1 deletion app/flows/minimum_wage_calculator_employers_flow/start.erb
Expand Up @@ -13,7 +13,7 @@
- you’re paying a worker the National Living Wage
- you owe your employee payments from the previous year because you underpaid them

^Your employee must be at least 23 years old to get the National Living Wage.^
^Your employee must be at least <%= this_year_living_wage_min_age("minimum_wage") %> years old to get the National Living Wage.^

Check [National Minimum Wage and National Living Wage rates](/national-minimum-wage-rates) before <%= last_year_end_text("minimum_wage") %>.
<% end %>
3 changes: 1 addition & 2 deletions app/flows/shared/minimum_wage_flow.rb
Expand Up @@ -6,8 +6,7 @@ def define
option "past_payment"

on_response do |response|
self.calculator = SmartAnswer::Calculators::MinimumWageCalculator.new
calculator.date = calculator.previous_period_start_date if response == "past_payment"
self.calculator = SmartAnswer::Calculators::MinimumWageCalculator.new(past_or_current_payment: response)
self.accommodation_charge = nil
end

Expand Down
32 changes: 17 additions & 15 deletions config/smart_answers/rates/minimum_wage.yml
Expand Up @@ -2,38 +2,40 @@
# make sure we have that at least. If adding a new set of data at
# the end, you may have to update dates/values in the test file.
---
- :start_date: 2022-04-01
:end_date: 2023-03-31
- :start_date: 2023-04-01
:end_date: 2024-03-31
:minimum_rates:
- :min_age: 0
:max_age: 18
:rate: 4.81
:rate: 5.28
- :min_age: 18
:max_age: 21
:rate: 6.83
:rate: 7.49
- :min_age: 21
:max_age: 23
:rate: 9.18
:rate: 10.18
- :min_age: 23
:max_age: 1000
:rate: 9.50
:apprentice_rate: 4.81
:accommodation_rate: 8.70
:rate: 10.42
:apprentice_rate: 5.28
:accommodation_rate: 9.10
:living_wage_min_age: 23

- :start_date: 2023-04-01
- :start_date: 2024-04-01
:end_date: 3000-01-01
:minimum_rates:
- :min_age: 0
:max_age: 18
:rate: 5.28
:rate: 6.40
- :min_age: 18
:max_age: 21
:rate: 7.49
:rate: 8.60
- :min_age: 21
:max_age: 23
:rate: 10.18
:rate: 11.44
- :min_age: 23
:max_age: 1000
:rate: 10.42
:apprentice_rate: 5.28
:accommodation_rate: 9.10
:rate: 11.44
:apprentice_rate: 6.40
:accommodation_rate: 9.99
:living_wage_min_age: 21
46 changes: 23 additions & 23 deletions lib/smart_answer/calculators/minimum_wage_calculator.rb
Expand Up @@ -8,28 +8,25 @@ class MinimumWageCalculator
:accommodation_cost,
:job_requirements_charge,
:unpaid_additional_hours
attr_reader :date

def initialize(params = {})
raise ArgumentError, "Missing past_or_current_payment argument" unless params[:past_or_current_payment]
raise ArgumentError, "Invalid past_or_current_payment value: #{params[:past_or_current_payment]}" unless %w[past_payment current_payment].include? params[:past_or_current_payment]

@age = params[:age]
@date = params[:date] || SmartAnswer::DateHelper.current_day
@past_or_current_payment = params[:past_or_current_payment]
@basic_hours = params[:basic_hours].to_f
@basic_pay = params[:basic_pay].to_f
@is_apprentice = params[:is_apprentice]
@pay_frequency = params[:pay_frequency] || 7
@accommodation_cost = 0
@minimum_wage_data = rates_for_date(@date)
@minimum_wage_data = rates
@job_requirements_charge = false
@unpaid_additional_hours = false
end

def date=(date)
@date = date
@minimum_wage_data = rates_for_date(@date)
end

def previous_period_start_date
data.previous_period(date:)[:start_date]
data.previous_period[:start_date]
end

def valid_age?(age)
Expand All @@ -53,8 +50,8 @@ def valid_accommodation_usage?(accommodation_usage)
end

def valid_age_for_living_wage?(age)
(age.to_i >= 23 && date >= Date.parse("2021-04-01")) ||
age.to_i >= 25
living_wage_min_age = @minimum_wage_data[:living_wage_min_age]
age.to_i >= living_wage_min_age
end

def basic_rate
Expand Down Expand Up @@ -82,7 +79,7 @@ def total_pay
end

def total_entitlement
minimum_hourly_rate * total_hours
(minimum_hourly_rate * total_hours).round(2)
end

def historical_entitlement
Expand All @@ -102,19 +99,18 @@ def accommodation_adjustment(charge, number_of_nights)
number_of_nights = number_of_nights.to_i

accommodation_cost = if charge > 0 # rubocop:disable Style/NumericPredicate
charged_accomodation_adjustment(charge, number_of_nights)
charged_accommodation_adjustment(charge, number_of_nights)
else
free_accommodation_adjustment(number_of_nights)
end
@accommodation_cost = (accommodation_cost * weekly_multiplier).round(2)
end

def per_hour_minimum_wage(date = @date)
data = rates_for_date(date)
def per_hour_minimum_wage
if @is_apprentice
data[:apprentice_rate]
@minimum_wage_data[:apprentice_rate]
else
rates = data[:minimum_rates]
rates = @minimum_wage_data[:minimum_rates]
rate_data = rates.find do |r|
@age >= r[:min_age] && @age < r[:max_age]
end
Expand All @@ -123,15 +119,15 @@ def per_hour_minimum_wage(date = @date)
end

def free_accommodation_rate
@minimum_wage_data.accommodation_rate
@minimum_wage_data[:accommodation_rate]
end

def apprentice_rate
@minimum_wage_data.apprentice_rate
@minimum_wage_data[:apprentice_rate]
end

def eligible_for_living_wage?
valid_age_for_living_wage?(age) && date >= Date.parse("2016-04-01")
valid_age_for_living_wage?(age)
end

def under_school_leaving_age?
Expand All @@ -152,7 +148,7 @@ def free_accommodation_adjustment(number_of_nights)
(free_accommodation_rate * number_of_nights).round(2)
end

def charged_accomodation_adjustment(charge, number_of_nights)
def charged_accommodation_adjustment(charge, number_of_nights)
if charge < free_accommodation_rate
0
else
Expand All @@ -162,8 +158,12 @@ def charged_accomodation_adjustment(charge, number_of_nights)

private

def rates_for_date(date = Time.zone.today)
data.rates(date)
def rates
if @past_or_current_payment == "past_payment"
data.previous_period
elsif @past_or_current_payment == "current_payment"
data.current_period
end
end

def data
Expand Down
15 changes: 10 additions & 5 deletions lib/smart_answer/calculators/rates_query.rb
Expand Up @@ -13,17 +13,22 @@ def initialize(rates_data)
@data = rates_data
end

def previous_period(date: nil)
date ||= SmartAnswer::DateHelper.current_day
def previous_period
previous_period = nil
data.each do |rates_hash|
break if rates_hash[:start_date] <= date && rates_hash[:end_date] >= date

previous_period = rates_hash
previous_period = rates_hash if !previous_period || rates_hash[:start_date] <= previous_period[:start_date]
end
previous_period
end

def current_period
current_period = nil
data.each do |rates_hash|
current_period = rates_hash if !current_period || rates_hash[:start_date] > current_period[:start_date]
end
current_period
end

def rates(date = nil)
date ||= SmartAnswer::DateHelper.current_day
relevant_rates = data.find do |rates_hash|
Expand Down
11 changes: 10 additions & 1 deletion lib/smart_answer/rate_dates_helper.rb
Expand Up @@ -8,9 +8,18 @@ def last_year_end_text(rates_file)
last_year(rates_file)[:end_date].strftime("%B %Y").to_s
end

def this_year_living_wage_min_age(rates_file)
this_year(rates_file)[:living_wage_min_age]
end

def this_year(rates_file)
data = SmartAnswer::Calculators::RatesQuery.from_file(rates_file)
data.current_period
end

def last_year(rates_file)
data = SmartAnswer::Calculators::RatesQuery.from_file(rates_file)
data.previous_period(date: SmartAnswer::DateHelper.current_day)
data.previous_period
end
end
end

0 comments on commit 44109cf

Please sign in to comment.