From 614cfdc0d3e32ce46888a8f12150872dc1f02802 Mon Sep 17 00:00:00 2001 From: Florian Lentsch Date: Fri, 23 Feb 2024 14:29:46 +0100 Subject: [PATCH] Some more fixes for #44 --- app/assets/javascripts/article-form.js | 16 ++++++++++++---- app/documents/order_by_articles.rb | 7 ++++--- app/documents/order_by_groups.rb | 6 +++--- app/helpers/group_order_articles_helper.rb | 2 +- app/views/order_articles/_edit.html.haml | 4 ++-- .../articles_by/_article_single.html.haml | 8 +++----- .../articles_by/_article_single_goa.html.haml | 3 ++- .../articles_by/_group_single_goa.html.haml | 3 +-- app/views/shared/articles_by/_groups.html.haml | 1 - lib/order_pdf.rb | 17 +++++++++++++++-- 10 files changed, 43 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/article-form.js b/app/assets/javascripts/article-form.js index cb5519b9..88ff935f 100644 --- a/app/assets/javascripts/article-form.js +++ b/app/assets/javascripts/article-form.js @@ -76,7 +76,7 @@ class ArticleForm { if (unit === undefined) { return '?'; } - return unit.label; + return unit.symbol != null ? unit.symbol : unit.label; } initializeFormSubmitListener() { @@ -495,7 +495,7 @@ class ArticleForm { const inputs$ = mergeJQueryObjects([this.unitsToOrder$, this.unitsReceived$]); inputs$.parent().find('.unit_label').remove(); if (billingUnitLabel.trim() !== '') { - inputs$.after($(`x ${billingUnitLabel}`)); + inputs$.after($(`${this.getUnitsConverter().isUnitSiConversible(billingUnitKey) ? '' : 'x '}${billingUnitLabel}`)); } if (this.previousBillingUnit !== undefined) { this.convertOrderedAndReceivedUnits(this.previousBillingUnit, billingUnitKey); @@ -507,8 +507,16 @@ class ArticleForm { const inputs$ = mergeJQueryObjects([this.unitsToOrder$, this.unitsReceived$]); inputs$.each((_, input) => { const input$ = $(input); - const convertedValue = this.getUnitRatio(input$.val(), fromUnit, toUnit); - input$.val(round(convertedValue)); + const val = input$.val(); + + if (val !== '') { + try { + const convertedValue = this.getUnitRatio(val, fromUnit, toUnit); + input$.val(round(convertedValue)); + } catch (e) { + // In some cases it's impossible to perform this conversion - just leave the original value + } + } }); } diff --git a/app/documents/order_by_articles.rb b/app/documents/order_by_articles.rb index 62f33eee..243c4dad 100644 --- a/app/documents/order_by_articles.rb +++ b/app/documents/order_by_articles.rb @@ -10,6 +10,7 @@ def title def body each_order_article do |order_article| + article_version = order_article.article_version dimrows = [] rows = [[ GroupOrder.human_attribute_name(:ordergroup), @@ -21,13 +22,13 @@ 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, - group_order_article_quantity_with_tolerance(goa), - goa.result, + billign_quantity_with_tolerance(goa), + article_version.convert_quantity(goa.result, article_version.group_order_unit, article_version.billing_unit), number_to_currency(goa.total_price)] end next unless rows.length > 1 - name = "#{order_article.article_version.name} (#{order_article.article_version.unit} | #{order_article.article_version.unit_quantity} | #{number_to_currency(order_article.article_version.fc_price)})" + 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] nice_table name, rows, dimrows do |table| table.column(0).width = bounds.width / 2 diff --git a/app/documents/order_by_groups.rb b/app/documents/order_by_groups.rb index 8323d3c1..a9690ed1 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, - group_order_article_quantity_with_tolerance(goa), - group_order_article_result(goa), - order_article_price_per_unit(goa.order_article), + billign_quantity_with_tolerance(goa), + billing_article_result(goa), + price_per_billing_unit(goa), number_to_currency(goa.total_price)] end next unless rows.length > 1 diff --git a/app/helpers/group_order_articles_helper.rb b/app/helpers/group_order_articles_helper.rb index bc63258e..b8c20c94 100644 --- a/app/helpers/group_order_articles_helper.rb +++ b/app/helpers/group_order_articles_helper.rb @@ -12,7 +12,7 @@ def group_order_article_edit_result(goa, convert_to_billing_unit = true) converted_value = convert_to_billing_unit ? article_version.convert_quantity(goa.result, article_version.group_order_unit, article_version.billing_unit) : result input_data = { min: 0 }.merge(quantity_data) input_data = input_data.merge('multiply-before-submit': article_version.convert_quantity(1, article_version.billing_unit, article_version.group_order_unit)) if convert_to_billing_unit - f.input_field(:result, as: :delta, class: 'input-nano', data: input_data, id: "r_#{goa.id}", value: converted_value) + f.input_field(:result, as: :delta, class: 'input-nano', data: input_data, id: "r_#{goa.id}", value: converted_value.round(3)) end end end diff --git a/app/views/order_articles/_edit.html.haml b/app/views/order_articles/_edit.html.haml index babd67b5..41e09e7f 100644 --- a/app/views/order_articles/_edit.html.haml +++ b/app/views/order_articles/_edit.html.haml @@ -7,9 +7,9 @@ = hidden_field_tag :without_units, true - else .fold-line - = form.input :units_to_order, hint: '', input_html: {class: 'input-mini'} + = form.input :units_to_order, hint: '', input_html: {class: 'input-mini', step: 0.001} -#= form.input :units_billed, label: 'invoice', input_html: {class: 'input-nano'} - = form.input :units_received, input_html: {class: 'input-mini'}, + = form.input :units_received, input_html: {class: 'input-mini', step: 0.001}, label: t('activerecord.attributes.order_article.units_received_short') %p.help-block= t 'simple_form.hints.order_article.units_to_order' diff --git a/app/views/shared/articles_by/_article_single.html.haml b/app/views/shared/articles_by/_article_single.html.haml index 611a2b19..6e8aa352 100644 --- a/app/views/shared/articles_by/_article_single.html.haml +++ b/app/views/shared/articles_by/_article_single.html.haml @@ -3,11 +3,9 @@ %tr.list-heading %th{:colspan => "4"}> %h4.name.pull-left - = order_article.article_version.name + - article_version = order_article.article_version + = article_version.name %small - = "(#{format_group_order_unit_with_ratios(order_article.article_version)}, #{number_to_currency order_article.article_version.fc_price}" - - pkg_info = pkg_helper(order_article.price) - = ", #{pkg_info}".html_safe unless pkg_info.blank? - ) + = "#{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))}" - for goa in order_article.group_order_articles.ordered = render 'shared/articles_by/article_single_goa', goa: goa diff --git a/app/views/shared/articles_by/_article_single_goa.html.haml b/app/views/shared/articles_by/_article_single_goa.html.haml index 1f727007..cdade7ab 100644 --- a/app/views/shared/articles_by/_article_single_goa.html.haml +++ b/app/views/shared/articles_by/_article_single_goa.html.haml @@ -1,5 +1,6 @@ %tr{class: if goa.result == 0 then 'unavailable' end, id: "goa_#{goa.id}"} + - article_version = goa.order_article.article_version %td{:style => "width:70%"}= goa.group_order.ordergroup_name - %td.center= "#{goa.quantity} + #{goa.tolerance}" + %td.center= "#{article_version.convert_quantity(goa.quantity, article_version.group_order_unit, article_version.billing_unit)} + #{article_version.convert_quantity(goa.tolerance, article_version.group_order_unit, article_version.billing_unit)}" %td.center.input-delta= group_order_article_edit_result(goa) %td.price{data: {value: goa.total_price}}= number_to_currency(goa.total_price) diff --git a/app/views/shared/articles_by/_group_single_goa.html.haml b/app/views/shared/articles_by/_group_single_goa.html.haml index 4b663bfd..59a1b80c 100644 --- a/app/views/shared/articles_by/_group_single_goa.html.haml +++ b/app/views/shared/articles_by/_group_single_goa.html.haml @@ -5,7 +5,6 @@ %td.center= "#{article_version.convert_quantity(goa.quantity, article_version.group_order_unit, article_version.billing_unit)} + #{article_version.convert_quantity(goa.tolerance, article_version.group_order_unit, article_version.billing_unit)}" %td.center.input-delta= group_order_article_edit_result(goa) %td.symbol × - %td= number_to_currency(article_version.convert_quantity(article_version.fc_price, article_version.billing_unit, article_version.group_order_unit)) + %td= number_to_currency(article_version.convert_quantity(article_version.fc_price, article_version.billing_unit, article_version.supplier_order_unit)) %td.symbol = %td.price{data: {value: goa.total_price}}= number_to_currency(goa.total_price) - %td= pkg_helper goa.order_article.price diff --git a/app/views/shared/articles_by/_groups.html.haml b/app/views/shared/articles_by/_groups.html.haml index 4bd9c285..8787a503 100644 --- a/app/views/shared/articles_by/_groups.html.haml +++ b/app/views/shared/articles_by/_groups.html.haml @@ -11,7 +11,6 @@ %th= heading_helper Article, :fc_price, short: true %th.symbol %th= t 'shared.articles_by.price' - %th= #heading_helper Article, :unit_quantity, short: true - for group_order in order.group_orders.ordered = render 'shared/articles_by/group_single', group_order: group_order diff --git a/lib/order_pdf.rb b/lib/order_pdf.rb index 9a298621..66a68619 100644 --- a/lib/order_pdf.rb +++ b/lib/order_pdf.rb @@ -55,14 +55,27 @@ 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 group_order_article_quantity_with_tolerance(goa) - goa.tolerance > 0 ? "#{goa.quantity} + #{goa.tolerance}" : "#{goa.quantity}" + def price_per_billing_unit(goa) + article_version = goa.order_article.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 billign_quantity_with_tolerance(goa) + 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 end def group_order_article_result(goa) number_with_precision goa.result, strip_insignificant_zeros: true end + def billing_article_result(goa) + article_version = goa.order_article.article_version + number_with_precision(article_version.convert_quantity(goa.result, article_version.group_order_unit, article_version.billing_unit), precision: 2, strip_insignificant_zeros: true) + end + def group_order_articles(ordergroup) GroupOrderArticle .includes(:group_order)