From: Sven Schöling Date: Fri, 16 Jan 2015 14:01:31 +0000 (+0100) Subject: DeliveryPlan: qtys manuell aus der Datenbank holen X-Git-Tag: release-3.2.0beta~72 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=db06bb909aa58d7c6482c7ea1acf7fa3bcf7e858;p=kivitendo-erp.git DeliveryPlan: qtys manuell aus der Datenbank holen Objektmethoden sind bei grossen Datenbanken zu langsam --- diff --git a/SL/Controller/DeliveryPlan.pm b/SL/Controller/DeliveryPlan.pm index 411a9940e..d05b46a12 100644 --- a/SL/Controller/DeliveryPlan.pm +++ b/SL/Controller/DeliveryPlan.pm @@ -9,6 +9,8 @@ use SL::DB::Business; use SL::Controller::Helper::GetModels; use SL::Controller::Helper::ReportGenerator; use SL::Locale::String; +use SL::AM; +use SL::DBUtils (); use Carp; use Rose::Object::MakeMethods::Generic ( @@ -41,6 +43,7 @@ sub action_list { my $orderitems = $self->models->get; + $self->calc_qtys($orderitems); $self->report_generator_list_objects(report => $self->{report}, objects => $orderitems); } @@ -70,11 +73,11 @@ sub prepare_report { ($rp_csv_mod ? '' : ' ' . $_[0]->unit) } }, unit => { sub => sub { $_[0]->unit }, visible => $rp_csv_mod }, - shipped_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->shipped_qty, 2) . + shipped_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]{shipped_qty}, 2) . ($rp_csv_mod ? '' : ' ' . $_[0]->unit) } }, - not_shipped_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->qty - $_[0]->shipped_qty, 2) . + not_shipped_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->qty - $_[0]{shipped_qty}, 2) . ($rp_csv_mod ? '' : ' ' . $_[0]->unit) } }, - delivered_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->delivered_qty, 2) . + delivered_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]{delivered_qty}, 2) . ($rp_csv_mod ? '' : ' ' . $_[0]->unit) } }, ordnumber => { sub => sub { $_[0]->order->ordnumber }, obj_link => sub { $self->link_to($_[0]->order) } }, @@ -115,6 +118,35 @@ sub prepare_report { ); } +sub calc_qtys { + my ($self, $orderitems) = @_; + # using $orderitem->shipped_qty 40 times is far too slow. need to do it manually + # + my %orderitems_by_id = map { $_->id => $_ } @$orderitems; + + my $query = <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 make_filter_summary { my ($self) = @_; my $vc = $self->vc;