73 lines
2.6 KiB
Ruby
73 lines
2.6 KiB
Ruby
class Origami::CheckInProcessController < BaseOrigamiController
|
|
|
|
def check_in_process
|
|
lookup_checkout_time = Lookup.collection_of("checkout_time")
|
|
today = Time.now.utc.getlocal
|
|
checkout_at = Time.now.utc.getlocal
|
|
if !lookup_checkout_time.empty?
|
|
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 <= checkout_at.strftime("%H:%M%p") && checkout_at.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")
|
|
@dining_facility = DiningFacility.find(params[:dining_id])
|
|
@dining_facility.status = "occupied"
|
|
@dining_facility.save!
|
|
|
|
if @dining_facility.type == "Table"
|
|
type = "TableBooking"
|
|
else
|
|
type = "RoomBooking"
|
|
end
|
|
|
|
@booking = Booking.create({:dining_facility_id => params[:dining_id],:type => type,
|
|
: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 })
|
|
@booking.save!
|
|
end
|
|
|
|
if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
|
|
check_in_out_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf
|
|
printer = PrintSetting.all
|
|
unique_code="CheckInOutPdf"
|
|
if !check_in_out_pdf.empty?
|
|
if !printer.empty?
|
|
printer.each do |printer_setting|
|
|
if printer_setting.unique_code == 'CheckInOutPdf'
|
|
unique_code="CheckInOutPdf"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
booking = Booking.find_by_booking_id(@booking.booking_id)
|
|
table = DiningFacility.find(params[:dining_id])
|
|
|
|
# print when complete click
|
|
print_settings = PrintSetting.find_by_unique_code(unique_code)
|
|
order_queue_printer = Printer::OrderQueuePrinter.new(print_settings)
|
|
order_queue_printer.print_check_in_out(print_settings, booking, table)
|
|
from = getCloudDomain #get sub domain in cloud mode
|
|
end
|
|
end
|
|
respond = {:status => 'ok'}
|
|
respond_to do |format|
|
|
format.json { render json: respond }
|
|
end
|
|
end
|
|
|
|
#get cloud domain
|
|
def getCloudDomain
|
|
from = ""
|
|
if ENV["SERVER_MODE"] == 'cloud'
|
|
from = request.subdomain + "." + request.domain
|
|
end
|
|
|
|
return from
|
|
end
|
|
|
|
end
|