test
This commit is contained in:
@@ -30,13 +30,13 @@ class Menu < ApplicationRecord
|
||||
cats = MenuCategory.where("menu_id=?",menu.id)
|
||||
cats.each do |cat|
|
||||
abc = MenuCategory.destroyCategory(cat)
|
||||
end
|
||||
end
|
||||
menu.destroy
|
||||
return false
|
||||
end
|
||||
|
||||
def self.to_csv
|
||||
m_attributes = %w{name is_active valid_days valid_time_from valid_time_to created_by created_at updated_at}
|
||||
m_attributes = %w{name is_active valid_days valid_time_from valid_time_to created_by created_at updated_at}
|
||||
CSV.generate(headers: true, row_sep: "\r\n") do |csv|
|
||||
csv << m_attributes
|
||||
menu = Menu.all
|
||||
@@ -46,8 +46,8 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.import(file, created_by)
|
||||
status = ""
|
||||
def self.import(file, created_by)
|
||||
status = ""
|
||||
spreadsheet = open_spreadsheet(file)
|
||||
if spreadsheet.sheets.count > 1
|
||||
sheet_count = spreadsheet.sheets.count-1
|
||||
@@ -59,7 +59,7 @@ class Menu < ApplicationRecord
|
||||
row = Hash[[header,spreadsheet.sheet(i).row(ii)].transpose]
|
||||
if sheet_name == "Account"
|
||||
# Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"])
|
||||
account = Account.find_by_id(row["id"])
|
||||
account = Account.find_by_id(row["id"])
|
||||
if account
|
||||
Account.create(title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"])
|
||||
else
|
||||
@@ -67,7 +67,7 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
elsif sheet_name == "Item Set"
|
||||
# ItemSet.create(id:row["id"], name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty])
|
||||
item_set = ItemSet.find_by_id(row["id"])
|
||||
item_set = ItemSet.find_by_id(row["id"])
|
||||
if item_set
|
||||
ItemSet.create( name: row["name"], alt_name: row["alt_name"], min_selectable_qty: row["min_selectable_qty"], max_selectable_qty: row["max_selectable_qty"])
|
||||
else
|
||||
@@ -128,7 +128,7 @@ class Menu < ApplicationRecord
|
||||
else
|
||||
MenuInstanceItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"])
|
||||
end
|
||||
elsif sheet_name == "Menu Item Set"
|
||||
elsif sheet_name == "Menu Item Set"
|
||||
# MenuItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"])
|
||||
menu_item_set = MenuItemSet.find_by_id(row["id"])
|
||||
if menu_item_set
|
||||
@@ -149,24 +149,24 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
sheet = spreadsheet.sheet(0)
|
||||
sheet = spreadsheet.sheet(0)
|
||||
menu = sheet.row(1)[1]
|
||||
is_ordering = sheet.row(1)[3]?sheet.row(1)[3]:0
|
||||
|
||||
imported_menu = Menu.create({name: menu, is_active: true, is_ordering: is_ordering, valid_days: "1,2,3,4,5,6,7",valid_time_from: "00:00:00", valid_time_to: "23:59:59", created_by: created_by})
|
||||
imported_menu = Menu.create({name: menu, is_active: true, is_ordering: is_ordering, valid_days: "1,2,3,4,5,6,7",valid_time_from: "00:00:00", valid_time_to: "23:59:59", created_by: created_by})
|
||||
|
||||
(4..sheet.last_row).each do |ii|
|
||||
row = Hash[[sheet.row(3),sheet.row(ii)].transpose]
|
||||
menu_cat = MenuCategory.find_by_code(row["Category Code"])
|
||||
(4..sheet.last_row).each do |ii|
|
||||
row = Hash[[sheet.row(3),sheet.row(ii)].transpose]
|
||||
menu_cat = MenuCategory.find_by_code(row["Category Code"])
|
||||
if !menu_cat
|
||||
menu_cat = MenuCategory.create({menu_id: imported_menu.id, code: row["Category Code"], name: row["Category Name"], alt_name: '', order_by: (ii - 3), created_by: created_by, menu_category_id: nil, is_available: 1})
|
||||
menu_cat = MenuCategory.create({menu_id: imported_menu.id, code: row["Category Code"], name: row["Category Name"], alt_name: '', order_by: (ii - 3), created_by: created_by, menu_category_id: nil, is_available: 1})
|
||||
end
|
||||
|
||||
# Menu Item Attributes
|
||||
item_attrs = []
|
||||
if !row["Attributes"].nil?
|
||||
attributes = row["Attributes"].split(',')
|
||||
attributes.each do |attr|
|
||||
attributes.each do |attr|
|
||||
attribute = MenuItemAttribute.find_by_name(attr)
|
||||
if attribute.nil?
|
||||
attribute = MenuItemAttribute.create({ attribute_type:"any", name: attr.capitalize, value: attr.downcase })
|
||||
@@ -188,7 +188,7 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
menu_itm = MenuItem.find_by_item_code(row["Item Code"])
|
||||
menu_itm = MenuItem.find_by_item_code(row["Item Code"])
|
||||
if !menu_itm
|
||||
account = Account.find_by_title(row["Account"])
|
||||
if account.nil?
|
||||
@@ -205,22 +205,22 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
|
||||
instance_attr = []
|
||||
menu_inst = MenuItemInstance.find_by_item_instance_code(row["Instance Code"])
|
||||
menu_inst = MenuItemInstance.find_by_item_instance_code(row["Instance Code"])
|
||||
if !menu_inst
|
||||
instance_name = ''
|
||||
if !row["Instance Name"].nil?
|
||||
if !row["Instance Name"].nil?
|
||||
instance_name = row["Instance Name"]
|
||||
end
|
||||
|
||||
if !row["Attributes"].nil?
|
||||
if !row["Instance Attribute"].nil?
|
||||
if !row["Instance Attribute"].nil?
|
||||
attributes = row["Attributes"].split(',')
|
||||
instance_attributes = row["Instance Attribute"].split(',')
|
||||
attributes.each do |attr|
|
||||
attributes.each do |attr|
|
||||
if attr == instance_attributes[0]
|
||||
ins_attr = MenuItemAttribute.find_by_name(attr)
|
||||
instance_attr.push(ins_attr.id)
|
||||
end
|
||||
instance_attr.push(ins_attr.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -231,7 +231,7 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
imported_instance = MenuItemInstance.create(menu_item_id: menu_itm.id, item_instance_code: row["Instance Code"], item_instance_name: instance_name, item_attributes: instance_attr, price: row["Price"], is_on_promotion: false, promotion_price: 0, is_available: true, is_default: is_default)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
# if status == ''
|
||||
status="Menu Imported!"
|
||||
@@ -249,4 +249,4 @@ class Menu < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user