change dynamic checkin checkout
This commit is contained in:
@@ -46,58 +46,84 @@ class Api::CheckInProcessController < Api::ApiController
|
||||
|
||||
def check_in_process
|
||||
if params[:dining_id]
|
||||
dining_facility = DiningFacility.find(params[:dining_id])
|
||||
dining_facility = DiningFacility.find(params[:dining_id])
|
||||
if dining_facility.status == "available"
|
||||
lookup_checkout_time = Lookup.collection_of("checkout_time")
|
||||
|
||||
if !lookup_checkout_time.empty?
|
||||
today = Time.now.utc.getlocal
|
||||
checkout_at = Time.now.utc.getlocal
|
||||
|
||||
lookup_checkout_time.each do |checkout_time|
|
||||
arr_time = checkout_time[0].split("-")
|
||||
start_time = Time.parse(arr_time[0].strip).utc.getlocal.strftime("%H:%M%p")
|
||||
end_time = Time.parse(arr_time[1].strip).utc.getlocal.strftime("%H:%M%p")
|
||||
if start_time <= today.strftime("%H:%M%p") && today.strftime("%H:%M%p") <= end_time
|
||||
checkout_at = checkout_at + (checkout_time[1]).to_i.minutes
|
||||
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
|
||||
end
|
||||
|
||||
if checkout_at.strftime("%Y-%m-%d %H:%M%p") > today.strftime("%Y-%m-%d %H:%M%p")
|
||||
# if dining_facility.type == "Table"
|
||||
# type = "TableBooking"
|
||||
# else
|
||||
# type = "RoomBooking"
|
||||
# end
|
||||
|
||||
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking",
|
||||
:checkin_by=>current_login_employee.name,:checkin_at => Time.now.utc,:checkout_at =>checkout_at, :booking_status => "assign", :reserved_at => checkout_at, :reserved_by => current_login_employee.name })
|
||||
if booking.save!
|
||||
dining_facility.status = "occupied"
|
||||
dining_facility.save!
|
||||
end
|
||||
terminal = DiningFacility.find_by_id(booking.dining_facility_id)
|
||||
cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id)
|
||||
|
||||
if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
|
||||
|
||||
unique_code = "CheckInOutPdf"
|
||||
printer = PrintSetting.find_by_unique_code(unique_code)
|
||||
|
||||
# print when complete click
|
||||
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
|
||||
|
||||
if !printer.nil?
|
||||
order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, dining_facility)
|
||||
end
|
||||
end
|
||||
render :json => { :status => true, :checkout_at => booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") }
|
||||
else
|
||||
render :json => { :status => true }
|
||||
render :json => { :status => false, :error_message => "Checkin time not available!" }
|
||||
end
|
||||
|
||||
else
|
||||
render :json => { :status => true }
|
||||
booking = dining_facility.get_current_checkout_booking
|
||||
if booking.nil?
|
||||
lookup_checkout_time = Lookup.collection_of("checkout_time")
|
||||
|
||||
if !lookup_checkout_time.empty?
|
||||
today = Time.now.utc.getlocal
|
||||
checkout_at = Time.now.utc.getlocal
|
||||
|
||||
lookup_checkout_time.each do |checkout_time|
|
||||
arr_time = checkout_time[0].split("-")
|
||||
start_time = Time.parse(arr_time[0].strip).utc.getlocal.strftime("%H:%M%p")
|
||||
end_time = Time.parse(arr_time[1].strip).utc.getlocal.strftime("%H:%M%p")
|
||||
if start_time <= today.strftime("%H:%M%p") && today.strftime("%H:%M%p") <= end_time
|
||||
checkout_at = checkout_at + (checkout_time[1]).to_i.minutes
|
||||
end
|
||||
end
|
||||
|
||||
if checkout_at.strftime("%Y-%m-%d %H:%M%p") > today.strftime("%Y-%m-%d %H:%M%p")
|
||||
# if dining_facility.type == "Table"
|
||||
# type = "TableBooking"
|
||||
# else
|
||||
# type = "RoomBooking"
|
||||
# end
|
||||
|
||||
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking",
|
||||
:checkin_by=>current_login_employee.name,:checkin_at => Time.now.utc,:checkout_at =>checkout_at, :booking_status => "assign", :reserved_at => checkout_at, :reserved_by => current_login_employee.name })
|
||||
if booking.save!
|
||||
dining_facility.status = "occupied"
|
||||
dining_facility.save!
|
||||
end
|
||||
terminal = DiningFacility.find_by_id(booking.dining_facility_id)
|
||||
cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id)
|
||||
|
||||
if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
|
||||
|
||||
unique_code = "CheckInOutPdf"
|
||||
printer = PrintSetting.find_by_unique_code(unique_code)
|
||||
|
||||
# print when complete click
|
||||
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
|
||||
|
||||
if !printer.nil?
|
||||
order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, dining_facility)
|
||||
end
|
||||
end
|
||||
render :json => { :status => true, :checkout_at => booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") }
|
||||
else
|
||||
render :json => { :status => true }
|
||||
end
|
||||
else
|
||||
render :json => { :status => true }
|
||||
end
|
||||
else
|
||||
render :json => { :status => false, :error_message => "Booking already exist!" }
|
||||
end
|
||||
end
|
||||
else
|
||||
error_message = "#{dining_facility.type} is not available!"
|
||||
@@ -136,6 +162,26 @@ class Api::CheckInProcessController < Api::ApiController
|
||||
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
|
||||
def check_in_process_params
|
||||
params.permit(:dining_id,:booking_id,:time)
|
||||
|
||||
Reference in New Issue
Block a user