$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();
}
$self->_recalc();
- $self->_js_redisplay_linetotals;
+ $self->_js_redisplay_line_values;
$self->_js_redisplay_amounts_and_taxes;
$self->js->render();
}
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];
->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 {
};
- 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 = '<span';
+ if (mt[0] === '-') h += ' class="plus0"';
+ h += '>' + mt + ' ' + mp + '%';
+ h += '</span>';
+ $(elt).find('[name="linemargin"]').html(h);
+ }
});
};
<th>[%- 'Subtotal' | $T8 %]</th>
<td>[% L.yes_no_tag("order.orderitems[].subtotal", ITEM.subtotal) %]</td>
[%- IF ITEM.order.is_sales %]
+ <th>[%- 'Ertrag' | $T8 %]</th>
+ <td>
+ <div name="linemargin">
+ <span[%- IF ITEM.marge_total < 0 -%] class="plus0"[%- END -%]>
+ [%- LxERP.format_amount(ITEM.marge_total, 2, 0) %]
+ [%- LxERP.format_amount(ITEM.marge_percent, 2, 0) %]%
+ </span>
+ </div>
+ </td>
<th>[%- 'LP' | $T8 %]</th>
<td>[%- LxERP.format_amount(ITEM.part.listprice, 2, 0) %]</td>
[%- END %]