X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FBP.pm;h=9cf0750e8322f31ae1357bb7c6b014b9184cfe74;hb=12f8fb507f7531f2e434214eb9a8c4d7a55c75d5;hp=c8b4a3ddd696449ddff4497490d908eecbceea43;hpb=9ae7f1f9554c44bb7146be17c31acf224c249c7e;p=kivitendo-erp.git diff --git a/SL/BP.pm b/SL/BP.pm index c8b4a3ddd..9cf0750e8 100644 --- a/SL/BP.pm +++ b/SL/BP.pm @@ -35,6 +35,7 @@ package BP; use SL::DBUtils; +use SL::DB; use strict; @@ -83,8 +84,6 @@ sub get_vc { $sth->finish; } - $dbh->disconnect; - $main::lxdebug->leave_sub(); } @@ -94,7 +93,7 @@ sub payment_accounts { my ($self, $myconfig, $form) = @_; # connect to database - my $dbh = $form->dbconnect($myconfig); + my $dbh = SL::DB->client->dbh; my $query = qq|SELECT DISTINCT ON (s.chart_id) c.accno, c.description | . @@ -109,7 +108,6 @@ sub payment_accounts { } $sth->finish; - $dbh->disconnect; $main::lxdebug->leave_sub(); } @@ -119,8 +117,7 @@ sub get_spoolfiles { my ($self, $myconfig, $form) = @_; - # connect to database - my $dbh = $form->dbconnect($myconfig); + my $dbh = SL::DB->client->dbh; my ($query, $arap, @values); my $invnumber = "invnumber"; @@ -187,16 +184,16 @@ sub get_spoolfiles { push(@values, conv_i($form->{"${vc}_id"})); } elsif ($form->{ $vc }) { $query .= " AND vc.name ILIKE ?"; - push(@values, $form->like($form->{ $vc })); + push(@values, like($form->{ $vc })); } foreach my $column (qw(invnumber ordnumber quonumber donumber)) { if ($form->{$column}) { $query .= " AND a.$column ILIKE ?"; - push(@values, $form->like($form->{$column})); + push(@values, like($form->{$column})); } } - if ($form->{type} =~ /(invoice|sales_order|sales_quotation|puchase_order|request_quotation|packing_list)$/) { + if ($form->{type} =~ /(invoice|sales_order|sales_quotation|purchase_order|request_quotation|packing_list)$/) { if ($form->{transdatefrom}) { $query .= " AND a.transdate >= ?"; push(@values, $form->{transdatefrom}); @@ -227,7 +224,6 @@ sub get_spoolfiles { } $sth->finish; - $dbh->disconnect; $main::lxdebug->leave_sub(); } @@ -239,42 +235,37 @@ sub delete_spool { my $spool = $::lx_office_conf{paths}->{spool}; - # connect to database, turn AutoCommit off - my $dbh = $form->dbconnect_noauto($myconfig); + SL::DB->client->with_transaction(sub { + my $dbh = SL::DB->client->dbh; - my $query; + my $query; - if ($form->{type} =~ /(check|receipt)/) { - $query = qq|DELETE FROM status WHERE spoolfile = ?|; - } else { - $query = - qq|UPDATE status SET spoolfile = NULL, printed = '1' | . - qq|WHERE spoolfile = ?|; - } - my $sth = $dbh->prepare($query) || $form->dberror($query); - - foreach my $i (1 .. $form->{rowcount}) { - if ($form->{"checked_$i"}) { - $sth->execute($form->{"spoolfile_$i"}) || $form->dberror($query); - $sth->finish; + if ($form->{type} =~ /(check|receipt)/) { + $query = qq|DELETE FROM status WHERE spoolfile = ?|; + } else { + $query = + qq|UPDATE status SET spoolfile = NULL, printed = '1' | . + qq|WHERE spoolfile = ?|; } - } + my $sth = $dbh->prepare($query) || $form->dberror($query); - # commit - my $rc = $dbh->commit; - $dbh->disconnect; + foreach my $i (1 .. $form->{rowcount}) { + if ($form->{"checked_$i"}) { + $sth->execute($form->{"spoolfile_$i"}) || $form->dberror($query); + $sth->finish; + } + } - if ($rc) { foreach my $i (1 .. $form->{rowcount}) { if ($form->{"checked_$i"}) { unlink(qq|$spool/$form->{"spoolfile_$i"}|); } } - } + 1; + }) or do { die SL::DB->client->error }; $main::lxdebug->leave_sub(); - - return $rc; + return 1; } sub print_spool { @@ -285,7 +276,7 @@ sub print_spool { my $spool = $::lx_office_conf{paths}->{spool}; # connect to database - my $dbh = $form->dbconnect($myconfig); + my $dbh = SL::DB->client->dbh; my $query = qq|UPDATE status SET printed = '1' | . @@ -316,8 +307,6 @@ sub print_spool { } } - $dbh->disconnect; - $main::lxdebug->leave_sub(); }