X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/03ba13d2594f31e7af5eb3868435495c750ef1cb..4858eee496c36d20673f0e2bcb680abc887fb8ba:/SL/Controller/Order.pm?ds=inline diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 76bc3f746..e4644983d 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -30,7 +30,7 @@ use SL::Helper::UserPreferences::UpdatePositions; use SL::Controller::Helper::GetModels; -use List::Util qw(first); +use List::Util qw(first sum0); use List::UtilsBy qw(sort_by uniq_by); use List::MoreUtils qw(any none pairwise first_index); use English qw(-no_match_vars); @@ -775,8 +775,13 @@ sub action_add_item { SELF => $self, ); - $self->js - ->append('#row_table_id', $row_as_html); + if ($::form->{insert_before_item_id}) { + $self->js + ->before ('.row_entry:has(#item_' . $::form->{insert_before_item_id} . ')', $row_as_html); + } else { + $self->js + ->append('#row_table_id', $row_as_html); + } if ( $item->part->is_assortment ) { $form_attr->{qty_as_number} = 1 unless $form_attr->{qty_as_number}; @@ -800,18 +805,24 @@ sub action_add_item { ID => $item_id, SELF => $self, ); - $self->js - ->append('#row_table_id', $row_as_html); + if ($::form->{insert_before_item_id}) { + $self->js + ->before ('.row_entry:has(#item_' . $::form->{insert_before_item_id} . ')', $row_as_html); + } else { + $self->js + ->append('#row_table_id', $row_as_html); + } }; }; $self->js ->val('.add_item_input', '') ->run('kivi.Order.init_row_handlers') - ->run('kivi.Order.row_table_scroll_down') ->run('kivi.Order.renumber_positions') ->focus('#add_item_parts_id_name'); + $self->js->run('kivi.Order.row_table_scroll_down') if !$::form->{insert_before_item_id}; + $self->js_redisplay_amounts_and_taxes; $self->js->render(); } @@ -882,16 +893,23 @@ sub action_add_multi_items { SELF => $self, ); - $self->js->append('#row_table_id', $row_as_html); + if ($::form->{insert_before_item_id}) { + $self->js + ->before ('.row_entry:has(#item_' . $::form->{insert_before_item_id} . ')', $row_as_html); + } else { + $self->js + ->append('#row_table_id', $row_as_html); + } } $self->js ->run('kivi.Order.close_multi_items_dialog') ->run('kivi.Order.init_row_handlers') - ->run('kivi.Order.row_table_scroll_down') ->run('kivi.Order.renumber_positions') ->focus('#add_item_parts_id_name'); + $self->js->run('kivi.Order.row_table_scroll_down') if !$::form->{insert_before_item_id}; + $self->js_redisplay_amounts_and_taxes; $self->js->render(); } @@ -1494,16 +1512,15 @@ sub recalc { $self->order->currency_id($::instance_conf->get_currency_id()); my %pat = $self->order->calculate_prices_and_taxes(); + $self->{taxes} = []; - foreach my $tax_chart_id (keys %{ $pat{taxes} }) { - my $tax = SL::DB::Manager::Tax->find_by(chart_id => $tax_chart_id); + foreach my $tax_id (keys %{ $pat{taxes_by_tax_id} }) { + my $netamount = sum0 map { $pat{amounts}->{$_}->{amount} } grep { $pat{amounts}->{$_}->{tax_id} == $tax_id } keys %{ $pat{amounts} }; - my @amount_keys = grep { $pat{amounts}->{$_}->{tax_id} == $tax->id } keys %{ $pat{amounts} }; - push(@{ $self->{taxes} }, { amount => $pat{taxes}->{$tax_chart_id}, - netamount => $pat{amounts}->{$amount_keys[0]}->{amount}, - tax => $tax }); + push(@{ $self->{taxes} }, { amount => $pat{taxes_by_tax_id}->{$tax_id}, + netamount => $netamount, + tax => SL::DB::Tax->new(id => $tax_id)->load }); } - pairwise { $a->{linetotal} = $b->{linetotal} } @{$self->order->items_sorted}, @{$pat{items}}; }