From 57a6f039178e308b26832a190038b257d66f9fe2 Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 21 Jun 2018 15:42:11 +0630 Subject: [PATCH 1/2] 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 From 748dff9eb36bdfe9fbf75702ef55fe528ff20f4d Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 21 Jun 2018 15:54:18 +0630 Subject: [PATCH 2/2] gudeline for import menu image --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 141e1f2c..84d87436 100755 --- a/README.md +++ b/README.md @@ -228,6 +228,15 @@ For Price 0 in receipt bill For Aston Request => Gift Voucher 1) settings/payment_method_settings => {payment_method:'GiftVoucher', is_active:true, ...} + +Menu Image (Import guideline) + + => First, check shop_code is there in shops table. + * If there is shop_code (mark in one place/ note and set NULL for this record for a while)/ there is no shop_code in shops table (* skip set NULL step), and copy and paste images into Application/[sxrestaurant]/public/image/menu_images. + => Second, import [menu].xlsx file in /settings/menus and then checked image is uploaded into Application/[sxrestaurant]/public/image/menu_images and insert into menu_items table in database. + => Last, if shop has shop_code, update marked/noted shop_code into shops table again. + + * ToDo list 1. Migration