-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathcalculate-statutory-sick-pay.rb
344 lines (289 loc) · 10 KB
/
calculate-statutory-sick-pay.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
module SmartAnswer
class CalculateStatutorySickPayFlow < Flow
def define
content_id "1c676a9e-0424-4ebb-bab8-d8cb8d2fc6f8"
name 'calculate-statutory-sick-pay'
status :published
satisfies_need "100262"
# Question 1
checkbox_question :is_your_employee_getting? do
option :statutory_maternity_pay
option :maternity_allowance
option :statutory_paternity_pay
option :statutory_adoption_pay
option :additional_statutory_paternity_pay
next_node_calculation :calculator do
Calculators::StatutorySickPayCalculator.new
end
next_node(permitted: :auto) do |response|
calculator.other_pay_types_received = response.split(",")
if calculator.already_getting_maternity_pay?
outcome :already_getting_maternity
else
question :employee_tell_within_limit?
end
end
end
# Question 2
multiple_choice :employee_tell_within_limit? do
option :yes
option :no
next_node(permitted: :auto) do |response|
if response == 'yes'
calculator.enough_notice_of_absence = true
else
calculator.enough_notice_of_absence = false
end
question :employee_work_different_days?
end
end
# Question 3
multiple_choice :employee_work_different_days? do
option :yes
option :no
next_node(permitted: :auto) do |response|
case response
when 'yes'
outcome :not_regular_schedule # Answer 4
when 'no'
question :first_sick_day? # Question 4
end
end
end
# Question 4
date_question :first_sick_day? do
from { Date.new(2011, 1, 1) }
to { Date.today.end_of_year }
validate_in_range
next_node(permitted: :auto) do |response|
calculator.sick_start_date = response
question :last_sick_day?
end
end
# Question 5
date_question :last_sick_day? do
from { Date.new(2011, 1, 1) }
to { Date.today.end_of_year }
validate_in_range
validate do |response|
calculator.valid_last_sick_day?(response)
end
next_node(permitted: :auto) do |response|
calculator.sick_end_date = response
if calculator.valid_period_of_incapacity_for_work?
question :has_linked_sickness?
else
outcome :must_be_sick_for_4_days
end
end
end
# Question 6
multiple_choice :has_linked_sickness? do
option :yes
option :no
next_node(permitted: :auto) do |response|
case response
when 'yes'
calculator.has_linked_sickness = true
question :linked_sickness_start_date?
when 'no'
calculator.has_linked_sickness = false
question :paid_at_least_8_weeks?
end
end
end
# Question 6.1
date_question :linked_sickness_start_date? do
from { Date.new(2010, 1, 1) }
to { Date.today.end_of_year }
validate_in_range
validate :linked_sickness_must_be_before do |response|
calculator.valid_linked_sickness_start_date?(response)
end
next_node(permitted: :auto) do |response|
calculator.linked_sickness_start_date = response
question :linked_sickness_end_date?
end
end
# Question 6.2
date_question :linked_sickness_end_date? do
from { Date.new(2010, 1, 1) }
to { Date.today.end_of_year }
validate_in_range
validate :must_be_within_eight_weeks do |response|
calculator.within_eight_weeks_of_current_sickness_period?(response)
end
validate :must_be_at_least_1_day_before_first_sick_day do |response|
calculator.at_least_1_day_before_first_sick_day?(response)
end
validate :must_be_valid_period_of_incapacity_for_work do |response|
calculator.valid_linked_period_of_incapacity_for_work?(response)
end
next_node(permitted: :auto) do |response|
calculator.linked_sickness_end_date = response
question :paid_at_least_8_weeks?
end
end
# Question 7.1
multiple_choice :paid_at_least_8_weeks? do
option :eight_weeks_more
option :eight_weeks_less
option :before_payday
precalculate :sick_start_date_for_awe do
calculator.sick_start_date_for_awe
end
next_node(permitted: :auto) do |response|
calculator.eight_weeks_earnings = response
if calculator.paid_at_least_8_weeks_of_earnings?
question :how_often_pay_employee_pay_patterns? # Question 7.2
elsif calculator.paid_less_than_8_weeks_of_earnings?
question :total_earnings_before_sick_period? # Question 10
elsif calculator.fell_sick_before_payday?
question :how_often_pay_employee_pay_patterns? # Question 7.2
end
end
end
# Question 7.2
multiple_choice :how_often_pay_employee_pay_patterns? do
option :weekly
option :fortnightly
option :every_4_weeks
option :monthly
option :irregularly
next_node(permitted: :auto) do |response|
calculator.pay_pattern = response
if calculator.paid_at_least_8_weeks_of_earnings?
question :last_payday_before_sickness? # Question 8
else
question :pay_amount_if_not_sick? # Question 9
end
end
end
# Question 8
date_question :last_payday_before_sickness? do
from { Date.new(2010, 1, 1) }
to { Date.today.end_of_year }
validate_in_range
precalculate :sick_start_date_for_awe do
calculator.sick_start_date_for_awe
end
validate do |response|
calculator.valid_last_payday_before_sickness?(response)
end
next_node(permitted: :auto) do |response|
calculator.relevant_period_to = response
question :last_payday_before_offset?
end
end
# Question 8.1
date_question :last_payday_before_offset? do
from { Date.new(2010, 1, 1) }
to { Date.today.end_of_year }
validate_in_range
precalculate :pay_day_offset do
calculator.pay_day_offset
end
validate do |response|
calculator.valid_last_payday_before_offset?(response)
end
next_node(permitted: :auto) do |response|
calculator.relevant_period_from = response + 1.day
question :total_employee_earnings?
end
end
# Question 8.2
money_question :total_employee_earnings? do
precalculate :relevant_period_from do
calculator.relevant_period_from
end
precalculate :relevant_period_to do
calculator.relevant_period_to
end
next_node(permitted: :auto) do |response|
calculator.total_employee_earnings = response
question :usual_work_days?
end
end
# Question 9
money_question :pay_amount_if_not_sick? do
precalculate :sick_start_date_for_awe do
calculator.sick_start_date_for_awe
end
next_node(permitted: :auto) do |response|
calculator.relevant_contractual_pay = response
question :contractual_days_covered_by_earnings?
end
end
# Question 9.1
value_question :contractual_days_covered_by_earnings? do
next_node(permitted: :auto) do |response|
calculator.contractual_days_covered_by_earnings = response
question :usual_work_days?
end
end
# Question 10
money_question :total_earnings_before_sick_period? do
next_node(permitted: :auto) do |response|
calculator.total_earnings_before_sick_period = response
question :days_covered_by_earnings?
end
end
# Question 10.1
value_question :days_covered_by_earnings? do
next_node(permitted: :auto) do |response|
calculator.days_covered_by_earnings = response.to_i
question :usual_work_days?
end
end
# Question 11
checkbox_question :usual_work_days? do
%w{1 2 3 4 5 6 0}.each { |n| option n.to_s }
next_node(permitted: :auto) do |response|
calculator.days_of_the_week_worked = response.split(",")
if calculator.not_earned_enough?
outcome :not_earned_enough
elsif calculator.maximum_entitlement_reached?
outcome :maximum_entitlement_reached # Answer 8
elsif calculator.entitled_to_sick_pay?
outcome :entitled_to_sick_pay # Answer 6
elsif calculator.maximum_entitlement_reached_v2?
outcome :maximum_entitlement_reached # Answer 8
else
outcome :not_entitled_3_days_not_paid # Answer 7
end
end
end
# Answer 1
outcome :already_getting_maternity
# Answer 2
outcome :must_be_sick_for_4_days
# Answer 4
outcome :not_regular_schedule
# Answer 5
outcome :not_earned_enough do
precalculate :lower_earning_limit do
calculator.lower_earning_limit
end
precalculate :employee_average_weekly_earnings do
calculator.employee_average_weekly_earnings
end
end
# Answer 6
outcome :entitled_to_sick_pay do
precalculate :ssp_payment do
calculator.ssp_payment
end
precalculate :days_paid do calculator.days_paid end
precalculate :normal_workdays_out do calculator.normal_workdays end
precalculate :pattern_days do calculator.pattern_days end
precalculate :pattern_days_total do calculator.pattern_days_total end
end
# Answer 7
outcome :not_entitled_3_days_not_paid do
precalculate :normal_workdays_out do calculator.normal_workdays end
end
# Answer 8
outcome :maximum_entitlement_reached
end
end
end