Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced matrix pdf #489

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ GEM
libv8 (3.16.14.17)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.6)
mail (2.6.4)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these version changes to a lower version really necessary? i don't think so

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No they are not necessary. The Gemfile.lock changed automatically and I was not sure if I should upload it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you would like to remove these changes, that would clean it up a bit (and avoid a conflict).
Or do you need a newer prawn? If you do, please rebase on current master.

mime-types (>= 1.16, < 4)
mailcatcher (0.6.4)
activesupport (~> 4.0)
Expand All @@ -237,7 +237,7 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini-smtp-server (0.0.2)
mini_portile2 (2.2.0)
mini_portile2 (2.1.0)
minitest (5.10.1)
mono_logger (1.1.0)
multi_json (1.12.1)
Expand All @@ -246,15 +246,15 @@ GEM
net-ssh (>= 2.6.5)
net-ssh (3.1.1)
netrc (0.11.0)
nokogiri (1.8.0)
mini_portile2 (~> 2.2.0)
pdf-core (0.6.1)
nokogiri (1.7.1)
mini_portile2 (~> 2.1.0)
pdf-core (0.7.0)
polyamorous (1.3.1)
activerecord (>= 3.0)
polyglot (0.3.5)
prawn (2.1.0)
pdf-core (~> 0.6.1)
ttfunk (~> 1.4.0)
prawn (2.2.2)
pdf-core (~> 0.7.0)
ttfunk (~> 1.5)
prawn-table (0.2.2)
prawn (>= 1.3.0, < 3.0.0)
protected_attributes (1.1.0)
Expand Down Expand Up @@ -437,7 +437,7 @@ GEM
thread_safe (0.3.6)
tilt (2.0.7)
tins (1.13.2)
ttfunk (1.4.0)
ttfunk (1.5.1)
twitter-bootstrap-rails (2.2.8)
actionpack (>= 3.1)
execjs
Expand Down Expand Up @@ -549,4 +549,4 @@ DEPENDENCIES
whenever

BUNDLED WITH
1.11.2
1.15.1
2 changes: 1 addition & 1 deletion app/documents/order_by_groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def body
# borders
table.cells.borders = [:bottom]
table.cells.border_width = 0.02
table.cells.border_color = 'dddddd'
table.cells.border_color = '000000'
table.rows(0).border_width = 1
table.rows(0).border_color = '666666'
table.rows(0).column(5).font_style = :bold
Expand Down
27 changes: 18 additions & 9 deletions app/documents/order_matrix.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# encoding: utf-8
class OrderMatrix < OrderPdf

MAX_ARTICLES_PER_PAGE = 16 # How many order_articles shoud written on a page
MAX_ARTICLES_PER_PAGE = 21 # How many order_articles shoud written on a page

def filename
I18n.t('documents.order_matrix.filename', :name => @order.name, :date => @order.ends.to_date) + '.pdf'
Expand All @@ -13,7 +13,7 @@ def title
end

def body
order_articles = @order.order_articles.ordered
order_articles = @order.order_articles.sort_by{|a| a.article.name.downcase}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do this sorting via ActiveRecord instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did the sorting still with sort_by, because I was afraid, that I make unwanted changes in the database with ActiveRecord sorting. Feel free to change this if this is a problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorting belongs in the database, this is a memory hog and doesn't scale for large orders. Please reconsider the ordered scope if you think a different sort order is useful everywhere; if it only makes sense here, don't use the .ordered scope but use active-record sorting. If you'd like case-insensitive sorting, indexes may also be needed.

Sorry for the condensed answer, if you need more explanation, please don't hesitate to ask. We'll do our best to help!


text I18n.t('documents.order_matrix.heading'), style: :bold
move_down 5
Expand All @@ -26,13 +26,15 @@ def body
order_articles_data << [a.article.name,
a.article.unit,
a.price.unit_quantity,
number_to_currency(a.price.price * a.price.unit_quantity),
number_with_precision(article_price(a), precision: 2),
a.units]
end

table order_articles_data, cell_style: {size: fontsize(8), overflow: :shrink_to_fit} do |table|
table.cells.border_width = 1
table.cells.border_color = '666666'
table.column(3).text_color = 'aeaeae'
end

page_number = 0
Expand All @@ -51,12 +53,14 @@ def body

# Make order_articles header
header = [""]

for header_article in current_order_articles
name = header_article.article.name.gsub(/[-\/]/, " ").gsub(".", ". ")
name = name.split.collect { |w| w.truncate(8) }.join(" ")
header << name.truncate(30)
name = name.split.collect { |w| w.truncate(20) }.join(" ")
header << "#{name.truncate(35)} - (#{header_article.article.unit})"

end

# Collect group results
groups_data = [header]

Expand All @@ -73,14 +77,19 @@ def body
end

# Make table
column_widths = [85]
(MAX_ARTICLES_PER_PAGE + 1).times { |i| column_widths << 41 unless i == 0 }
table groups_data, column_widths: column_widths, cell_style: {size: fontsize(8), overflow: :shrink_to_fit} do |table|
column_widths = [55]
(MAX_ARTICLES_PER_PAGE + 1).times { |i| column_widths << 32 unless i == 0 }
table groups_data, column_widths: column_widths, cell_style: {size: fontsize(5), overflow: :shrink_to_fit } do |table|

table.rows(0).padding = 2
table.rows(0).height = 35
table.rows(0).overflow = :truncate
table.rows(0).min_font_size = 8
table.cells.border_width = 1
table.cells.border_color = '666666'
table.row_colors = ['ffffff','ececec']
end

end
end

Expand Down
1 change: 1 addition & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ de:
- Artikel
- Einheit
- Gebinde
- Nettopreis
- FC-Preis
- Menge
title: 'Sortiermatrix der Bestellung: %{name}, beendet am %{date}'
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ en:
- Article
- Unit
- Unit quantity
- Price (net)
- FC-Price
- Amount
title: 'Order sorting matrix: %{name}, closed at %{date}'
Expand Down
1 change: 1 addition & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ fr:
- Nom du produit
- Unité
- Nombre d'unités
- Prix HT
- Prix coop
- Quantité
title: 'Tableau de répartition pour la commande: %{name}; clôturée le %{date}'
Expand Down
1 change: 1 addition & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ nl:
- Artikel
- Eenheid
- Gr.Eenh.
- Netto prijs
- Foodcoop-prijs
- Aantal
title: 'Sorteermatrix van bestelling: %{name}, gesloten op %{date}'
Expand Down