diff --git a/app/documents/order_by_articles.rb b/app/documents/order_by_articles.rb index a19bfc93..04ac9e26 100644 --- a/app/documents/order_by_articles.rb +++ b/app/documents/order_by_articles.rb @@ -22,21 +22,31 @@ def body each_group_order_article_for_order_article(order_article) do |goa| dimrows << rows.length if goa.result == 0 rows << [goa.group_order.ordergroup_name, - billing_quantity_with_tolerance(goa), - number_with_precision(article_version.convert_quantity(goa.result, article_version.group_order_unit, - article_version.billing_unit)), + group_order_quantity_with_tolerance(goa), + billing_quantity(goa), number_to_currency(goa.total_price)] end next unless rows.length > 1 - name = "#{article_version.name}, #{format_billing_unit_with_ratios(article_version)}, #{number_to_currency(article_version.convert_quantity( - article_version.fc_price, article_version.billing_unit, article_version.supplier_order_unit - ))}" - name += " #{order_article.order.name}" if @options[:show_supplier] + show_total = order_article.group_order_articles.size > 1 + if show_total + rows << [I18n.t('documents.total'), + total_group_order_quantity_with_tolerance(order_article), + total_billing_quantity(order_article), + number_to_currency(order_article.group_orders_sum[:price])] + end + + name = "#{article_version.name} - #{price_per_billing_unit(article_version)}" + name += " - #{order_article.order.name}" if @options[:show_supplier] nice_table name, rows, dimrows do |table| table.column(0).width = bounds.width / 2 table.columns(1..-1).align = :right table.column(2).font_style = :bold + table.row(-1).borders = [] + if show_total + table.row(-2).border_width = 1 + table.row(-2).border_color = '666666' + end end end end diff --git a/app/documents/order_by_groups.rb b/app/documents/order_by_groups.rb index 7a19a9dc..f4528b6d 100644 --- a/app/documents/order_by_groups.rb +++ b/app/documents/order_by_groups.rb @@ -25,9 +25,9 @@ def body dimrows << rows.length if goa.result == 0 rows << [goa.order_article.article_version.name, goa.group_order.order.name, - billing_quantity_with_tolerance(goa), - billing_article_result(goa), - price_per_billing_unit(goa), + group_order_quantity_with_tolerance(goa, strip_insignificant_zeros: true), + billing_quantity(goa, strip_insignificant_zeros: true), + price_per_billing_unit(goa.order_article.article_version), number_to_currency(goa.total_price)] end next unless rows.length > 1 diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 24c1d3c5..818524b7 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -24,7 +24,12 @@ def options_for_suppliers_to_select end def format_units_to_order(order_article, strip_insignificant_zeros: false) - format_amount(order_article.units_to_order, order_article, strip_insignificant_zeros: strip_insignificant_zeros) + format_units_amount(order_article.units_to_order, order_article.article_version.supplier_order_unit, strip_insignificant_zeros: strip_insignificant_zeros) + end + + def format_units_amount(amount, unit, strip_insignificant_zeros: false) + strip_insignificant_zeros = true unless ArticleUnitsLib.unit_is_si_convertible(unit) + number_with_precision(amount, precision: 3, strip_insignificant_zeros: strip_insignificant_zeros) end # "1×2 ordered, 2×2 billed, 2×2 received" @@ -210,11 +215,4 @@ def receive_button(order, options = {}) class: "btn#{' btn-success' unless order.received?} #{options[:class]}" end end - - private - - def format_amount(amount, order_article, strip_insignificant_zeros: false) - strip_insignificant_zeros = true unless order_article.article_version.supplier_order_unit_is_si_convertible - number_with_precision(amount, precision: 3, strip_insignificant_zeros: strip_insignificant_zeros) - end end diff --git a/app/lib/order_pdf.rb b/app/lib/order_pdf.rb index 3af817b7..3e7d029b 100644 --- a/app/lib/order_pdf.rb +++ b/app/lib/order_pdf.rb @@ -1,5 +1,6 @@ class OrderPdf < RenderPdf include ArticlesHelper + include OrdersHelper attr_reader :order def initialize(order, options = {}) @@ -55,23 +56,46 @@ def order_article_price_per_unit(order_article) "#{number_to_currency(order_article_price(order_article))} / #{format_group_order_unit_with_ratios(order_article.article_version)}" end - def price_per_billing_unit(goa) - article_version = goa.order_article.article_version + def price_per_billing_unit(article_version) "#{number_to_currency(article_version.convert_quantity(article_version.fc_price, article_version.billing_unit, article_version.supplier_order_unit))} / #{format_billing_unit_with_ratios(article_version)}" end - def billing_quantity_with_tolerance(goa) + def group_order_quantity_with_tolerance(goa, strip_insignificant_zeros: false) article_version = goa.order_article.article_version - quantity = number_with_precision( - article_version.convert_quantity(goa.quantity, article_version.group_order_unit, - article_version.billing_unit), strip_insignificant_zeros: true, precision: 2 - ) - tolerance = number_with_precision( - article_version.convert_quantity(goa.tolerance, article_version.group_order_unit, - article_version.billing_unit), strip_insignificant_zeros: true, precision: 2 - ) - goa.tolerance > 0 ? "#{quantity} + #{tolerance}" : quantity + quantity = format_units_amount(goa.quantity, article_version.group_order_unit, strip_insignificant_zeros: strip_insignificant_zeros) + tolerance = format_units_amount(goa.tolerance, article_version.group_order_unit, strip_insignificant_zeros: strip_insignificant_zeros) + amount = goa.tolerance > 0 ? "#{quantity} + #{tolerance}" : quantity.to_s + amount += " #{format_group_order_unit_with_ratios(article_version)}" + amount + end + + def billing_quantity(goa, strip_insignificant_zeros: false) + article_version = goa.order_article.article_version + amount = format_units_amount(article_version.convert_quantity(goa.result, + article_version.group_order_unit, + article_version.billing_unit), + article_version.billing_unit, + strip_insignificant_zeros: strip_insignificant_zeros) + "#{amount} #{format_billing_unit_with_ratios(article_version)}" + end + + def total_group_order_quantity_with_tolerance(order_article) + article_version = order_article.article_version + quantity = format_units_amount(order_article.quantity, article_version.group_order_unit) + tolerance = format_units_amount(order_article.tolerance, article_version.group_order_unit) + amount = order_article.tolerance > 0 ? "#{quantity} + #{tolerance}" : quantity.to_s + amount += " #{format_group_order_unit_with_ratios(article_version)}" + amount + end + + def total_billing_quantity(order_article) + article_version = order_article.article_version + amount = format_units_amount(article_version.convert_quantity(order_article.group_orders_sum[:quantity], + article_version.group_order_unit, + article_version.billing_unit), + article_version.billing_unit) + "#{amount} #{format_billing_unit_with_ratios(article_version)}" end def group_order_article_result(goa) diff --git a/config/locales/de.yml b/config/locales/de.yml index 01ea2183..c31fd5fd 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -799,6 +799,7 @@ de: update: notice: Lieferung wurde aktualisiert. documents: + total: Gesamt order_by_articles: filename: Bestellung %{name}-%{date} - Artikelsortierung title: 'Artikelsortierung der Bestellung: %{name}, beendet am %{date}' diff --git a/config/locales/en.yml b/config/locales/en.yml index 319f1a1f..1e8e5cf7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -801,6 +801,7 @@ en: update: notice: Delivery was updated. documents: + total: Total order_by_articles: filename: Order %{name}-%{date} - by articles title: 'Order sorted by articles: %{name}, closed at %{date}'