fix foodcourt sales transaction
This commit is contained in:
@@ -87,8 +87,6 @@ class Foodcourt::AddordersController < BaseFoodcourtController
|
||||
end
|
||||
|
||||
def create
|
||||
new_booking =true
|
||||
booking_id =nil
|
||||
if params[:booking_id].present?
|
||||
booking = Booking.find(params[:booking_id])
|
||||
end
|
||||
@@ -105,82 +103,64 @@ class Foodcourt::AddordersController < BaseFoodcourtController
|
||||
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
|
||||
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)
|
||||
end
|
||||
items_arr.push(items)
|
||||
}
|
||||
|
||||
if params[:order_source] == "quick_service" && params[:table_id].to_i == 0
|
||||
customer_id = takeaway.customer_id # for no customer id from mobile
|
||||
else
|
||||
customer_id = params[:customer_id].present? ? params[:customer_id] : Customer.walkin.customer_id # for no customer id from mobile
|
||||
end
|
||||
if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved'
|
||||
new_booking = true
|
||||
else
|
||||
new_booking = false
|
||||
booking_id = booking.booking_id
|
||||
end
|
||||
@order =Order.create(source: params[:order_source],
|
||||
order_type: params[:order_type],
|
||||
customer_id: customer_id,
|
||||
items: items_arr,
|
||||
guest: params[:guest_info],
|
||||
table_id: params[:table_id],
|
||||
new_booking: new_booking,
|
||||
waiters: current_login_employee.name,
|
||||
employee_name: current_login_employee.name,
|
||||
is_extra_time: is_extra_time,
|
||||
extra_time: extra_time,
|
||||
booking_id: booking_id
|
||||
)
|
||||
@status, @booking = @order.generate
|
||||
customer_id = params[:customer_id].present? ? params[:customer_id] : Customer.walkin.customer_id
|
||||
|
||||
if @status && @booking
|
||||
#send order broadcast to order_channel
|
||||
if @order.table_id.to_i > 0
|
||||
table = DiningFacility.find(@booking.dining_facility_id)
|
||||
type = 'order'
|
||||
from = getCloudDomain #get sub domain in cloud mode
|
||||
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
|
||||
Order.transaction do
|
||||
@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
|
||||
|
||||
if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved'
|
||||
@order.new_booking = true
|
||||
else
|
||||
@order.new_booking = false
|
||||
@order.booking_id = booking.booking_id
|
||||
end
|
||||
|
||||
if params[:order_source] != "quick_service" && params[:order_source] != "food_court"
|
||||
process_order_queue(@order.order_id,@order.table_id,@order.source)
|
||||
end
|
||||
end
|
||||
@status, @booking = @order.generate
|
||||
|
||||
if current_user.role != "waiter" && params[:create_type] == "create_pay"
|
||||
if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court')
|
||||
|
||||
@status, @sale = Sale.request_bill(@order,current_user,current_login_employee)
|
||||
|
||||
# for second display
|
||||
if @order.source == 'quick_service'
|
||||
if @status && @booking
|
||||
#send order broadcast to order_channel
|
||||
if @order.table_id.to_i > 0
|
||||
table = DiningFacility.find(@booking.dining_facility_id)
|
||||
type = 'order'
|
||||
from = getCloudDomain #get sub domain in cloud mode
|
||||
ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale",from:from
|
||||
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
|
||||
end
|
||||
#end
|
||||
result = {:status=> @status, :data => @sale ,:current_user_role =>current_user.role}
|
||||
render :json => result.to_json
|
||||
end
|
||||
else
|
||||
result = {:status=> @status, :data => 0 }
|
||||
render :json => result.to_json
|
||||
end
|
||||
|
||||
if current_user.role != "waiter" && params[:create_type] == "create_pay"
|
||||
if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court')
|
||||
|
||||
@status, @sale = Sale.request_bill(@order,current_user,current_login_employee)
|
||||
|
||||
# for second display
|
||||
if @order.source == 'quick_service'
|
||||
from = getCloudDomain #get sub domain in cloud mode
|
||||
ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale",from:from
|
||||
end
|
||||
#end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# render json for http status code
|
||||
|
||||
Reference in New Issue
Block a user