Module: DuplicateBookingChecker

Extended by:
ActiveSupport::Concern
Included in:
ReservationService::Create, ReservationService::Form::Base
Defined in:
app/my_lib/duplicate_booking_checker.rb

Overview

guest booking is identified by phone number

Instance Method Summary collapse

Instance Method Details

#duplicate_error_messageObject



16
17
18
# File 'app/my_lib/duplicate_booking_checker.rb', line 16

def duplicate_error_message
  @duplicate_error_message
end

#multiple_bookings_allowed?(user, reservation) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/my_lib/duplicate_booking_checker.rb', line 20

def multiple_bookings_allowed?(user, reservation)
  booking_channel = reservation.booking_channel

  # allow multiple bookings for all types of vendor bookings whether prepaid or postpaid
  return true if booking_channel&.vendor_skips_payment_check_for_multiple_bookings?(booking_channel&.name)
  # allow multiple bookings only for paid bookings from vendors
  return true if payment_handled_by_vendor?(booking_channel) && params[:vendor_payment].present?

  last_reservation = find_last_reservation(user, reservation)

  return true if last_reservation.blank?
  return true if last_reservation.private_channel? || last_reservation.corporate_order?
  return true if last_reservation.vendor_payment.present?
  return true if last_reservation.prepayment_percent > 0 || last_reservation.paid_amount.positive?
  return true if conditions_met_for_reservation_from_different_restaurant?(last_reservation, reservation)
  return true if conditions_met_for_reservation_from_same_restaurant?(last_reservation, reservation)

  @duplicate_error_message = I18n.t('reservation.duplicated')
  false
end