X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAR.pm;h=b4b686748ff572a957631ac3b5953b236dd79028;hb=e1f93c184a9f6fe0826306383f23c454011dc9b3;hp=8e8cf2f2cbf1b3b5b32051bc89a09bab04333352;hpb=a1f105327081e1bf4b139f531a158136d55b1f8c;p=kivitendo-erp.git diff --git a/SL/AR.pm b/SL/AR.pm index 8e8cf2f2c..b4b686748 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -42,12 +42,21 @@ use SL::MoreCommon; use SL::DB::Default; use SL::TransNumber; use SL::Util qw(trim); +use SL::DB; use strict; sub post_transaction { + my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_; $main::lxdebug->enter_sub(); + my $rc = SL::DB->client->with_transaction(\&_post_transaction, $self, $myconfig, $form, $provided_dbh, $payments_only); + + $::lxdebug->leave_sub; + return $rc; +} + +sub _post_transaction { my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_; my ($query, $sth, $null, $taxrate, $amount, $tax); @@ -56,7 +65,7 @@ sub post_transaction { my @values; - my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig); + my $dbh = $provided_dbh || SL::DB->client->dbh; $form->{defaultcurrency} = $form->get_default_currency($myconfig); # set exchangerate @@ -323,18 +332,11 @@ sub post_transaction { $datev->export; if ($datev->errors) { - $dbh->rollback; die join "\n", $::locale->text('DATEV check returned errors:'), $datev->errors; } } - my $rc = 1; - if (!$provided_dbh) { - $rc = $dbh->commit(); - $dbh->disconnect(); - } - - $main::lxdebug->leave_sub() and return $rc; + return 1; } sub _delete_payments { @@ -377,12 +379,19 @@ sub _delete_payments { } sub post_payment { + my ($self, $myconfig, $form, $locale) = @_; $main::lxdebug->enter_sub(); + my $rc = SL::DB->client->with_transaction(\&_post_payment, $self, $myconfig, $form, $locale); + + $::lxdebug->leave_sub; + return $rc; +} + +sub _post_payment { my ($self, $myconfig, $form, $locale) = @_; - # connect to database, turn off autocommit - my $dbh = $form->dbconnect_noauto($myconfig); + my $dbh = SL::DB->client->dbh; my (%payments, $old_form, $row, $item, $query, %keep_vars); @@ -431,12 +440,7 @@ sub post_payment { restore_form($old_form); - my $rc = $dbh->commit(); - $dbh->disconnect(); - - $main::lxdebug->leave_sub(); - - return $rc; + return 1; } sub delete_transaction { @@ -444,20 +448,16 @@ sub delete_transaction { my ($self, $myconfig, $form) = @_; - # connect to database, turn AutoCommit off - my $dbh = $form->dbconnect_noauto($myconfig); - - # acc_trans entries are deleted by database triggers. - my $query = qq|DELETE FROM ar WHERE id = ?|; - do_query($form, $dbh, $query, $form->{id}); - - # commit - my $rc = $dbh->commit; - $dbh->disconnect; + SL::DB->client->with_transaction(sub { + # acc_trans entries are deleted by database triggers. + my $query = qq|DELETE FROM ar WHERE id = ?|; + do_query($form, SL::DB->client->dbh, $query, $form->{id}); + 1; + }) or do { die SL::DB->client->error }; $main::lxdebug->leave_sub(); - return $rc; + return 1; } sub ar_transactions { @@ -657,7 +657,7 @@ sub get_transdate { my ($self, $myconfig, $form) = @_; # connect to database - my $dbh = $form->dbconnect($myconfig); + my $dbh = SL::DB->client->dbh; my $query = "SELECT COALESCE(" . @@ -666,8 +666,6 @@ sub get_transdate { " current_date)"; ($form->{transdate}) = $dbh->selectrow_array($query); - $dbh->disconnect; - $main::lxdebug->leave_sub(); } @@ -683,7 +681,7 @@ sub setup_form { $form->{forex} = $form->{exchangerate}; $exchangerate = $form->{exchangerate} ? $form->{exchangerate} : 1; - # expected keys: AR, AR_paid, AR_tax, AR_amount + # expected keys: AR, AR_paid, AR_tax, AR_amount foreach my $key (keys %{ $form->{AR_links} }) { $j = 0; $k = 0; @@ -788,12 +786,21 @@ sub setup_form { } sub storno { + my ($self, $form, $myconfig, $id) = @_; $main::lxdebug->enter_sub(); + my $rc = SL::DB->client->with_transaction(\&_storno, $self, $form, $myconfig, $id); + + $::lxdebug->leave_sub; + return $rc; +} + + +sub _storno { my ($self, $form, $myconfig, $id) = @_; my ($query, $new_id, $storno_row, $acc_trans_rows); - my $dbh = $form->get_standard_dbh($myconfig); + my $dbh = SL::DB->client->dbh; $query = qq|SELECT nextval('glid')|; ($new_id) = selectrow_query($form, $dbh, $query); @@ -838,9 +845,7 @@ sub storno { map { IO->set_datepaid(table => 'ar', id => $_, dbh => $dbh) } ($id, $new_id); - $dbh->commit; - - $main::lxdebug->leave_sub(); + return 1; }