make receive delta work when unit_quantity changes
This commit is contained in:
parent
45e529b008
commit
3b2d50b47d
3 changed files with 27 additions and 10 deletions
|
@ -58,9 +58,12 @@ module OrdersHelper
|
|||
|
||||
def receive_input_field(form)
|
||||
order_article = form.object
|
||||
units_expected = (order_article.units_billed or order_article.units_to_order)
|
||||
units_expected = (order_article.units_billed or order_article.units_to_order) *
|
||||
1.0 * order_article.article.unit_quantity / order_article.article_price.unit_quantity
|
||||
|
||||
input_html = form.text_field :units_received, class: 'input input-nano package units_received',
|
||||
input_classes = 'input input-nano units_received'
|
||||
input_classes += ' package' unless order_article.article_price.unit_quantity == 1
|
||||
input_html = form.text_field :units_received, class: input_classes,
|
||||
data: {'units-expected' => units_expected},
|
||||
disabled: order_article.result_manually_changed?,
|
||||
autocomplete: 'off'
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
function update_delta(input) {
|
||||
var units = $(input).val();
|
||||
var expected = $(input).data('units-expected');
|
||||
var delta = Math.round((units-expected)*100)/100.0;
|
||||
var html;
|
||||
|
||||
if (units.replace(/\s/g,"")=="") {
|
||||
|
@ -13,17 +14,20 @@
|
|||
html = '';
|
||||
} else if (isNaN(units)) {
|
||||
html = '<i class="icon-remove" style="color: red"></i>';
|
||||
} else if (units == expected) {
|
||||
} else if (delta == 0) {
|
||||
// equal value
|
||||
html = '<i class="icon-ok" style="color: green"></i>';
|
||||
} else {
|
||||
if (units < expected) {
|
||||
html = '<span style="color: red">- '+(expected-units)+'</span>';
|
||||
if (delta < 0) {
|
||||
html = '<span style="color: red">- '+(-delta)+'</span>';
|
||||
} else /*if (units> expected)*/ {
|
||||
html = '<span style="color: green">+ '+(units-expected)+'</span>';
|
||||
html = '<span style="color: green">+ '+(delta)+'</span>';
|
||||
}
|
||||
// show package icon only if the receive field has one
|
||||
if ($(input).hasClass('package')) {
|
||||
html += '#{j pkg_helper_icon}';
|
||||
}
|
||||
}
|
||||
|
||||
$(input).closest('tr').find('.units_delta').html(html);
|
||||
}
|
||||
|
|
|
@ -4,9 +4,19 @@
|
|||
// get old element and update the cell which is reused
|
||||
var old_order_article_entry = $('#order_article_<%= @order_article.id %>');
|
||||
|
||||
$('td.units_received_cell span.package', old_order_article_entry).replaceWith(
|
||||
'<%= j pkg_helper(@order_article.article_price, icon: false) %>'
|
||||
);
|
||||
// update package info after input
|
||||
$('td.units_received_cell span.package', old_order_article_entry).remove();
|
||||
$('<%= j pkg_helper(@order_article.article_price, icon: false) %>')
|
||||
.appendTo($('td.units_received_cell', old_order_article_entry));
|
||||
|
||||
// update package icon on input too
|
||||
$('input', old_order_article_entry).toggleClass('package', <%= @order_article.article_price.unit_quantity == 1 ? 'false' : 'true' %>);
|
||||
|
||||
// update expected units, since unit_quantity may have been changed
|
||||
$('input', old_order_article_entry).data('units-expected', <%=
|
||||
(@order_article.units_billed or @order_article.units_to_order) *
|
||||
1.0 * @order_article.article.unit_quantity / @order_article.article_price.unit_quantity
|
||||
%>);
|
||||
|
||||
// render new element and inject dynamic cell
|
||||
var new_order_article_entry = $(
|
||||
|
|
Loading…
Reference in a new issue