2014-03-06 16:26:16 +01:00
|
|
|
require 'csv'
|
|
|
|
|
2023-01-06 16:12:41 +01:00
|
|
|
class OrderCsv < RenderCsv
|
2014-05-08 12:42:50 +02:00
|
|
|
def header
|
2023-02-14 16:57:37 +01:00
|
|
|
params = @options[:custom_csv]
|
|
|
|
arr = if params.nil?
|
|
|
|
[
|
|
|
|
OrderArticle.human_attribute_name(:units_to_order),
|
|
|
|
Article.human_attribute_name(:order_number),
|
|
|
|
Article.human_attribute_name(:name),
|
|
|
|
Article.human_attribute_name(:unit),
|
|
|
|
Article.human_attribute_name(:unit_quantity_short),
|
|
|
|
ArticlePrice.human_attribute_name(:price),
|
|
|
|
OrderArticle.human_attribute_name(:total_price)
|
|
|
|
]
|
|
|
|
else
|
|
|
|
[
|
|
|
|
params[:first],
|
|
|
|
params[:second],
|
|
|
|
params[:third],
|
|
|
|
params[:fourth],
|
|
|
|
params[:fifth],
|
|
|
|
params[:sixth],
|
|
|
|
params[:seventh]
|
|
|
|
]
|
|
|
|
end
|
2014-03-06 16:26:16 +01:00
|
|
|
end
|
|
|
|
|
2014-05-08 12:42:50 +02:00
|
|
|
def data
|
|
|
|
@object.order_articles.ordered.includes([:article, :article_price]).all.map do |oa|
|
|
|
|
yield [
|
2023-02-14 16:57:37 +01:00
|
|
|
match_params(oa, header[0]),
|
|
|
|
match_params(oa, header[1]),
|
|
|
|
match_params(oa, header[2]),
|
|
|
|
match_params(oa, header[3]),
|
|
|
|
match_params(oa, header[4]),
|
|
|
|
match_params(oa, header[5]),
|
|
|
|
match_params(oa, header[6])
|
2021-03-01 15:27:26 +01:00
|
|
|
]
|
2014-03-06 16:26:16 +01:00
|
|
|
end
|
|
|
|
end
|
2023-02-14 16:57:37 +01:00
|
|
|
|
|
|
|
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
|
2014-03-06 16:26:16 +01:00
|
|
|
end
|