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
Rails.logger.debug "Order Source - " + params[:order_source].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|
i["item_instance_code"] = i["item_instance_code"].downcase.to_s
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)
if checkin_checkout_time(params[:booking_id])
#for extratime
is_extra_time = false
extra_time = ''
params[:order_items].each { |i|
i["item_instance_code"] = i["item_instance_code"].downcase.to_s
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 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
}
#end extra time
@order.is_extra_time = is_extra_time
@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)
# 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
if sale_status
return return_json_status_with_code(400, "bill requested")
@order.is_extra_time = is_extra_time
@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
else
@order.new_booking = false
@order.booking_id = params[:booking_id]
sale_status = check_order_with_table(params[:table_id])
if sale_status
return return_json_status_with_code(400, "bill requested")
end
end
else
sale_status = check_order_with_table(params[:table_id])
end #booking exists
else
sale_status = check_order_with_table(params[:table_id])
if sale_status
return return_json_status_with_code(400, "bill requested")
end
if sale_status
# return false , @message = "bill requested"
return return_json_status_with_code(400, "bill requested")
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
@status, @booking = @order.generate
# # for parallel order
# remoteIP = ""
# begin
# @status, @booking = @order.generate
# remoteIP = request.remote_ip
# end while request.remote_ip != remoteIP
@status, @booking = @order.generate
# # for parallel order
# remoteIP = ""
# begin
# @status, @booking = @order.generate
# remoteIP = request.remote_ip
# end while request.remote_ip != remoteIP
else
return return_json_status_with_code(406, "Checkout time is over!")
end
end
# render json for http status code
def return_json_status_with_code(code, msg)
render status: code, json: {
message: msg,
booking_id: booking_id
message: msg
# booking_id: booking_id
}.to_json
end
@@ -174,4 +180,18 @@ class Api::OrdersController < Api::ApiController
:customer_id,:guest_info, :table_id, :room_id,
order_items: [:item_code, :qty, :option, :remark])
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