-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathestimate-self-assessment-penalties.rb
151 lines (128 loc) · 3.96 KB
/
estimate-self-assessment-penalties.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
module SmartAnswer
class EstimateSelfAssessmentPenaltiesFlow < Flow
def define
content_id "32b54f44-fca1-4480-b13b-ddeb0b0238e1"
name 'estimate-self-assessment-penalties'
status :published
satisfies_need "100615"
calculator_dates = {
online_filing_deadline: {
"2011-12": Date.new(2013, 1, 31),
"2012-13": Date.new(2014, 1, 31),
"2013-14": Date.new(2015, 1, 31),
},
offline_filing_deadline: {
"2011-12": Date.new(2012, 10, 31),
"2012-13": Date.new(2013, 10, 31),
"2013-14": Date.new(2014, 10, 31),
},
payment_deadline: {
"2011-12": Date.new(2013, 1, 31),
"2012-13": Date.new(2014, 1, 31),
"2013-14": Date.new(2015, 1, 31),
},
}
multiple_choice :which_year? do
option :"2011-12"
option :"2012-13"
option :"2013-14"
save_input_as :tax_year
calculate :start_of_next_tax_year do |response|
if response == '2011-12'
Date.new(2012, 4, 6)
elsif response == '2012-13'
Date.new(2013, 4, 6)
else
Date.new(2014, 4, 6)
end
end
calculate :start_of_next_tax_year_formatted do
start_of_next_tax_year.strftime("%e %B %Y")
end
calculate :one_year_after_start_date_for_penalties do |response|
if response == '2011-12'
Date.new(2014, 2, 01)
elsif response == '2012-13'
Date.new(2015, 2, 01)
else
Date.new(2016, 2, 01)
end
end
next_node :how_submitted?
end
multiple_choice :how_submitted? do
option :online
option :paper
save_input_as :submission_method
next_node :when_submitted?
end
date_question :when_submitted? do
from { 3.year.ago(Date.today) }
to { 2.years.since(Date.today) }
save_input_as :filing_date
calculate :filing_date_formatted do
filing_date.strftime("%e %B %Y")
end
next_node(permitted: :auto) do |response|
if response < start_of_next_tax_year
raise SmartAnswer::InvalidResponse
else
question :when_paid?
end
end
end
date_question :when_paid? do
from { 3.year.ago(Date.today) }
to { 2.years.since(Date.today) }
save_input_as :payment_date
next_node(permitted: :auto) do |response|
if filing_date > response
raise SmartAnswer::InvalidResponse
else
calculator = Calculators::SelfAssessmentPenalties.new(
submission_method: submission_method,
filing_date: filing_date,
payment_date: response,
dates: calculator_dates,
tax_year: tax_year
)
if calculator.paid_on_time?
outcome :filed_and_paid_on_time
else
question :how_much_tax?
end
end
end
end
money_question :how_much_tax? do
save_input_as :estimated_bill
next_node :late
end
outcome :late do
precalculate :calculator do
Calculators::SelfAssessmentPenalties.new(
submission_method: submission_method,
filing_date: filing_date,
payment_date: payment_date,
estimated_bill: estimated_bill,
dates: calculator_dates,
tax_year: tax_year
)
end
precalculate :late_filing_penalty do
calculator.late_filing_penalty
end
precalculate :total_owed do
calculator.total_owed_plus_filing_penalty
end
precalculate :interest do
calculator.interest
end
precalculate :late_payment_penalty do
calculator.late_payment_penalty
end
end
outcome :filed_and_paid_on_time
end
end
end