Class: OrderMatrix
- Defined in:
- app/documents/order_matrix.rb
Constant Summary collapse
- HEADER_ROTATE =
-30
- PLACEHOLDER_CHAR =
'X'
Constants inherited from RenderPdf
RenderPdf::BOTTOM_MARGIN, RenderPdf::DEFAULT_FONT, RenderPdf::FOOTER_FONT_SIZE, RenderPdf::FOOTER_SPACE, RenderPdf::HEADER_FONT_SIZE, RenderPdf::HEADER_SPACE, RenderPdf::TOP_MARGIN
Instance Attribute Summary
Attributes inherited from OrderPdf
Instance Method Summary collapse
Methods inherited from OrderPdf
#each_group_order_article_for_order_article, #each_group_order_article_for_ordergroup, #each_order_article, #each_ordergroup, #each_ordergroup_batch, #group_order_article_quantity_with_tolerance, #group_order_article_result, #group_order_articles, #initialize, #nice_table, #order_article_price, #order_article_price_per_unit, #order_articles, #ordergroups, #stock_ordergroup_name
Methods inherited from RenderPdf
#down_or_page, #font_path, #font_size, #fontsize, #initialize, #number_to_currency, #pdf_add_page_breaks?, #to_pdf
Methods included from ApplicationHelper
#base_errors, #bootstrap_flash_patched, #close_button, #expand, #foodcoop_css_path, #foodcoop_css_tag, #format_currency, #format_date, #format_datetime, #format_datetime_timespec, #format_iban, #format_roles, #format_time, #heading_helper, #icon, #items_per_page, #link_to_gmaps, #link_to_top, #pagination_links_remote, #remote_link_to, #show_title?, #show_user, #show_user_link, #sort_link_helper, #tab_is_active?, #truncate, #weekday
Methods included from PathHelper
#finance_group_transactions_path
Constructor Details
This class inherits a constructor from OrderPdf
Instance Method Details
#body ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/documents/order_matrix.rb', line 14 def body 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| order_articles_data << [a.article.name, a.article.supplier.name, a.price.unit_quantity, a.units, order_article_price_per_unit(a)] end order_articles_data.each { |row| row.delete_at 1 } unless @options[:show_supplier] name = I18n.t('documents.order_matrix.heading', count: order_articles_data.size - 1) 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 end font_size 8 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 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 each_ordergroup_batch batch_size do |batch_groups, batch_results| start_new_page unless first_page 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) end rows = [[nil, nil] + header] last_supplier_id = -1 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 end 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 end table rows, header: true, cell_style: { overflow: :shrink_to_fit } do |table| table.cells.padding = [0, 0, 2, 0] table.cells.borders = [:left] table.cells.border_width = 0.5 table.cells.border_color = '666666' table.row(0).borders = %i[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 table.cells[0, 0].borders = [] table.cells[0, 1].borders = [] 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| table.column(2 + idx).border_width = 2 end table.row_colors = %w[dddddd ffffff] end first_page = false end end |
#filename ⇒ Object
5 6 7 |
# File 'app/documents/order_matrix.rb', line 5 def filename I18n.t('documents.order_matrix.filename', name: @order.name, date: @order.ends.to_date) + '.pdf' end |
#title ⇒ Object
9 10 11 12 |
# File 'app/documents/order_matrix.rb', line 9 def title I18n.t('documents.order_matrix.title', name: @order.name, date: @order.ends.strftime(I18n.t('date.formats.default'))) end |