menu import and exp update

This commit is contained in:
Yan
2018-04-02 15:59:36 +06:30
parent 3ee12df0bc
commit c176b41e79
9 changed files with 291 additions and 120 deletions

View File

@@ -62,7 +62,8 @@ class Settings::MenusController < ApplicationController
def destroy
# @settings_menu.destroy
abc = Menu.destroyMenu(@settings_menu)
@settings_menu_item_set.destroy
# @settings_menu_item_set.destroy
flash[:notice] = 'Menu was successfully destroyed.'
render :json => {:status=> "Success", :url => settings_menus_path }.to_json
# respond_to do |format|
@@ -71,12 +72,108 @@ class Settings::MenusController < ApplicationController
# end
end
def export
@settings_menus = Menu.all.page(params[:page]).per(10)
menu = Menu.find(params[:id])
p = Axlsx::Package.new
wb = p.workbook
wb.styles do |s|
time_format = wb.styles.add_style :format_code => 'hh:mm:ss'
title = s.add_style :fg_color => "004586"
wrap_text = s.add_style :sz => 11,
:alignment => { :horizontal => :left,:vertical => :center ,
:wrap_text => true}
header_text = s.add_style :fg_color=> "a7a7a7",
:b => true,
:sz => 12,
:border => { :style => :thin, :color => "00" },
:alignment => { :horizontal => :left,
:vertical => :center ,
:header_text => true}
# Menu Sheet
wb.add_worksheet(name: menu.name) do |sheet|
sheet.add_row ["Name",menu.name], :style=>title
sheet.add_row
sheet.add_row ["Category Code", "Category Name", "Item Code", "Item Name", "Item AltName", "Taxable", "Instance Code", "Instance Name", "Price"], :style=>header_text
menu.menu_categories.each do |mc|
mc.menu_items.each do |mi|
mi.menu_item_instances.each do |mii|
sheet.add_row [ mc.code, mc.name, mi.item_code, mi.name, mi.alt_name, mi.taxable, mii.item_instance_code, mii.item_instance_name, mii.price], :style=>wrap_text
end
end
end
# # Category
# menu.menu_categories.each do |mc|
# sheet.add_row ["Category"], :style=>wrap_text
# sheet.add_row %w(id menu_id code name alt_name order_by created_by menu_category_id is_available), :style=>header_text
# sheet.add_row [mc.id, mc.menu_id, mc.code, mc.name, mc.alt_name, mc.order_by, mc.created_by, mc.menu_category_id, mc.is_available], :style=>wrap_text
# sheet.add_row
# # Menu Item
# mc.menu_items.each do |mi|
# sheet.add_row ["Menu Item"], :style=>wrap_text
# sheet.add_row %w(id item_code name alt_name image_path description information unit type menu_category_id item_attributes item_options account_id min_qty taxable is_sub_item is_available created_by), :style=>header_text
# sheet.add_row [mi.id,mi.item_code, mi.name, mi.alt_name, mi.image_path, mi.description, mi.information, mi.unit, mi.type, mi.menu_category_id, mi.item_attributes, mi.item_options, mi.account_id, mi.min_qty, mi.taxable, mi.is_sub_item, mi.is_available, mi.created_by], :style=>wrap_text
# sheet.add_row
# # Menu Item Instance
# sheet.add_row ["Menu Item Instance"], :style=>wrap_text
# sheet.add_row %w(id menu_item_id item_instance_code item_instance_name item_attributes price is_on_promotion promotion_price is_available is_default), :style=>header_text
# mi.menu_item_instances.each do |mii|
# sheet.add_row [mii.id, mii.menu_item_id, mii.item_instance_code, mii.item_instance_name, mii.item_attributes, mii.price, mii.is_on_promotion, mii.promotion_price, mii.is_available, mii.is_default], :style=>wrap_text
# end
# sheet.add_row
# end
# end
end
# # Account
# wb.add_worksheet(name: "Account") do |sheet|
# sheet.add_row %w(id title account_type discount point bonus rebate), :style=>header_text
# Account.all.each do |acc|
# sheet.add_row [acc.id, acc.title,acc.account_type,acc.discount,acc.point,acc.bonus,acc.rebate], :style=>wrap_text
# end
# end
# # Item set
# wb.add_worksheet(name: "Item Set") do |sheet|
# sheet.add_row %w(id name alt_name min_selectable_qty max_selectable_qty), :style=>header_text
# ItemSet.all.each do |set|
# sheet.add_row [set.id,set.name, set.alt_name, set.min_selectable_qty, set.max_selectable_qty], :style=>wrap_text
# end
# end
# # Item Options
# wb.add_worksheet(name: "Menu Item Options") do |sheet|
# sheet.add_row %w(id option_type name value), :style=>header_text
# MenuItemOption.all.each do |option|
# sheet.add_row [option.id, option.option_type, option.name, option.value], :style=>wrap_text
# end
# end
# # Item Attributes
# wb.add_worksheet(name: "Menu Item Attributes") do |sheet|
# sheet.add_row %w(id attribute_type name value), :style=>header_text
# MenuItemAttribute.all.each do |attr|
# sheet.add_row [attr.id, attr.attribute_type,attr.name,attr.value], :style=>wrap_text
# end
# end
end
p.serialize("tmp/menus/" + menu.name + ".xlsx")
render :json => {status: true}
end
def import
if params[:file]
Menu.import(params[:file])
redirect_to settings_menus_path, notice: "Menu was successfully Imported"
end
status = Menu.import(params[:file], current_user.name)
redirect_to settings_menus_path, notice: status
end
end
private