2015-01-18 02:04:57 +01:00
|
|
|
require 'roo'
|
2012-10-28 18:03:50 +01:00
|
|
|
|
2015-01-18 02:04:57 +01:00
|
|
|
# Foodsoft-file import
|
|
|
|
class FoodsoftFile
|
2009-01-06 11:49:19 +01:00
|
|
|
|
|
|
|
# parses a string from a foodsoft-file
|
|
|
|
# returns two arrays with articles and outlisted_articles
|
|
|
|
# the parsed article is a simple hash
|
2015-01-18 02:04:57 +01:00
|
|
|
def self.parse(file, options = {})
|
|
|
|
filepath = file.is_a?(String) ? file : file.to_path
|
|
|
|
filename = options[:filename] || filepath
|
|
|
|
fileext = ::File.extname(filename)
|
|
|
|
options = {col_sep: ';', encoding: 'utf-8'}.merge(options)
|
|
|
|
s = Roo::Spreadsheet.open filepath, extension: fileext, csv_options: options
|
|
|
|
|
|
|
|
row_index = 1
|
|
|
|
s.each do |row|
|
|
|
|
if row_index == 1
|
|
|
|
# @todo try to detect headers; for now using the index is ok
|
|
|
|
|
|
|
|
elsif !row[2].blank?
|
|
|
|
article = {:order_number => row[1],
|
2009-01-06 11:49:19 +01:00
|
|
|
:name => row[2],
|
|
|
|
:note => row[3],
|
|
|
|
:manufacturer => row[4],
|
|
|
|
:origin => row[5],
|
|
|
|
:unit => row[6],
|
|
|
|
:price => row[7],
|
|
|
|
:tax => row[8],
|
|
|
|
:deposit => (row[9].nil? ? "0" : row[9]),
|
|
|
|
:unit_quantity => row[10],
|
2015-01-18 02:04:57 +01:00
|
|
|
:article_category => row[13]}
|
|
|
|
status = row[0] && row[0].strip.downcase == 'x' ? :outlisted : nil
|
|
|
|
yield status, article, row_index
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
row_index += 1
|
|
|
|
end
|
2015-01-18 02:04:57 +01:00
|
|
|
row_index
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2015-01-18 02:04:57 +01:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|