Complete refactoring of orders-workflow.

OrderResult tables are removed. Data consistency is now possible through new article.price-history (ArticlePrice).
Balancing-workflow needs to be updated.
This commit is contained in:
Benjamin Meichsner 2009-01-29 01:57:51 +01:00
parent 80287aeea4
commit 9eb2125f15
98 changed files with 1121 additions and 1717 deletions

View file

@ -1,4 +1,4 @@
title = "#{@order.name}, beendet am #{@order.ends.strftime('%d.%m.%Y')}"
title = "#{@order.supplier.name}, beendet am #{@order.ends.strftime('%d.%m.%Y')}"
# Define header and footer
pdf.header [pdf.margin_box.left,pdf.margin_box.top+20] do
@ -9,64 +9,64 @@ pdf.footer [pdf.margin_box.left, pdf.margin_box.bottom-5] do
pdf.text "Seite #{pdf.page_count}", :size => 8
end
max_articles_per_page = 17 # How many articles shoud written on a page
articles = @order.order_article_results
max_order_articles_per_page = 17 # How many order_articles shoud written on a page
order_articles = @order.order_articles
pdf.text "Artikelübersicht", :style => :bold
pdf.move_down 5
pdf.text "Insgesamt #{articles.size} Artikel", :size => 8
pdf.text "Insgesamt #{order_articles.size} Artikel", :size => 8
pdf.move_down 10
articles_data = articles.collect do |a|
[a.name, a.unit, a.unit_quantity, a.gross_price, a.units_to_order]
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]
end
pdf.table articles_data,
pdf.table order_articles_data,
:font_size => 8,
:border_style => :grid,
:vertical_padding => 3,
:headers => ["Artikel", "Einheit", "Gebinde", "Preis", "Menge"]
:headers => ["Artikel", "Einheit", "Gebinde", "Preis", "Menge"],
:align => { 3 => :right }
page_number = 0
total_num_articles = articles.size
total_num_order_articles = order_articles.size
while (page_number * max_articles_per_page < total_num_articles) do # Start page generating
while (page_number * max_order_articles_per_page < total_num_order_articles) do # Start page generating
page_number += 1
pdf.start_new_page(:layout => :landscape)
# Collect articles for this page
current_articles = articles.select do |a|
articles.index(a) >= (page_number-1) * max_articles_per_page and
articles.index(a) < page_number * max_articles_per_page
# 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
end
# Make articles header
# Make order_articles header
header = [""]
for header_article in current_articles
name = header_article.name.split("-").join(" ").split(".").join(". ").split("/").join(" ")
for header_article in current_order_articles
name = header_article.article.name.split("-").join(" ").split(".").join(". ").split("/").join(" ")
name = name.split.collect { |w| truncate(w, 8, "..") }.join(" ")
header << truncate(name, 30, " ..")
end
# Collect group results
groups_data = []
for group_order_result in @order.group_order_results
for group_order in @order.group_orders.all(:include => :ordergroup)
group_result = [truncate(group_order_result.group_name, 20)]
group_result = [truncate(group_order.ordergroup.name, 20)]
for article in current_articles
# get the OrdergroupResult for this article
result = GroupOrderArticleResult.find(:first,
:conditions => ['order_article_result_id = ? AND group_order_result_id = ?', article.id, group_order_result.id])
group_result << ((result.nil? || result == 0) ? "" : result.quantity.to_i)
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 }
group_result << ((goa.nil? || goa == 0) ? "" : goa.quantity.to_i)
end
groups_data << group_result
end
# Make table
widths = { }
(max_articles_per_page + 1).times { |i| widths.merge!({ i => 40 }) unless i == 0 }
widths = { } # Generate widths-hash for table layout
(max_order_articles_per_page + 1).times { |i| widths.merge!({ i => 40 }) unless i == 0 }
pdf.table groups_data,
:font_size => 8,
:border_style => :grid,