Skip to content

Enhanced matrix pdf #489

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ gem 'rails-i18n'

gem 'mysql2'
gem 'prawn'
gem 'prawn-table'
gem 'prawn-table', :git => 'https://github.com/straydogstudio/prawn-table.git', ref: '759a27b6'
Copy link
Member

Choose a reason for hiding this comment

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

this revision is from 2014. the latest upstream version is from 2016. do you see any chance that the commit from straydogstudio gets accepted in upstream? I do not like the idea of using such an outdated version. If the merge in upstream is not possible: Could you rebase the commit from straydogstudio to upstream master, publish them in a new repository and use that in the Gemfile?

gem 'haml-rails'
gem 'kaminari'
gem 'simple_form'
Expand Down
31 changes: 18 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ GIT
specs:
localize_input (0.1.0)

GIT
remote: https://github.com/straydogstudio/prawn-table.git
revision: 759a27b6fef2e682c035fc83f2182e53c3270279
ref: 759a27b6
specs:
prawn-table (0.2.1)

GIT
remote: https://github.com/technoweenie/acts_as_versioned.git
revision: 63b1fc8529d028fae632fe80ec0cb25df56cd76b
Expand Down Expand Up @@ -217,7 +224,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 +244,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,17 +253,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-table (0.2.2)
prawn (>= 1.3.0, < 3.0.0)
prawn (2.2.2)
pdf-core (~> 0.7.0)
ttfunk (~> 1.5)
protected_attributes (1.1.0)
activemodel (>= 4.0.1, < 5.0)
pry (0.10.3)
Expand Down Expand Up @@ -437,7 +442,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 @@ -512,7 +517,7 @@ DEPENDENCIES
meta_request
mysql2
prawn
prawn-table
prawn-table!
protected_attributes (= 1.1.0)
pry-rescue
pry-stack_explorer
Expand Down Expand Up @@ -549,4 +554,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
37 changes: 26 additions & 11 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 = 22 # 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,22 +13,26 @@ 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
text I18n.t('documents.order_matrix.total', :count => order_articles.size), size: fontsize(8)
move_down 10

order_articles_data = [I18n.t('documents.order_matrix.rows')]

Copy link
Member

Choose a reason for hiding this comment

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

please avoid unnecessary whitespace changes


order_articles.each do |a|
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

#order_articles_data.sort_by!{|a| a[0].downcase}
Copy link
Member

Choose a reason for hiding this comment

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

please avoid useless comments


table order_articles_data, cell_style: {size: fontsize(8), overflow: :shrink_to_fit} do |table|
table.cells.border_width = 1
Expand All @@ -51,12 +55,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+')'
Copy link
Member

Choose a reason for hiding this comment

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

header << "#{name.truncate(35)} - (#{header_article.article.unit})" might be easier to read


end

# Collect group results
groups_data = [header]

Expand All @@ -74,13 +80,22 @@ def body

# 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|
table.cells.border_width = 1
table.cells.border_color = '666666'
table.row_colors = ['ffffff','ececec']
(MAX_ARTICLES_PER_PAGE + 1).times { |i| column_widths << 30 unless i == 0 }
table groups_data, column_widths: column_widths, cell_style: {size: fontsize(8), overflow: :shrink_to_fit } do |table|

table.rows(0).rotate = 90
table.rows(0).padding = 2
table.rows(0).height = 90
table.rows(0).overflow = :truncate
table.rows(0).align = :left
table.rows(0).min_font_size = 6
# table.rows(0).valign = :bottom

table.cells.border_width = 1
table.cells.border_color = '666666'
table.row_colors = ['ffffff','ececec']
Copy link
Member

Choose a reason for hiding this comment

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

you removed the indentation for this block

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
- Netto price
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 compare it to the other translations "Nettopreis" in german is usually "Price" in english

please also update the other languages. the translation should be easy to find

- FC-Price
- Amount
title: 'Order sorting matrix: %{name}, closed at %{date}'
Expand Down