json.id menu.id
json.name menu.name
json.is_active menu.is_active
json.valid_time_from menu.valid_time_from.strftime("%H:%M")
json.valid_time_to menu.valid_time_to.strftime("%H:%M")

if (menu.menu_categories)
  order_by = Lookup.find_by_lookup_type("order_by")
  # if !order_by.nil? && order_by.value == "name"
  #   categories = MenuCategory.unscoped.where("menu_id ='#{menu.id}'").order("name asc")
  # else
  #   categories = menu.menu_categories
  # end
   categories = menu.menu_categories
  json.categories  categories do |category|

    menu_category = MenuCategory.find_by_menu_category_id(category.id)
    if !menu_category.nil?
      json.sub_category "true"
    else
      json.sub_category "false"
    end
    valid_time = category.valid_time
    json.valid_time valid_time

    json.id category.id
    json.code category.code
    json.order_by category.order_by
    json.name category.name
    json.alt_name category.alt_name
    json.order_by category.order_by
    json.parent_id category.menu_category_id
    json.is_available category.is_available

    if !order_by.nil? && order_by.value == "name"
      menu_items = MenuItem.unscoped.where("menu_category_id = ?",category.id).order("name asc")
    else
      menu_items = category.menu_items
    end

    if category.menu_items
      json.items menu_items do |item|
        if item.is_available
          json.partial! 'origami/addorders/menu_item', item: item
        end
      end
    end
  end
end
