Files
sx-fc/app/controllers/foodcourt/orders_controller.rb
Myat Zin Wai Maw 6c1b6fe79f app
2019-12-04 14:18:37 +06:30

83 lines
3.7 KiB
Ruby
Executable File

class Foodcourt::OrdersController < BaseFoodcourtController
def show
@webview = false
if check_mobile
@webview = true
end
@tables = Table.unscoped.all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc')
@complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d'))
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@order = Order.find(params[:order_id])
booking = Booking.select('bookings.booking_id, bookings.dining_facility_id')
.joins(" JOIN booking_orders as bo on bo.booking_id = bookings.booking_id")
.where("bo.order_id='#{params[:order_id]}'").first()
@booking = Array.new
if !booking.nil?
if booking.dining_facility_id.to_i > 0
dining_facilities = DiningFacility.find_by_id(booking.dining_facility_id)
@booking.push({'booking_id' => booking.booking_id, 'dining_facility_id' => booking.dining_facility_id, 'type' => dining_facilities.type})
else
@booking.push({'booking_id' => booking.booking_id, 'dining_facility_id' => booking.dining_facility_id, 'type' => nil})
end
end
@customers = Customer.pluck("customer_id, name")
#for split bill
lookup_spit_bill = Lookup.collection_of('split_bill')
@split_bill = 0
if !lookup_spit_bill[0].nil?
@split_bill = lookup_spit_bill[0][1]
end
sale_order = SaleOrder.find_by_order_id(@order.order_id)
if sale_order
unless sale_order.sale_id.nil?
sale = Sale.find(sale_order.sale_id)
@sale_status = sale.sale_status
end
end
@order.order_items.each_with_index do |item, order_item_index|
if !item.set_menu_items.nil?
instance_item_sets = JSON.parse(item.set_menu_items)
arr_instance_item_sets = Array.new
instance_item_sets.each do |instance_item|
item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name
arr_instance_item_sets.push(item_instance_name)
item.price = item.price.to_f + instance_item["price"].to_f
end
@order.order_items[order_item_index].set_menu_items = arr_instance_item_sets
end
end
end
def app_orders
if !params[:booking_id].nil? && !params[:booking_id].blank?
@booking = Booking.select("orders.*,bookings.*,customers.*")
.joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id")
.joins("JOIN orders ON orders.order_id=booking_orders.order_id")
.joins("JOIN customers ON orders.customer_id=customers.customer_id")
.where("orders.source='app' and bookings.booking_id='#{params[:booking_id]}'").first
@customer_id =@booking.customer_id
@booking_id =@booking.booking_id
end
@bookings = Booking.select("bookings.*,customers.*")
.joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id")
.joins("JOIN orders ON orders.order_id=booking_orders.order_id")
.joins("JOIN order_items ON orders.order_id=order_items.order_id")
.joins("JOIN customers ON orders.customer_id=customers.customer_id")
.where("orders.source='app'").order("bookings.created_at desc").uniq
end
def completed
customer =Customer.find_by_customer_id(params[:customer_id])
phone_number =customer.contact_no
if Order.send_message(phone_number,params[:booking_id])
booking =Booking.find(params[:booking_id])
booking.booking_status ='completed'
booking.save!
end
end
end