diff --git a/app/lib/order_csv.rb b/app/lib/order_csv.rb index b238f90c..653edf90 100644 --- a/app/lib/order_csv.rb +++ b/app/lib/order_csv.rb @@ -2,28 +2,60 @@ require 'csv' class OrderCsv < RenderCsv def header - [ - 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) - ] + 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 end def data @object.order_articles.ordered.includes([:article, :article_price]).all.map do |oa| yield [ - oa.units_to_order, - oa.article.order_number, - oa.article.name, - oa.article.unit, - oa.price.unit_quantity > 1 ? oa.price.unit_quantity : nil, - number_to_currency(oa.price.price * oa.price.unit_quantity), - number_to_currency(oa.total_price) + 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]) ] 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 diff --git a/app/lib/render_csv.rb b/app/lib/render_csv.rb index 1f20b075..c1fd24db 100644 --- a/app/lib/render_csv.rb +++ b/app/lib/render_csv.rb @@ -20,6 +20,7 @@ class RenderCsv end data { |d| csv << d } 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) end