Skip to content

Commit

Permalink
Adapt article & group sorted order PDF (solves #49)
Browse files Browse the repository at this point in the history
  • Loading branch information
twothreenine committed Jul 31, 2024
1 parent 3297e5e commit a8d87d7
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 30 deletions.
24 changes: 17 additions & 7 deletions app/documents/order_by_articles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/documents/order_by_groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions app/helpers/orders_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
48 changes: 36 additions & 12 deletions app/lib/order_pdf.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class OrderPdf < RenderPdf
include ArticlesHelper
include OrdersHelper
attr_reader :order

def initialize(order, options = {})
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand Down

0 comments on commit a8d87d7

Please sign in to comment.