2012-10-02 02:50:48 +02:00
|
|
|
class OrderMatrix < OrderPdf
|
2017-11-15 19:22:55 +01:00
|
|
|
HEADER_ROTATE = -30
|
|
|
|
PLACEHOLDER_CHAR = 'X'
|
2016-02-25 02:08:04 +01:00
|
|
|
|
2012-10-02 02:50:48 +02:00
|
|
|
def filename
|
2013-04-04 02:04:31 +02:00
|
|
|
I18n.t('documents.order_matrix.filename', :name => @order.name, :date => @order.ends.to_date) + '.pdf'
|
2012-10-02 02:50:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def title
|
2013-04-04 02:04:31 +02:00
|
|
|
I18n.t('documents.order_matrix.title', :name => @order.name,
|
2021-03-01 15:27:26 +01:00
|
|
|
:date => @order.ends.strftime(I18n.t('date.formats.default')))
|
2012-10-02 02:50:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def body
|
2017-11-15 19:22:55 +01:00
|
|
|
order_articles_data = [[
|
|
|
|
OrderArticle.human_attribute_name(:article),
|
|
|
|
Article.human_attribute_name(:supplier),
|
|
|
|
ArticlePrice.human_attribute_name(:unit_quantity),
|
|
|
|
OrderArticle.human_attribute_name(:units_received),
|
|
|
|
Article.human_attribute_name(:fc_price_short)
|
|
|
|
]]
|
|
|
|
|
|
|
|
each_order_article do |a|
|
2012-10-02 02:50:48 +02:00
|
|
|
order_articles_data << [a.article.name,
|
2017-11-15 19:22:55 +01:00
|
|
|
a.article.supplier.name,
|
2012-10-02 02:50:48 +02:00
|
|
|
a.price.unit_quantity,
|
2017-11-15 19:22:55 +01:00
|
|
|
a.units,
|
|
|
|
order_article_price_per_unit(a)]
|
2012-10-02 02:50:48 +02:00
|
|
|
end
|
|
|
|
|
2017-11-15 19:22:55 +01:00
|
|
|
order_articles_data.each { |row| row.delete_at 1 } unless @options[:show_supplier]
|
|
|
|
|
2021-03-01 15:27:26 +01:00
|
|
|
name = I18n.t('documents.order_matrix.heading', count: order_articles_data.size - 1)
|
2017-11-15 19:22:55 +01:00
|
|
|
nice_table name, order_articles_data do |table|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
table.columns(-3..-1).align = :right
|
|
|
|
table.column(-2).font_style = :bold
|
2012-10-02 02:50:48 +02:00
|
|
|
end
|
|
|
|
|
2017-11-15 19:22:55 +01:00
|
|
|
font_size 8
|
2012-10-02 02:50:48 +02:00
|
|
|
|
2017-11-15 19:22:55 +01:00
|
|
|
row_height_1 = height_of(PLACEHOLDER_CHAR) + 3
|
|
|
|
col_width_0 = width_of(PLACEHOLDER_CHAR * 20)
|
|
|
|
col_width_1 = width_of("#{number_to_currency(888.88)} / #{PLACEHOLDER_CHAR * 4}") + 3
|
|
|
|
col_width_2 = width_of(PLACEHOLDER_CHAR * 3) + 5
|
2012-10-02 02:50:48 +02:00
|
|
|
|
2017-11-15 19:22:55 +01:00
|
|
|
first_page = true
|
|
|
|
start_new_page(layout: :landscape)
|
|
|
|
batch_size = (bounds.width - col_width_0 - col_width_1) / col_width_2
|
|
|
|
batch_size = batch_size.floor
|
2012-10-02 02:50:48 +02:00
|
|
|
|
2017-11-15 19:22:55 +01:00
|
|
|
each_ordergroup_batch batch_size do |batch_groups, batch_results|
|
|
|
|
start_new_page unless first_page
|
2012-10-02 02:50:48 +02:00
|
|
|
|
2017-11-15 19:22:55 +01:00
|
|
|
header = batch_groups.map do |name, total|
|
|
|
|
text = "#{name.try(:truncate, 20)} <b>#{number_to_currency(total)}</b>"
|
|
|
|
RotatedCell.new(self, text, inline_format: true, rotate: HEADER_ROTATE)
|
2012-10-02 02:50:48 +02:00
|
|
|
end
|
|
|
|
|
2017-11-15 19:22:55 +01:00
|
|
|
rows = [[nil, nil] + header]
|
2012-10-02 02:50:48 +02:00
|
|
|
|
2017-11-15 19:22:55 +01:00
|
|
|
last_supplier_id = -1
|
2012-10-02 02:50:48 +02:00
|
|
|
|
2017-11-15 19:22:55 +01:00
|
|
|
each_order_article do |order_article|
|
|
|
|
supplier = order_article.article.supplier
|
|
|
|
if @options[:show_supplier] && last_supplier_id != supplier.id
|
|
|
|
row = [make_cell(supplier.name, colspan: 2, font_style: :bold)]
|
|
|
|
batch_groups.each { row << nil }
|
|
|
|
rows << row
|
|
|
|
last_supplier_id = supplier.id
|
2012-10-02 02:50:48 +02:00
|
|
|
end
|
2017-11-15 19:22:55 +01:00
|
|
|
|
|
|
|
row = [order_article.article.name, order_article_price_per_unit(order_article)]
|
|
|
|
row += batch_results[order_article.id] if batch_results[order_article.id]
|
|
|
|
rows << row
|
2012-10-02 02:50:48 +02:00
|
|
|
end
|
|
|
|
|
2021-03-01 15:27:26 +01:00
|
|
|
table rows, header: true, cell_style: { overflow: :shrink_to_fit } do |table|
|
2017-11-15 19:22:55 +01:00
|
|
|
table.cells.padding = [0, 0, 2, 0]
|
|
|
|
table.cells.borders = [:left]
|
|
|
|
table.cells.border_width = 0.5
|
2012-10-02 02:50:48 +02:00
|
|
|
table.cells.border_color = '666666'
|
2017-11-15 19:22:55 +01:00
|
|
|
|
|
|
|
table.row(0).borders = [:bottom, :left]
|
|
|
|
table.row(0).padding = [2, 0, 2, 0]
|
|
|
|
table.row(1..-1).height = row_height_1
|
|
|
|
table.column(0..1).borders = []
|
|
|
|
table.column(1).align = :right
|
|
|
|
table.column(1).padding = [0, 3, 2, 0]
|
|
|
|
table.column(2..-1).align = :center
|
2021-03-01 15:27:26 +01:00
|
|
|
table.cells[0, 0].borders = []
|
|
|
|
table.cells[0, 1].borders = []
|
2017-11-15 19:22:55 +01:00
|
|
|
|
|
|
|
table.column(0).overflow = :truncate
|
|
|
|
table.column(0).width = col_width_0
|
|
|
|
table.column(1).width = col_width_1
|
|
|
|
table.column(2..-1).width = col_width_2
|
|
|
|
|
|
|
|
(0..batch_size).step(5).each do |idx|
|
2021-03-01 15:27:26 +01:00
|
|
|
table.column(2 + idx).border_width = 2
|
2017-11-15 19:22:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
table.row_colors = ['dddddd', 'ffffff']
|
2012-10-02 02:50:48 +02:00
|
|
|
end
|
|
|
|
|
2017-11-15 19:22:55 +01:00
|
|
|
first_page = false
|
2012-10-02 02:50:48 +02:00
|
|
|
end
|
|
|
|
end
|
2013-04-04 02:04:31 +02:00
|
|
|
end
|