control order to logout

This commit is contained in:
Yan
2017-06-29 19:09:01 +06:30
parent fd857146e8
commit dd95b29d7d
3 changed files with 31 additions and 18 deletions

View File

@@ -68,10 +68,10 @@ class Api::OrdersController < Api::ApiController
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)
puts "WWwwWWWWWWww"
puts sale_status
puts "WWwwWWWWWWww"
puts sale_status
if sale_status
return false , @message = "bill requested"
return return_json_status_with_code(400, "bill requested")
end
else
@order.new_booking = false
@@ -79,43 +79,45 @@ class Api::OrdersController < Api::ApiController
end
else
sale_status = check_order_with_table(params[:table_id])
puts "OOOOOOOOO"
puts sale_status
puts "OOOOOOOOO"
puts sale_status
if sale_status
return false , @message = "bill requested"
return return_json_status_with_code(400, "bill requested")
end
end
end #booking exists
else
sale_status = check_order_with_table(params[:table_id])
puts "MMMMMMMM"
puts sale_status
puts "MMMMMMMM"
puts sale_status
if sale_status
return false , @message = "bill requested"
# return false , @message = "bill requested"
return return_json_status_with_code(400, "bill requested")
end
end
@status, @booking = @order.generate
end
# render json for http status code 202
def return_json_status_with_code(code, msg, booking_id)
# 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
}.to_json
end
def check_order_with_table(table_id)
table = DiningFacility.find(table_id)
if table
booking = table.get_current_booking
booking = table.get_moved_booking
puts booking
if booking
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed"
if !booking.sale_id.nil?
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new"
@order.new_booking = true
return true
else
end
else
@order.new_booking = false
@order.booking_id = booking.booking_id
return false
@@ -124,8 +126,9 @@ class Api::OrdersController < Api::ApiController
end
end
# this can always true
def check_order_with_booking(booking)
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed"
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new"
@order.new_booking = true
return true
else

View File

@@ -39,6 +39,16 @@ class DiningFacility < ApplicationRecord
end
end
def get_moved_booking
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='moved' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1)
if booking.count > 0 then
return booking[0]
else
return nil
end
end
def get_new_booking
# query for new
# if status

View File

@@ -54,7 +54,7 @@ class Order < ApplicationRecord
end
return false, @message = "booking fail"
return false
end