class Api::Foodcourt::OrdersController < Api::ApiController

  def create
    Order.transaction do
      if params[:order_items].present?
        if shift = ShiftSale.current_open_shift(current_login_employee)

          @order = Order.new
          @order.source = params[:source] || "food_court"
          @order.order_type = params[:order_type] || "Takeaway"
          @order.customer_id = params[:customer_id] || takeaway.customer_id # for no customer id from mobile
          @order.items = params[:order_items]
          @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

          @status, @booking = @order.generate

          unless @status && @booking
            @status = false
            @error_message = "Create order failed, some error occurred!"
          end
        else
          @status = false
          @error_message = "No Current Open Shift!"
        end
      else
        @status = false
        @error_message = "Parameters missing!"
      end
    end
  end

end
