- class Booking < ActiveRecord::Base
- belongs_to :property
- belongs_to :booking_status
- has_one :guest_comment
- validates_numericality_of :rental_charge, :damages_deposit, :linen_charge, :cleaning_charge,:baby_equipment_charge, :total_amount_due, :deposit_requested, :deposit_paid,:balance_due
- validates_presence_of :property_id, :booking_status_id, :firstname, :surname, :email, :address, :telephone, :arrival_date, :departure_date, :number_of_adults, :number_of_children, :number_of_babies, :total_in_party
- validates_numericality_of :number_of_adults, :number_of_children, :number_of_babies, :total_in_party
- validates_inclusion_of :number_of_adults, :in => 1..20, :message => "values of 1 to 20 allowed"
- validates_inclusion_of :total_in_party, :in => 1..20, :message => "values of 1 to 20 allowed"
- validate :arrival_must_be_before_departure
- validate :check_total_in_the_party_adds_up
- validate :arrival_must_be_on_a_saturday
- def arrival_must_be_before_departure
- # when we've got an arrival and departure date make sure we arrive before we depart
- errors.add(:arrival_date, "You must arrive before you depart") if !arrival_date.blank? && !departure_date.blank? and arrival_date > departure_date
- end
- def arrival_must_be_on_a_saturday
- # you need to arrive on a Saturday
- if self.property.user.saturday_arrivals_only == true
- errors.add(:arrival_date, "Arrival must be on a Saturday") if !arrival_date.blank? and arrival_date.wday != 6
- end
- end
- def check_total_in_the_party_adds_up
- # check the total for the party is correct
- errors.add(:total_in_party, "Number in the party does not add up") if number_of_adults.to_i + number_of_children.to_i + number_of_babies.to_i != total_in_party
- end
- def booking_reference
- [self.firstname,self.surname,(I18n.l self.arrival_date),(I18n.l self.departure_date)].join("_")
- end
- def booking_dates
- [(I18n.l self.arrival_date),(I18n.l self.departure_date)].join(" to ")
- end
- end
- # validates_length_of :name, :within => 2..30
- # validates_format_of :name, :with => /\A[a-zA-Z]+\z/, :message => "only letters allowed"
- # validates_format_of :occurrences, :with => /\A[0-9]+\z/, :message => "only numbers allowed"
- # validates_format_of :rank, :with => /\A[0-9]+\z/, :message => "only numbers allowed"
- # validates_format_of :gender, :with => /Boy|Girl/, :message => "only Boy or Girl allowed"
- # validates_presence_of :advert_type, :message => "can't be blank"
- # validates_length_of :tag_line, :within => 10..140, :message => "Required field. 10 to 140 characters allowed."
- # validates_length_of :name, :within => 3..40, :message => "Required field. 3 to 40 characters allowed."
- # validates_length_of :body, :within => 10..1000, :message => "Required field. 10 to 1000 characters."
- # validates_length_of :resort_ids, :minimum => 1, :message => " : Please tick any resort checkbox to link your advert to a relevant location(s)."
- # validates_format_of :landline_phone_number, :landline_fax_number, :mobile_phone_number,
- # :message => "must be a valid telephone number.",
- # :with => /^([\(\)0-9\- \+\.]{10,20})?$/
- #
- # validates_format_of :web_site,
- # :allow_nil => true,
- # :allow_blank => true,
- # :with => /(^(http|https):\/\/[a-z0-9]+([-.]{1}[a-z0-9]*)+. [a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix,
- # :message => "needs to be a valid address e.g. with 'http://something.com'."