Repository navigation
Expand file tree
/
Copy pathchild_benefit_tax_calculator_flow.rb
More file actions
213 lines (177 loc) · 4.97 KB
/
Copy pathchild_benefit_tax_calculator_flow.rb
File metadata and controls
213 lines (177 loc) · 4.97 KB
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
class ChildBenefitTaxCalculatorFlow < SmartAnswer::Flow
def define
name "child-benefit-tax-calculator"
content_id "0e1de8f1-9909-4e45-a6a3-bffe95470275"
status :published
# Q1
value_question :how_many_children?, parse: Integer do
on_response do |response|
self.calculator = SmartAnswer::Calculators::ChildBenefitTaxCalculator.new
calculator.children_count = response.to_i
end
validate(:valid_number_of_children) do
calculator.valid_number_of_children?
end
next_node do
question :which_tax_year?
end
end
# Q2
radio :which_tax_year? do
SmartAnswer::Calculators::ChildBenefitTaxCalculator.tax_years.each do |tax_year|
option :"#{tax_year}"
end
on_response do |response|
calculator.tax_year = response
end
next_node do |response|
if response == "2024"
question :between_april_june?
else
question :is_part_year_claim?
end
end
end
# Q2-b
radio :between_april_june? do
option :yes
option :no
on_response do |response|
calculator.between_april_june = response
end
next_node do
question :is_part_year_claim?
end
end
# Q3
radio :is_part_year_claim? do
option :yes
option :no
next_node do |response|
if response == "yes"
question :how_many_children_part_year?
else
question :income_details?
end
end
end
# Q3a
value_question :how_many_children_part_year?, parse: Integer do
on_response do |response|
calculator.part_year_children_count = response
end
validate(:valid_number_of_part_year_children) do
calculator.valid_number_of_part_year_children?
end
next_node do
question :child_benefit_1_start?
end
end
(1..SmartAnswer::Calculators::ChildBenefitTaxCalculator::MAX_CHILDREN).each do |child_number|
# Q3b
date_question "child_benefit_#{child_number}_start?".to_sym do
template_name "child_benefit_start"
on_response do |response|
calculator.store_date(:start_date, response)
end
validate(:valid_within_tax_year) do
calculator.valid_within_tax_year?(:start_date)
end
next_node do
question "add_child_benefit_#{child_number}_stop?".to_sym
end
end
# Q3c
radio "add_child_benefit_#{child_number}_stop?".to_sym do
template_name "add_child_benefit_stop"
option :yes
option :no
next_node do |response|
if response == "yes"
question "child_benefit_#{child_number}_stop?".to_sym
else
calculator.child_number = child_number + 1
if calculator.child_number <= calculator.part_year_children_count
question "child_benefit_#{calculator.child_number}_start?".to_sym
else
question :income_details?
end
end
end
end
# Q3d
date_question "child_benefit_#{child_number}_stop?".to_sym do
template_name "child_benefit_stop"
on_response do |response|
calculator.store_date(:end_date, response)
end
validate(:valid_within_tax_year) do
calculator.valid_within_tax_year?(:end_date)
end
validate(:valid_end_date) do
calculator.valid_end_date?
end
next_node do
calculator.child_number = child_number + 1
if calculator.child_number <= calculator.part_year_children_count
question "child_benefit_#{calculator.child_number}_start?".to_sym
else
question :income_details?
end
end
end
end
# Q4
money_question :income_details? do
on_response do |response|
calculator.income_details = response
end
next_node do
question :add_allowable_deductions?
end
end
# Q5
radio :add_allowable_deductions? do
option :yes
option :no
next_node do |response|
if response == "yes"
question :allowable_deductions?
else
outcome :results
end
end
end
# Q5a
money_question :allowable_deductions? do
on_response do |response|
calculator.allowable_deductions = response
end
next_node do
question :add_other_allowable_deductions?
end
end
# Q6
radio :add_other_allowable_deductions? do
option :yes
option :no
next_node do |response|
if response == "yes"
question :other_allowable_deductions?
else
outcome :results
end
end
end
# Q6a
money_question :other_allowable_deductions? do
on_response do |response|
calculator.other_allowable_deductions = response
end
next_node do
outcome :results
end
end
outcome :results
end
end