Skip to content

Instantly share code, notes, and snippets.

@ldenman
Created August 4, 2010 19:18
Show Gist options
  • Save ldenman/508628 to your computer and use it in GitHub Desktop.
Save ldenman/508628 to your computer and use it in GitHub Desktop.
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
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