41 lines
1.1 KiB
Ruby
41 lines
1.1 KiB
Ruby
module JamRuby
|
|
class LessonSessionMonthlyPrice
|
|
|
|
# calculate the price for a given month
|
|
def self.price(lesson_booking, start_day)
|
|
|
|
raise "lesson_booking is not monthly paid #{lesson_booking.admin_url}" if !lesson_booking.is_monthly_payment?
|
|
|
|
data = lesson_booking.predicted_times_for_month(start_day.year, start_day.month)
|
|
|
|
times = data[:times]
|
|
session = data[:session]
|
|
|
|
true_start = start_day
|
|
if session
|
|
# if there is already a session for the month, that is the real star
|
|
true_start = session.scheduled_start.to_date
|
|
end
|
|
|
|
# filter out anything before the start day
|
|
times.select! { |time| time.to_date >= true_start }
|
|
|
|
result = nil
|
|
if times.length == 0
|
|
result = 0
|
|
elsif times.length == 1
|
|
result = (lesson_booking.booked_price * 0.25).round(2)
|
|
elsif times.length == 2
|
|
result = (lesson_booking.booked_price * 0.50).round(2)
|
|
elsif times.length == 3
|
|
result = (lesson_booking.booked_price * 0.75).round(2)
|
|
else
|
|
result = lesson_booking.booked_price
|
|
end
|
|
|
|
result
|
|
end
|
|
end
|
|
end
|
|
|