check checkout time and server time when order from api

This commit is contained in:
phyusin
2018-01-24 17:32:23 +06:30
parent c6023729d3
commit 89b89a3197

View File

@@ -49,83 +49,89 @@ class Api::OrdersController < Api::ApiController
def create def create
Rails.logger.debug "Order Source - " + params[:order_source].to_s Rails.logger.debug "Order Source - " + params[:order_source].to_s
Rails.logger.debug "Table ID - " + params[:table_id].to_s Rails.logger.debug "Table ID - " + params[:table_id].to_s
#for extratime
is_extra_time = false
extra_time = ''
params[:order_items].each { |i| if checkin_checkout_time(params[:booking_id])
i["item_instance_code"] = i["item_instance_code"].downcase.to_s #for extratime
if i["item_instance_code"].include? "ext" is_extra_time = false
is_extra_time = true extra_time = ''
arr_exts = i["item_instance_code"].split("_")
if arr_exts[1].match(/^(\d)+$/) params[:order_items].each { |i|
time = arr_exts[1].to_i*60*i["quantity"].to_i i["item_instance_code"] = i["item_instance_code"].downcase.to_s
extra_time = Time.at(time) if i["item_instance_code"].include? "ext"
is_extra_time = true
arr_exts = i["item_instance_code"].split("_")
if arr_exts[1].match(/^(\d)+$/)
time = arr_exts[1].to_i*60*i["quantity"].to_i
extra_time = Time.at(time)
end
end end
end }
} #end extra time
#end extra time
# begin
@order = Order.new
@order.source = params[:order_source]
@order.order_type = params[:order_type]
@order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
@order.items = params[:order_items]
@order.guest = params[:guest_info]
@order.table_id = params[:table_id] # this is dining facilities's id
@order.new_booking = true
@order.waiters = current_login_employee.name
@order.employee_name = current_login_employee.name
@order.is_extra_time = is_extra_time # begin
@order.extra_time = extra_time @order = Order.new
#Create Table Booking or Room Booking @order.source = params[:order_source]
if !params["booking_id"].nil? @order.order_type = params[:order_type]
# check booking id is already completed. @order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
booking = Booking.find(params[:booking_id]) @order.items = params[:order_items]
if booking @order.guest = params[:guest_info]
if booking.dining_facility_id.to_i == params[:table_id].to_i && booking.booking_status != 'moved' @order.table_id = params[:table_id] # this is dining facilities's id
if !booking.sale_id.nil? @order.new_booking = true
sale_status = check_order_with_booking(booking) @order.waiters = current_login_employee.name
@order.employee_name = current_login_employee.name
if sale_status @order.is_extra_time = is_extra_time
return return_json_status_with_code(400, "bill requested") @order.extra_time = extra_time
#Create Table Booking or Room Booking
if !params["booking_id"].nil?
# check booking id is already completed.
booking = Booking.find(params[:booking_id])
if booking
if booking.dining_facility_id.to_i == params[:table_id].to_i && booking.booking_status != 'moved'
if !booking.sale_id.nil?
sale_status = check_order_with_booking(booking)
if sale_status
return return_json_status_with_code(400, "bill requested")
end
else
@order.new_booking = false
@order.booking_id = params[:booking_id]
end end
else else
@order.new_booking = false sale_status = check_order_with_table(params[:table_id])
@order.booking_id = params[:booking_id]
if sale_status
return return_json_status_with_code(400, "bill requested")
end
end end
else end #booking exists
sale_status = check_order_with_table(params[:table_id]) else
sale_status = check_order_with_table(params[:table_id])
if sale_status if sale_status
return return_json_status_with_code(400, "bill requested") # return false , @message = "bill requested"
end return return_json_status_with_code(400, "bill requested")
end end
end #booking exists
else
sale_status = check_order_with_table(params[:table_id])
if sale_status
# return false , @message = "bill requested"
return return_json_status_with_code(400, "bill requested")
end end
end
@status, @booking = @order.generate @status, @booking = @order.generate
# # for parallel order # # for parallel order
# remoteIP = "" # remoteIP = ""
# begin # begin
# @status, @booking = @order.generate # @status, @booking = @order.generate
# remoteIP = request.remote_ip # remoteIP = request.remote_ip
# end while request.remote_ip != remoteIP # end while request.remote_ip != remoteIP
else
return return_json_status_with_code(406, "Checkout time is over!")
end
end end
# render json for http status code # render json for http status code
def return_json_status_with_code(code, msg) def return_json_status_with_code(code, msg)
render status: code, json: { render status: code, json: {
message: msg, message: msg
booking_id: booking_id # booking_id: booking_id
}.to_json }.to_json
end end
@@ -174,4 +180,18 @@ class Api::OrdersController < Api::ApiController
:customer_id,:guest_info, :table_id, :room_id, :customer_id,:guest_info, :table_id, :room_id,
order_items: [:item_code, :qty, :option, :remark]) order_items: [:item_code, :qty, :option, :remark])
end end
#checked checkin and checkout time
def checkin_checkout_time(booking_id)
status = true
today = Time.now.utc
booking = Booking.find(params[:booking_id])
if !booking.nil?
checkout_time = booking.checkout_at.utc
if checkout_time <= today
status = false
end
end
return status
end
end end