From 57a6f039178e308b26832a190038b257d66f9fe2 Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 21 Jun 2018 15:42:11 +0630 Subject: [PATCH] image import from csv --- app/controllers/settings/menus_controller.rb | 4 ++-- app/models/menu.rb | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/controllers/settings/menus_controller.rb b/app/controllers/settings/menus_controller.rb index 49a42320..4fd99852 100755 --- a/app/controllers/settings/menus_controller.rb +++ b/app/controllers/settings/menus_controller.rb @@ -72,7 +72,7 @@ class Settings::MenusController < ApplicationController # end end - def export + def export @settings_menus = Menu.all.page(params[:page]).per(10) menu = Menu.find(params[:id]) @@ -135,7 +135,7 @@ class Settings::MenusController < ApplicationController if mii.item_attributes.length > 0 attribute = MenuItemAttribute.find(mii.item_attributes[0]).name end - sheet.add_row [ mc.code, mc.name, mi.item_code, mi.name, mi.account.title, mi.alt_name, mi.taxable, attributes, options, mii.item_instance_code, mii.item_instance_name, attribute, mii.price, mii.is_default, mi.image_path.to_s.remove("/image/menu_images/")], :style=>wrap_text + sheet.add_row [ mc.code, mc.name, mi.item_code, mi.name, mi.account.title, mi.alt_name, mi.taxable, attributes, options, mii.item_instance_code, mii.item_instance_name, attribute, mii.price, mii.is_default, mi.image_path.to_s.remove("/image/menu_images")], :style=>wrap_text end end end diff --git a/app/models/menu.rb b/app/models/menu.rb index b513b5f2..98667b7e 100755 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -140,6 +140,14 @@ class Menu < ApplicationRecord end else # Menu by Menu Import + @shop = Shop.first + shop_code = "" + if !@shop.nil? + if @shop.shop_code + shop_code = @shop.shop_code + "_" + end + end + sheet = spreadsheet.sheet(0) menu = sheet.row(1)[1] imported_menu = Menu.create({name: menu, is_active: true, 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}) @@ -184,11 +192,10 @@ class Menu < ApplicationRecord account = Account.create({title: row["Account"], account_type: "0"}) end - image_path = row["Image Path"] ? row["Image Path"] : "" + image_path = row["Image Path"] ? URI.parse('public/image/menu_images/'+row["Image Path"]) : "" + puts "image_path" puts image_path - menu_itm = MenuItem.create(item_code: row["Item Code"], name: row["Item Name"], account_id: account.id, alt_name: row["Item AltName"], image_path: image_path.to_s, description: '', information: '', unit: '', type: "SimpleMenuItem", menu_category_id: menu_cat.id, item_attributes: item_attrs, item_options: item_opts, is_sub_item: 0, is_available: 1, created_by: created_by) - puts "menu_itm" - puts menu_itm.to_json + menu_itm = MenuItem.create(item_code: row["Item Code"], name: row["Item Name"], account_id: account.id, alt_name: row["Item AltName"], image_path: image_path, description: '', information: '', unit: '', type: "SimpleMenuItem", menu_category_id: menu_cat.id, item_attributes: item_attrs, item_options: item_opts, is_sub_item: 0, is_available: 1, created_by: created_by) # else # status = status + "Item Code already exists for " + row["Item Name"] + "." end