equal split and order split in order tab'

This commit is contained in:
phyusin
2018-02-16 12:13:35 +06:30
parent e77d523a7f
commit 0ddaee7444
16 changed files with 481 additions and 85 deletions

View File

@@ -18,10 +18,10 @@ class Origami::SplitBillController < BaseOrigamiController
if @booking
@booking.booking_orders.each do |booking_order|
arr_order_items = Array.new
@order = Order.find(booking_order.order_id)
if (@order.status == "new")
@orders.push(@order)
@order_items.push({'all_order' => @order.order_items})
@order.order_items.each do |item|
if !item.set_menu_items.nil?
@@ -59,19 +59,19 @@ class Origami::SplitBillController < BaseOrigamiController
'updated_at' => item.updated_at}
i += 1
@order_items.push({@order.order_id => arr_item})
arr_order_items.push(arr_item)
end
else
arr_order_items.push(item)
@order_items.push({@order.order_id => item})
end
end
@order_items.push({'all_order' => arr_order_items})
end
end
else
@booking = nil
end
puts "@order_items"
puts @order_items.to_json
end
def create
@@ -160,19 +160,19 @@ class Origami::SplitBillController < BaseOrigamiController
if !updated_order_id.empty?
order_ids.each do |odr_id|
unless updated_order_id.include?(odr_id)
BookingOrder.find_by_order_id(odr_id).delete
# BookingOrder.find_by_order_id(odr_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id})
end
end
order_items.each do |order_item|
if updated_order_id.include?(order_item["order_id"])
update_order_item(order_item)
update_order_item(order_id, order_item)
end
end
else
order_ids.each do |odr_id|
BookingOrder.find_by_order_id(odr_id).delete
# BookingOrder.find_by_order_id(odr_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id})
end
end
@@ -181,12 +181,15 @@ class Origami::SplitBillController < BaseOrigamiController
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_id})
order_items.each do |order_item|
update_order_item(order_item)
update_order_item(order_id, order_item)
end
end
else
if order_ids.count == 1 && order_id_count > 0 && order_item_count == 1
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
else
customer = Customer.find(params[:customer_id])
order_type = "dine_in"
@@ -214,7 +217,7 @@ class Origami::SplitBillController < BaseOrigamiController
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item|
update_order_item(order_item)
update_order_item(order.id, order_item)
end
end
end
@@ -239,7 +242,7 @@ class Origami::SplitBillController < BaseOrigamiController
end
end
def update_order_item(order_item)
def update_order_item(order_id, order_item)
orderItem = OrderItem.find(order_item["id"])
if orderItem.qty.to_f != order_item['qty'].to_f
OrderItem.processs_item(orderItem.item_code,
@@ -251,13 +254,13 @@ class Origami::SplitBillController < BaseOrigamiController
orderItem.price,
orderItem.options,
orderItem.set_menu_items,
orderItem.order_id,
order_id,
orderItem.item_order_by,
orderItem.taxable)
orderItem.qty = orderItem.qty.to_f - order_item['qty'].to_f
else
orderItem.order_id = order.order_id
orderItem.order_id = order_id
end
orderItem.save!
end