Created
August 4, 2010 19:18
-
-
Save ldenman/508628 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pending_total | |
if not_needed? | |
0.00 | |
else | |
# everyone gets the member pricing | |
daily_rate = ACCOMMODATION_RATES[room_type][:member] | |
departure_date = departure.to_date | |
arrival_date = arrival.to_date | |
total_days = departure_date - arrival_date | |
before_discounted_days = [[start_date - arrival_date, 3].min, 0].max | |
after_discounted_days = [[departure_date - end_date, 3].min, 0].max | |
discounted_days = before_discounted_days + after_discounted_days | |
(discounted_days * DISCOUNT_RATE) + ((total_days - discounted_days) * daily_rate) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def accommodation_total | |
accommodation ? accommodation.total + discounted_stay_price : 0.0 | |
end | |
def discounted_stay_price | |
discounted_additional_days * DISCOUNTED_STAY_RATE | |
end | |
def customer_stay_duration | |
(departure - arrival).to_i | |
end | |
def discounted_additional_days | |
additional_days > MAX_DISCOUNTED_DAYS ? MAX_DISCOUNTED_DAYS : additional_days | |
end | |
def additional_days | |
(location_duration - customer_stay_duration).to_i | |
end | |
def location_duration | |
(location.end_date - location.start_date).to_i | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment