-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathself_assessment_penalties.rb
109 lines (96 loc) · 3.17 KB
/
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
require "ostruct"
module SmartAnswer::Calculators
class SelfAssessmentPenalties < OpenStruct
def paid_on_time?
(filing_date <= filing_deadline) && (payment_date <= payment_deadline)
end
def late_filing_penalty
#Less than 6 months
if overdue_filing_days <= 0
result = 0
elsif submission_method == "online"
if overdue_filing_days <= 89
result = 100
elsif overdue_filing_days <= 181
result = (overdue_filing_days - 89) * 10 + 100
#this fine can't be more than 1000£
if result > 1000
result = 1000
end
end
else
if overdue_filing_days <= 92
result = 100
elsif overdue_filing_days <= 181
result = (overdue_filing_days - 92) * 10 + 100
#this fine can't be more than 1000£
if result > 1000
result = 1000
end
end
end
#More than 6 months, same for paper and online return
if (overdue_filing_days > 181) && (overdue_filing_days <= 365)
#if 5% of tax due is higher than 300£ then charge 5% of tax due otherwise charge 300£
if estimated_bill.value > 6002
result = 1000 + (estimated_bill.value * 0.05)
else
result = 1000 + 300
end
#if more than 1 year
elsif overdue_filing_days > 365
# if 5% of tax due is higher than 300£ then charge 5% of tax due otherwise charge 300£ + all other fines
if estimated_bill.value > 6002
result = 1000 + (estimated_bill.value * 0.05) + (estimated_bill.value * 0.05)
else
result = 1000 + 600
end
end
SmartAnswer::Money.new(result)
end
def interest
if overdue_payment_days <= 0
0
else
SmartAnswer::Money.new(calculate_interest(estimated_bill.value, overdue_payment_days).round(2))
end
end
def total_owed
SmartAnswer::Money.new((estimated_bill.value + interest.to_f + late_payment_penalty.to_f).floor)
end
def total_owed_plus_filing_penalty
SmartAnswer::Money.new(total_owed.value + late_filing_penalty.value)
end
def late_payment_penalty
if overdue_payment_days <= 30
0
elsif overdue_payment_days <= 181
SmartAnswer::Money.new(late_payment_penalty_part.round(2))
elsif overdue_payment_days <= 365
SmartAnswer::Money.new((late_payment_penalty_part * 2).round(2))
else
SmartAnswer::Money.new((late_payment_penalty_part * 3).round(2))
end
end
private
def overdue_filing_days
(filing_date - filing_deadline).to_i
end
def overdue_payment_days
(payment_date - payment_deadline).to_i
end
def late_payment_penalty_part
0.05 * estimated_bill.value
end
def filing_deadline
submission_method == "online" ? dates[:online_filing_deadline][tax_year.to_sym] : dates[:offline_filing_deadline][tax_year.to_sym]
end
def payment_deadline
dates[:payment_deadline][tax_year.to_sym]
end
#interest is 3% per annum
def calculate_interest(amount, number_of_days)
(amount * (0.03 / 365) * (number_of_days - 1)).round(10)
end
end
end