update check_in_process

This commit is contained in:
Thein Lin Kyaw
2020-02-20 11:07:06 +06:30
parent b980fd7fc4
commit 306b430299
2 changed files with 56 additions and 89 deletions

View File

@@ -19,12 +19,13 @@ class Api::CheckInProcessController < Api::ApiController
table = DiningFacility.find(params[:dining_id])
#Send to background job for processing
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
from = ""
end
ActionCable.server.broadcast "check_in_booking_channel",table: table,from:from
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
from = ""
end
ActionCable.server.broadcast "check_in_booking_channel",table: table,from:from
check_out_time = nil
extra_minutes = nil
alert_time_min = 0
@@ -65,93 +66,59 @@ class Api::CheckInProcessController < Api::ApiController
if params[:dining_id]
dining_facility = DiningFacility.find(params[:dining_id])
if dining_facility.is_active && dining_facility.status == "available"
if params[:checkin_time]
checkin_at = nil
if !params[:checkin_time].empty?
checkin_at = Time.parse(params[:checkin_time]).utc
if dining_facility.current_checkin_booking.nil?
if params[:checkin_time].present?
checkin_at = Time.parse(params[:checkin_time])
else
checkin_at = Time.now.utc
checkin_at = Time.now
end
if !checkin_at.nil?
if dining_facility.check_time(checkin_at, "checkin")
booking = dining_facility.get_current_booking
if booking.nil?
checkout_at = nil
lookup_checkout_time = Lookup.collection_of("checkout_time")
today = Time.now
if !lookup_checkout_time.empty?
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!" }
lookup_checkout_time.each do |checkout_time|
start_time, end_time = checkout_time[0].split("-").map{ |t| Time.parse(t.strip).strftime("%H:%M%p") }
if start_time <= today.strftime("%H:%M%p") && today.strftime("%H:%M%p") <= end_time
checkout_at = checkin_at + (checkout_time[1]).to_i.minutes
end
else
render :json => { :status => false, :error_message => "Checkin time not available!" }
end
else
render :json => { :status => false, :error_message => "Operation failed!" }
end
booking = nil
ActiveRecord::Base.transaction do
booking = Booking.create({
:dining_facility_id => params[:dining_id],
:type => "TableBooking",
:checkin_by => current_login_employee.name,
:checkin_at => checkin_at,
:checkout_at => checkout_at,
:booking_status => "assign",
:reserved_at => checkout_at,
:reserved_by => current_login_employee.name })
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, :booking_id => booking.booking_id, :checkin_at => booking.checkin_at.strftime("%Y-%m-%d %H:%M"), :checkout_at => booking.checkout_at.strftime("%Y-%m-%d %H:%M") }
else
booking = dining_facility.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, :booking_id => booking.booking_id, :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
render :json => { :status => false, :error_message => "Booking already exist!" }
end
else
error_message = "#{dining_facility.type} is not available!"
@@ -161,6 +128,8 @@ class Api::CheckInProcessController < Api::ApiController
error_message = "dining_id is required!"
render :json => { :status => false, :error_message => error_message }
end
rescue ActiveRecord::RecordInvalid => exception
render :json => { :status => false, :error_message => exception.message }
end
def request_time

View File

@@ -37,18 +37,16 @@ class Api::OrdersController < Api::ApiController
@booking = table.get_booking
end
@tax_profile = nil
@tax_profile = TaxProfile.where("lower(group_type)='cashier'")
# arr_tax = []
# if !arr_tax.empty?
# @tax_profile = TaxProfile.where(:id => arr_tax)
# else
@tax_profile = TaxProfile.where("lower(group_type)='cashier'")
# @tax_profile = TaxProfile.where("lower(group_type)='cashier'")
# end
@shop = Shop.current_shop
puts "Hello world"
puts @shop.to_json
return @shop.to_json
end