formulas 0.1.1.1 → 0.1.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05cc76051c2d5ff9889d39b8448fe5b1b5fabdb60703b9b4c1afd9a58aa72a87
4
- data.tar.gz: 01213c4a728219396108c266d8b4398d28829140957c4fb7e957ee401e20fd51
3
+ metadata.gz: 83d6fc2b5bb6cca7fd953251292a8c7a6ca875d9863baca8172e3a28b3adb9d4
4
+ data.tar.gz: 7ccc7609cf9eeb47e90997c9a119801c04a573c8ae7501726a4f9b56f6d0367f
5
5
  SHA512:
6
- metadata.gz: 948b740e1a3e8965ab9991fdcf448081dfe896ff71fbd2f4f7fda2a98c356f37d2c741ef14ca19330168d5d93d211383659f1551fe0cc50b7bac74e5d5fde8bd
7
- data.tar.gz: 8bc92d9ea8b509ce304afaeabfdf4db5d443d4a0a542ca8e4ffb34f71652fdec9f79941a3028df5096647a93c57c6c7937e6ea5d953fae82bb4fb8fe3e5e673a
6
+ metadata.gz: 5ee13fdf52c560cda1700fb92e14c84759444bb2550504cdf2066a92fa273b6ee61ad701a3b3589d2a577b32274db66a9cefa0b57f4c64ba4ea74082d9028792
7
+ data.tar.gz: 3391896c0adc427c1edb1a568c8a4578df8ee339831fc4245ac45acb37b99a8b88fd7d76a1bc0e54c53446fa8aa3e4fbfea25ca3e4ec62616f4b07407451f724
data/formulas.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'formulas'
3
- s.version = '0.1.1.1'
3
+ s.version = '0.1.1.5'
4
4
  s.summary = "formulas"
5
5
  s.description = "Home loan formulas"
6
6
  s.authors = ["formulas"]
data/lib/formulas/paye.rb CHANGED
@@ -19,6 +19,8 @@ module Formulas
19
19
  [[180_000], 39]
20
20
  ]
21
21
 
22
+ MAX_ACC_LEVY_PAYABLE = 130_911
23
+
22
24
  def initialize(gross_pay:, frequency: Formulas::MONTHLY)
23
25
  super(gross_pay, frequency, TAX_RATES)
24
26
  end
@@ -26,5 +28,13 @@ module Formulas
26
28
  def tax(request_frequency: Formulas::WEEKLY)
27
29
  calculate_tax(request_frequency)
28
30
  end
31
+
32
+ def levy
33
+ 0.0139
34
+ end
35
+
36
+ def acc_payable
37
+ annual_gross_pay > MAX_ACC_LEVY_PAYABLE ? MAX_ACC_LEVY_PAYABLE : annual_gross_pay
38
+ end
29
39
  end
30
40
  end
@@ -16,11 +16,11 @@ module Formulas
16
16
  attr_reader :frequency
17
17
 
18
18
  def initialize(pay:, frequency:)
19
- invalid_frequency unless FREQUENCIES.include?(frequency)
20
- raise ArgumentError, 'Gross pay must be numeric' unless Numeric === pay
21
-
22
19
  @pay = pay
23
- @frequency = frequency
20
+ @frequency = frequency.to_sym
21
+
22
+ invalid_frequency unless FREQUENCIES.include?(@frequency)
23
+ raise ArgumentError, 'Gross pay must be numeric' unless Numeric === pay
24
24
  end
25
25
 
26
26
  def pay(request_frequency: @frequency)
@@ -12,11 +12,11 @@ module Formulas
12
12
  FIX_RATE = 0.12
13
13
 
14
14
  DEFAULT_THRESHOLD = {
15
- weekly: [390, 52],
16
- fortnightly: [780, 26],
17
- four_weeks: [1560, 13],
18
- monthly: [1690, 12],
19
- annually: [20280, 1],
15
+ weekly: [390, 52],
16
+ fortnightly: [780, 26],
17
+ four_weeks: [1560, 13],
18
+ monthly: [1690, 12],
19
+ annually: [20280, 1],
20
20
  }
21
21
 
22
22
  def repayment
@@ -15,9 +15,9 @@ module Formulas
15
15
  #
16
16
  #
17
17
  module StudentLoanRepayment
18
- autoload :RepaymentBase, './lib/formulas/student_loan_repayment/repayment_base'
19
- autoload :FixRepaymentPerPeriod, './lib/formulas/student_loan_repayment/fix_repayment_per_period'
20
- autoload :PercentRepaymentPerThreshold, './lib/formulas/student_loan_repayment/percent_repayment_per_threshold'
18
+ autoload :RepaymentBase, 'formulas/student_loan_repayment/repayment_base'
19
+ autoload :FixRepaymentPerPeriod, 'formulas/student_loan_repayment/fix_repayment_per_period'
20
+ autoload :PercentRepaymentPerThreshold, 'formulas/student_loan_repayment/percent_repayment_per_threshold'
21
21
  attr_reader :repayment
22
22
 
23
23
  def initialize(income_strategy: , repayment_strategy:, rates:)
@@ -4,10 +4,25 @@ module Formulas
4
4
  class WithholdingTax
5
5
  include FrequencyConversions
6
6
 
7
- def initialize(gross_pay, origin_frequency, tax_rate)
7
+ attr_reader :origin_frequency
8
+
9
+ def initialize(gross_pay, origin_frequency, tax_rate, options: {})
8
10
  @gross_pay = gross_pay
9
11
  @origin_frequency = origin_frequency
10
12
  @tax_rate = tax_rate
13
+ @options = options
14
+ end
15
+
16
+ def net_pay(request_frequency:)
17
+ annual_pay_after_tax = annual_gross_pay - calculate_tax(Formulas::ANNUALLY)
18
+
19
+ if respond_to?(:levy)
20
+ net_pay = annual_pay_after_tax - (acc_payable * send(:levy))
21
+ end
22
+
23
+ return net_pay if request_frequency.to_s == Formulas::ANNUALLY.to_s
24
+
25
+ send("convert_annually_to_#{request_frequency}", net_pay).round(2)
11
26
  end
12
27
 
13
28
  protected
@@ -15,7 +30,7 @@ module Formulas
15
30
  def calculate_tax(request_frequency)
16
31
  @request_frequency = request_frequency
17
32
 
18
- return annual_tax if request_frequency == Formulas::ANNUALLY
33
+ return annual_tax if request_frequency.to_s == Formulas::ANNUALLY.to_s
19
34
 
20
35
  send("convert_annually_to_#{request_frequency}", annual_tax).round(2)
21
36
  end
@@ -25,22 +40,24 @@ module Formulas
25
40
  def annual_tax
26
41
  annual_result = 0
27
42
 
28
- if gross_pay_tax_index > 0
29
- @tax_rate[0..gross_pay_tax_index].each_with_index do |current, index|
30
- l = (index == gross_pay_tax_index) ? @gross_pay : current[0][1]
31
- annual_result += ((l - current[0][0]) * (current[1].to_f / 100))
32
- end
43
+ @tax_rate[0..gross_pay_tax_index].each_with_index do |current, index|
44
+ l = (index == gross_pay_tax_index) ? annual_gross_pay : current[0][1]
45
+ annual_result += ((l - current[0][0]) * (current[1].to_f / 100))
33
46
  end
47
+
34
48
  annual_result
35
49
  end
36
50
 
37
51
  def annual_gross_pay
38
- return @gross_pay if @origin_frequency == Formulas::ANNUALLY
52
+ return @gross_pay if @origin_frequency.to_s == Formulas::ANNUALLY.to_s
39
53
  send("convert_#{@origin_frequency}_to_annually", @gross_pay)
40
54
  end
41
55
 
42
56
  def gross_pay_tax_index
43
- @tax_rate.index { |current| current[0][0] <= annual_gross_pay && current[0][1] >= annual_gross_pay }
57
+ @tax_rate.index do |current|
58
+ (current[0][0] <= annual_gross_pay && current[0][1].nil?) ||
59
+ (current[0][0] <= annual_gross_pay && current[0][1] >= annual_gross_pay)
60
+ end
44
61
  end
45
62
  end
46
63
  end
data/lib/formulas.rb CHANGED
@@ -25,6 +25,13 @@ module Formulas
25
25
  FREQUENCIES = [ANNUALLY, WEEKLY, FORTNIGHTLY, MONTHLY]
26
26
 
27
27
  module FrequencyConversions
28
+ def convert_annually_to_annually(number)
29
+ number
30
+ end
31
+ alias :convert_weekly_to_weekly convert_annually_to_annually
32
+ alias :convert_fortnightly_to_fortnightly convert_annually_to_annually
33
+ alias :convert_monthly_to_monthly convert_annually_to_annually
34
+
28
35
  def convert_annually_to_weekly(number)
29
36
  number.to_f / 52
30
37
  end
@@ -60,5 +67,17 @@ module Formulas
60
67
  def convert_monthly_to_fortnightly(number)
61
68
  number.to_f * 12 / 26
62
69
  end
70
+
71
+ def convert_fortnightly_to_annually(number)
72
+ number.to_f * 26
73
+ end
74
+
75
+ def convert_fortnightly_to_weekly(number)
76
+ number.to_f / 2
77
+ end
78
+
79
+ def convert_fortnightly_to_monthly(number)
80
+ (number.to_f * 26) / 12
81
+ end
63
82
  end
64
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formulas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.1
4
+ version: 0.1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - formulas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-28 00:00:00.000000000 Z
11
+ date: 2021-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  requirements: []
82
- rubygems_version: 3.0.9
82
+ rubygems_version: 3.1.2
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: formulas