251 lines
7.5 KiB
Ruby
Executable File
251 lines
7.5 KiB
Ruby
Executable File
class Origami::AddordersController < BaseOrigamiController
|
|
# before_action :set_dining, only: [:detail]
|
|
|
|
def index
|
|
@webview = false
|
|
if check_mobile
|
|
@webview = true
|
|
end
|
|
|
|
@tables = Table.all.active.order('zone_id asc').group("zone_id")
|
|
@rooms = Room.all.active.order('zone_id asc').group("zone_id")
|
|
@all_table = Table.all.active.order('status desc')
|
|
@all_room = Room.all.active.order('status desc')
|
|
end
|
|
|
|
def detail
|
|
@webview = false
|
|
if check_mobile
|
|
@webview = true
|
|
end
|
|
|
|
# if params[:menu] == "true"
|
|
@menus = []
|
|
@menu = []
|
|
# else
|
|
# @menus = Menu.all
|
|
# @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc')
|
|
# end
|
|
|
|
@table_id = params[:id]
|
|
@table = DiningFacility.find(@table_id)
|
|
@booking = @table.get_booking
|
|
if @booking
|
|
@booking_id = @booking.booking_id
|
|
@order_items = Array.new
|
|
@booking.booking_orders.each do |booking_order|
|
|
order = Order.find(booking_order.order_id)
|
|
if (order.status == "new")
|
|
@obj_order = order
|
|
@customer = order.customer
|
|
@date = order.created_at
|
|
order.order_items.each do |item|
|
|
@order_items.push(item)
|
|
end
|
|
end
|
|
end
|
|
else
|
|
@booking = nil
|
|
end
|
|
end
|
|
|
|
def get_menu_category ()
|
|
if (params[:id])
|
|
|
|
#Pull this menu
|
|
@menu = MenuCategory.find_by_id(params[:id])
|
|
|
|
# puts @menu.menu_items[1].item_attributes.to_json
|
|
return @menu
|
|
else
|
|
MenuCategory.current_menu
|
|
end
|
|
end
|
|
|
|
def get_item_instance
|
|
@instance = MenuItemInstance.find(params[:id])
|
|
end
|
|
|
|
def get_menu()
|
|
puts "sssssssssssssss"
|
|
puts params[:id]
|
|
if (params[:id])
|
|
#Pull this menu
|
|
@menu = Menu.find_by_id(params[:id])
|
|
@menu_category = MenuCategory.where("menu_id='#{@menu.id}'").order("order_by asc")
|
|
# puts @menu.menu_items[1].item_attributes.to_json
|
|
return @menu
|
|
else
|
|
Menu.current_menu
|
|
end
|
|
end
|
|
|
|
def get_menu_sub_category ()
|
|
|
|
id = params[:id]
|
|
|
|
if (id)
|
|
#Pull this menu
|
|
@sub_menu = MenuCategory.where("menu_category_id = #{id}").active
|
|
|
|
# puts @menu.menu_items[1].item_attributes.to_json
|
|
return @sub_menu
|
|
end
|
|
end
|
|
|
|
def get_all_product()
|
|
@product = Product.all
|
|
end
|
|
|
|
def create
|
|
Rails.logger.debug "Order Source - " + params[:order_source].to_s
|
|
Rails.logger.debug "Table ID - " + params[:table_id].to_s
|
|
is_extra_time = false
|
|
extra_time = ''
|
|
|
|
items_arr = []
|
|
JSON.parse(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
|
|
if i["parent_order_item_id"];
|
|
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])}
|
|
else
|
|
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])}
|
|
end
|
|
items_arr.push(items)
|
|
}
|
|
# begin
|
|
# if params[:order_source] == "quick_service"
|
|
# customer_id = "CUS-000000000002" # for no customer id from mobile
|
|
# else
|
|
customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
|
|
# end
|
|
@order = Order.new
|
|
@order.source = params[:order_source]
|
|
@order.order_type = params[:order_type]
|
|
@order.customer_id = customer_id
|
|
@order.items = items_arr
|
|
@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
|
|
@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 params[:table_id].to_i > 0
|
|
table_status = booking.dining_facility_id.to_i == params[:table_id].to_i
|
|
else
|
|
table_status = true
|
|
end
|
|
if booking
|
|
if table_status && 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
|
|
if params[:table_id].to_i > 0
|
|
sale_status = check_order_with_table(params[:table_id])
|
|
if sale_status
|
|
return return_json_status_with_code(400, "bill requested")
|
|
end
|
|
end
|
|
end
|
|
end #booking exists
|
|
else
|
|
if params[:table_id].to_i > 0
|
|
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
|
|
|
|
# Order.send_customer_view(@booking)
|
|
|
|
if current_user.role != "waiter" && params[:create_type] == "create_pay"
|
|
if @status && @booking && @order.source == 'quick_service'
|
|
|
|
@status, @sale = Sale.request_bill(@order,current_user,current_login_employee)
|
|
# for second display
|
|
#if ENV["SERVER_MODE"] != 'cloud'
|
|
ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale"
|
|
#end
|
|
result = {:status=> @status, :data => @sale }
|
|
render :json => result.to_json
|
|
end
|
|
else
|
|
result = {:status=> @status, :data => 0 }
|
|
render :json => result.to_json
|
|
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
|
|
}.to_json
|
|
end
|
|
|
|
def check_order_with_table(table_id)
|
|
table = DiningFacility.find(table_id)
|
|
if table
|
|
booking = table.get_current_booking
|
|
# puts booking
|
|
if booking
|
|
if !booking.sale_id.nil?
|
|
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new"
|
|
@order.new_booking = true
|
|
return false
|
|
end
|
|
else
|
|
@order.new_booking = false
|
|
@order.booking_id = booking.booking_id
|
|
return false
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
# this can always true
|
|
def check_order_with_booking(booking)
|
|
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new"
|
|
@order.new_booking = true
|
|
return false
|
|
else
|
|
@order.new_booking = false
|
|
@order.booking_id = params[:booking_id]
|
|
return false
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
# def set_dining
|
|
# @dining = DiningFacility.find(params[:id])
|
|
# end
|
|
|
|
end
|