From ecb95993cd0a1635dc759e0733cac883be3fdc0c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Mon, 24 Jul 2017 17:14:06 +0200 Subject: [PATCH] DeliveryPlan: calc_qtys mit SL::Helper::ShippedQty berechnen --- SL/Controller/DeliveryPlan.pm | 59 ++++------------------------------- 1 file changed, 6 insertions(+), 53 deletions(-) diff --git a/SL/Controller/DeliveryPlan.pm b/SL/Controller/DeliveryPlan.pm index 16991cf3c..2332462ac 100644 --- a/SL/Controller/DeliveryPlan.pm +++ b/SL/Controller/DeliveryPlan.pm @@ -9,6 +9,7 @@ use SL::DB::Business; use SL::Controller::Helper::GetModels; use SL::Controller::Helper::ReportGenerator; use SL::Locale::String; +use SL::Helper::ShippedQty; use SL::AM; use SL::DBUtils (); use Carp; @@ -26,7 +27,6 @@ my %sort_columns = ( partnumber => t8('Part Number'), qty => t8('Qty'), shipped_qty => t8('shipped'), - delivered_qty => t8('transferred in / out'), not_shipped_qty => t8('not shipped'), ordnumber => t8('Order'), customer => t8('Customer'), @@ -54,7 +54,7 @@ sub prepare_report { my $report = SL::ReportGenerator->new(\%::myconfig, $::form); $self->{report} = $report; - my @columns = qw(reqdate customer vendor ordnumber partnumber description qty shipped_qty not_shipped_qty delivered_qty); + my @columns = qw(reqdate customer vendor ordnumber partnumber description qty shipped_qty not_shipped_qty); my @sortable = qw(reqdate customer vendor ordnumber partnumber description); @@ -67,7 +67,6 @@ sub prepare_report { qty => { sub => sub { $_[0]->qty_as_number . ' ' . $_[0]->unit } }, shipped_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]{shipped_qty}, 2) . ' ' . $_[0]->unit } }, not_shipped_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->qty - $_[0]{shipped_qty}, 2) . ' ' . $_[0]->unit } }, - delivered_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]{delivered_qty}, 2) .' ' . $_[0]->unit } }, ordnumber => { sub => sub { $_[0]->order->ordnumber }, obj_link => sub { $self->link_to($_[0]->order) } }, vendor => { sub => sub { $_[0]->order->vendor->name }, @@ -105,59 +104,13 @@ sub prepare_report { sub calc_qtys { my ($self, $orderitems) = @_; - # using $orderitem->shipped_qty 40 times is far too slow. need to do it manually - # return unless scalar @$orderitems; - my %orderitems_by_id = map { $_->id => $_ } @$orderitems; - - my $query = $self->use_linked_items ? _calc_qtys_query_linked_items(scalar @$orderitems) - : _calc_qtys_query_match_parts(scalar @$orderitems); - - my $result = SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, $query, map { $_->id } @$orderitems); - - for my $row (@$result) { - my $item = $orderitems_by_id{ $row->{id} }; - $item->{shipped_qty} ||= 0; - $item->{delivered_qty} ||= 0; - $item->{shipped_qty} += AM->convert_unit($row->{unit} => $item->unit) * $row->{qty}; - $item->{delivered_qty} += AM->convert_unit($row->{unit} => $item->unit) * $row->{qty} if $row->{delivered}; - } -} - -sub _calc_qtys_query_match_parts { - my ($num_items) = @_; - - my $query = <new(fill_up => !$self->use_linked_items) + ->calculate($orderitems) + ->write_to_objects; } sub make_filter_summary { -- 2.20.1