From: Sven Schöling Date: Mon, 24 Jul 2017 16:40:56 +0000 (+0200) Subject: DO: mark_orders_if_delivered mit SL::Helper::ShippedQty berechnen X-Git-Tag: release-3.5.4~964 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=78c1cb3235240552968d2501bf18e8b7db7f5171;p=kivitendo-erp.git DO: mark_orders_if_delivered mit SL::Helper::ShippedQty berechnen --- diff --git a/SL/DO.pm b/SL/DO.pm index b51fc0f1b..e97b0fd3f 100644 --- a/SL/DO.pm +++ b/SL/DO.pm @@ -44,6 +44,7 @@ use SL::CVar; use SL::DB::DeliveryOrder; use SL::DB::Status; use SL::DBUtils; +use SL::Helper::ShippedQty; use SL::HTML::Restrict; use SL::RecordLinks; use SL::IC; @@ -561,28 +562,24 @@ SQL } sub mark_orders_if_delivered { - $main::lxdebug->enter_sub(); - - my $self = shift; - my %params = @_; + my ($self, %params) = @_; Common::check_params(\%params, qw(do_id type)); - my $myconfig = \%main::myconfig; - my $form = $main::form; + my $do = SL::DB::Manager::DeliveryOrder->find_by(id => $params{do_id}); + my $orders = $do->linked_records(from => 'Order'); - SL::DB->client->with_transaction(sub { - my $dbh = $params{dbh} || SL::DB->client->dbh; + SL::Helper::ShippedQty->new->calculate($orders)->write_to_objects; - my %ship = $self->get_shipped_qty('dbh' => $dbh, 'do_id' => $form->{id}, 'delivered' => 1); + SL::DB->client->with_transaction(sub { + for my $oe (@$orders) { + next if $params{type} eq 'sales' && !$oe->customer_id; + next if $params{type} eq 'purchase' && !$oe->vendor_id; - foreach my $oe_id (keys %ship) { - do_query($form, $dbh,"UPDATE oe SET delivered = ".($ship{$oe_id}->{delivered}?"TRUE":"FALSE")." WHERE id = ?", $oe_id); + $oe->update_attributes(delivered => $oe->{delivered}); } 1; }) or do { die SL::DB->client->error }; - - $main::lxdebug->leave_sub(); } sub close_orders {