Skip to content

Commit

Permalink
Merge pull request #2035 from alphagov/convert-pay-leave-for-parents-…
Browse files Browse the repository at this point in the history
…to-ruby

Convert pay-leave-for-parents to Ruby
  • Loading branch information
chrisroos committed Oct 28, 2015
2 parents c35c7c2 + ea6f6f7 commit 12d5f6e
Show file tree
Hide file tree
Showing 16,740 changed files with 223,974 additions and 237,964 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
112 changes: 112 additions & 0 deletions lib/smart_answer/calculators/pay_leave_for_parents_calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
module SmartAnswer::Calculators
class PayLeaveForParentsCalculator
def continuity_start_date(date)
saturday_before(date - 39.weeks)
end

def continuity_end_date(date)
sunday_before(date - 15.weeks)
end

def lower_earnings_amount(due_date)
start_date = lower_earnings_start_date(due_date)
if in_2013_2014_fin_year?(start_date)
SmartAnswer::Money.new(109)
elsif in_2014_2015_fin_year?(start_date)
SmartAnswer::Money.new(111)
elsif in_2015_2016_fin_year?(start_date)
SmartAnswer::Money.new(112)
else
SmartAnswer::Money.new(112)
end
end

def lower_earnings_start_date(date)
saturday_before(date - 22.weeks)
end

def lower_earnings_end_date(date)
saturday_before(date - 14.weeks)
end

def earnings_employment_start_date(date)
sunday_before(date - 66.weeks)
end

def earnings_employment_end_date(date)
saturday_before(date)
end

def continuity(job_before, job_after)
job_before == "yes" && job_after == "yes"
end

#Lower earnings test: person has earned more than
#the lower earnings limit
def lower_earnings(lel)
lel == "yes"
end

#Earnings and employment test
def earnings_employment(earnings_employment, work_employment)
earnings_employment == "yes" && work_employment == "yes"
end

def range_in_2013_2014_fin_year?(date)
date_in_39_week_range?(2013, 2014, date)
end

def range_in_2014_2015_fin_year?(date)
date_in_39_week_range?(2014, 2015, date)
end

def range_in_2015_2016_fin_year?(date)
date_in_39_week_range?(2015, 2016, date)
end

def start_of_maternity_allowance(date)
sunday_before(date - 11.weeks)
end

def earliest_start_mat_leave(date)
sunday_before(date - 11.weeks)
end

def maternity_leave_notice_date(date)
saturday_before(date - 14.weeks)
end

def paternity_leave_notice_date(date)
saturday_before(date - 14.weeks)
end

def in_2013_2014_fin_year?(date)
(Date.new(2013, 05, 06)..Date.new(2014, 05, 05)).cover?(date)
end

def in_2014_2015_fin_year?(date)
(Date.new(2014, 05, 06)..Date.new(2015, 05, 05)).cover?(date)
end

def in_2015_2016_fin_year?(date)
(Date.new(2015, 05, 06)..Date.new(2016, 05, 05)).cover?(date)
end

private

def saturday_before(date)
(date - date.wday) - 1.day
end

def sunday_before(date)
date - date.wday
end

def date_in_39_week_range?(range_start, range_end, date)
start_date = date
end_date = start_date + 39.weeks
(Date.new(range_start, 05, 06)..Date.new(range_end, 05, 05)).cover?(start_date) ||
(Date.new(range_start, 05, 06)..Date.new(range_end, 05, 05)).cover?(end_date)
end
end
end
112 changes: 112 additions & 0 deletions lib/smart_answer_flows/locales/en/pay-leave-for-parents.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
en-GB:
flow:
pay-leave-for-parents:
two_carers:
title: Will you care for the child with a partner?
post_body: |-
The partner must be one of the following:
- your husband, wife, civil partner or joint adopter
- the child’s other parent
- your partner (if they live with you and the child)
options:
'yes': 'Yes'
'no': 'No'
due_date:
title: When is the baby due?
employment_status_of_mother:
title: What’s the employment status of the mother?
post_body: Read about [employment statuses](/employment-status) if you aren’t
sure which one applies.
options:
employee: Employee
worker: Worker or agency worker
self-employed: Self-employed
unemployed: Unemployed
employment_status_of_partner:
title: What’s the employment status of the mother’s partner?
post_body: Read about [employment statuses](/employment-status) if you aren’t
sure which one applies.
options:
employee: Employee
worker: Worker or agency worker
self-employed: Self-employed
unemployed: Unemployed
mother_started_working_before_continuity_start_date:
title: Did the mother start her current or most recent job before %{continuity_start_date}?
options:
'yes': 'Yes'
'no': 'No'
mother_still_working_on_continuity_end_date:
title: Was the mother (or will she be) still working in that job on %{continuity_end_date}?
options:
'yes': 'Yes'
'no': 'No'
mother_salary:
title: How much does the mother earn (or did she earn, if she’s left her job)?
post_body: This is her total take-home pay before any deductions, eg tax.
mother_earned_more_than_lower_earnings_limit:
title: Has the mother earned (or will she have earned) more than %{lower_earnings_amount}
per week between %{lower_earnings_start_date} and %{lower_earnings_end_date}?
options:
'yes': 'Yes'
'no': 'No'
mother_worked_at_least_26_weeks:
title: Did the mother work (or will she have worked) for at least 26 weeks
between %{earnings_employment_start_date} and %{earnings_employment_end_date}?
post_body: The 26 weeks don’t need to be in a row. They can be full or part
weeks.
options:
'yes': 'Yes'
'no': 'No'
mother_earned_at_least_390:
title: Did the mother earn (or will she have earned) a total of £390 or more
in any 13 weeks between %{earnings_employment_start_date} and
%{earnings_employment_end_date}?
post_body: The 13 weeks don’t need to be in a row.
options:
'yes': 'Yes'
'no': 'No'
salary_1_66_weeks:
title: How much did the mother earn between %{earnings_employment_start_date}
and %{earnings_employment_end_date}?
partner_started_working_before_continuity_start_date:
title: Did the mother’s partner start their current or most recent job before
%{continuity_start_date}?
options:
'yes': 'Yes'
'no': 'No'
partner_still_working_on_continuity_end_date:
title: Was the mother’s partner (or will they be) still working in that job
on %{continuity_end_date}?
options:
'yes': 'Yes'
'no': 'No'
partner_salary:
title: How much does the mother’s partner earn (or did they earn, if they’ve
left their job)?
post_body: This is their total take-home pay before any deductions, eg tax.
partner_earned_more_than_lower_earnings_limit:
title: Has the mother’s partner earned (or will they have earned) more than
%{lower_earnings_amount} per week between %{lower_earnings_start_date}
and %{lower_earnings_end_date}?
options:
'yes': 'Yes'
'no': 'No'
partner_worked_at_least_26_weeks:
title: Did the mother’s partner work (or will they have worked) for at least
26 weeks between %{earnings_employment_start_date} and %{earnings_employment_end_date}?
post_body: The 26 weeks don’t need to be in a row. They can be full or part
weeks.
options:
'yes': 'Yes'
'no': 'No'
partner_earned_at_least_390:
title: Did the mother’s partner earn (or will they have earned) a total of
£390 or more in any 13 weeks between %{earnings_employment_start_date}
and %{earnings_employment_end_date}?
post_body: The 13 weeks don’t need to be in a row.
options:
'yes': 'Yes'
'no': 'No'
Loading

0 comments on commit 12d5f6e

Please sign in to comment.