-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathpart-year-profit-tax-credits.rb
128 lines (103 loc) · 4.22 KB
/
part-year-profit-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
module SmartAnswer
class PartYearProfitTaxCreditsFlow < Flow
def define
name 'part-year-profit-tax-credits'
status :published
satisfies_need "103438"
content_id "de6723a5-7256-4bfd-aad3-82b04b06b73e"
date_question :when_did_your_tax_credits_award_end? do
from { Calculators::PartYearProfitTaxCreditsCalculator::TAX_CREDITS_AWARD_ENDS_EARLIEST_DATE }
to { Calculators::PartYearProfitTaxCreditsCalculator::TAX_CREDITS_AWARD_ENDS_LATEST_DATE }
next_node_calculation :calculator do
Calculators::PartYearProfitTaxCreditsCalculator.new
end
next_node(permitted: :auto) do |response|
calculator.tax_credits_award_ends_on = response
question :what_date_do_your_accounts_go_up_to?
end
end
date_question :what_date_do_your_accounts_go_up_to? do
default_year { 0 }
next_node(permitted: :auto) do |response|
calculator.accounts_end_month_and_day = response
question :have_you_stopped_trading?
end
end
multiple_choice :have_you_stopped_trading? do
option "yes"
option "no"
next_node(permitted: :auto) do |response|
if response == 'yes'
calculator.stopped_trading = true
question :did_you_start_trading_before_the_relevant_accounting_year?
elsif response == 'no'
calculator.stopped_trading = false
question :do_your_accounts_cover_a_12_month_period?
end
end
end
multiple_choice :did_you_start_trading_before_the_relevant_accounting_year? do
option "yes"
option "no"
precalculate(:accounting_year_begins_on) { calculator.accounting_year.begins_on }
next_node(permitted: :auto) do |response|
if response == "yes"
question :when_did_you_stop_trading?
elsif response == "no"
question :when_did_you_start_trading?
end
end
end
date_question :when_did_you_stop_trading? do
from { Calculators::PartYearProfitTaxCreditsCalculator::START_OR_STOP_TRADING_EARLIEST_DATE }
to { Calculators::PartYearProfitTaxCreditsCalculator::START_OR_STOP_TRADING_LATEST_DATE }
precalculate(:tax_year_begins_on) { calculator.tax_year.begins_on }
precalculate(:tax_year_ends_on) { calculator.tax_year.ends_on }
validate(:not_in_tax_year_error) do |response|
calculator.valid_stopped_trading_date?(response)
end
next_node(permitted: :auto) do |response|
calculator.stopped_trading_on = response
question :what_is_your_taxable_profit?
end
end
multiple_choice :do_your_accounts_cover_a_12_month_period? do
option "yes"
option "no"
precalculate(:accounting_year_ends_on) { calculator.accounting_year.ends_on }
next_node(permitted: :auto) do |response|
if response == "yes"
question :what_is_your_taxable_profit?
else
question :when_did_you_start_trading?
end
end
end
date_question :when_did_you_start_trading? do
from { Calculators::PartYearProfitTaxCreditsCalculator::START_OR_STOP_TRADING_EARLIEST_DATE }
to { Calculators::PartYearProfitTaxCreditsCalculator::START_OR_STOP_TRADING_LATEST_DATE }
precalculate(:award_period_ends_on) { calculator.award_period.ends_on }
validate(:invalid_start_trading_date) do |response|
calculator.valid_start_trading_date?(response)
end
next_node(permitted: :auto) do |response|
calculator.started_trading_on = response
if calculator.stopped_trading
question :when_did_you_stop_trading?
else
question :what_is_your_taxable_profit?
end
end
end
money_question :what_is_your_taxable_profit? do
precalculate(:basis_period_begins_on) { calculator.basis_period.begins_on }
precalculate(:basis_period_ends_on) { calculator.basis_period.ends_on }
next_node(permitted: :auto) do |response|
calculator.taxable_profit = response
outcome :result
end
end
outcome :result
end
end
end