change dynamic checkin checkout

This commit is contained in:
phyusin
2018-11-20 18:10:48 +06:30
parent cd33da68fa
commit d641a09d41
5 changed files with 155 additions and 51 deletions

View File

@@ -48,6 +48,29 @@ class Api::CheckInProcessController < Api::ApiController
if params[:dining_id] if params[:dining_id]
dining_facility = DiningFacility.find(params[:dining_id]) dining_facility = DiningFacility.find(params[:dining_id])
if dining_facility.status == "available" if dining_facility.status == "available"
if params[:checkin_time]
if dining_facility.check_time(params[:checkin_time], "checkin")
booking = dining_facility.get_current_booking
if booking.nil?
checkin_at = Time.parse(params[:checkin_time]).utc
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking",
:checkin_by=>current_login_employee.name,:checkin_at => checkin_at,:checkout_at =>nil, :booking_status => "assign", :reserved_at => nil, :reserved_by => nil })
if booking.save!
dining_facility.status = "occupied"
dining_facility.save!
render :json => { :status => true, :booking_id => booking.booking_id, :checkin_at => booking.checkin_at.utc.getlocal.strftime("%Y-%m-%d %H:%M:%S"), :message => "Check-in success" }
else
render :json => { :status => false, :error_message => "Booking does not create successfully!" }
end
else
render :json => { :status => false, :error_message => "Booking already exist!" }
end
else
render :json => { :status => false, :error_message => "Checkin time not available!" }
end
else
booking = dining_facility.get_current_checkout_booking
if booking.nil?
lookup_checkout_time = Lookup.collection_of("checkout_time") lookup_checkout_time = Lookup.collection_of("checkout_time")
if !lookup_checkout_time.empty? if !lookup_checkout_time.empty?
@@ -95,10 +118,13 @@ class Api::CheckInProcessController < Api::ApiController
else else
render :json => { :status => true } render :json => { :status => true }
end end
else else
render :json => { :status => true } render :json => { :status => true }
end end
else
render :json => { :status => false, :error_message => "Booking already exist!" }
end
end
else else
error_message = "#{dining_facility.type} is not available!" error_message = "#{dining_facility.type} is not available!"
render :json => { :status => false, :error_message => error_message } render :json => { :status => false, :error_message => error_message }
@@ -136,6 +162,26 @@ class Api::CheckInProcessController < Api::ApiController
end end
end end
def check_out_process
if !params[:booking_id].nil? && !params[:checkout_time].nil?
booking = Booking.find(params[:booking_id])
dining_facility = DiningFacility.find(booking.dining_facility_id)
if dining_facility.check_time(params[:checkout_time], booking, "checkout")
checkout_time = Time.parse(params[:checkout_time].strip).utc.getlocal
booking.checkout_at = checkout_time
booking.reserved_at = checkout_time
booking.reserved_by = current_login_employee.name
if booking.save!
render :json => { :status => true, :checkin_at => booking.checkin_at.utc.getlocal.strftime("%Y-%m-%d %H:%M:%S"), :checkout_at => booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M:%S"), :message => "Checkout success." }
end
else
render :json => { :status => false, :error_message => "Checkout time not available!" }
end
else
render :json => { :status => false, :error_message => "booking_id and checkout_time are required!" }
end
end
private private
def check_in_process_params def check_in_process_params
params.permit(:dining_id,:booking_id,:time) params.permit(:dining_id,:booking_id,:time)

View File

@@ -180,4 +180,23 @@ class DiningFacility < ApplicationRecord
end end
end end
def check_time(time, booking = nil, type)
status = true
today = Time.now.utc
check_time = Time.parse(time.strip).utc
if type.downcase == "checkin"
if check_time < today
status = false
end
else
if !booking.nil?
checkin_at = booking.checkin_at.utc
if check_time <= checkin_at
status = false
end
end
end
return status
end
end end

View File

@@ -165,7 +165,9 @@ class Sale < ApplicationRecord
booking.sale_id = self.id booking.sale_id = self.id
if !booking.checkout_at.nil? if !booking.checkout_at.nil?
if Time.parse(booking.checkout_at).utc < Time.now.utc
booking.checkout_at = Time.now.utc.getlocal booking.checkout_at = Time.now.utc.getlocal
end
else else
booking.checkout_at = Time.now.utc.getlocal booking.checkout_at = Time.now.utc.getlocal
end end

View File

@@ -6,21 +6,39 @@ if @zones
#List all tables #List all tables
json.tables zone.tables do |table| json.tables zone.tables do |table|
if table.is_active if table.is_active
current_booking = table.get_current_booking
json.id table.id json.id table.id
json.name table.name json.name table.name
json.status table.status json.status table.status
json.zone_id table.zone_id #Add this zone_id to keep data structure consistance json.zone_id table.zone_id #Add this zone_id to keep data structure consistance
json.current_booking table.get_current_booking.booking_id rescue "" if !current_booking.nil?
json.current_booking current_booking.booking_id
json.checkin_at Time.parse(current_booking.checkin_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S")
json.checkout_at current_booking.checkout_at ? Time.parse(current_booking.checkout_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S") : ""
else
json.current_booking ""
json.checkin_at ""
json.checkout_at ""
end
end end
end end
json.rooms zone.rooms do |room| json.rooms zone.rooms do |room|
if room.is_active if room.is_active
current_booking = room.get_current_booking
json.id room.id json.id room.id
json.name room.name json.name room.name
json.status room.status json.status room.status
json.zone_id room.zone_id #Add this zone_id to keep data structure consistance json.zone_id room.zone_id #Add this zone_id to keep data structure consistance
json.current_booking room.get_current_booking.booking_id rescue "" if !current_booking.nil?
json.current_booking current_booking.booking_id
json.checkin_at Time.parse(current_booking.checkin_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S")
json.checkout_at current_booking.checkout_at ? Time.parse(current_booking.checkout_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S") : ""
else
json.current_booking ""
json.checkin_at ""
json.checkout_at ""
end
end end
end end
end end
@@ -28,21 +46,39 @@ if @zones
else #list all tables and rooms with out zones else #list all tables and rooms with out zones
json.tables @all_tables do |table| json.tables @all_tables do |table|
if table.is_active if table.is_active
current_booking = table.get_current_booking
json.id table.id json.id table.id
json.name table.name json.name table.name
json.status table.status json.status table.status
json.zone_id table.zone_id #Add this zone_id to keep data structure consistance json.zone_id table.zone_id #Add this zone_id to keep data structure consistance
json.current_booking table.get_current_booking.booking_id rescue "" if !current_booking.nil?
json.current_booking current_booking.booking_id
json.checkin_at Time.parse(current_booking.checkin_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S")
json.checkout_at current_booking.checkout_at ? Time.parse(current_booking.checkout_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S") : ""
else
json.current_booking ""
json.checkin_at ""
json.checkout_at ""
end
end end
end end
json.rooms @all_rooms do |room| json.rooms @all_rooms do |room|
if room.is_active if room.is_active
current_booking = room.get_current_booking
json.id room.id json.id room.id
json.name room.name json.name room.name
json.status room.status json.status room.status
json.zone_id room.zone_id #Add this zone_id to keep data structure consistance json.zone_id room.zone_id #Add this zone_id to keep data structure consistance
json.current_booking room.get_current_booking.booking_id rescue "" if !current_booking.nil?
json.current_booking current_booking.booking_id
json.checkin_at Time.parse(current_booking.checkin_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S")
json.checkout_at current_booking.checkout_at ? Time.parse(current_booking.checkout_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S") : ""
else
json.current_booking ""
json.checkin_at ""
json.checkout_at ""
end
end end
end end
end end

View File

@@ -82,6 +82,7 @@ scope "(:locale)", locale: /en|mm/ do
post "call_waiter" => "call_waiters#index" post "call_waiter" => "call_waiters#index"
get "survey/:id" => "survey#index" get "survey/:id" => "survey#index"
post "survey/:id" => "survey#create" post "survey/:id" => "survey#create"
post "check_out" => "check_in_process#check_out_process"
end end
#order and reservation api #order and reservation api