$self->js->render();
}
+sub action_unit_changed {
+ my ($self) = @_;
+
+ my $idx = first_index { $_ eq $::form->{item_id} } @{ $::form->{orderitem_ids} };
+ my $item = $self->order->items->[$idx];
+
+ my $old_unit_obj = SL::DB::Unit->new(name => $::form->{old_unit})->load;
+ $item->sellprice($item->unit_obj->convert_to($item->sellprice, $old_unit_obj));
+
+ $self->_recalc();
+
+ $self->js
+ ->run('update_sellprice', $::form->{item_id}, $item->sellprice_as_number);
+ $self->_js_redisplay_linetotals;
+ $self->_js_redisplay_amounts_and_taxes;
+ $self->js->render();
+}
+
sub action_add_item {
my ($self) = @_;
->val('.add_item_input', '')
->run('row_table_scroll_down')
->run('row_set_keyboard_events_by_id', $item_id)
+ ->run('set_unit_change_with_oldval_by_id', $item_id)
->on('.recalc', 'change', 'recalc_amounts_and_taxes')
->on('.reformat_number', 'change', 'reformat_number')
->focus('#add_item_parts_id_name');
$self->js
->append('#row_table_id', $row_as_html)
- ->run('row_set_keyboard_events_by_id', $item_id);
+ ->run('row_set_keyboard_events_by_id', $item_id)
+ ->run('set_unit_change_with_oldval_by_id', $item_id);
}
$self->js
$.post("controller.pl", data, kivi.eval_json_result);
}
+function unit_change(event) {
+ var row = $(event.target).parents("tbody").first();
+ var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
+ var sellprice_dom = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
+ var select_elt = $(row).find('[name="order.orderitems[].unit"]');
+
+ var oldval = $(select_elt).data('oldval');
+ $(select_elt).data('oldval', $(select_elt).val());
+
+ var data = $('#order_form').serialize();
+ data += '&action=Order/unit_changed';
+ data += '&item_id=' + item_id_dom.val();
+ data += '&old_unit=' + oldval;
+ data += '&sellprice_dom_id=' + sellprice_dom.attr('id');
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+}
+
+function update_sellprice(item_id, price_str) {
+ var row = $('#item_' + item_id).parents("tbody").first();
+ var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
+ var html_elt = $(row).find('[name="sellprice_text"]');
+ price_elt.val(price_str);
+ html_elt.html(price_str);
+}
+
function add_item() {
if ($('#add_item_parts_id').val() == '') return;
if (!check_cv()) return;
});
}
+function set_unit_change_with_oldval_by_id(item_id) {
+ var row = $('#item_' + item_id).parents("tbody").first();
+ var select_elt = $(row).find('[name="order.orderitems[].unit"]');
+
+ set_unit_change_with_oldval(select_elt);
+}
+
+function set_unit_change_with_oldval(selects) {
+ selects.each(function(idx,elt) {
+ $(elt).data('oldval', $(elt).val());
+ });
+
+ selects.change(unit_change);
+}
+
var email_dialog;
function show_email_dialog(html) {
row_set_keyboard_events($('.row_entry'));
$('.recalc').change(recalc_amounts_and_taxes);
$('.reformat_number').change(reformat_number);
+
+ set_unit_change_with_oldval($('.unitselect'));
});
</script>