-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathchildcare-costs-for-tax-credits.rb
403 lines (347 loc) · 10.7 KB
/
childcare-costs-for-tax-credits.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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
module SmartAnswer
class ChildcareCostsForTaxCreditsFlow < Flow
def define
content_id "f8c575b7-d7a2-41a4-9911-069a06f1a2cc"
name 'childcare-costs-for-tax-credits'
status :published
satisfies_need "100422"
use_erb_templates_for_questions
#Q1
multiple_choice :currently_claiming? do
option :yes
option :no
calculate :cost_change_4_weeks do
nil
end
permitted_next_nodes = [
:have_costs_changed?,
:how_often_use_childcare?
]
next_node(permitted: permitted_next_nodes) do |response|
case response
when 'yes'
:have_costs_changed? #Q3
when 'no'
:how_often_use_childcare? #Q2
end
end
end
#Q2
multiple_choice :how_often_use_childcare? do
option :regularly_less_than_year
option :regularly_more_than_year
option :only_short_while
permitted_next_nodes = [
:how_often_pay_1?,
:pay_same_each_time?,
:call_helpline_detailed
]
next_node(permitted: permitted_next_nodes) do |response|
case response
when 'regularly_less_than_year'
:how_often_pay_1? #Q4
when 'regularly_more_than_year'
:pay_same_each_time? #Q11
when 'only_short_while'
:call_helpline_detailed #O1
end
end
end
#Q3
multiple_choice :have_costs_changed? do
option :yes
option :no
permitted_next_nodes = [
:how_often_pay_2?,
:no_change
]
next_node(permitted: permitted_next_nodes) do |response|
case response
when 'yes'
:how_often_pay_2? #Q5
when 'no'
:no_change #O2
end
end
end
#Q4
multiple_choice :how_often_pay_1? do
option :weekly_same_amount
option :weekly_diff_amount
option :monthly_same_amount
option :monthly_diff_amount
option :other
permitted_next_nodes = [
:round_up_weekly,
:how_much_52_weeks_1?,
:how_much_each_month?,
:how_much_12_months_1?
]
next_node(permitted: permitted_next_nodes) do |response|
case response
when 'weekly_same_amount'
:round_up_weekly #O3
when 'weekly_diff_amount'
:how_much_52_weeks_1? #Q7
when 'monthly_same_amount'
:how_much_each_month? #Q10
when 'monthly_diff_amount', 'other'
:how_much_12_months_1? #Q6
end
end
end
#Q5
multiple_choice :how_often_pay_2? do
option :weekly_same_amount
option :weekly_diff_amount
option :monthly_same_amount
option :monthly_diff_amount
option :other
permitted_next_nodes = [
:new_weekly_costs?,
:how_much_52_weeks_2?,
:new_monthly_cost?,
:how_much_12_months_2?
]
next_node(permitted: permitted_next_nodes) do |response|
case response
when 'weekly_same_amount'
:new_weekly_costs? #Q17
when 'weekly_diff_amount', 'other'
:how_much_52_weeks_2? #Q8
when 'monthly_same_amount'
:new_monthly_cost? #Q19
when 'monthly_diff_amount'
:how_much_12_months_2? #Q9
end
end
end
#Q6
money_question :how_much_12_months_1? do
calculate :weekly_cost do |response|
SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost(response)
end
next_node :weekly_costs_are_x #O4
end
#Q7
money_question :how_much_52_weeks_1? do
calculate :weekly_cost do |response|
SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost(response)
end
next_node :weekly_costs_are_x #O4
end
#Q8
money_question :how_much_52_weeks_2? do
calculate :weekly_cost do |response|
SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost(response)
end
permitted_next_nodes = [
:no_longer_paying,
:old_weekly_amount_1?
]
next_node(permitted: permitted_next_nodes) do |response|
amount = Money.new(response)
amount == 0 ? :no_longer_paying : :old_weekly_amount_1?
end
end
#Q9
money_question :how_much_12_months_2? do
calculate :weekly_cost do |response|
SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost(response)
end
permitted_next_nodes = [
:no_longer_paying,
:old_weekly_amount_1?
]
next_node(permitted: permitted_next_nodes) do |response|
amount = Money.new(response)
amount == 0 ? :no_longer_paying : :old_weekly_amount_1?
end
end
#Q10
money_question :how_much_each_month? do
calculate :weekly_cost do |response|
SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost_from_monthly(response)
end
next_node :weekly_costs_are_x #O4
end
#Q11
multiple_choice :pay_same_each_time? do
option :yes
option :no
permitted_next_nodes = [
:how_often_pay_providers?,
:how_much_spent_last_12_months?
]
next_node(permitted: permitted_next_nodes) do |response|
case response
when 'yes'
:how_often_pay_providers? #Q12
when 'no'
:how_much_spent_last_12_months? #Q16
end
end
end
#Q12
multiple_choice :how_often_pay_providers? do
option :weekly
option :fortnightly
option :every_4_weeks
option :every_month
option :termly
option :yearly
option :other
permitted_next_nodes = [
:round_up_weekly,
:how_much_fortnightly?,
:how_much_4_weeks?,
:how_much_each_month?,
:call_helpline_plain,
:how_much_yearly?
]
next_node(permitted: permitted_next_nodes) do |response|
case response
when 'weekly'
:round_up_weekly #O3
when 'fortnightly'
:how_much_fortnightly? #Q13
when 'every_4_weeks'
:how_much_4_weeks? #Q14
when 'every_month'
:how_much_each_month? #Q10
when 'termly', 'other'
:call_helpline_plain #O5
when 'yearly'
:how_much_yearly? #Q15
end
end
end
#Q13
money_question :how_much_fortnightly? do
calculate :weekly_cost do |response|
SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost_from_fortnightly(response)
end
next_node :weekly_costs_are_x #O4
end
#Q14
money_question :how_much_4_weeks? do
calculate :weekly_cost do |response|
SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost_from_four_weekly(response)
end
next_node :weekly_costs_are_x #04
end
#Q15
money_question :how_much_yearly? do
calculate :weekly_cost do |response|
SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost(response)
end
next_node :weekly_costs_are_x #O4
end
#Q16
money_question :how_much_spent_last_12_months? do
calculate :weekly_cost do |response|
SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost(response)
end
next_node :weekly_costs_are_x #O4
end
#Q17
money_question :new_weekly_costs? do
calculate :new_weekly_costs do |response|
Float(response).ceil
end
permitted_next_nodes = [
:no_longer_paying,
:old_weekly_amount_2?
]
next_node(permitted: permitted_next_nodes) do |response|
amount = Money.new(response)
amount == 0 ? :no_longer_paying : :old_weekly_amount_2?
end
end
#Q18
money_question :old_weekly_amount_1? do
# get weekly amount from Q8 or Q9 (whichever the user answered)
# calculate different using input from Q18
calculate :old_weekly_cost do |response|
Float(response).ceil
end
calculate :weekly_difference do
SmartAnswer::Calculators::ChildcareCostCalculator.cost_change(weekly_cost, old_weekly_cost)
end
calculate :weekly_difference_abs do
weekly_difference.abs
end
next_node :cost_changed
end
#Q19
money_question :new_monthly_cost? do
calculate :new_weekly_costs do |response|
SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost_from_monthly(response)
end
permitted_next_nodes = [
:no_longer_paying,
:old_weekly_amount_3?
]
next_node(permitted: permitted_next_nodes) do |response|
amount = Money.new(response)
amount == 0 ? :no_longer_paying : :old_weekly_amount_3?
end
end
#Q20
money_question :old_weekly_amount_2? do
calculate :old_weekly_costs do |response|
Float(response).ceil
end
calculate :weekly_difference do
SmartAnswer::Calculators::ChildcareCostCalculator.cost_change(new_weekly_costs, old_weekly_costs)
end
calculate :weekly_difference_abs do
weekly_difference.abs
end
calculate :cost_change_4_weeks do true end
next_node :cost_changed
end
#Q21
money_question :old_weekly_amount_3? do
calculate :old_weekly_costs do |response|
Float(response).ceil
end
calculate :weekly_difference do
SmartAnswer::Calculators::ChildcareCostCalculator.cost_change(new_weekly_costs, old_weekly_costs)
end
calculate :weekly_difference_abs do
weekly_difference.abs
end
next_node :cost_changed
end
### Outcomes
#O1
outcome :call_helpline_detailed
#O5
outcome :call_helpline_plain
#O2
outcome :no_change
#O3
outcome :round_up_weekly
#O4
outcome :weekly_costs_are_x
#O6, 7, 8
outcome :cost_changed do
precalculate :ten_or_more do
weekly_difference_abs >= 10
end
precalculate :cost_change_4_weeks do
cost_change_4_weeks || false
end
precalculate :title_change_text do
weekly_difference >= 10 ? "increased" : "decreased"
end
precalculate :difference_money do
Money.new(weekly_difference.abs)
end
end
#O9
outcome :no_longer_paying
end
end
end