X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/kivitendo-erp.git/blobdiff_plain/05a0faf917f346a0ff4883ba8597d94753ef1f46..7cd6d451d97d1f1e7f3c0f9db2de03735dc8c8f0:/SL/ARAP.pm diff --git a/SL/ARAP.pm b/SL/ARAP.pm index 977eefb4a..1d044eaad 100644 --- a/SL/ARAP.pm +++ b/SL/ARAP.pm @@ -4,6 +4,7 @@ use SL::AM; use SL::Common; use SL::DBUtils; use SL::MoreCommon; +use SL::DB; use Data::Dumper; use strict; @@ -19,7 +20,7 @@ sub close_orders_if_billed { my $myconfig = \%main::myconfig; my $form = $main::form; - my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); + my $dbh = $params{dbh} || SL::DB->client->dbh; # First, find all order IDs from which this invoice has been # created. Either directly by a conversion from an order to this invoice @@ -75,6 +76,10 @@ sub close_orders_if_billed { # said order. Again consider both direct conversions and indirect # conversions via delivery orders. foreach my $oe_id (@oe_ids) { + + # Dont close orders with periodic invoice + next if SL::DB::Manager::PeriodicInvoicesConfig->find_by(oe_id => $oe_id); + # Direct conversions "order -> invoice": @links = RecordLinks->get_links('dbh' => $dbh, 'from_table' => 'oe', @@ -150,10 +155,11 @@ sub close_orders_if_billed { # Close orders that have been billed fully. if (scalar @close_oe_ids) { - my $query = qq|UPDATE oe SET closed = TRUE WHERE id IN (| . join(', ', ('?') x scalar @close_oe_ids) . qq|)|; - do_query($form, $dbh, $query, @close_oe_ids); - - $dbh->commit unless $params{dbh}; + SL::DB->client->with_transaction(sub { + my $query = qq|UPDATE oe SET closed = TRUE WHERE id IN (| . join(', ', ('?') x scalar @close_oe_ids) . qq|)|; + do_query($form, $dbh, $query, @close_oe_ids); + 1; + }) or do { die SL::DB->client->error }; } $main::lxdebug->leave_sub();