Skip to content

Commit

Permalink
Some more fixes for #44
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Feb 23, 2024
1 parent f351dee commit 614cfdc
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 24 deletions.
16 changes: 12 additions & 4 deletions app/assets/javascripts/article-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ArticleForm {
if (unit === undefined) {
return '?';
}
return unit.label;
return unit.symbol != null ? unit.symbol : unit.label;
}

initializeFormSubmitListener() {
Expand Down Expand Up @@ -495,7 +495,7 @@ class ArticleForm {
const inputs$ = mergeJQueryObjects([this.unitsToOrder$, this.unitsReceived$]);
inputs$.parent().find('.unit_label').remove();
if (billingUnitLabel.trim() !== '') {
inputs$.after($(`<span class="unit_label ml-1">x ${billingUnitLabel}</span>`));
inputs$.after($(`<span class="unit_label ml-1">${this.getUnitsConverter().isUnitSiConversible(billingUnitKey) ? '' : 'x '}${billingUnitLabel}</span>`));
}
if (this.previousBillingUnit !== undefined) {
this.convertOrderedAndReceivedUnits(this.previousBillingUnit, billingUnitKey);
Expand All @@ -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
}
}
});
}

Expand Down
7 changes: 4 additions & 3 deletions app/documents/order_by_articles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
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,
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
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/group_order_articles_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/views/order_articles/_edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
8 changes: 3 additions & 5 deletions app/views/shared/articles_by/_article_single.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion app/views/shared/articles_by/_article_single_goa.html.haml
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 1 addition & 2 deletions app/views/shared/articles_by/_group_single_goa.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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 &times;
%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
1 change: 0 additions & 1 deletion app/views/shared/articles_by/_groups.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 15 additions & 2 deletions lib/order_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 614cfdc

Please sign in to comment.