add functionality to choose column headers + order for custom csv and append order.sum gross&net to custom csv
This commit is contained in:
parent
ea0fba9010
commit
928a02ed3f
2 changed files with 49 additions and 16 deletions
|
@ -2,6 +2,8 @@ require 'csv'
|
||||||
|
|
||||||
class OrderCsv < RenderCsv
|
class OrderCsv < RenderCsv
|
||||||
def header
|
def header
|
||||||
|
params = @options[:custom_csv]
|
||||||
|
arr = if params.nil?
|
||||||
[
|
[
|
||||||
OrderArticle.human_attribute_name(:units_to_order),
|
OrderArticle.human_attribute_name(:units_to_order),
|
||||||
Article.human_attribute_name(:order_number),
|
Article.human_attribute_name(:order_number),
|
||||||
|
@ -11,19 +13,49 @@ class OrderCsv < RenderCsv
|
||||||
ArticlePrice.human_attribute_name(:price),
|
ArticlePrice.human_attribute_name(:price),
|
||||||
OrderArticle.human_attribute_name(:total_price)
|
OrderArticle.human_attribute_name(:total_price)
|
||||||
]
|
]
|
||||||
|
else
|
||||||
|
[
|
||||||
|
params[:first],
|
||||||
|
params[:second],
|
||||||
|
params[:third],
|
||||||
|
params[:fourth],
|
||||||
|
params[:fifth],
|
||||||
|
params[:sixth],
|
||||||
|
params[:seventh]
|
||||||
|
]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def data
|
def data
|
||||||
@object.order_articles.ordered.includes([:article, :article_price]).all.map do |oa|
|
@object.order_articles.ordered.includes([:article, :article_price]).all.map do |oa|
|
||||||
yield [
|
yield [
|
||||||
oa.units_to_order,
|
match_params(oa, header[0]),
|
||||||
oa.article.order_number,
|
match_params(oa, header[1]),
|
||||||
oa.article.name,
|
match_params(oa, header[2]),
|
||||||
oa.article.unit,
|
match_params(oa, header[3]),
|
||||||
oa.price.unit_quantity > 1 ? oa.price.unit_quantity : nil,
|
match_params(oa, header[4]),
|
||||||
number_to_currency(oa.price.price * oa.price.unit_quantity),
|
match_params(oa, header[5]),
|
||||||
number_to_currency(oa.total_price)
|
match_params(oa, header[6])
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def match_params(object, attribute)
|
||||||
|
case attribute
|
||||||
|
when OrderArticle.human_attribute_name(:units_to_order)
|
||||||
|
object.units_to_order
|
||||||
|
when Article.human_attribute_name(:order_number)
|
||||||
|
object.article.order_number
|
||||||
|
when Article.human_attribute_name(:name)
|
||||||
|
object.article.name
|
||||||
|
when Article.human_attribute_name(:unit)
|
||||||
|
object.article.unit
|
||||||
|
when Article.human_attribute_name(:unit_quantity_short)
|
||||||
|
object.price.unit_quantity > 1 ? object.price.unit_quantity : nil
|
||||||
|
when ArticlePrice.human_attribute_name(:price)
|
||||||
|
number_to_currency(object.price.price * object.price.unit_quantity)
|
||||||
|
when OrderArticle.human_attribute_name(:total_price)
|
||||||
|
number_to_currency(object.total_price)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,6 +20,7 @@ class RenderCsv
|
||||||
end
|
end
|
||||||
data { |d| csv << d }
|
data { |d| csv << d }
|
||||||
end
|
end
|
||||||
|
ret << I18n.t('.orders.articles.prices_sum') << ";" << "#{number_to_currency(@object.sum(:gross))}/#{number_to_currency(@object.sum(:net))}" if @options[:custom_csv]
|
||||||
ret.encode(@options[:encoding], invalid: :replace, undef: :replace)
|
ret.encode(@options[:encoding], invalid: :replace, undef: :replace)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue