2009-02-05 16:40:02 +01:00
|
|
|
title = "#{@order.name}, beendet am #{@order.ends.strftime('%d.%m.%Y')}"
|
2009-01-08 14:10:51 +01:00
|
|
|
|
|
|
|
# Define header and footer
|
|
|
|
pdf.header [pdf.margin_box.left,pdf.margin_box.top+20] do
|
|
|
|
pdf.text title, :size => 10, :align => :center
|
|
|
|
end
|
|
|
|
pdf.footer [pdf.margin_box.left, pdf.margin_box.bottom-5] do
|
|
|
|
pdf.stroke_horizontal_rule
|
|
|
|
pdf.text "Seite #{pdf.page_count}", :size => 8
|
|
|
|
end
|
|
|
|
|
2009-01-29 01:57:51 +01:00
|
|
|
max_order_articles_per_page = 17 # How many order_articles shoud written on a page
|
2009-02-03 21:14:48 +01:00
|
|
|
order_articles = @order.order_articles.ordered
|
2009-01-08 14:10:51 +01:00
|
|
|
|
|
|
|
pdf.text "Artikelübersicht", :style => :bold
|
|
|
|
pdf.move_down 5
|
2009-01-29 01:57:51 +01:00
|
|
|
pdf.text "Insgesamt #{order_articles.size} Artikel", :size => 8
|
2009-01-08 14:10:51 +01:00
|
|
|
pdf.move_down 10
|
|
|
|
|
2009-01-29 01:57:51 +01:00
|
|
|
order_articles_data = order_articles.collect do |a|
|
|
|
|
[a.article.name, a.article.unit, a.price.unit_quantity, a.price.fc_price, a.units_to_order]
|
2009-01-08 14:10:51 +01:00
|
|
|
end
|
2009-01-29 01:57:51 +01:00
|
|
|
pdf.table order_articles_data,
|
2009-01-08 14:10:51 +01:00
|
|
|
:font_size => 8,
|
|
|
|
:border_style => :grid,
|
|
|
|
:vertical_padding => 3,
|
2009-01-29 01:57:51 +01:00
|
|
|
:headers => ["Artikel", "Einheit", "Gebinde", "Preis", "Menge"],
|
|
|
|
:align => { 3 => :right }
|
2009-01-08 14:10:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
page_number = 0
|
2009-01-29 01:57:51 +01:00
|
|
|
total_num_order_articles = order_articles.size
|
2009-01-08 14:10:51 +01:00
|
|
|
|
2009-01-29 01:57:51 +01:00
|
|
|
while (page_number * max_order_articles_per_page < total_num_order_articles) do # Start page generating
|
2009-01-08 14:10:51 +01:00
|
|
|
|
|
|
|
page_number += 1
|
|
|
|
pdf.start_new_page(:layout => :landscape)
|
|
|
|
|
2009-01-29 01:57:51 +01:00
|
|
|
# Collect order_articles for this page
|
|
|
|
current_order_articles = order_articles.select do |a|
|
|
|
|
order_articles.index(a) >= (page_number-1) * max_order_articles_per_page and
|
|
|
|
order_articles.index(a) < page_number * max_order_articles_per_page
|
2009-01-08 14:10:51 +01:00
|
|
|
end
|
|
|
|
|
2009-01-29 01:57:51 +01:00
|
|
|
# Make order_articles header
|
2009-01-08 14:10:51 +01:00
|
|
|
header = [""]
|
2009-01-29 01:57:51 +01:00
|
|
|
for header_article in current_order_articles
|
|
|
|
name = header_article.article.name.split("-").join(" ").split(".").join(". ").split("/").join(" ")
|
2009-01-08 14:10:51 +01:00
|
|
|
name = name.split.collect { |w| truncate(w, 8, "..") }.join(" ")
|
|
|
|
header << truncate(name, 30, " ..")
|
|
|
|
end
|
|
|
|
|
|
|
|
# Collect group results
|
|
|
|
groups_data = []
|
2009-01-29 01:57:51 +01:00
|
|
|
for group_order in @order.group_orders.all(:include => :ordergroup)
|
2009-01-08 14:10:51 +01:00
|
|
|
|
2009-01-29 01:57:51 +01:00
|
|
|
group_result = [truncate(group_order.ordergroup.name, 20)]
|
2009-01-08 14:10:51 +01:00
|
|
|
|
2009-01-29 01:57:51 +01:00
|
|
|
for order_article in current_order_articles
|
|
|
|
# get the Ordergroup result for this order_article
|
|
|
|
goa = order_article.group_order_articles.first :conditions => { :group_order_id => group_order.id }
|
2009-02-04 16:41:01 +01:00
|
|
|
group_result << ((goa.nil? || goa == 0) ? "" : goa.result.to_i)
|
2009-01-08 14:10:51 +01:00
|
|
|
end
|
|
|
|
groups_data << group_result
|
|
|
|
end
|
|
|
|
|
|
|
|
# Make table
|
2009-01-29 01:57:51 +01:00
|
|
|
widths = { } # Generate widths-hash for table layout
|
|
|
|
(max_order_articles_per_page + 1).times { |i| widths.merge!({ i => 40 }) unless i == 0 }
|
2009-01-08 14:10:51 +01:00
|
|
|
pdf.table groups_data,
|
|
|
|
:font_size => 8,
|
|
|
|
:border_style => :grid,
|
|
|
|
:vertical_padding => 3,
|
|
|
|
:headers => header,
|
|
|
|
:widths => widths,
|
|
|
|
:row_colors => ['ffffff','ececec']
|
|
|
|
|
|
|
|
end
|