generated from DFE-Digital/govuk-rails-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathoutput_payment_calculator.rb
62 lines (50 loc) · 2.14 KB
/
output_payment_calculator.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
# frozen_string_literal: true
module PaymentCalculator
module ECF
class OutputPaymentCalculator
include HasDIParameters
delegate :bands, to: :contract
def call(event_type:, total_participants:, total_previous_participants:)
bands.each_with_index.map do |band, i|
{
band: i,
participants: band.number_of_participants_in_this_band(total_participants, total_previous_participants),
per_participant: output_payment_per_participant_for_event(event_type:, band:),
subtotal: output_payment_for_event(
total_participants:,
total_previous_participants:,
event_type:,
band:,
),
}
end
end
def output_payment_for_event(event_type:, total_participants:, total_previous_participants:, band:)
band.number_of_participants_in_this_band(total_participants, total_previous_participants) * output_payment_per_participant_for_event(event_type:, band:)
end
def output_payment_per_participant_for_event(event_type:, band:)
event_type = event_type.parameterize.underscore.intern if event_type.is_a?(String)
send(event_type) * band.output_payment_per_participant
end
private
def start_and_completion_event_percentage
0.2
end
alias_method :started, :start_and_completion_event_percentage
alias_method :completed, :start_and_completion_event_percentage
def interim_retained_period_event_percentage
0.15
end
alias_method :retained_1, :interim_retained_period_event_percentage
alias_method :retained_2, :interim_retained_period_event_percentage
alias_method :retained_3, :interim_retained_period_event_percentage
alias_method :retained_4, :interim_retained_period_event_percentage
def interim_extended_period_event_percentage
0.15
end
alias_method :extended_1, :interim_extended_period_event_percentage
alias_method :extended_2, :interim_extended_period_event_percentage
alias_method :extended_3, :interim_extended_period_event_percentage
end
end
end