fixed set menu item update and individual payment
This commit is contained in:
70
app/controllers/origami/split_bill_controller.rb
Normal file → Executable file
70
app/controllers/origami/split_bill_controller.rb
Normal file → Executable file
@@ -77,6 +77,10 @@ class Origami::SplitBillController < BaseOrigamiController
|
||||
|
||||
def create
|
||||
order_ids = params[:order_ids]
|
||||
arr_order_ids = nil
|
||||
if !params[:arr_order_ids].nil?
|
||||
arr_order_ids = JSON.parse(params[:arr_order_ids])
|
||||
end
|
||||
orders = nil
|
||||
if !params[:orders].empty?
|
||||
orders = JSON.parse(params[:orders])
|
||||
@@ -136,14 +140,15 @@ class Origami::SplitBillController < BaseOrigamiController
|
||||
order_id_count = 0
|
||||
order_id = nil
|
||||
|
||||
order_items.each do |order_item|
|
||||
order_item_count = 0
|
||||
order = Order.find(order_item["order_id"])
|
||||
if order.order_items.count == 1
|
||||
order_id = order.id
|
||||
order_id_count += 1
|
||||
else
|
||||
order_item_count += 1
|
||||
arr_order_ids.each do |order|
|
||||
order.each do |odr|
|
||||
data = Order.find(odr[0])
|
||||
if data.order_items.count == odr[1]
|
||||
order_id = odr[0]
|
||||
order_id_count += 1
|
||||
else
|
||||
order_item_count += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -158,10 +163,12 @@ class Origami::SplitBillController < BaseOrigamiController
|
||||
puts "order_id_count > 1"
|
||||
|
||||
updated_order_id = Array.new
|
||||
order_ids.each do |odr_id|
|
||||
odr = Order.find(odr_id)
|
||||
if odr.order_items.count > 1
|
||||
updated_order_id.push(odr_id)
|
||||
arr_order_ids.each do |order|
|
||||
order.each do |odr|
|
||||
data = Order.find(odr[0])
|
||||
if data.order_items.count != odr[1]
|
||||
updated_order_id.push(odr[0])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -266,12 +273,32 @@ class Origami::SplitBillController < BaseOrigamiController
|
||||
end
|
||||
end
|
||||
else
|
||||
# puts order_ids
|
||||
if order_ids.count == 1 && order_id_count == 0 && order_item_count == 1
|
||||
BookingOrder.find_by_order_id(order_ids[0]).delete
|
||||
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_ids[0]})
|
||||
order_items.each do |order_item|
|
||||
update_order_item(order_ids[0], order_item)
|
||||
if order_ids.count == 1 && order_item_count == 1
|
||||
if order_id_count == 0
|
||||
customer = Customer.find(params[:customer_id])
|
||||
order_type = "dine_in"
|
||||
if !customer.nil?
|
||||
if customer.customer_type == "Takeaway"
|
||||
order_type = "takeaway"
|
||||
elsif customer.customer_type == "Delivery"
|
||||
order_type = "delivery"
|
||||
end
|
||||
end
|
||||
|
||||
# begin
|
||||
order = create_order(params,order_type,order_items.count,current_user)
|
||||
|
||||
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
|
||||
|
||||
order_items.each do |order_item|
|
||||
update_order_item(order.order_id, order_item)
|
||||
end
|
||||
else
|
||||
BookingOrder.find_by_order_id(order_ids[0]).delete
|
||||
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_ids[0]})
|
||||
order_items.each do |order_item|
|
||||
update_order_item(order_ids[0], order_item)
|
||||
end
|
||||
end
|
||||
else
|
||||
customer = Customer.find(params[:customer_id])
|
||||
@@ -366,4 +393,11 @@ class Origami::SplitBillController < BaseOrigamiController
|
||||
|
||||
render :json => { status: true }
|
||||
end
|
||||
|
||||
#Shop Name in Navbor
|
||||
helper_method :shop_detail
|
||||
def shop_detail
|
||||
@shop = Shop.first
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user