100 lines
2.8 KiB
Ruby
Executable File
100 lines
2.8 KiB
Ruby
Executable File
class DiningFacility < ApplicationRecord
|
|
belongs_to :zone
|
|
has_many :dining_charges
|
|
has_many :in_juties
|
|
|
|
TABLE_TYPE = "Table"
|
|
ROOM_TYPE = "Room"
|
|
|
|
default_scope { order('order_by asc') }
|
|
|
|
scope :active, -> {where(is_active: true)}
|
|
|
|
def make_available
|
|
self.status = 'available'
|
|
self.save
|
|
end
|
|
|
|
def make_occupied
|
|
self.status = 'occupied'
|
|
self.save
|
|
end
|
|
|
|
def get_booking
|
|
booking = self.get_current_booking
|
|
if booking
|
|
if booking.dining_facility_id.to_i == self.id
|
|
if booking.booking_status == 'assign'
|
|
return booking
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
def get_current_booking
|
|
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_by is null").limit(1) #and checkout_at is null
|
|
if booking.count > 0 then
|
|
return booking[0]
|
|
else
|
|
return nil
|
|
end
|
|
end
|
|
|
|
def get_moved_booking
|
|
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='moved' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1)
|
|
|
|
if booking.count > 0 then
|
|
return booking[0]
|
|
else
|
|
return nil
|
|
end
|
|
end
|
|
|
|
def get_new_booking
|
|
# query for new
|
|
# if status
|
|
# to ask when req bill booking_status?
|
|
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id is null and checkout_at is null").limit(1)
|
|
# else
|
|
# booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id not null").limit(1)
|
|
# end
|
|
|
|
if booking.count > 0 then
|
|
return booking[0].booking_id
|
|
else
|
|
return nil
|
|
end
|
|
end
|
|
|
|
def get_current_checkout_booking
|
|
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null").limit(1)
|
|
if booking.count > 0 then
|
|
return booking[0]
|
|
else
|
|
return nil
|
|
end
|
|
end
|
|
|
|
def get_checkout_booking
|
|
booking = self.get_current_checkout_booking
|
|
if booking
|
|
now = Time.now.utc.getlocal
|
|
hr = (now.strftime("%H").to_i).to_int
|
|
min = (now.strftime("%M").to_i).to_int
|
|
if !booking.checkout_at.nil?
|
|
checkout_at = booking.checkout_at.utc.getlocal
|
|
checkout_at_hr = (checkout_at.strftime("%H").to_i).to_int
|
|
checkout_at_min = (checkout_at.strftime("%M").to_i).to_int
|
|
checkout_at_min -= min
|
|
if (checkout_at_hr <= hr) && (checkout_at_min <= 15)
|
|
return booking
|
|
else
|
|
return nil
|
|
end
|
|
else
|
|
return nil
|
|
end
|
|
end
|
|
end
|
|
end
|