From: Bernd Bleßmann Date: Mon, 16 Nov 2015 16:18:45 +0000 (+0100) Subject: Auftrags-Controller: Einheiten per Select ändern können und sellprice anpassen. X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=refs%2Fheads%2Forder_controller;p=kivitendo-erp.git Auftrags-Controller: Einheiten per Select ändern können und sellprice anpassen. --- diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 2538b8e86..83e7219a6 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -313,6 +313,24 @@ sub action_customer_vendor_changed { $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) = @_; @@ -338,6 +356,7 @@ sub action_add_item { ->val('#add_item_discount_as_percent', '') ->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'); @@ -389,7 +408,8 @@ sub action_add_multi_items { $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 diff --git a/templates/webpages/order/tabs/_row.html b/templates/webpages/order/tabs/_row.html index 26e96d331..164dc17fd 100644 --- a/templates/webpages/order/tabs/_row.html +++ b/templates/webpages/order/tabs/_row.html @@ -42,10 +42,12 @@ class="recalc") %] - [%- L.input_tag("order.orderitems[].unit", - ITEM.unit, - size = 5, - class="recalc") %] + [%- L.select_tag("order.orderitems[].unit", + ITEM.part.available_units, + default = ITEM.unit, + title_key = 'name', + value_key = 'name', + class = 'unitselect') %] [%- L.button_tag("price_chooser_item_row(this)", diff --git a/templates/webpages/order/tabs/basic_data.html b/templates/webpages/order/tabs/basic_data.html index d575cab9d..87815bdff 100644 --- a/templates/webpages/order/tabs/basic_data.html +++ b/templates/webpages/order/tabs/basic_data.html @@ -267,6 +267,32 @@ function reload_cv_dependend_selections() { $.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; @@ -445,6 +471,19 @@ function row_set_keyboard_events(rows) { }); } +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.data('oldval', selects.val()); + + selects.change(unit_change); +} + var email_dialog; function show_email_dialog(html) { @@ -494,6 +533,8 @@ $(function(){ row_set_keyboard_events($('.row_entry')); $('.recalc').change(recalc_amounts_and_taxes); $('.reformat_number').change(reformat_number); + + set_unit_change_with_oldval($('.unitselect')); });