From 5737ce39a18326f1c3ae70a5afcc2d494fb901c7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Wed, 7 Dec 2016 15:25:42 +0100 Subject: [PATCH] Auftrags-Controller: Marge in zweiter Zeile --- SL/Controller/Order.pm | 29 +++++++++++++++---- js/kivi.Order.js | 15 ++++++++-- .../webpages/order/tabs/_second_row.html | 9 ++++++ 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 34f7b4726..8346821fd 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -387,7 +387,7 @@ sub action_unit_changed { $self->js ->run('kivi.Order.update_sellprice', $::form->{item_id}, $item->sellprice_as_number); - $self->_js_redisplay_linetotals; + $self->_js_redisplay_line_values; $self->_js_redisplay_amounts_and_taxes; $self->js->render(); } @@ -539,7 +539,7 @@ sub action_recalc_amounts_and_taxes { $self->_recalc(); - $self->_js_redisplay_linetotals; + $self->_js_redisplay_line_values; $self->_js_redisplay_amounts_and_taxes; $self->js->render(); } @@ -601,6 +601,8 @@ sub action_get_item_longdescription { sub action_load_second_rows { my ($self) = @_; + $self->_recalc() if $self->order->is_sales; # for margin calculation + foreach my $item_id (@{ $::form->{item_ids} }) { my $idx = first_index { $_ eq $item_id } @{ $::form->{orderitem_ids} }; my $item = $self->order->items_sorted->[$idx]; @@ -631,12 +633,29 @@ sub _js_load_second_row { ->data('.row_entry:has(#item_' . $item_id . ') [name = "second_row"]', 'loaded', 1); } -sub _js_redisplay_linetotals { +sub _js_redisplay_line_values { my ($self) = @_; - my @data = map {$::form->format_amount(\%::myconfig, $_->{linetotal}, 2, 0)} @{ $self->order->items_sorted }; + my $is_sales = $self->order->is_sales; + + # sales orders with margins + my @data; + if ($is_sales) { + @data = map { + [ + $::form->format_amount(\%::myconfig, $_->{linetotal}, 2, 0), + $::form->format_amount(\%::myconfig, $_->{marge_total}, 2, 0), + $::form->format_amount(\%::myconfig, $_->{marge_percent}, 2, 0), + ]} @{ $self->order->items_sorted }; + } else { + @data = map { + [ + $::form->format_amount(\%::myconfig, $_->{linetotal}, 2, 0), + ]} @{ $self->order->items_sorted }; + } + $self->js - ->run('kivi.Order.redisplay_linetotals', \@data); + ->run('kivi.Order.redisplay_line_values', $is_sales, \@data); } sub _js_redisplay_amounts_and_taxes { diff --git a/js/kivi.Order.js b/js/kivi.Order.js index 538e26e4a..c3673b474 100644 --- a/js/kivi.Order.js +++ b/js/kivi.Order.js @@ -296,9 +296,18 @@ namespace('kivi.Order', function(ns) { }; - ns.redisplay_linetotals = function(data) { - $('.row_entry [name="linetotal"]').each(function(idx, elt) { - $(elt).html(data[idx]); + ns.redisplay_line_values = function(is_sales, data) { + $('.row_entry').each(function(idx, elt) { + $(elt).find('[name="linetotal"]').html(data[idx][0]); + if (is_sales && $(elt).find('[name="second_row"]').data('loaded') == 1) { + var mt = data[idx][1]; + var mp = data[idx][2]; + var h = '[%- 'Subtotal' | $T8 %] [% L.yes_no_tag("order.orderitems[].subtotal", ITEM.subtotal) %] [%- IF ITEM.order.is_sales %] + [%- 'Ertrag' | $T8 %] + +
+ + [%- LxERP.format_amount(ITEM.marge_total, 2, 0) %]   + [%- LxERP.format_amount(ITEM.marge_percent, 2, 0) %]% + +
+ [%- 'LP' | $T8 %] [%- LxERP.format_amount(ITEM.part.listprice, 2, 0) %] [%- END %] -- 2.20.1