X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FARAP.pm;h=1d044eaade50ffc191e660df824a39cab7bf185a;hb=d56bda4518586c3b0220c18445394f35ec121d84;hp=977eefb4a0bbdbcf7353f64abb48aca406686122;hpb=05a0faf917f346a0ff4883ba8597d94753ef1f46;p=kivitendo-erp.git 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();