2012-10-02 02:50:48 +02:00
|
|
|
class OrderByGroups < OrderPdf
|
|
|
|
def filename
|
2023-05-12 13:01:12 +02:00
|
|
|
I18n.t('documents.order_by_groups.filename', name: order.name, date: order.ends.to_date) + '.pdf'
|
2012-10-02 02:50:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def title
|
2023-05-12 13:01:12 +02:00
|
|
|
I18n.t('documents.order_by_groups.title', name: order.name,
|
|
|
|
date: order.ends.strftime(I18n.t('date.formats.default')))
|
2012-10-02 02:50:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def body
|
2021-02-08 01:07:39 +01:00
|
|
|
each_ordergroup do |oa_name, oa_total, oa_id, oa_transport|
|
|
|
|
has_transport = !oa_transport.nil? && oa_transport > 0
|
2013-09-16 23:52:58 +02:00
|
|
|
dimrows = []
|
2017-11-15 19:22:55 +01:00
|
|
|
rows = [[
|
|
|
|
OrderArticle.human_attribute_name(:article),
|
|
|
|
Article.human_attribute_name(:supplier),
|
|
|
|
GroupOrderArticle.human_attribute_name(:ordered),
|
|
|
|
GroupOrderArticle.human_attribute_name(:received),
|
|
|
|
GroupOrderArticle.human_attribute_name(:unit_price),
|
|
|
|
GroupOrderArticle.human_attribute_name(:total_price)
|
|
|
|
]]
|
|
|
|
|
|
|
|
each_group_order_article_for_ordergroup(oa_id) do |goa|
|
|
|
|
dimrows << rows.length if goa.result == 0
|
2021-03-01 15:27:26 +01:00
|
|
|
rows << [goa.order_article.article.name,
|
|
|
|
goa.group_order.order.name,
|
|
|
|
group_order_article_quantity_with_tolerance(goa),
|
|
|
|
group_order_article_result(goa),
|
|
|
|
order_article_price_per_unit(goa.order_article),
|
|
|
|
number_to_currency(goa.total_price)]
|
2012-10-02 02:50:48 +02:00
|
|
|
end
|
2017-11-15 19:22:55 +01:00
|
|
|
next unless rows.length > 1
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2017-11-15 19:22:55 +01:00
|
|
|
rows << [nil, nil, nil, nil, nil, number_to_currency(oa_total)]
|
2021-02-08 01:07:39 +01:00
|
|
|
if has_transport
|
|
|
|
rows << [GroupOrder.human_attribute_name(:transport), nil, nil, nil, nil, number_to_currency(oa_transport)]
|
|
|
|
rows << [nil, nil, nil, nil, nil, number_to_currency(oa_total + oa_transport)]
|
|
|
|
end
|
2012-10-02 02:50:48 +02:00
|
|
|
|
2017-11-15 19:22:55 +01:00
|
|
|
rows.each { |row| row.delete_at 1 } unless @options[:show_supplier]
|
2012-10-02 02:50:48 +02:00
|
|
|
|
2017-11-15 19:22:55 +01:00
|
|
|
nice_table oa_name || stock_ordergroup_name, rows, dimrows do |table|
|
2021-02-08 01:07:39 +01:00
|
|
|
if has_transport
|
|
|
|
table.row(-4).border_width = 1
|
|
|
|
table.row(-4).border_color = '666666'
|
|
|
|
end
|
|
|
|
|
2017-11-15 19:22:55 +01:00
|
|
|
table.row(-2).border_width = 1
|
|
|
|
table.row(-2).border_color = '666666'
|
|
|
|
table.row(-1).borders = []
|
2013-09-16 23:52:58 +02:00
|
|
|
|
2017-11-15 19:22:55 +01:00
|
|
|
if @options[:show_supplier]
|
|
|
|
table.column(0).width = bounds.width / 3
|
|
|
|
table.column(1).width = bounds.width / 4
|
|
|
|
else
|
|
|
|
table.column(0).width = bounds.width / 2
|
2015-07-10 18:59:50 +02:00
|
|
|
end
|
2017-11-15 19:22:55 +01:00
|
|
|
|
|
|
|
table.columns(-4..-1).align = :right
|
|
|
|
table.column(-3).font_style = :bold
|
|
|
|
table.column(-1).font_style = :bold
|
2012-10-02 02:50:48 +02:00
|
|
|
end
|
|
|
|
end
|
2016-06-04 21:37:47 +02:00
|
|
|
end
|
2013-04-04 02:04:31 +02:00
|
|
|
end
|