add bnn_upload plugin that overrides some controller methods to use order_bnn
This commit is contained in:
parent
f8c91b46cd
commit
b1ec0fd2fc
12 changed files with 70 additions and 27 deletions
|
|
@ -1,6 +1,5 @@
|
|||
require "deface"
|
||||
require 'foodsoft_bnn_upload/engine'
|
||||
|
||||
module FoodsoftBnnUpload
|
||||
def self.enabled?
|
||||
FoodsoftConfig[:use_bnn_upload]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
module FoodsoftBnnUpload
|
||||
class Engine < ::Rails::Engine
|
||||
config.to_prepare do
|
||||
Dir.glob(Rails.root + "app/decorators/**/*_decorator*.rb").each do |c|
|
||||
require_dependency(c)
|
||||
end
|
||||
end
|
||||
def default_foodsoft_config(cfg)
|
||||
cfg[:use_bnn_upload] = true
|
||||
end
|
||||
|
|
|
|||
42
plugins/bnn_upload/lib/foodsoft_bnn_upload/order_bnn.rb
Normal file
42
plugins/bnn_upload/lib/foodsoft_bnn_upload/order_bnn.rb
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
module FoodsoftBnnUpload
|
||||
class OrderBnn < RenderCsv
|
||||
def initialize(object, options = {})
|
||||
super
|
||||
@options[:col_sep] = ""
|
||||
@options[:row_sep] = "\n"
|
||||
@options[:encoding] = 'IBM850'
|
||||
end
|
||||
|
||||
def header
|
||||
customer_id = "000001"
|
||||
delivery_date = Time.zone.now.strftime("%y%m%d")
|
||||
pickup = " "
|
||||
|
||||
["D##{customer_id}#{delivery_date}#{pickup}#{@object.id}"]
|
||||
end
|
||||
|
||||
def data
|
||||
@object.order_articles.ordered.includes([:article, :article_price]).all.map do |oa|
|
||||
yield [
|
||||
pad_to_length(oa.article.order_number, 13),
|
||||
"+",
|
||||
pad_float_values(oa.units_to_order),
|
||||
pad_to_length(oa.article.name, 30),
|
||||
pad_float_values(oa.article.unit_quantity),
|
||||
pad_to_length(oa.article.unit, 14),
|
||||
pad_to_length(oa.article.manufacturer, 3),
|
||||
pad_to_length("", 26)
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
def pad_float_values(number, digits_before=4, digits_after=3)
|
||||
format_string = "%0#{digits_before + digits_after}d"
|
||||
formatted_number = sprintf(format_string, (number * 10 ** digits_after).to_i)
|
||||
end
|
||||
|
||||
def pad_to_length(string, length)
|
||||
string.to_s.rjust(length, " ")[0, length]
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue